UNPKG

@anolilab/package-json-utils

Version:

Shared utilities for parsing information from a package.json.

32 lines (22 loc) 2.73 kB
import { realpathSync, existsSync } from 'fs'; import g from 'module'; import { dirname, join } from 'path'; import { cwd, env, versions, exit } from 'process'; import { getByPath } from 'dot-path-value'; import $ from 'read-pkg-up'; var l=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(n,t)=>(typeof require<"u"?require:n)[t]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var {packageJson:o,path:u}=$.sync({cwd:realpathSync(cwd())})??{packageJson:void 0,path:void 0},p=e=>e.split("@").includes("@")?e:`${e}@latest`,w=e=>{if(o!==void 0)return getByPath(o,e)},U=e=>n=>w(`${e}.${n}`),c=e=>!!(o!==void 0&&getByPath(o,e)),d=e=>n=>c(`${e}.${n}`),x=(e,n)=>n?e.every(t=>c(t)):e.some(t=>c(t)),a=e=>(n,t)=>x(n.map(r=>`${e}.${r}`),t),T=e=>!!(env[e]&&env[e]!=="undefined"),_=(e,n)=>{if(T(e))try{return JSON.parse(env[e]??"")}catch{return env[e]}return n},m=u?dirname(u):"",C=m,S=(...e)=>join(m,...e),M=(...e)=>existsSync(S(...e)),G=a("scripts"),H=d("peerDependencies"),j=a("peerDependencies"),R=d("dependencies"),J=a("dependencies"),V=d("devDependencies"),q=a("devDependencies"),K=(e,n)=>[J,q,n?.peerDeps===!1?()=>!1:j].some(t=>t(e,n?.strict)),Q=(R("typescript")||V("typescript"))&&M("tsconfig.json"),A=x(["type"])&&o?.type==="module",B=e=>{if(versions.pnp){let n=import.meta.url,r=g.findPnpApi(n).resolveRequest(e,n);if(r)return r}else if(A){let n=import.meta.url;try{return g.createRequire(n).resolve(e)}catch{return}}try{return l.resolve(e)}catch{return}},W=e=>B(e)!==void 0,X=(e,n,t={})=>{let r=n.length===1?"":"s";console[t.consoleType??"warn"](` ${t.preMessage??""} ${e} could not find the following package${r} ${n.join(` `)} To install the missing package${r}, please run the following command: npm install ${n.map(s=>p(s)).join(" ")} --save-dev or yarn add ${n.map(s=>p(s)).join(" ")} --dev or pnpm add ${n.map(s=>p(s)).join(" ")} -D ${t.postMessage??""} `),(env.NODE_ENV!=="test"||t.exit===!0)&&exit(1);},Y=e=>[...new Set(e)],Z=o; export { C as appDirectory, T as environmentIsSet, S as fromRoot, w as getPackageProperty, U as getPackageSubProperty, K as hasAnyDep, J as hasDependencies, R as hasDependency, q as hasDevDependencies, V as hasDevDependency, M as hasFile, x as hasPackageProperties, c as hasPackageProperty, a as hasPackageSubProperties, d as hasPackageSubProperty, j as hasPeerDependencies, H as hasPeerDependency, G as hasScripts, Q as hasTypescript, W as isPackageAvailable, A as packageIsTypeModule, _ as parseEnvironment, Z as pkg, m as projectPath, B as resolvePackage, X as showMissingPackages, Y as unique }; //# sourceMappingURL=out.js.map //# sourceMappingURL=index.mjs.map