UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

2 lines 1.11 kB
import e from"../errors/lucid-error.mjs";import{findPackageJSON as t}from"node:module";import n from"node:fs/promises";import r from"node:path";import{fileURLToPath as i,pathToFileURL as a}from"node:url";const o=async e=>{try{return await n.access(e),!0}catch{return!1}},s=async(e,n)=>{let i=e.split(`/`),s=e.startsWith(`@`)?2:1;if(i.length<=s)return;let c;try{c=t(e,a(r.join(n,`package.json`)))}catch{return}if(!c)return;let l=r.join(r.dirname(c),...i.slice(s));return await o(l)?l:void 0},c=async(t,n)=>{if(t instanceof URL)return i(t);if(r.isAbsolute(t))return t;let a=n?.projectRoot??process.cwd(),c=r.join(a,t);if(await o(c)||t.startsWith(`.`)||!t.startsWith(`@`)&&!t.includes(`/`))return c;try{let e=await s(t,a);if(e)return e;let n=import.meta.resolve(t),r=new URL(n);if(r.protocol!==`file:`)throw Error(`Expected a file URL but received "${n}".`);return i(r)}catch(r){throw new e({message:`${n?.label??`Source`} package specifier "${t}" could not be resolved.`,data:{error:r instanceof Error?r.message:r}})}};export{o as pathExists,c as resolveSourcePath}; //# sourceMappingURL=resolve-source-path.mjs.map