nf3 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/dist/_chunks/libs/exsolve.mjs +1 -1
- package/dist/_chunks/trace.mjs +38 -28
- package/dist/index.d.mts +9 -1
- package/dist/index.mjs +42 -1
- package/dist/node_modules/@vercel/nft/out/utils/binary-locators.js +1 -1
- package/dist/plugin.mjs +1 -1
- package/package.json +11 -11
- package/dist/_chunks/libs/confbox.mjs +0 -7
- package/dist/_chunks/libs/pkg-types.mjs +0 -1
package/README.md
CHANGED
|
@@ -90,6 +90,16 @@ rollupNodeFileTrace({
|
|
|
90
90
|
});
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
+
## Native packages DB
|
|
94
|
+
|
|
95
|
+
nf3 exports a list of known packages that include native code and require platform-specific builds.
|
|
96
|
+
|
|
97
|
+
These packages cannot be bundled and should be traced as external dependencies most of the time and often need tracing.
|
|
98
|
+
|
|
99
|
+
```js
|
|
100
|
+
import { nodeNativePackages } from "nf3";
|
|
101
|
+
```
|
|
102
|
+
|
|
93
103
|
## Development
|
|
94
104
|
|
|
95
105
|
<details>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import fs,{lstatSync,realpathSync,statSync}from"node:fs";import{URL as URL$1,fileURLToPath,pathToFileURL}from"node:url";import path,{isAbsolute}from"node:path";import assert from"node:assert";import process$1 from"node:process";import v8 from"node:v8";import{format,inspect}from"node:util";const nodeBuiltins=`_http_agent._http_client._http_common._http_incoming._http_outgoing._http_server._stream_duplex._stream_passthrough._stream_readable._stream_transform._stream_wrap._stream_writable._tls_common._tls_wrap.assert.assert/strict.async_hooks.buffer.child_process.cluster.console.constants.crypto.dgram.diagnostics_channel.dns.dns/promises.domain.events.fs.fs/promises.http.http2.https.inspector.inspector/promises.module.net.os.path.path/posix.path/win32.perf_hooks.process.punycode.querystring.readline.readline/promises.repl.stream.stream/consumers.stream/promises.stream/web.string_decoder.sys.timers.timers/promises.tls.trace_events.tty.url.util.util/types.v8.vm.wasi.worker_threads.zlib`.split(`.`),own$1={}.hasOwnProperty,classRegExp=/^([A-Z][a-z\d]*)+$/,kTypes=new Set([`string`,`function`,`number`,`object`,`Function`,`Object`,`boolean`,`bigint`,`symbol`]),messages=new Map;let userStackTraceLimit;function formatList(l,R=`and`){return l.length<3?l.join(` ${R} `):`${l.slice(0,-1).join(`, `)}, ${R} ${l.at(-1)}`}function createError(l,R,z){return messages.set(l,R),makeNodeErrorWithCode(z,l)}function makeNodeErrorWithCode(l,R){return function(...z){let B=Error.stackTraceLimit;isErrorStackTraceLimitWritable()&&(Error.stackTraceLimit=0);let V=new l;isErrorStackTraceLimitWritable()&&(Error.stackTraceLimit=B);let H=getMessage(R,z,V);return Object.defineProperties(V,{message:{value:H,enumerable:!1,writable:!0,configurable:!0},toString:{value(){return`${this.name} [${R}]: ${this.message}`},enumerable:!1,writable:!0,configurable:!0}}),captureLargerStackTrace(V),V.code=R,V}}function isErrorStackTraceLimitWritable(){try{if(v8.startupSnapshot.isBuildingSnapshot())return!1}catch{}let l=Object.getOwnPropertyDescriptor(Error,`stackTraceLimit`);return l===void 0?Object.isExtensible(Error):own$1.call(l,`writable`)&&l.writable!==void 0?l.writable:l.set!==void 0}function hideStackFrames(l){let R=`__node_internal_`+l.name;return Object.defineProperty(l,`name`,{value:R}),l}const captureLargerStackTrace=hideStackFrames(function(l){let R=isErrorStackTraceLimitWritable();return R&&(userStackTraceLimit=Error.stackTraceLimit,Error.stackTraceLimit=1/0),Error.captureStackTrace(l),R&&(Error.stackTraceLimit=userStackTraceLimit),l});function getMessage(l,R,z){let B=messages.get(l);if(assert.ok(B!==void 0,"expected `message` to be found"),typeof B==`function`)return assert.ok(B.length<=R.length,`Code: ${l}; The provided arguments length (${R.length}) does not match the required ones (${B.length}).`),Reflect.apply(B,z,R);let V=/%[dfijoOs]/g,H=0;for(;V.exec(B)!==null;)H++;return assert.ok(H===R.length,`Code: ${l}; The provided arguments length (${R.length}) does not match the required ones (${H}).`),R.length===0?B:(R.unshift(B),Reflect.apply(format,null,R))}function determineSpecificType(l){if(l==null)return String(l);if(typeof l==`function`&&l.name)return`function ${l.name}`;if(typeof l==`object`)return l.constructor&&l.constructor.name?`an instance of ${l.constructor.name}`:`${inspect(l,{depth:-1})}`;let R=inspect(l,{colors:!1});return R.length>28&&(R=`${R.slice(0,25)}...`),`type ${typeof l} (${R})`}createError(`ERR_INVALID_ARG_TYPE`,(l,R,z)=>{assert.ok(typeof l==`string`,`'name' must be a string`),Array.isArray(R)||(R=[R]);let B=`The `;if(l.endsWith(` argument`))B+=`${l} `;else{let R=l.includes(`.`)?`property`:`argument`;B+=`"${l}" ${R} `}B+=`must be `;let V=[],H=[],U=[];for(let l of R)assert.ok(typeof l==`string`,`All expected entries have to be of type string`),kTypes.has(l)?V.push(l.toLowerCase()):classRegExp.exec(l)===null?(assert.ok(l!==`object`,`The value "object" should be written as "Object"`),U.push(l)):H.push(l);if(H.length>0){let l=V.indexOf(`object`);l!==-1&&(V.slice(l,1),H.push(`Object`))}return V.length>0&&(B+=`${V.length>1?`one of type`:`of type`} ${formatList(V,`or`)}`,(H.length>0||U.length>0)&&(B+=` or `)),H.length>0&&(B+=`an instance of ${formatList(H,`or`)}`,U.length>0&&(B+=` or `)),U.length>0&&(U.length>1?B+=`one of ${formatList(U,`or`)}`:(U[0]?.toLowerCase()!==U[0]&&(B+=`an `),B+=`${U[0]}`)),B+=`. Received ${determineSpecificType(z)}`,B},TypeError);const ERR_INVALID_MODULE_SPECIFIER=createError(`ERR_INVALID_MODULE_SPECIFIER`,(l,R,z)=>`Invalid module "${l}" ${R}${z?` imported from ${z}`:``}`,TypeError),ERR_INVALID_PACKAGE_CONFIG=createError(`ERR_INVALID_PACKAGE_CONFIG`,(l,R,z)=>`Invalid package config ${l}${R?` while importing ${R}`:``}${z?`. ${z}`:``}`,Error),ERR_INVALID_PACKAGE_TARGET=createError(`ERR_INVALID_PACKAGE_TARGET`,(l,R,z,B=!1,V)=>{let H=typeof z==`string`&&!B&&z.length>0&&!z.startsWith(`./`);return R===`.`?(assert.ok(B===!1),`Invalid "exports" main target ${JSON.stringify(z)} defined in the package config ${l}package.json${V?` imported from ${V}`:``}${H?`; targets must start with "./"`:``}`):`Invalid "${B?`imports`:`exports`}" target ${JSON.stringify(z)} defined for '${R}' in the package config ${l}package.json${V?` imported from ${V}`:``}${H?`; targets must start with "./"`:``}`},Error),ERR_MODULE_NOT_FOUND=createError(`ERR_MODULE_NOT_FOUND`,(l,R,z=!1)=>`Cannot find ${z?`module`:`package`} '${l}' imported from ${R}`,Error);createError(`ERR_NETWORK_IMPORT_DISALLOWED`,`import of '%s' by %s is not supported: %s`,Error);const ERR_PACKAGE_IMPORT_NOT_DEFINED=createError(`ERR_PACKAGE_IMPORT_NOT_DEFINED`,(l,R,z)=>`Package import specifier "${l}" is not defined${R?` in package ${R||``}package.json`:``} imported from ${z}`,TypeError),ERR_PACKAGE_PATH_NOT_EXPORTED=createError(`ERR_PACKAGE_PATH_NOT_EXPORTED`,(l,R,z)=>R===`.`?`No "exports" main defined in ${l}package.json${z?` imported from ${z}`:``}`:`Package subpath '${R}' is not defined by "exports" in ${l}package.json${z?` imported from ${z}`:``}`,Error),ERR_UNSUPPORTED_DIR_IMPORT=createError(`ERR_UNSUPPORTED_DIR_IMPORT`,`Directory import '%s' is not supported resolving ES modules imported from %s`,Error),ERR_UNSUPPORTED_RESOLVE_REQUEST=createError(`ERR_UNSUPPORTED_RESOLVE_REQUEST`,`Failed to resolve module specifier "%s" from "%s": Invalid relative URL or base scheme is not hierarchical.`,TypeError),ERR_UNKNOWN_FILE_EXTENSION=createError(`ERR_UNKNOWN_FILE_EXTENSION`,(l,R)=>`Unknown file extension "${l}" for ${R}`,TypeError);createError(`ERR_INVALID_ARG_VALUE`,(l,R,z=`is invalid`)=>{let B=inspect(R);return B.length>128&&(B=`${B.slice(0,128)}...`),`The ${l.includes(`.`)?`property`:`argument`} '${l}' ${z}. Received ${B}`},TypeError);const hasOwnProperty$1={}.hasOwnProperty,cache=new Map;function read(R,{base:z,specifier:B}){let V=cache.get(R);if(V)return V;let U;try{U=fs.readFileSync(path.toNamespacedPath(R),`utf8`)}catch(l){let R=l;if(R.code!==`ENOENT`)throw R}let G={exists:!1,pjsonPath:R,main:void 0,name:void 0,type:`none`,exports:void 0,imports:void 0};if(U!==void 0){let l;try{l=JSON.parse(U)}catch(l){let V=new ERR_INVALID_PACKAGE_CONFIG(R,(z?`"${B}" from `:``)+fileURLToPath(z||B),l.message);throw V.cause=l,V}G.exists=!0,hasOwnProperty$1.call(l,`name`)&&typeof l.name==`string`&&(G.name=l.name),hasOwnProperty$1.call(l,`main`)&&typeof l.main==`string`&&(G.main=l.main),hasOwnProperty$1.call(l,`exports`)&&(G.exports=l.exports),hasOwnProperty$1.call(l,`imports`)&&(G.imports=l.imports),hasOwnProperty$1.call(l,`type`)&&(l.type===`commonjs`||l.type===`module`)&&(G.type=l.type)}return cache.set(R,G),G}function getPackageScopeConfig(l){let R=new URL(`package.json`,l);for(;!R.pathname.endsWith(`node_modules/package.json`);){let z=read(fileURLToPath(R),{specifier:l});if(z.exists)return z;let B=R;if(R=new URL(`../package.json`,R),R.pathname===B.pathname)break}return{pjsonPath:fileURLToPath(R),exists:!1,type:`none`}}const hasOwnProperty={}.hasOwnProperty,extensionFormatMap={__proto__:null,".json":`json`,".cjs":`commonjs`,".cts":`commonjs`,".js":`module`,".ts":`module`,".mts":`module`,".mjs":`module`},protocolHandlers={__proto__:null,"data:":getDataProtocolModuleFormat,"file:":getFileProtocolModuleFormat,"node:":()=>`builtin`};function mimeToFormat(l){return l&&/\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?/i.test(l)?`module`:l===`application/json`?`json`:null}function getDataProtocolModuleFormat(l){let{1:R}=/^([^/]+\/[^;,]+)[^,]*?(;base64)?,/.exec(l.pathname)||[null,null,null];return mimeToFormat(R)}function extname(l){let R=l.pathname,z=R.length;for(;z--;){let l=R.codePointAt(z);if(l===47)return``;if(l===46)return R.codePointAt(z-1)===47?``:R.slice(z)}return``}function getFileProtocolModuleFormat(l,R,z){let B=extname(l);if(B===`.js`){let{type:R}=getPackageScopeConfig(l);return R===`none`?`commonjs`:R}if(B===``){let{type:R}=getPackageScopeConfig(l);return R===`none`||R===`commonjs`?`commonjs`:`module`}let V=extensionFormatMap[B];if(V)return V;if(!z)throw new ERR_UNKNOWN_FILE_EXTENSION(B,fileURLToPath(l))}function defaultGetFormatWithoutErrors(l,R){let z=l.protocol;return hasOwnProperty.call(protocolHandlers,z)&&protocolHandlers[z](l,R,!0)||null}const RegExpPrototypeSymbolReplace=RegExp.prototype[Symbol.replace],own={}.hasOwnProperty,invalidSegmentRegEx=/(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))?(\\|\/|$)/i,deprecatedInvalidSegmentRegEx=/(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))(\\|\/|$)/i,invalidPackageNameRegEx=/^\.|%|\\/,patternRegEx=/\*/g,encodedSeparatorRegEx=/%2f|%5c/i,emittedPackageWarnings=new Set,doubleSlashRegEx=/[/\\]{2}/;function emitInvalidSegmentDeprecation(l,R,z,B,V,U,W){if(process$1.noDeprecation)return;let G=fileURLToPath(B),K=doubleSlashRegEx.exec(W?l:R)!==null;process$1.emitWarning(`Use of deprecated ${K?`double slash`:`leading or trailing slash matching`} resolving "${l}" for module request "${R}" ${R===z?``:`matched to "${z}" `}in the "${V?`imports`:`exports`}" field module resolution of the package at ${G}${U?` imported from ${fileURLToPath(U)}`:``}.`,`DeprecationWarning`,`DEP0166`)}function emitLegacyIndexDeprecation(l,R,z,B){if(process$1.noDeprecation||defaultGetFormatWithoutErrors(l,{parentURL:z.href})!==`module`)return;let U=fileURLToPath(l.href),G=fileURLToPath(new URL$1(`.`,R)),K=fileURLToPath(z);B?path.resolve(G,B)!==U&&process$1.emitWarning(`Package ${G} has a "main" field set to "${B}", excluding the full filename and extension to the resolved file at "${U.slice(G.length)}", imported from ${K}.\n Automatic extension resolution of the "main" field is deprecated for ES modules.`,`DeprecationWarning`,`DEP0151`):process$1.emitWarning(`No "main" or "exports" field defined in the package.json for ${G} resolving the main entry point "${U.slice(G.length)}", imported from ${K}.\nDefault "index" lookups for the main are deprecated for ES modules.`,`DeprecationWarning`,`DEP0151`)}function tryStatSync(l){try{return statSync(l)}catch{}}function fileExists(l){let R=statSync(l,{throwIfNoEntry:!1});return(R?R.isFile():void 0)??!1}function legacyMainResolve(l,R,z){let B;if(R.main!==void 0){if(B=new URL$1(R.main,l),fileExists(B))return B;let H=[`./${R.main}.js`,`./${R.main}.json`,`./${R.main}.node`,`./${R.main}/index.js`,`./${R.main}/index.json`,`./${R.main}/index.node`],U=-1;for(;++U<H.length&&(B=new URL$1(H[U],l),!fileExists(B));)B=void 0;if(B)return emitLegacyIndexDeprecation(B,l,z,R.main),B}let U=[`./index.js`,`./index.json`,`./index.node`],W=-1;for(;++W<U.length&&(B=new URL$1(U[W],l),!fileExists(B));)B=void 0;if(B)return emitLegacyIndexDeprecation(B,l,z,R.main),B;throw new ERR_MODULE_NOT_FOUND(fileURLToPath(new URL$1(`.`,l)),fileURLToPath(z))}function finalizeResolution(l,R,B){if(encodedSeparatorRegEx.exec(l.pathname)!==null)throw new ERR_INVALID_MODULE_SPECIFIER(l.pathname,String.raw`must not include encoded "/" or "\" characters`,fileURLToPath(R));let V;try{V=fileURLToPath(l)}catch(z){throw Object.defineProperty(z,`input`,{value:String(l)}),Object.defineProperty(z,`module`,{value:String(R)}),z}let G=tryStatSync(V.endsWith(`/`)?V.slice(-1):V);if(G&&G.isDirectory()){let z=new ERR_UNSUPPORTED_DIR_IMPORT(V,fileURLToPath(R));throw z.url=String(l),z}if(!G||!G.isFile()){let z=new ERR_MODULE_NOT_FOUND(V||l.pathname,R&&fileURLToPath(R),!0);throw z.url=String(l),z}if(!B){let R=realpathSync(V),{search:B,hash:H}=l;l=pathToFileURL(R+(V.endsWith(path.sep)?`/`:``)),l.search=B,l.hash=H}return l}function importNotDefined(l,R,z){return new ERR_PACKAGE_IMPORT_NOT_DEFINED(l,R&&fileURLToPath(new URL$1(`.`,R)),fileURLToPath(z))}function exportsNotFound(l,R,z){return new ERR_PACKAGE_PATH_NOT_EXPORTED(fileURLToPath(new URL$1(`.`,R)),l,z&&fileURLToPath(z))}function throwInvalidSubpath(l,R,z,B,V){throw new ERR_INVALID_MODULE_SPECIFIER(l,`request is not a valid match in pattern "${R}" for the "${B?`imports`:`exports`}" resolution of ${fileURLToPath(z)}`,V&&fileURLToPath(V))}function invalidPackageTarget(l,R,z,B,U){return R=typeof R==`object`&&R?JSON.stringify(R,null,``):`${R}`,new ERR_INVALID_PACKAGE_TARGET(fileURLToPath(new URL$1(`.`,z)),l,R,B,U&&fileURLToPath(U))}function resolvePackageTargetString(l,R,z,B,H,U,W,G,K){if(R!==``&&!U&&l.at(-1)!==`/`)throw invalidPackageTarget(z,l,B,W,H);if(!l.startsWith(`./`)){if(W&&!l.startsWith(`../`)&&!l.startsWith(`/`)){let z=!1;try{new URL$1(l),z=!0}catch{}if(!z)return packageResolve(U?RegExpPrototypeSymbolReplace.call(patternRegEx,l,()=>R):l+R,B,K)}throw invalidPackageTarget(z,l,B,W,H)}if(invalidSegmentRegEx.exec(l.slice(2))!==null)if(deprecatedInvalidSegmentRegEx.exec(l.slice(2))===null){if(!G){let V=U?z.replace(`*`,()=>R):z+R;emitInvalidSegmentDeprecation(U?RegExpPrototypeSymbolReplace.call(patternRegEx,l,()=>R):l,V,z,B,W,H,!0)}}else throw invalidPackageTarget(z,l,B,W,H);let q=new URL$1(l,B),J=q.pathname,Y=new URL$1(`.`,B).pathname;if(!J.startsWith(Y))throw invalidPackageTarget(z,l,B,W,H);if(R===``)return q;if(invalidSegmentRegEx.exec(R)!==null){let V=U?z.replace(`*`,()=>R):z+R;deprecatedInvalidSegmentRegEx.exec(R)===null?G||emitInvalidSegmentDeprecation(U?RegExpPrototypeSymbolReplace.call(patternRegEx,l,()=>R):l,V,z,B,W,H,!1):throwInvalidSubpath(V,z,B,W,H)}return U?new URL$1(RegExpPrototypeSymbolReplace.call(patternRegEx,q.href,()=>R)):new URL$1(R,q)}function isArrayIndex(l){let R=Number(l);return`${R}`===l?R>=0&&R<4294967295:!1}function resolvePackageTarget(l,R,z,B,V,U,W,G,K){if(typeof R==`string`)return resolvePackageTargetString(R,z,B,l,V,U,W,G,K);if(Array.isArray(R)){let H=R;if(H.length===0)return null;let q,J=-1;for(;++J<H.length;){let R=H[J],Y;try{Y=resolvePackageTarget(l,R,z,B,V,U,W,G,K)}catch(l){let R=l;if(q=R,R.code===`ERR_INVALID_PACKAGE_TARGET`)continue;throw l}if(Y!==void 0){if(Y===null){q=null;continue}return Y}}if(q==null)return null;throw q}if(typeof R==`object`&&R){let q=Object.getOwnPropertyNames(R),J=-1;for(;++J<q.length;){let R=q[J];if(isArrayIndex(R))throw new ERR_INVALID_PACKAGE_CONFIG(fileURLToPath(l),fileURLToPath(V),`"exports" cannot contain numeric property keys.`)}for(J=-1;++J<q.length;){let H=q[J];if(H===`default`||K&&K.has(H)){let q=R[H],J=resolvePackageTarget(l,q,z,B,V,U,W,G,K);if(J===void 0)continue;return J}}return null}if(R===null)return null;throw invalidPackageTarget(B,R,l,W,V)}function isConditionalExportsMainSugar(l,R,z){if(typeof l==`string`||Array.isArray(l))return!0;if(typeof l!=`object`||!l)return!1;let B=Object.getOwnPropertyNames(l),V=!1,U=0,W=-1;for(;++W<B.length;){let l=B[W],G=l===``||l[0]!==`.`;if(U++===0)V=G;else if(V!==G)throw new ERR_INVALID_PACKAGE_CONFIG(fileURLToPath(R),fileURLToPath(z),`"exports" cannot contain some keys starting with '.' and some not. The exports object must either be an object of package subpath keys or an object of main entry condition name keys only.`)}return V}function emitTrailingSlashPatternDeprecation(l,R,z){if(process$1.noDeprecation)return;let B=fileURLToPath(R);emittedPackageWarnings.has(B+`|`+l)||(emittedPackageWarnings.add(B+`|`+l),process$1.emitWarning(`Use of deprecated trailing slash pattern mapping "${l}" in the "exports" field module resolution of the package at ${B}${z?` imported from ${fileURLToPath(z)}`:``}. Mapping specifiers ending in "/" is no longer supported.`,`DeprecationWarning`,`DEP0155`))}function packageExportsResolve(l,R,z,B,V){let H=z.exports;if(isConditionalExportsMainSugar(H,l,B)&&(H={".":H}),own.call(H,R)&&!R.includes(`*`)&&!R.endsWith(`/`)){let z=H[R],U=resolvePackageTarget(l,z,``,R,B,!1,!1,!1,V);if(U==null)throw exportsNotFound(R,l,B);return U}let U=``,W=``,G=Object.getOwnPropertyNames(H),K=-1;for(;++K<G.length;){let z=G[K],V=z.indexOf(`*`);if(V!==-1&&R.startsWith(z.slice(0,V))){R.endsWith(`/`)&&emitTrailingSlashPatternDeprecation(R,l,B);let H=z.slice(V+1);R.length>=z.length&&R.endsWith(H)&&patternKeyCompare(U,z)===1&&z.lastIndexOf(`*`)===V&&(U=z,W=R.slice(V,R.length-H.length))}}if(U){let z=H[U],G=resolvePackageTarget(l,z,W,U,B,!0,!1,R.endsWith(`/`),V);if(G==null)throw exportsNotFound(R,l,B);return G}throw exportsNotFound(R,l,B)}function patternKeyCompare(l,R){let z=l.indexOf(`*`),B=R.indexOf(`*`),V=z===-1?l.length:z+1,H=B===-1?R.length:B+1;return V>H?-1:H>V||z===-1?1:B===-1||l.length>R.length?-1:R.length>l.length?1:0}function packageImportsResolve(l,R,z){if(l===`#`||l.startsWith(`#/`)||l.endsWith(`/`))throw new ERR_INVALID_MODULE_SPECIFIER(l,`is not a valid internal imports specifier name`,fileURLToPath(R));let B,V=getPackageScopeConfig(R);if(V.exists){B=pathToFileURL(V.pjsonPath);let H=V.imports;if(H)if(own.call(H,l)&&!l.includes(`*`)){let V=resolvePackageTarget(B,H[l],``,l,R,!1,!0,!1,z);if(V!=null)return V}else{let V=``,U=``,W=Object.getOwnPropertyNames(H),G=-1;for(;++G<W.length;){let R=W[G],z=R.indexOf(`*`);if(z!==-1&&l.startsWith(R.slice(0,-1))){let B=R.slice(z+1);l.length>=R.length&&l.endsWith(B)&&patternKeyCompare(V,R)===1&&R.lastIndexOf(`*`)===z&&(V=R,U=l.slice(z,l.length-B.length))}}if(V){let l=H[V],W=resolvePackageTarget(B,l,U,V,R,!0,!0,!1,z);if(W!=null)return W}}}throw importNotDefined(l,B,R)}function parsePackageName(l,R){let z=l.indexOf(`/`),B=!0,V=!1;l[0]===`@`&&(V=!0,z===-1||l.length===0?B=!1:z=l.indexOf(`/`,z+1));let U=z===-1?l:l.slice(0,z);if(invalidPackageNameRegEx.exec(U)!==null&&(B=!1),!B)throw new ERR_INVALID_MODULE_SPECIFIER(l,`is not a valid package name`,fileURLToPath(R));return{packageName:U,packageSubpath:`.`+(z===-1?``:l.slice(z)),isScoped:V}}function packageResolve(l,R,z){if(nodeBuiltins.includes(l))return new URL$1(`node:`+l);let{packageName:B,packageSubpath:W,isScoped:G}=parsePackageName(l,R),K=getPackageScopeConfig(R);if(K.exists&&K.name===B&&K.exports!==void 0&&K.exports!==null)return packageExportsResolve(pathToFileURL(K.pjsonPath),W,K,R,z);let q=new URL$1(`./node_modules/`+B+`/package.json`,R),J=fileURLToPath(q),Y;do{let U=tryStatSync(J.slice(0,-13));if(!U||!U.isDirectory()){Y=J,q=new URL$1((G?`../../../../node_modules/`:`../../../node_modules/`)+B+`/package.json`,q),J=fileURLToPath(q);continue}let K=read(J,{base:R,specifier:l});return K.exports!==void 0&&K.exports!==null?packageExportsResolve(q,W,K,R,z):W===`.`?legacyMainResolve(q,K,R):new URL$1(W,q)}while(J.length!==Y.length);throw new ERR_MODULE_NOT_FOUND(B,fileURLToPath(R),!1)}function isRelativeSpecifier(l){return l[0]===`.`&&(l.length===1||l[1]===`/`||l[1]===`.`&&(l.length===2||l[2]===`/`))}function shouldBeTreatedAsRelativeOrAbsolutePath(l){return l===``?!1:l[0]===`/`?!0:isRelativeSpecifier(l)}function moduleResolve(l,R,z,B){let H=R.protocol,U=H===`data:`,W;if(shouldBeTreatedAsRelativeOrAbsolutePath(l))try{W=new URL$1(l,R)}catch(z){let B=new ERR_UNSUPPORTED_RESOLVE_REQUEST(l,R);throw B.cause=z,B}else if(H===`file:`&&l[0]===`#`)W=packageImportsResolve(l,R,z);else try{W=new URL$1(l)}catch(B){if(U&&!nodeBuiltins.includes(l)){let z=new ERR_UNSUPPORTED_RESOLVE_REQUEST(l,R);throw z.cause=B,z}W=packageResolve(l,R,z)}return assert.ok(W!==void 0,`expected to be defined`),W.protocol===`file:`?finalizeResolution(W,R,B):W}const DEFAULT_CONDITIONS_SET=new Set([`node`,`import`]),isWindows=(()=>process.platform===`win32`)(),globalCache=(()=>globalThis.__EXSOLVE_CACHE__||=new Map)();function resolveModuleURL(l,B){let V=_parseInput(l);if(`external`in V)return V.external;let H=V.specifier,W=V.url,G=V.absolutePath,K,q;if(B?.cache!==!1&&(K=_cacheKey(G||H,B),q=B?.cache&&typeof B?.cache==`object`?B.cache:globalCache),q){let l=q.get(K);if(typeof l==`string`)return l;if(l instanceof Error){if(B?.try)return;throw l}}if(G)try{let l=lstatSync(G);if(l.isSymbolicLink()&&(G=realpathSync(G),W=pathToFileURL(G)),l.isFile())return q&&q.set(K,W.href),W.href}catch(l){if(l?.code!==`ENOENT`)throw q&&q.set(K,l),l}let J=B?.conditions?new Set(B.conditions):DEFAULT_CONDITIONS_SET,Y=H||W.href,X=_normalizeBases(B?.from),Z=B?.suffixes||[``],Q=B?.extensions?[``,...B.extensions]:[``],$;for(let l of X){for(let R of Z){let z=_join(Y,R);z===`.`&&(z+=`/.`);for(let R of Q)if($=_tryModuleResolve(z+R,l,J),$)break;if($)break}if($)break}if(!$){let R=Error(`Cannot resolve module "${l}" (from: ${X.map(l=>_fmtPath(l)).join(`, `)})`);if(R.code=`ERR_MODULE_NOT_FOUND`,q&&q.set(K,R),B?.try)return;throw R}return q&&q.set(K,$.href),$.href}function resolveModulePath(l,R){let z=resolveModuleURL(l,R);if(!z||!z.startsWith(`file://`)&&R?.try)return;let B=fileURLToPath(z);return isWindows?_normalizeWinPath(B):B}function _tryModuleResolve(l,R,z){try{return moduleResolve(l,R,z)}catch{}}function _normalizeBases(l){let R=(Array.isArray(l)?l:[l]).flatMap(l=>_normalizeBase(l));return R.length===0?[pathToFileURL(`./`)]:R}function _normalizeBase(l){if(!l)return[];if(_isURL(l))return[l];if(typeof l!=`string`)return[];if(/^(?:node|data|http|https|file):/.test(l))return new URL(l);try{return l.endsWith(`/`)||statSync(l).isDirectory()?pathToFileURL(l+`/`):pathToFileURL(l)}catch{return[pathToFileURL(l+`/`),pathToFileURL(l)]}}function _fmtPath(l){try{return fileURLToPath(l)}catch{return l}}function _cacheKey(l,R){return JSON.stringify([l,(R?.conditions||[`node`,`import`]).sort(),R?.extensions,R?.from,R?.suffixes])}function _join(l,R){return!l||!R||R===`/`?l:(l.endsWith(`/`)?l:l+`/`)+(R.startsWith(`/`)?R.slice(1):R)}function _normalizeWinPath(l){return l.replace(/\\/g,`/`).replace(/^[a-z]:\//,l=>l.toUpperCase())}function _isURL(l){return l instanceof URL||l?.constructor?.name===`URL`}function _parseInput(l){if(typeof l==`string`){if(l.startsWith(`file:`)){let R=new URL(l);return{url:R,absolutePath:fileURLToPath(R)}}return isAbsolute(l)?{url:pathToFileURL(l),absolutePath:l}:/^(?:node|data|http|https):/.test(l)?{external:l}:nodeBuiltins.includes(l)&&!l.includes(`:`)?{external:`node:${l}`}:{specifier:l}}if(_isURL(l))return l.protocol===`file:`?{url:l,absolutePath:fileURLToPath(l)}:{external:l.href};throw TypeError("id must be a `string` or `URL`")}export{resolveModulePath as t};
|
|
1
|
+
import fs,{lstatSync,realpathSync,statSync}from"node:fs";import{URL as URL$1,fileURLToPath,pathToFileURL}from"node:url";import path,{isAbsolute}from"node:path";import assert from"node:assert";import process$1 from"node:process";import v8 from"node:v8";import{format,inspect}from"node:util";const nodeBuiltins=`_http_agent._http_client._http_common._http_incoming._http_outgoing._http_server._stream_duplex._stream_passthrough._stream_readable._stream_transform._stream_wrap._stream_writable._tls_common._tls_wrap.assert.assert/strict.async_hooks.buffer.child_process.cluster.console.constants.crypto.dgram.diagnostics_channel.dns.dns/promises.domain.events.fs.fs/promises.http.http2.https.inspector.inspector/promises.module.net.os.path.path/posix.path/win32.perf_hooks.process.punycode.querystring.readline.readline/promises.repl.stream.stream/consumers.stream/promises.stream/web.string_decoder.sys.timers.timers/promises.tls.trace_events.tty.url.util.util/types.v8.vm.wasi.worker_threads.zlib`.split(`.`),own$1={}.hasOwnProperty,classRegExp=/^([A-Z][a-z\d]*)+$/,kTypes=new Set([`string`,`function`,`number`,`object`,`Function`,`Object`,`boolean`,`bigint`,`symbol`]),messages=new Map;let userStackTraceLimit;function formatList(l,R=`and`){return l.length<3?l.join(` ${R} `):`${l.slice(0,-1).join(`, `)}, ${R} ${l.at(-1)}`}function createError(l,R,z){return messages.set(l,R),makeNodeErrorWithCode(z,l)}function makeNodeErrorWithCode(l,R){return function(...z){let B=Error.stackTraceLimit;isErrorStackTraceLimitWritable()&&(Error.stackTraceLimit=0);let V=new l;isErrorStackTraceLimitWritable()&&(Error.stackTraceLimit=B);let H=getMessage(R,z,V);return Object.defineProperties(V,{message:{value:H,enumerable:!1,writable:!0,configurable:!0},toString:{value(){return`${this.name} [${R}]: ${this.message}`},enumerable:!1,writable:!0,configurable:!0}}),captureLargerStackTrace(V),V.code=R,V}}function isErrorStackTraceLimitWritable(){try{if(v8.startupSnapshot.isBuildingSnapshot())return!1}catch{}let l=Object.getOwnPropertyDescriptor(Error,`stackTraceLimit`);return l===void 0?Object.isExtensible(Error):own$1.call(l,`writable`)&&l.writable!==void 0?l.writable:l.set!==void 0}function hideStackFrames(l){let R=`__node_internal_`+l.name;return Object.defineProperty(l,`name`,{value:R}),l}const captureLargerStackTrace=hideStackFrames(function(l){let R=isErrorStackTraceLimitWritable();return R&&(userStackTraceLimit=Error.stackTraceLimit,Error.stackTraceLimit=1/0),Error.captureStackTrace(l),R&&(Error.stackTraceLimit=userStackTraceLimit),l});function getMessage(l,R,z){let B=messages.get(l);if(assert.ok(B!==void 0,"expected `message` to be found"),typeof B==`function`)return assert.ok(B.length<=R.length,`Code: ${l}; The provided arguments length (${R.length}) does not match the required ones (${B.length}).`),Reflect.apply(B,z,R);let V=/%[dfijoOs]/g,H=0;for(;V.exec(B)!==null;)H++;return assert.ok(H===R.length,`Code: ${l}; The provided arguments length (${R.length}) does not match the required ones (${H}).`),R.length===0?B:(R.unshift(B),Reflect.apply(format,null,R))}function determineSpecificType(l){if(l==null)return String(l);if(typeof l==`function`&&l.name)return`function ${l.name}`;if(typeof l==`object`)return l.constructor&&l.constructor.name?`an instance of ${l.constructor.name}`:`${inspect(l,{depth:-1})}`;let R=inspect(l,{colors:!1});return R.length>28&&(R=`${R.slice(0,25)}...`),`type ${typeof l} (${R})`}createError(`ERR_INVALID_ARG_TYPE`,(l,R,z)=>{assert.ok(typeof l==`string`,`'name' must be a string`),Array.isArray(R)||(R=[R]);let B=`The `;if(l.endsWith(` argument`))B+=`${l} `;else{let R=l.includes(`.`)?`property`:`argument`;B+=`"${l}" ${R} `}B+=`must be `;let V=[],H=[],U=[];for(let l of R)assert.ok(typeof l==`string`,`All expected entries have to be of type string`),kTypes.has(l)?V.push(l.toLowerCase()):classRegExp.exec(l)===null?(assert.ok(l!==`object`,`The value "object" should be written as "Object"`),U.push(l)):H.push(l);if(H.length>0){let l=V.indexOf(`object`);l!==-1&&(V.slice(l,1),H.push(`Object`))}return V.length>0&&(B+=`${V.length>1?`one of type`:`of type`} ${formatList(V,`or`)}`,(H.length>0||U.length>0)&&(B+=` or `)),H.length>0&&(B+=`an instance of ${formatList(H,`or`)}`,U.length>0&&(B+=` or `)),U.length>0&&(U.length>1?B+=`one of ${formatList(U,`or`)}`:(U[0]?.toLowerCase()!==U[0]&&(B+=`an `),B+=`${U[0]}`)),B+=`. Received ${determineSpecificType(z)}`,B},TypeError);const ERR_INVALID_MODULE_SPECIFIER=createError(`ERR_INVALID_MODULE_SPECIFIER`,(l,R,z)=>`Invalid module "${l}" ${R}${z?` imported from ${z}`:``}`,TypeError),ERR_INVALID_PACKAGE_CONFIG=createError(`ERR_INVALID_PACKAGE_CONFIG`,(l,R,z)=>`Invalid package config ${l}${R?` while importing ${R}`:``}${z?`. ${z}`:``}`,Error),ERR_INVALID_PACKAGE_TARGET=createError(`ERR_INVALID_PACKAGE_TARGET`,(l,R,z,B=!1,V)=>{let H=typeof z==`string`&&!B&&z.length>0&&!z.startsWith(`./`);return R===`.`?(assert.ok(B===!1),`Invalid "exports" main target ${JSON.stringify(z)} defined in the package config ${l}package.json${V?` imported from ${V}`:``}${H?`; targets must start with "./"`:``}`):`Invalid "${B?`imports`:`exports`}" target ${JSON.stringify(z)} defined for '${R}' in the package config ${l}package.json${V?` imported from ${V}`:``}${H?`; targets must start with "./"`:``}`},Error),ERR_MODULE_NOT_FOUND=createError(`ERR_MODULE_NOT_FOUND`,(l,R,z=!1)=>`Cannot find ${z?`module`:`package`} '${l}' imported from ${R}`,Error);createError(`ERR_NETWORK_IMPORT_DISALLOWED`,`import of '%s' by %s is not supported: %s`,Error);const ERR_PACKAGE_IMPORT_NOT_DEFINED=createError(`ERR_PACKAGE_IMPORT_NOT_DEFINED`,(l,R,z)=>`Package import specifier "${l}" is not defined${R?` in package ${R||``}package.json`:``} imported from ${z}`,TypeError),ERR_PACKAGE_PATH_NOT_EXPORTED=createError(`ERR_PACKAGE_PATH_NOT_EXPORTED`,(l,R,z)=>R===`.`?`No "exports" main defined in ${l}package.json${z?` imported from ${z}`:``}`:`Package subpath '${R}' is not defined by "exports" in ${l}package.json${z?` imported from ${z}`:``}`,Error),ERR_UNSUPPORTED_DIR_IMPORT=createError(`ERR_UNSUPPORTED_DIR_IMPORT`,`Directory import '%s' is not supported resolving ES modules imported from %s`,Error),ERR_UNSUPPORTED_RESOLVE_REQUEST=createError(`ERR_UNSUPPORTED_RESOLVE_REQUEST`,`Failed to resolve module specifier "%s" from "%s": Invalid relative URL or base scheme is not hierarchical.`,TypeError),ERR_UNKNOWN_FILE_EXTENSION=createError(`ERR_UNKNOWN_FILE_EXTENSION`,(l,R)=>`Unknown file extension "${l}" for ${R}`,TypeError);createError(`ERR_INVALID_ARG_VALUE`,(l,R,z=`is invalid`)=>{let B=inspect(R);return B.length>128&&(B=`${B.slice(0,128)}...`),`The ${l.includes(`.`)?`property`:`argument`} '${l}' ${z}. Received ${B}`},TypeError);const hasOwnProperty$1={}.hasOwnProperty,cache=new Map;function read(R,{base:z,specifier:B}){let V=cache.get(R);if(V)return V;let U;try{U=fs.readFileSync(path.toNamespacedPath(R),`utf8`)}catch(l){let R=l;if(R.code!==`ENOENT`)throw R}let G={exists:!1,pjsonPath:R,main:void 0,name:void 0,type:`none`,exports:void 0,imports:void 0};if(U!==void 0){let l;try{l=JSON.parse(U)}catch(l){let V=new ERR_INVALID_PACKAGE_CONFIG(R,(z?`"${B}" from `:``)+fileURLToPath(z||B),l.message);throw V.cause=l,V}G.exists=!0,hasOwnProperty$1.call(l,`name`)&&typeof l.name==`string`&&(G.name=l.name),hasOwnProperty$1.call(l,`main`)&&typeof l.main==`string`&&(G.main=l.main),hasOwnProperty$1.call(l,`exports`)&&(G.exports=l.exports),hasOwnProperty$1.call(l,`imports`)&&(G.imports=l.imports),hasOwnProperty$1.call(l,`type`)&&(l.type===`commonjs`||l.type===`module`)&&(G.type=l.type)}return cache.set(R,G),G}function getPackageScopeConfig(l){let R=new URL(`package.json`,l);for(;!R.pathname.endsWith(`node_modules/package.json`);){let z=read(fileURLToPath(R),{specifier:l});if(z.exists)return z;let B=R;if(R=new URL(`../package.json`,R),R.pathname===B.pathname)break}return{pjsonPath:fileURLToPath(R),exists:!1,type:`none`}}const hasOwnProperty={}.hasOwnProperty,extensionFormatMap={__proto__:null,".json":`json`,".cjs":`commonjs`,".cts":`commonjs`,".js":`module`,".ts":`module`,".mts":`module`,".mjs":`module`},protocolHandlers={__proto__:null,"data:":getDataProtocolModuleFormat,"file:":getFileProtocolModuleFormat,"node:":()=>`builtin`};function mimeToFormat(l){return l&&/\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?/i.test(l)?`module`:l===`application/json`?`json`:null}function getDataProtocolModuleFormat(l){let{1:R}=/^([^/]+\/[^;,]+)[^,]*?(;base64)?,/.exec(l.pathname)||[null,null,null];return mimeToFormat(R)}function extname(l){let R=l.pathname,z=R.length;for(;z--;){let l=R.codePointAt(z);if(l===47)return``;if(l===46)return R.codePointAt(z-1)===47?``:R.slice(z)}return``}function getFileProtocolModuleFormat(l,R,z){let B=extname(l);if(B===`.js`){let{type:R}=getPackageScopeConfig(l);return R===`none`?`commonjs`:R}if(B===``){let{type:R}=getPackageScopeConfig(l);return R===`none`||R===`commonjs`?`commonjs`:`module`}let V=extensionFormatMap[B];if(V)return V;if(!z)throw new ERR_UNKNOWN_FILE_EXTENSION(B,fileURLToPath(l))}function defaultGetFormatWithoutErrors(l,R){let z=l.protocol;return hasOwnProperty.call(protocolHandlers,z)&&protocolHandlers[z](l,R,!0)||null}const RegExpPrototypeSymbolReplace=RegExp.prototype[Symbol.replace],own={}.hasOwnProperty,invalidSegmentRegEx=/(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))?(\\|\/|$)/i,deprecatedInvalidSegmentRegEx=/(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))(\\|\/|$)/i,invalidPackageNameRegEx=/^\.|%|\\/,patternRegEx=/\*/g,encodedSeparatorRegEx=/%2f|%5c/i,emittedPackageWarnings=new Set,doubleSlashRegEx=/[/\\]{2}/;function emitInvalidSegmentDeprecation(l,R,z,B,V,U,W){if(process$1.noDeprecation)return;let G=fileURLToPath(B),K=doubleSlashRegEx.exec(W?l:R)!==null;process$1.emitWarning(`Use of deprecated ${K?`double slash`:`leading or trailing slash matching`} resolving "${l}" for module request "${R}" ${R===z?``:`matched to "${z}" `}in the "${V?`imports`:`exports`}" field module resolution of the package at ${G}${U?` imported from ${fileURLToPath(U)}`:``}.`,`DeprecationWarning`,`DEP0166`)}function emitLegacyIndexDeprecation(l,R,z,B){if(process$1.noDeprecation||defaultGetFormatWithoutErrors(l,{parentURL:z.href})!==`module`)return;let U=fileURLToPath(l.href),G=fileURLToPath(new URL$1(`.`,R)),K=fileURLToPath(z);B?path.resolve(G,B)!==U&&process$1.emitWarning(`Package ${G} has a "main" field set to "${B}", excluding the full filename and extension to the resolved file at "${U.slice(G.length)}", imported from ${K}.\n Automatic extension resolution of the "main" field is deprecated for ES modules.`,`DeprecationWarning`,`DEP0151`):process$1.emitWarning(`No "main" or "exports" field defined in the package.json for ${G} resolving the main entry point "${U.slice(G.length)}", imported from ${K}.\nDefault "index" lookups for the main are deprecated for ES modules.`,`DeprecationWarning`,`DEP0151`)}function tryStatSync(l){try{return statSync(l)}catch{}}function fileExists(l){let R=statSync(l,{throwIfNoEntry:!1});return(R?R.isFile():void 0)??!1}function legacyMainResolve(l,R,z){let B;if(R.main!==void 0){if(B=new URL$1(R.main,l),fileExists(B))return B;let H=[`./${R.main}.js`,`./${R.main}.json`,`./${R.main}.node`,`./${R.main}/index.js`,`./${R.main}/index.json`,`./${R.main}/index.node`],U=-1;for(;++U<H.length&&(B=new URL$1(H[U],l),!fileExists(B));)B=void 0;if(B)return emitLegacyIndexDeprecation(B,l,z,R.main),B}let U=[`./index.js`,`./index.json`,`./index.node`],W=-1;for(;++W<U.length&&(B=new URL$1(U[W],l),!fileExists(B));)B=void 0;if(B)return emitLegacyIndexDeprecation(B,l,z,R.main),B;throw new ERR_MODULE_NOT_FOUND(fileURLToPath(new URL$1(`.`,l)),fileURLToPath(z))}function finalizeResolution(l,R,B){if(encodedSeparatorRegEx.exec(l.pathname)!==null)throw new ERR_INVALID_MODULE_SPECIFIER(l.pathname,String.raw`must not include encoded "/" or "\" characters`,fileURLToPath(R));let V;try{V=fileURLToPath(l)}catch(z){throw Object.defineProperty(z,`input`,{value:String(l)}),Object.defineProperty(z,`module`,{value:String(R)}),z}let G=tryStatSync(V.endsWith(`/`)?V.slice(-1):V);if(G&&G.isDirectory()){let z=new ERR_UNSUPPORTED_DIR_IMPORT(V,fileURLToPath(R));throw z.url=String(l),z}if(!G||!G.isFile()){let z=new ERR_MODULE_NOT_FOUND(V||l.pathname,R&&fileURLToPath(R),!0);throw z.url=String(l),z}if(!B){let R=realpathSync(V),{search:B,hash:H}=l;l=pathToFileURL(R+(V.endsWith(path.sep)?`/`:``)),l.search=B,l.hash=H}return l}function importNotDefined(l,R,z){return new ERR_PACKAGE_IMPORT_NOT_DEFINED(l,R&&fileURLToPath(new URL$1(`.`,R)),fileURLToPath(z))}function exportsNotFound(l,R,z){return new ERR_PACKAGE_PATH_NOT_EXPORTED(fileURLToPath(new URL$1(`.`,R)),l,z&&fileURLToPath(z))}function throwInvalidSubpath(l,R,z,B,V){throw new ERR_INVALID_MODULE_SPECIFIER(l,`request is not a valid match in pattern "${R}" for the "${B?`imports`:`exports`}" resolution of ${fileURLToPath(z)}`,V&&fileURLToPath(V))}function invalidPackageTarget(l,R,z,B,U){return R=typeof R==`object`&&R?JSON.stringify(R,null,``):`${R}`,new ERR_INVALID_PACKAGE_TARGET(fileURLToPath(new URL$1(`.`,z)),l,R,B,U&&fileURLToPath(U))}function resolvePackageTargetString(l,R,z,B,H,U,W,G,K){if(R!==``&&!U&&l.at(-1)!==`/`)throw invalidPackageTarget(z,l,B,W,H);if(!l.startsWith(`./`)){if(W&&!l.startsWith(`../`)&&!l.startsWith(`/`)){let z=!1;try{new URL$1(l),z=!0}catch{}if(!z)return packageResolve(U?RegExpPrototypeSymbolReplace.call(patternRegEx,l,()=>R):l+R,B,K)}throw invalidPackageTarget(z,l,B,W,H)}if(invalidSegmentRegEx.exec(l.slice(2))!==null)if(deprecatedInvalidSegmentRegEx.exec(l.slice(2))===null){if(!G){let V=U?z.replace(`*`,()=>R):z+R;emitInvalidSegmentDeprecation(U?RegExpPrototypeSymbolReplace.call(patternRegEx,l,()=>R):l,V,z,B,W,H,!0)}}else throw invalidPackageTarget(z,l,B,W,H);let q=new URL$1(l,B),J=q.pathname,Y=new URL$1(`.`,B).pathname;if(!J.startsWith(Y))throw invalidPackageTarget(z,l,B,W,H);if(R===``)return q;if(invalidSegmentRegEx.exec(R)!==null){let V=U?z.replace(`*`,()=>R):z+R;deprecatedInvalidSegmentRegEx.exec(R)===null?G||emitInvalidSegmentDeprecation(U?RegExpPrototypeSymbolReplace.call(patternRegEx,l,()=>R):l,V,z,B,W,H,!1):throwInvalidSubpath(V,z,B,W,H)}return U?new URL$1(RegExpPrototypeSymbolReplace.call(patternRegEx,q.href,()=>R)):new URL$1(R,q)}function isArrayIndex(l){let R=Number(l);return`${R}`===l?R>=0&&R<4294967295:!1}function resolvePackageTarget(l,R,z,B,V,U,W,G,K){if(typeof R==`string`)return resolvePackageTargetString(R,z,B,l,V,U,W,G,K);if(Array.isArray(R)){let H=R;if(H.length===0)return null;let q,J=-1;for(;++J<H.length;){let R=H[J],Y;try{Y=resolvePackageTarget(l,R,z,B,V,U,W,G,K)}catch(l){let R=l;if(q=R,R.code===`ERR_INVALID_PACKAGE_TARGET`)continue;throw l}if(Y!==void 0){if(Y===null){q=null;continue}return Y}}if(q==null)return null;throw q}if(typeof R==`object`&&R){let q=Object.getOwnPropertyNames(R),J=-1;for(;++J<q.length;){let R=q[J];if(isArrayIndex(R))throw new ERR_INVALID_PACKAGE_CONFIG(fileURLToPath(l),fileURLToPath(V),`"exports" cannot contain numeric property keys.`)}for(J=-1;++J<q.length;){let H=q[J];if(H===`default`||K&&K.has(H)){let q=R[H],J=resolvePackageTarget(l,q,z,B,V,U,W,G,K);if(J===void 0)continue;return J}}return null}if(R===null)return null;throw invalidPackageTarget(B,R,l,W,V)}function isConditionalExportsMainSugar(l,R,z){if(typeof l==`string`||Array.isArray(l))return!0;if(typeof l!=`object`||!l)return!1;let B=Object.getOwnPropertyNames(l),V=!1,U=0,W=-1;for(;++W<B.length;){let l=B[W],G=l===``||l[0]!==`.`;if(U++===0)V=G;else if(V!==G)throw new ERR_INVALID_PACKAGE_CONFIG(fileURLToPath(R),fileURLToPath(z),`"exports" cannot contain some keys starting with '.' and some not. The exports object must either be an object of package subpath keys or an object of main entry condition name keys only.`)}return V}function emitTrailingSlashPatternDeprecation(l,R,z){if(process$1.noDeprecation)return;let B=fileURLToPath(R);emittedPackageWarnings.has(B+`|`+l)||(emittedPackageWarnings.add(B+`|`+l),process$1.emitWarning(`Use of deprecated trailing slash pattern mapping "${l}" in the "exports" field module resolution of the package at ${B}${z?` imported from ${fileURLToPath(z)}`:``}. Mapping specifiers ending in "/" is no longer supported.`,`DeprecationWarning`,`DEP0155`))}function packageExportsResolve(l,R,z,B,V){let H=z.exports;if(isConditionalExportsMainSugar(H,l,B)&&(H={".":H}),own.call(H,R)&&!R.includes(`*`)&&!R.endsWith(`/`)){let z=H[R],U=resolvePackageTarget(l,z,``,R,B,!1,!1,!1,V);if(U==null)throw exportsNotFound(R,l,B);return U}let U=``,W=``,G=Object.getOwnPropertyNames(H),K=-1;for(;++K<G.length;){let z=G[K],V=z.indexOf(`*`);if(V!==-1&&R.startsWith(z.slice(0,V))){R.endsWith(`/`)&&emitTrailingSlashPatternDeprecation(R,l,B);let H=z.slice(V+1);R.length>=z.length&&R.endsWith(H)&&patternKeyCompare(U,z)===1&&z.lastIndexOf(`*`)===V&&(U=z,W=R.slice(V,R.length-H.length))}}if(U){let z=H[U],G=resolvePackageTarget(l,z,W,U,B,!0,!1,R.endsWith(`/`),V);if(G==null)throw exportsNotFound(R,l,B);return G}throw exportsNotFound(R,l,B)}function patternKeyCompare(l,R){let z=l.indexOf(`*`),B=R.indexOf(`*`),V=z===-1?l.length:z+1,H=B===-1?R.length:B+1;return V>H?-1:H>V||z===-1?1:B===-1||l.length>R.length?-1:R.length>l.length?1:0}function packageImportsResolve(l,R,z){if(l===`#`||l.startsWith(`#/`)||l.endsWith(`/`))throw new ERR_INVALID_MODULE_SPECIFIER(l,`is not a valid internal imports specifier name`,fileURLToPath(R));let B,V=getPackageScopeConfig(R);if(V.exists){B=pathToFileURL(V.pjsonPath);let H=V.imports;if(H)if(own.call(H,l)&&!l.includes(`*`)){let V=resolvePackageTarget(B,H[l],``,l,R,!1,!0,!1,z);if(V!=null)return V}else{let V=``,U=``,W=Object.getOwnPropertyNames(H),G=-1;for(;++G<W.length;){let R=W[G],z=R.indexOf(`*`);if(z!==-1&&l.startsWith(R.slice(0,-1))){let B=R.slice(z+1);l.length>=R.length&&l.endsWith(B)&&patternKeyCompare(V,R)===1&&R.lastIndexOf(`*`)===z&&(V=R,U=l.slice(z,l.length-B.length))}}if(V){let l=H[V],W=resolvePackageTarget(B,l,U,V,R,!0,!0,!1,z);if(W!=null)return W}}}throw importNotDefined(l,B,R)}function parsePackageName(l,R){let z=l.indexOf(`/`),B=!0,V=!1;l[0]===`@`&&(V=!0,z===-1||l.length===0?B=!1:z=l.indexOf(`/`,z+1));let U=z===-1?l:l.slice(0,z);if(invalidPackageNameRegEx.exec(U)!==null&&(B=!1),!B)throw new ERR_INVALID_MODULE_SPECIFIER(l,`is not a valid package name`,fileURLToPath(R));return{packageName:U,packageSubpath:`.`+(z===-1?``:l.slice(z)),isScoped:V}}function packageResolve(l,R,z){if(nodeBuiltins.includes(l))return new URL$1(`node:`+l);let{packageName:B,packageSubpath:W,isScoped:G}=parsePackageName(l,R),K=getPackageScopeConfig(R);if(K.exists&&K.name===B&&K.exports!==void 0&&K.exports!==null)return packageExportsResolve(pathToFileURL(K.pjsonPath),W,K,R,z);let q=new URL$1(`./node_modules/`+B+`/package.json`,R),J=fileURLToPath(q),Y;do{let U=tryStatSync(J.slice(0,-13));if(!U||!U.isDirectory()){Y=J,q=new URL$1((G?`../../../../node_modules/`:`../../../node_modules/`)+B+`/package.json`,q),J=fileURLToPath(q);continue}let K=read(J,{base:R,specifier:l});return K.exports!==void 0&&K.exports!==null?packageExportsResolve(q,W,K,R,z):W===`.`?legacyMainResolve(q,K,R):new URL$1(W,q)}while(J.length!==Y.length);throw new ERR_MODULE_NOT_FOUND(B,fileURLToPath(R),!1)}function isRelativeSpecifier(l){return l[0]===`.`&&(l.length===1||l[1]===`/`||l[1]===`.`&&(l.length===2||l[2]===`/`))}function shouldBeTreatedAsRelativeOrAbsolutePath(l){return l===``?!1:l[0]===`/`?!0:isRelativeSpecifier(l)}function moduleResolve(l,R,z,B){let H=R.protocol,U=H===`data:`,W;if(shouldBeTreatedAsRelativeOrAbsolutePath(l))try{W=new URL$1(l,R)}catch(z){let B=new ERR_UNSUPPORTED_RESOLVE_REQUEST(l,R);throw B.cause=z,B}else if(H===`file:`&&l[0]===`#`)W=packageImportsResolve(l,R,z);else try{W=new URL$1(l)}catch(B){if(U&&!nodeBuiltins.includes(l)){let z=new ERR_UNSUPPORTED_RESOLVE_REQUEST(l,R);throw z.cause=B,z}W=packageResolve(l,R,z)}return assert.ok(W!==void 0,`expected to be defined`),W.protocol===`file:`?finalizeResolution(W,R,B):W}const DEFAULT_CONDITIONS_SET=new Set([`node`,`import`]),isWindows=process.platform===`win32`,globalCache=globalThis.__EXSOLVE_CACHE__||=new Map;function resolveModuleURL(l,B){let V=_parseInput(l);if(`external`in V)return V.external;let H=V.specifier,W=V.url,G=V.absolutePath,K,q;if(B?.cache!==!1&&(K=_cacheKey(G||H,B),q=B?.cache&&typeof B?.cache==`object`?B.cache:globalCache),q){let l=q.get(K);if(typeof l==`string`)return l;if(l instanceof Error){if(B?.try)return;throw l}}if(G)try{let l=lstatSync(G);if(l.isSymbolicLink()&&(G=realpathSync(G),W=pathToFileURL(G)),l.isFile())return q&&q.set(K,W.href),W.href}catch(l){if(l?.code!==`ENOENT`)throw q&&q.set(K,l),l}let J=B?.conditions?new Set(B.conditions):DEFAULT_CONDITIONS_SET,Y=H||W.href,X=_normalizeBases(B?.from),Z=B?.suffixes||[``],Q=B?.extensions?[``,...B.extensions]:[``],$;for(let l of X){for(let R of Z){let z=_join(Y,R);z===`.`&&(z+=`/.`);for(let R of Q)if($=_tryModuleResolve(z+R,l,J),$)break;if($)break}if($)break}if(!$){let R=Error(`Cannot resolve module "${l}" (from: ${X.map(l=>_fmtPath(l)).join(`, `)})`);if(R.code=`ERR_MODULE_NOT_FOUND`,q&&q.set(K,R),B?.try)return;throw R}return q&&q.set(K,$.href),$.href}function resolveModulePath(l,R){let z=resolveModuleURL(l,R);if(!z||!z.startsWith(`file://`)&&R?.try)return;let B=fileURLToPath(z);return isWindows?_normalizeWinPath(B):B}function _tryModuleResolve(l,R,z){try{return moduleResolve(l,R,z)}catch{}}function _normalizeBases(l){let R=(Array.isArray(l)?l:[l]).flatMap(l=>_normalizeBase(l));return R.length===0?[pathToFileURL(`./`)]:R}function _normalizeBase(l){if(!l)return[];if(_isURL(l))return[l];if(typeof l!=`string`)return[];if(/^(?:node|data|http|https|file):/.test(l))return new URL(l);try{return l.endsWith(`/`)||statSync(l).isDirectory()?pathToFileURL(l+`/`):pathToFileURL(l)}catch{return[pathToFileURL(l+`/`),pathToFileURL(l)]}}function _fmtPath(l){try{return fileURLToPath(l)}catch{return l}}function _cacheKey(l,R){return JSON.stringify([l,(R?.conditions||[`node`,`import`]).sort(),R?.extensions,R?.from,R?.suffixes])}function _join(l,R){return!l||!R||R===`/`?l:(l.endsWith(`/`)?l:l+`/`)+(R.startsWith(`/`)?R.slice(1):R)}function _normalizeWinPath(l){return l.replace(/\\/g,`/`).replace(/^[a-z]:\//,l=>l.toUpperCase())}function _isURL(l){return l instanceof URL||l?.constructor?.name===`URL`}function _parseInput(l){if(typeof l==`string`){if(l.startsWith(`file:`)){let R=new URL(l);return{url:R,absolutePath:fileURLToPath(R)}}return isAbsolute(l)?{url:pathToFileURL(l),absolutePath:l}:/^(?:node|data|http|https):/.test(l)?{external:l}:nodeBuiltins.includes(l)&&!l.includes(`:`)?{external:`node:${l}`}:{specifier:l}}if(_isURL(l))return l.protocol===`file:`?{url:l,absolutePath:fileURLToPath(l)}:{external:l.href};throw TypeError("id must be a `string` or `URL`")}export{resolveModulePath as t};
|
package/dist/_chunks/trace.mjs
CHANGED
|
@@ -1,27 +1,25 @@
|
|
|
1
|
-
import { a as relative, o as resolve, r as join
|
|
2
|
-
import { n as writePackageJSON, t as readPackageJSON } from "./libs/pkg-types.mjs";
|
|
1
|
+
import { a as relative, i as normalize, n as isAbsolute, o as resolve, r as join, t as dirname } from "./libs/pathe.mjs";
|
|
3
2
|
import { createRequire } from "node:module";
|
|
4
3
|
import { promises } from "node:fs";
|
|
5
4
|
import { nodeFileTrace } from "@vercel/nft";
|
|
6
|
-
import { isAbsolute } from "node:path";
|
|
7
5
|
import semver from "semver";
|
|
8
|
-
import {
|
|
6
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
9
7
|
|
|
10
8
|
//#region src/_utils.ts
|
|
11
9
|
const isWindows = process.platform === "win32";
|
|
12
|
-
const NODE_MODULES_RE = /^(?<dir
|
|
13
|
-
function parseNodeModulePath(path
|
|
14
|
-
return NODE_MODULES_RE.exec(path
|
|
10
|
+
const NODE_MODULES_RE = /^(?<dir>.+[\\/]node_modules[\\/])(?<name>[^@\\/]+|@[^\\/]+[\\/][^\\/]+)(?:[\\/](?<subpath>.+))?$/;
|
|
11
|
+
function parseNodeModulePath(path) {
|
|
12
|
+
return NODE_MODULES_RE.exec(path)?.groups || {};
|
|
15
13
|
}
|
|
16
|
-
const IMPORT_RE = /^(?!\.)(?<name>[
|
|
14
|
+
const IMPORT_RE = /^(?!\.)(?<name>[^@/\\]+|@[^/\\]+[/\\][^/\\]+)(?:[/\\](?<subpath>.+))?$/;
|
|
17
15
|
function toImport(id) {
|
|
18
16
|
if (isAbsolute(id)) {
|
|
19
17
|
const { name, subpath } = parseNodeModulePath(id) || {};
|
|
20
18
|
if (name && subpath) return join(name, subpath);
|
|
21
19
|
} else if (IMPORT_RE.test(id)) return id;
|
|
22
20
|
}
|
|
23
|
-
function guessSubpath(path
|
|
24
|
-
const { dir, name, subpath } = NODE_MODULES_RE.exec(path
|
|
21
|
+
function guessSubpath(path, conditions) {
|
|
22
|
+
const { dir, name, subpath } = NODE_MODULES_RE.exec(path)?.groups || {};
|
|
25
23
|
if (!dir || !name || !subpath) return;
|
|
26
24
|
const exports = getPkgJSON(join(dir, name) + "/")?.exports;
|
|
27
25
|
if (!exports || typeof exports !== "object") return;
|
|
@@ -61,6 +59,12 @@ function flattenExports(exports = {}, parentSubpath = "./") {
|
|
|
61
59
|
function escapeRegExp(string) {
|
|
62
60
|
return string.replace(/[-\\^$*+?.()|[\]{}]/g, String.raw`\$&`);
|
|
63
61
|
}
|
|
62
|
+
async function readJSON(path) {
|
|
63
|
+
return JSON.parse(await readFile(path, "utf8"));
|
|
64
|
+
}
|
|
65
|
+
async function writeJSON(path, data) {
|
|
66
|
+
return await writeFile(path, JSON.stringify(data, null, 2), "utf8");
|
|
67
|
+
}
|
|
64
68
|
function pathRegExp(string) {
|
|
65
69
|
if (isWindows) string = string.replace(/\\/g, "/");
|
|
66
70
|
let escaped = escapeRegExp(string);
|
|
@@ -95,17 +99,17 @@ async function traceNodeModules(input, opts) {
|
|
|
95
99
|
...opts.nft
|
|
96
100
|
});
|
|
97
101
|
await opts?.hooks?.traceResult?.(traceResult);
|
|
98
|
-
const _resolveTracedPath = (p) => promises.realpath(resolve(opts.nft?.base || "/", p));
|
|
102
|
+
const _resolveTracedPath = (p) => promises.realpath(resolve(opts.nft?.base || "/", p)).then((p$1) => normalize(p$1));
|
|
99
103
|
const tracedFiles = Object.fromEntries(await Promise.all([...traceResult.reasons.entries()].map(async ([_path, reasons]) => {
|
|
100
104
|
if (reasons.ignored) return;
|
|
101
|
-
const path
|
|
102
|
-
if (!path
|
|
103
|
-
if (!await isFile(path
|
|
104
|
-
const { dir: baseDir, name: pkgName, subpath } = parseNodeModulePath(path
|
|
105
|
+
const path = await _resolveTracedPath(_path);
|
|
106
|
+
if (!path.includes("node_modules")) return;
|
|
107
|
+
if (!await isFile(path)) return;
|
|
108
|
+
const { dir: baseDir, name: pkgName, subpath } = parseNodeModulePath(path);
|
|
105
109
|
if (!baseDir || !pkgName) return;
|
|
106
|
-
const pkgPath = join
|
|
107
|
-
return [path
|
|
108
|
-
path
|
|
110
|
+
const pkgPath = join(baseDir, pkgName);
|
|
111
|
+
return [path, {
|
|
112
|
+
path,
|
|
109
113
|
parents: await Promise.all([...reasons.parents].map((p) => _resolveTracedPath(p))),
|
|
110
114
|
subpath,
|
|
111
115
|
pkgName,
|
|
@@ -114,14 +118,20 @@ async function traceNodeModules(input, opts) {
|
|
|
114
118
|
})).then((r) => r.filter(Boolean)));
|
|
115
119
|
await opts?.hooks?.tracedFiles?.(tracedFiles);
|
|
116
120
|
const tracedPackages = {};
|
|
121
|
+
const pkgCache = /* @__PURE__ */ new Map();
|
|
117
122
|
for (const tracedFile of Object.values(tracedFiles)) {
|
|
118
123
|
const pkgName = tracedFile.pkgName;
|
|
119
124
|
let tracedPackage = tracedPackages[pkgName];
|
|
120
|
-
let pkgJSON =
|
|
121
|
-
if (!pkgJSON)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
+
let pkgJSON = pkgCache.get(tracedFile.pkgPath);
|
|
126
|
+
if (!pkgJSON) {
|
|
127
|
+
pkgJSON = await readJSON(join(tracedFile.pkgPath, "package.json")).catch(() => {
|
|
128
|
+
return {
|
|
129
|
+
name: pkgName,
|
|
130
|
+
version: "0.0.0"
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
pkgCache.set(tracedFile.pkgPath, pkgJSON);
|
|
134
|
+
}
|
|
125
135
|
if (!tracedPackage) {
|
|
126
136
|
tracedPackage = {
|
|
127
137
|
name: pkgName,
|
|
@@ -163,7 +173,7 @@ async function traceNodeModules(input, opts) {
|
|
|
163
173
|
}
|
|
164
174
|
const pkgJSON = pkg.versions[version].pkgJSON;
|
|
165
175
|
applyProductionCondition(pkgJSON.exports);
|
|
166
|
-
const pkgJSONPath = join
|
|
176
|
+
const pkgJSONPath = join(outDir, pkgPath, "package.json");
|
|
167
177
|
await promises.mkdir(dirname(pkgJSONPath), { recursive: true });
|
|
168
178
|
await promises.writeFile(pkgJSONPath, JSON.stringify(pkgJSON, null, 2), "utf8");
|
|
169
179
|
if (opts.traceAlias && opts.traceAlias[pkgPath]) {
|
|
@@ -172,8 +182,8 @@ async function traceNodeModules(input, opts) {
|
|
|
172
182
|
}
|
|
173
183
|
};
|
|
174
184
|
const linkPackage = async (from, to) => {
|
|
175
|
-
const src = join
|
|
176
|
-
const dst = join
|
|
185
|
+
const src = join(outDir, from);
|
|
186
|
+
const dst = join(outDir, to);
|
|
177
187
|
if ((await promises.lstat(dst).catch(() => null))?.isSymbolicLink()) return;
|
|
178
188
|
await promises.mkdir(dirname(dst), { recursive: true });
|
|
179
189
|
await promises.symlink(relative(dirname(dst), src), dst, isWindows ? "junction" : "dir").catch((error) => {
|
|
@@ -181,7 +191,7 @@ async function traceNodeModules(input, opts) {
|
|
|
181
191
|
});
|
|
182
192
|
};
|
|
183
193
|
const findPackageParents = (pkg, version) => {
|
|
184
|
-
const versionFiles = pkg.versions[version].files.map((path
|
|
194
|
+
const versionFiles = pkg.versions[version].files.map((path) => tracedFiles[path]);
|
|
185
195
|
return [...new Set(versionFiles.flatMap((file) => file.parents.map((parentPath) => {
|
|
186
196
|
const parentFile = tracedFiles[parentPath];
|
|
187
197
|
if (!parentFile || parentFile.pkgName === pkg.name) return null;
|
|
@@ -219,7 +229,7 @@ async function traceNodeModules(input, opts) {
|
|
|
219
229
|
}
|
|
220
230
|
}
|
|
221
231
|
}
|
|
222
|
-
if (opts.writePackageJson) await
|
|
232
|
+
if (opts.writePackageJson) await writeJSON(resolve(outDir, "../package.json"), {
|
|
223
233
|
name: "traced-node-modules",
|
|
224
234
|
version: "1.0.0",
|
|
225
235
|
type: "module",
|
package/dist/index.d.mts
CHANGED
|
@@ -4,4 +4,12 @@ import { PackageJson } from "pkg-types";
|
|
|
4
4
|
//#region src/trace.d.ts
|
|
5
5
|
declare function traceNodeModules(input: string[], opts: ExternalsTraceOptions): Promise<void>;
|
|
6
6
|
//#endregion
|
|
7
|
-
|
|
7
|
+
//#region src/db.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* Known packages that include native code and require platform-specific builds.
|
|
10
|
+
*
|
|
11
|
+
* These packages cannot be bundled and should be traced as external dependencies most of the time.
|
|
12
|
+
*/
|
|
13
|
+
declare const NodeNativePackages: readonly string[];
|
|
14
|
+
//#endregion
|
|
15
|
+
export { type ExternalsTraceOptions, NodeNativePackages, traceNodeModules };
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,44 @@
|
|
|
1
1
|
import { r as traceNodeModules } from "./_chunks/trace.mjs";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
//#region src/db.ts
|
|
4
|
+
/**
|
|
5
|
+
* Known packages that include native code and require platform-specific builds.
|
|
6
|
+
*
|
|
7
|
+
* These packages cannot be bundled and should be traced as external dependencies most of the time.
|
|
8
|
+
*/
|
|
9
|
+
const NodeNativePackages = Object.freeze([
|
|
10
|
+
"canvas",
|
|
11
|
+
"sharp",
|
|
12
|
+
"gl",
|
|
13
|
+
"bcrypt",
|
|
14
|
+
"kerberos",
|
|
15
|
+
"scrypt",
|
|
16
|
+
"blake-hash",
|
|
17
|
+
"sodium-native",
|
|
18
|
+
"better-sqlite3",
|
|
19
|
+
"leveldown",
|
|
20
|
+
"lmdb",
|
|
21
|
+
"sqlite3",
|
|
22
|
+
"lz4",
|
|
23
|
+
"deasync",
|
|
24
|
+
"node-gyp",
|
|
25
|
+
"node-sass",
|
|
26
|
+
"@parcel/watcher",
|
|
27
|
+
"@parcel/source-map",
|
|
28
|
+
"@mapbox/node-pre-gyp",
|
|
29
|
+
"edge-js",
|
|
30
|
+
"fsevents",
|
|
31
|
+
"node-pty",
|
|
32
|
+
"usb",
|
|
33
|
+
"ffi-napi",
|
|
34
|
+
"ref-napi",
|
|
35
|
+
"ref-struct-napi",
|
|
36
|
+
"ref-union-napi",
|
|
37
|
+
"grpc",
|
|
38
|
+
"bufferutil",
|
|
39
|
+
"utf-8-validate",
|
|
40
|
+
"keytar"
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
export { NodeNativePackages, traceNodeModules };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __importDefault=this&&this.__importDefault||function(
|
|
1
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,`__esModule`,{value:!0}),exports.pregyp=void 0,exports.nbind=nbind;const path_1=__importDefault(require(`path`)),graceful_fs_1=__importDefault(require(`graceful-fs`)),versioning=require(`@mapbox/node-pre-gyp/lib/util/versioning.js`),napi=require(`@mapbox/node-pre-gyp/lib/util/napi.js`),pregypFind=(e,t)=>{let n=JSON.parse(graceful_fs_1.default.readFileSync(e).toString());versioning.validate_config(n,t);var r;return napi.get_napi_build_versions(n,t)&&(r=napi.get_best_napi_build_version(n,t)),t||={},t.module_root||=path_1.default.dirname(e),versioning.evaluate(n,t,r).module};exports.pregyp={default:{find:pregypFind},find:pregypFind};function makeModulePathList(e,t){return[[e,t],[e,`build`,t],[e,`build`,`Debug`,t],[e,`build`,`Release`,t],[e,`out`,`Debug`,t],[e,`Debug`,t],[e,`out`,`Release`,t],[e,`Release`,t],[e,`build`,`default`,t],[e,process.env.NODE_BINDINGS_COMPILED_DIR||`compiled`,process.versions.node,process.platform,process.arch,t]]}function findCompiledModule(basePath,specList){for(var resolvedList=[],ext=path_1.default.extname(basePath),_i=0,specList_1=specList;_i<specList_1.length;_i++){var spec=specList_1[_i];if(ext==spec.ext)try{return spec.path=eval(`require.resolve(basePath)`),spec}catch{resolvedList.push(basePath)}}for(var _a=0,specList_2=specList;_a<specList_2.length;_a++)for(var spec=specList_2[_a],_b=0,_c=makeModulePathList(basePath,spec.name);_b<_c.length;_b++){var pathParts=_c[_b],resolvedPath=path_1.default.resolve.apply(path_1.default,pathParts);try{spec.path=eval(`require.resolve(resolvedPath)`)}catch{resolvedList.push(resolvedPath);continue}return spec}return null}function nbind(e=process.cwd()){return findCompiledModule(e,[{ext:`.node`,name:`nbind.node`,type:`node`},{ext:`.js`,name:`nbind.js`,type:`emcc`}])}
|
package/dist/plugin.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as isAbsolute, o as resolve } from "./_chunks/libs/pathe.mjs";
|
|
2
|
-
import { t as resolveModulePath } from "./_chunks/libs/exsolve.mjs";
|
|
3
2
|
import { a as pathRegExp, i as guessSubpath, o as toImport, s as toPathRegExp, t as DEFAULT_CONDITIONS } from "./_chunks/trace.mjs";
|
|
3
|
+
import { t as resolveModulePath } from "./_chunks/libs/exsolve.mjs";
|
|
4
4
|
import { builtinModules } from "node:module";
|
|
5
5
|
import { pathToFileURL } from "node:url";
|
|
6
6
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nf3",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": "unjs/nf3",
|
|
6
6
|
"license": "MIT",
|
|
@@ -26,26 +26,26 @@
|
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
29
|
-
"@types/node": "^
|
|
29
|
+
"@types/node": "^25.0.3",
|
|
30
30
|
"@types/semver": "^7.7.1",
|
|
31
31
|
"@vercel/nft": "^1.1.1",
|
|
32
|
-
"@vitest/coverage-v8": "^4.0.
|
|
32
|
+
"@vitest/coverage-v8": "^4.0.16",
|
|
33
33
|
"automd": "^0.4.2",
|
|
34
34
|
"changelogen": "^0.6.2",
|
|
35
|
-
"eslint": "^9.39.
|
|
36
|
-
"eslint-config-unjs": "^0.
|
|
35
|
+
"eslint": "^9.39.2",
|
|
36
|
+
"eslint-config-unjs": "^0.6.2",
|
|
37
37
|
"exsolve": "^1.0.8",
|
|
38
|
-
"obuild": "^0.4.
|
|
39
|
-
"oxc-minify": "^0.
|
|
38
|
+
"obuild": "^0.4.10",
|
|
39
|
+
"oxc-minify": "^0.107.0",
|
|
40
40
|
"pathe": "^2.0.3",
|
|
41
41
|
"pkg-types": "^2.3.0",
|
|
42
42
|
"prettier": "^3.7.4",
|
|
43
|
-
"rolldown": "^1.0.0-beta.
|
|
44
|
-
"rollup": "^4.
|
|
43
|
+
"rolldown": "^1.0.0-beta.58",
|
|
44
|
+
"rollup": "^4.55.1",
|
|
45
45
|
"rollup-plugin-esbuild": "^6.2.1",
|
|
46
46
|
"semver": "^7.7.3",
|
|
47
47
|
"typescript": "^5.9.3",
|
|
48
|
-
"vitest": "^4.0.
|
|
48
|
+
"vitest": "^4.0.16"
|
|
49
49
|
},
|
|
50
|
-
"packageManager": "pnpm@10.
|
|
50
|
+
"packageManager": "pnpm@10.27.0"
|
|
51
51
|
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
const b=/^(?:( )+|\t+)/,d=`space`;function g(n,a){let o=new Map,s=0,c,l;for(let u of n.split(/\n/g)){if(!u)continue;let n,f,p,y,D,O=u.match(b);if(O===null)s=0,c=``;else{if(n=O[0].length,f=O[1]?d:`tab`,a&&f===d&&n===1)continue;f!==c&&(s=0),c=f,p=1,y=0;let e=n-s;if(s=n,e===0)p=0,y=1;else{let t=e>0?e:-e;l=T(f,t)}D=o.get(l),D=D===void 0?[1,0]:[D[0]+p,D[1]+y],o.set(l,D)}}return o}function T(e,n){return(e===d?`s`:`t`)+String(n)}function w(e){return{type:e[0]===`s`?d:`tab`,amount:Number(e.slice(1))}}function E(e){let t,n=0,i=0;for(let[a,[o,s]]of e)(o>n||o===n&&s>i)&&(n=o,i=s,t=a);return t}function S$1(e,n){return(e===d?` `:` `).repeat(n)}function _(e){if(typeof e!=`string`)throw TypeError(`Expected a string`);let t=g(e,!0);t.size===0&&(t=g(e,!1));let i=E(t),c,l=0,u=``;return i!==void 0&&({type:c,amount:l}=w(i),u=S$1(c,l)),{amount:l,type:c,indent:u}}const m=Symbol.for(`__confbox_fmt__`),k=/^(\s+)/,v=/(\s+)$/;function x$1(e,t={}){return{sample:t.indent===void 0&&t.preserveIndentation!==!1&&e.slice(0,t?.sampleSize||1024),whiteSpace:t.preserveWhitespace===!1?void 0:{start:k.exec(e)?.[0]||``,end:v.exec(e)?.[0]||``}}}function N(e,t,n){!t||typeof t!=`object`||Object.defineProperty(t,m,{enumerable:!1,configurable:!0,writable:!0,value:x$1(e,n)})}function C(e,t){if(!e||typeof e!=`object`||!(m in e))return{indent:t?.indent??2,whitespace:{start:``,end:``}};let n=e[m];return{indent:t?.indent||_(n.sample||``).indent,whitespace:n.whiteSpace||{start:``,end:``}}}function $(e,t=!1){let n=e.length,i=0,a=``,o=0,s=16,c=0,l=0,u=0,f=0,p=0;function y(t,n){let a=0,o=0;for(;a<t;){let t=e.charCodeAt(i);if(t>=48&&t<=57)o=o*16+t-48;else if(t>=65&&t<=70)o=o*16+t-65+10;else if(t>=97&&t<=102)o=o*16+t-97+10;else break;i++,a++}return a<t&&(o=-1),o}function D(e){i=e,a=``,o=0,s=16,p=0}function O(){let t=i;if(e.charCodeAt(i)===48)i++;else for(i++;i<e.length&&L(e.charCodeAt(i));)i++;if(i<e.length&&e.charCodeAt(i)===46)if(i++,i<e.length&&L(e.charCodeAt(i)))for(i++;i<e.length&&L(e.charCodeAt(i));)i++;else return p=3,e.substring(t,i);let n=i;if(i<e.length&&(e.charCodeAt(i)===69||e.charCodeAt(i)===101))if(i++,(i<e.length&&e.charCodeAt(i)===43||e.charCodeAt(i)===45)&&i++,i<e.length&&L(e.charCodeAt(i))){for(i++;i<e.length&&L(e.charCodeAt(i));)i++;n=i}else p=3;return e.substring(t,n)}function M(){let t=``,a=i;for(;;){if(i>=n){t+=e.substring(a,i),p=2;break}let o=e.charCodeAt(i);if(o===34){t+=e.substring(a,i),i++;break}if(o===92){if(t+=e.substring(a,i),i++,i>=n){p=2;break}switch(e.charCodeAt(i++)){case 34:t+=`"`;break;case 92:t+=`\\`;break;case 47:t+=`/`;break;case 98:t+=`\b`;break;case 102:t+=`\f`;break;case 110:t+=`
|
|
2
|
-
`;break;case 114:t+=`\r`;break;case 116:t+=` `;break;case 117:let e=y(4);e>=0?t+=String.fromCharCode(e):p=4;break;default:p=5}a=i;continue}if(o>=0&&o<=31)if(r(o)){t+=e.substring(a,i),p=2;break}else p=6;i++}return t}function F(){if(a=``,p=0,o=i,l=c,f=u,i>=n)return o=n,s=17;let t=e.charCodeAt(i);if(J(t)){do i++,a+=String.fromCharCode(t),t=e.charCodeAt(i);while(J(t));return s=15}if(r(t))return i++,a+=String.fromCharCode(t),t===13&&e.charCodeAt(i)===10&&(i++,a+=`
|
|
3
|
-
`),c++,u=i,s=14;switch(t){case 123:return i++,s=1;case 125:return i++,s=2;case 91:return i++,s=3;case 93:return i++,s=4;case 58:return i++,s=6;case 44:return i++,s=5;case 34:return i++,a=M(),s=10;case 47:let l=i-1;if(e.charCodeAt(i+1)===47){for(i+=2;i<n&&!r(e.charCodeAt(i));)i++;return a=e.substring(l,i),s=12}if(e.charCodeAt(i+1)===42){i+=2;let t=n-1,o=!1;for(;i<t;){let t=e.charCodeAt(i);if(t===42&&e.charCodeAt(i+1)===47){i+=2,o=!0;break}i++,r(t)&&(t===13&&e.charCodeAt(i)===10&&i++,c++,u=i)}return o||(i++,p=1),a=e.substring(l,i),s=13}return a+=String.fromCharCode(t),i++,s=16;case 45:if(a+=String.fromCharCode(t),i++,i===n||!L(e.charCodeAt(i)))return s=16;case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return a+=O(),s=11;default:for(;i<n&&I(t);)i++,t=e.charCodeAt(i);if(o!==i){switch(a=e.substring(o,i),a){case`true`:return s=8;case`false`:return s=9;case`null`:return s=7}return s=16}return a+=String.fromCharCode(t),i++,s=16}}function I(e){if(J(e)||r(e))return!1;switch(e){case 125:case 93:case 123:case 91:case 34:case 58:case 44:case 47:return!1}return!0}function R(){let e;do e=F();while(e>=12&&e<=15);return e}return{setPosition:D,getPosition:()=>i,scan:t?R:F,getToken:()=>s,getTokenValue:()=>a,getTokenOffset:()=>o,getTokenLength:()=>i-o,getTokenStartLine:()=>l,getTokenStartCharacter:()=>o-f,getTokenError:()=>p}}function J(e){return e===32||e===9}function r(e){return e===10||e===13}function L(e){return e>=48&&e<=57}var Q;(function(e){e[e.lineFeed=10]=`lineFeed`,e[e.carriageReturn=13]=`carriageReturn`,e[e.space=32]=`space`,e[e._0=48]=`_0`,e[e._1=49]=`_1`,e[e._2=50]=`_2`,e[e._3=51]=`_3`,e[e._4=52]=`_4`,e[e._5=53]=`_5`,e[e._6=54]=`_6`,e[e._7=55]=`_7`,e[e._8=56]=`_8`,e[e._9=57]=`_9`,e[e.a=97]=`a`,e[e.b=98]=`b`,e[e.c=99]=`c`,e[e.d=100]=`d`,e[e.e=101]=`e`,e[e.f=102]=`f`,e[e.g=103]=`g`,e[e.h=104]=`h`,e[e.i=105]=`i`,e[e.j=106]=`j`,e[e.k=107]=`k`,e[e.l=108]=`l`,e[e.m=109]=`m`,e[e.n=110]=`n`,e[e.o=111]=`o`,e[e.p=112]=`p`,e[e.q=113]=`q`,e[e.r=114]=`r`,e[e.s=115]=`s`,e[e.t=116]=`t`,e[e.u=117]=`u`,e[e.v=118]=`v`,e[e.w=119]=`w`,e[e.x=120]=`x`,e[e.y=121]=`y`,e[e.z=122]=`z`,e[e.A=65]=`A`,e[e.B=66]=`B`,e[e.C=67]=`C`,e[e.D=68]=`D`,e[e.E=69]=`E`,e[e.F=70]=`F`,e[e.G=71]=`G`,e[e.H=72]=`H`,e[e.I=73]=`I`,e[e.J=74]=`J`,e[e.K=75]=`K`,e[e.L=76]=`L`,e[e.M=77]=`M`,e[e.N=78]=`N`,e[e.O=79]=`O`,e[e.P=80]=`P`,e[e.Q=81]=`Q`,e[e.R=82]=`R`,e[e.S=83]=`S`,e[e.T=84]=`T`,e[e.U=85]=`U`,e[e.V=86]=`V`,e[e.W=87]=`W`,e[e.X=88]=`X`,e[e.Y=89]=`Y`,e[e.Z=90]=`Z`,e[e.asterisk=42]=`asterisk`,e[e.backslash=92]=`backslash`,e[e.closeBrace=125]=`closeBrace`,e[e.closeBracket=93]=`closeBracket`,e[e.colon=58]=`colon`,e[e.comma=44]=`comma`,e[e.dot=46]=`dot`,e[e.doubleQuote=34]=`doubleQuote`,e[e.minus=45]=`minus`,e[e.openBrace=123]=`openBrace`,e[e.openBracket=91]=`openBracket`,e[e.plus=43]=`plus`,e[e.slash=47]=`slash`,e[e.formFeed=12]=`formFeed`,e[e.tab=9]=`tab`})(Q||={}),Array(20).fill(0).map((e,t)=>` `.repeat(t)),Array(200).fill(0).map((e,t)=>`
|
|
4
|
-
`+` `.repeat(t)),Array(200).fill(0).map((e,t)=>`\r`+` `.repeat(t)),Array(200).fill(0).map((e,t)=>`\r
|
|
5
|
-
`+` `.repeat(t)),Array(200).fill(0).map((e,t)=>`
|
|
6
|
-
`+` `.repeat(t)),Array(200).fill(0).map((e,t)=>`\r`+` `.repeat(t)),Array(200).fill(0).map((e,t)=>`\r
|
|
7
|
-
`+` `.repeat(t));var U;(function(e){e.DEFAULT={allowTrailingComma:!1}})(U||={});function S(e,t=[],n=U.DEFAULT){let i=null,a=[],o=[];function s(e){Array.isArray(a)?a.push(e):i!==null&&(a[i]=e)}return P(e,{onObjectBegin:()=>{let e={};s(e),o.push(a),a=e,i=null},onObjectProperty:e=>{i=e},onObjectEnd:()=>{a=o.pop()},onArrayBegin:()=>{let e=[];s(e),o.push(a),a=e,i=null},onArrayEnd:()=>{a=o.pop()},onLiteralValue:s,onError:(e,n,i)=>{t.push({error:e,offset:n,length:i})}},n),a[0]}function P(e,t,n=U.DEFAULT){let i=$(e,!1),a=[],o=0;function s(e){return e?()=>o===0&&e(i.getTokenOffset(),i.getTokenLength(),i.getTokenStartLine(),i.getTokenStartCharacter()):()=>!0}function c(e){return e?t=>o===0&&e(t,i.getTokenOffset(),i.getTokenLength(),i.getTokenStartLine(),i.getTokenStartCharacter()):()=>!0}function l(e){return e?t=>o===0&&e(t,i.getTokenOffset(),i.getTokenLength(),i.getTokenStartLine(),i.getTokenStartCharacter(),()=>a.slice()):()=>!0}function u(e){return e?()=>{o>0?o++:e(i.getTokenOffset(),i.getTokenLength(),i.getTokenStartLine(),i.getTokenStartCharacter(),()=>a.slice())===!1&&(o=1)}:()=>!0}function f(e){return e?()=>{o>0&&o--,o===0&&e(i.getTokenOffset(),i.getTokenLength(),i.getTokenStartLine(),i.getTokenStartCharacter())}:()=>!0}let p=u(t.onObjectBegin),y=l(t.onObjectProperty),D=f(t.onObjectEnd),A=u(t.onArrayBegin),ee=f(t.onArrayEnd),j=l(t.onLiteralValue),M=c(t.onSeparator),I=s(t.onComment),R=c(t.onError),B=n&&n.disallowComments,V=n&&n.allowTrailingComma;function G(){for(;;){let e=i.scan();switch(i.getTokenError()){case 4:Y(14);break;case 5:Y(15);break;case 3:Y(13);break;case 1:B||Y(11);break;case 2:Y(12);break;case 6:Y(16);break}switch(e){case 12:case 13:B?Y(10):I();break;case 16:Y(1);break;case 15:case 14:break;default:return e}}}function Y(e,t=[],n=[]){if(R(e),t.length+n.length>0){let e=i.getToken();for(;e!==17;){if(t.indexOf(e)!==-1){G();break}else if(n.indexOf(e)!==-1)break;e=G()}}}function X(e){let t=i.getTokenValue();return e?j(t):(y(t),a.push(t)),G(),!0}function te(){switch(i.getToken()){case 11:let e=i.getTokenValue(),t=Number(e);isNaN(t)&&(Y(2),t=0),j(t);break;case 7:j(null);break;case 8:j(!0);break;case 9:j(!1);break;default:return!1}return G(),!0}function ne(){return i.getToken()===10?(X(!1),i.getToken()===6?(M(`:`),G(),Z()||Y(4,[],[2,5])):Y(5,[],[2,5]),a.pop(),!0):(Y(3,[],[2,5]),!1)}function re(){p(),G();let e=!1;for(;i.getToken()!==2&&i.getToken()!==17;){if(i.getToken()===5){if(e||Y(4,[],[]),M(`,`),G(),i.getToken()===2&&V)break}else e&&Y(6,[],[]);ne()||Y(4,[],[2,5]),e=!0}return D(),i.getToken()===2?G():Y(7,[2],[]),!0}function ie(){A(),G();let e=!0,t=!1;for(;i.getToken()!==4&&i.getToken()!==17;){if(i.getToken()===5){if(t||Y(4,[],[]),M(`,`),G(),i.getToken()===4&&V)break}else t&&Y(6,[],[]);e?(a.push(0),e=!1):a[a.length-1]++,Z()||Y(4,[],[4,5]),t=!0}return ee(),e||a.pop(),i.getToken()===4?G():Y(8,[4],[]),!0}function Z(){switch(i.getToken()){case 3:return ie();case 1:return re();case 10:return X(!0);default:return te()}}return G(),i.getToken()===17?n.allowEmptyContent?!0:(Y(4,[],[]),!1):Z()?(i.getToken()!==17&&Y(9,[],[]),!0):(Y(4,[],[]),!1)}var W;(function(e){e[e.None=0]=`None`,e[e.UnexpectedEndOfComment=1]=`UnexpectedEndOfComment`,e[e.UnexpectedEndOfString=2]=`UnexpectedEndOfString`,e[e.UnexpectedEndOfNumber=3]=`UnexpectedEndOfNumber`,e[e.InvalidUnicode=4]=`InvalidUnicode`,e[e.InvalidEscapeCharacter=5]=`InvalidEscapeCharacter`,e[e.InvalidCharacter=6]=`InvalidCharacter`})(W||={});var H;(function(e){e[e.OpenBraceToken=1]=`OpenBraceToken`,e[e.CloseBraceToken=2]=`CloseBraceToken`,e[e.OpenBracketToken=3]=`OpenBracketToken`,e[e.CloseBracketToken=4]=`CloseBracketToken`,e[e.CommaToken=5]=`CommaToken`,e[e.ColonToken=6]=`ColonToken`,e[e.NullKeyword=7]=`NullKeyword`,e[e.TrueKeyword=8]=`TrueKeyword`,e[e.FalseKeyword=9]=`FalseKeyword`,e[e.StringLiteral=10]=`StringLiteral`,e[e.NumericLiteral=11]=`NumericLiteral`,e[e.LineCommentTrivia=12]=`LineCommentTrivia`,e[e.BlockCommentTrivia=13]=`BlockCommentTrivia`,e[e.LineBreakTrivia=14]=`LineBreakTrivia`,e[e.Trivia=15]=`Trivia`,e[e.Unknown=16]=`Unknown`,e[e.EOF=17]=`EOF`})(H||={});const K=S;var q;(function(e){e[e.InvalidSymbol=1]=`InvalidSymbol`,e[e.InvalidNumberFormat=2]=`InvalidNumberFormat`,e[e.PropertyNameExpected=3]=`PropertyNameExpected`,e[e.ValueExpected=4]=`ValueExpected`,e[e.ColonExpected=5]=`ColonExpected`,e[e.CommaExpected=6]=`CommaExpected`,e[e.CloseBraceExpected=7]=`CloseBraceExpected`,e[e.CloseBracketExpected=8]=`CloseBracketExpected`,e[e.EndOfFileExpected=9]=`EndOfFileExpected`,e[e.InvalidCommentToken=10]=`InvalidCommentToken`,e[e.UnexpectedEndOfComment=11]=`UnexpectedEndOfComment`,e[e.UnexpectedEndOfString=12]=`UnexpectedEndOfString`,e[e.UnexpectedEndOfNumber=13]=`UnexpectedEndOfNumber`,e[e.InvalidUnicode=14]=`InvalidUnicode`,e[e.InvalidEscapeCharacter=15]=`InvalidEscapeCharacter`,e[e.InvalidCharacter=16]=`InvalidCharacter`})(q||={});function x(e,t){let n=JSON.parse(e,t?.reviver);return N(e,n,t),n}function z(e,t){let n=C(e,t),i=JSON.stringify(e,t?.replacer,n.indent);return n.whitespace.start+i+n.whitespace.end}function h(e,t){let n=K(e,t?.errors,t);return N(e,n,t),n}export{x as n,z as r,h as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{i as normalize,n as isAbsolute,o as resolve,r as join}from"./pathe.mjs";import{n as x,r as z,t as h}from"./confbox.mjs";import{t as resolveModulePath}from"./exsolve.mjs";import{promises,statSync}from"node:fs";import{fileURLToPath}from"node:url";import"node:fs/promises";const defaultFindOptions={startingFrom:`.`,rootPattern:/^node_modules$/,reverse:!1,test:e=>{try{if(statSync(e).isFile())return!0}catch{}}};async function findFile(e,u={}){let p=Array.isArray(e)?e:[e],m={...defaultFindOptions,...u},g=resolve(m.startingFrom),_=g[0]===`/`,v=g.split(`/`).filter(Boolean);if(p.includes(v.at(-1))&&await m.test(g))return g;_&&(v[0]=`/`+v[0]);let y=v.findIndex(e=>e.match(m.rootPattern));if(y===-1&&(y=0),m.reverse)for(let e=y+1;e<=v.length;e++)for(let u of p){let d=join(...v.slice(0,e),u);if(await m.test(d))return d}else for(let e=v.length;e>y;e--)for(let u of p){let d=join(...v.slice(0,e),u);if(await m.test(d))return d}throw Error(`Cannot find matching ${e} in ${m.startingFrom} or parent directories`)}function findNearestFile(e,u={}){return findFile(e,u)}function _resolvePath(d,f={}){return d instanceof URL||d.startsWith(`file://`)?normalize(fileURLToPath(d)):isAbsolute(d)?normalize(d):resolveModulePath(d,{...f,from:f.from||f.parent||f.url})}const FileCache=new Map;async function readPackageJSON(e,u={}){let d=await resolvePackageJSON(e,u),f=u.cache&&typeof u.cache!=`boolean`?u.cache:FileCache;if(u.cache&&f.has(d))return f.get(d);let m=await promises.readFile(d,`utf8`),_;try{_=x(m)}catch{_=h(m)}return f.set(d,_),_}async function writePackageJSON(e,u){await promises.writeFile(e,z(u))}async function resolvePackageJSON(e=process.cwd(),u={}){return findNearestFile(`package.json`,{...u,startingFrom:_resolvePath(e,u)})}export{writePackageJSON as n,readPackageJSON as t};
|