UNPKG

houdini-adapter-auto

Version:

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

3 lines (2 loc) 1.46 kB
import{detectTools as i}from"houdini";import{resolve as s}from"import-meta-resolve";import{execSync as d}from"node:child_process";import{pathToFileURL as c}from"node:url";var l=[{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"}],p=async e=>{let t;for(let r of l)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 u(t))(e)};async function u({module:e}){try{return await o(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 i(),a={yarn:"add -D",npm:"install -D",pnpm:"add -D"};try{return d(`${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 o(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 o(e){let t=c(process.cwd()).href;return(await import(s(e,t+"/x.js"))).default}var g=p;export{g as default};