UNPKG

houdini-adapter-auto

Version:

An adapter for deploying your Houdini application according to the build environment

3 lines (2 loc) 1.89 kB
"use strict";var o=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var f=(e,t)=>{for(var a in t)o(e,a,{get:t[a],enumerable:!0})},y=(e,t,a,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of u(t))!m.call(e,n)&&n!==a&&o(e,n,{get:()=>t[n],enumerable:!(r=p(t,n))||r.enumerable});return e};var h=e=>y(o({},"__esModule",{value:!0}),e);var A={};f(A,{default:()=>$});module.exports=h(A);var s=require("houdini"),d=require("import-meta-resolve"),c=require("child_process"),l=require("url"),g=[{name:"CloudFlare Pages",test:()=>!!process.env.CF_PAGES,module:"houdini-adapter-cloudflare"},{name:"HoudiniCloud",test:()=>!!process.env.HOUDINI_CLOUD,module:"houdini-cloud-adapter"},{name:"Node",test:()=>!0,module:"houdini-adapter-node"}],w=async e=>{let t;for(let r of g)if(r.test()){t=r;break}if(!t)throw new Error("Could not identify environment");return console.log(`\u{1F3A9} Identified environment: ${t.name}`),(await v(t))(e)};async function v({module:e}){try{return await i(e)}catch(r){let n=r;if(n.code!=="ERR_MODULE_NOT_FOUND"||!n.message.startsWith(`Cannot find package '${e}'`))throw r}let{package_manager:t}=await(0,s.detectTools)(),a={yarn:"add -D",npm:"install -D",pnpm:"add -D"};try{return(0,c.execSync)(`${t} ${a[t]} ${e}`,{stdio:"inherit",env:{...process.env,NODE_ENV:void 0}}),console.log(`Successfully installed ${e}!`),console.warn(`If you plan on staying in this environment, consider adding ${e} to your project so you don't have to install it every time you build your application.`),await i(e)}catch(r){throw new Error(`Could not install package ${e}. Please install it manually or maybe consider replacing houdini-adapter-auto with ${e}. ${r.message}`)}}async function i(e){let t=(0,l.pathToFileURL)(process.cwd()).href;return(await import((0,d.resolve)(e,t+"/x.js"))).default}var $=w;