diff --git a/.pnp.cjs b/.pnp.cjs index 604ccdb..c5e453d 100644 --- a/.pnp.cjs +++ b/.pnp.cjs @@ -2961,7 +2961,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { ["assertion-error", "npm:1.1.0"],\ ["check-error", "npm:1.0.2"],\ ["deep-eql", "npm:4.1.3"],\ - ["get-func-name", "npm:2.0.0"],\ + ["get-func-name", "npm:2.0.2"],\ ["loupe", "npm:2.3.6"],\ ["pathval", "npm:1.1.1"],\ ["type-detect", "npm:4.0.8"]\ @@ -3534,10 +3534,10 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { }]\ ]],\ ["get-func-name", [\ - ["npm:2.0.0", {\ - "packageLocation": "./.yarn/cache/get-func-name-npm-2.0.0-afbf363765-8d82e69f3e.zip/node_modules/get-func-name/",\ + ["npm:2.0.2", {\ + "packageLocation": "./.yarn/cache/get-func-name-npm-2.0.2-409dbe3703-3f62f4c236.zip/node_modules/get-func-name/",\ "packageDependencies": [\ - ["get-func-name", "npm:2.0.0"]\ + ["get-func-name", "npm:2.0.2"]\ ],\ "linkType": "HARD"\ }]\ @@ -3971,7 +3971,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { "packageLocation": "./.yarn/cache/loupe-npm-2.3.6-b8b37d55e7-cc83f1b124.zip/node_modules/loupe/",\ "packageDependencies": [\ ["loupe", "npm:2.3.6"],\ - ["get-func-name", "npm:2.0.0"]\ + ["get-func-name", "npm:2.0.2"]\ ],\ "linkType": "HARD"\ }]\ @@ -13844,7 +13844,6 @@ function reportRequiredFilesToWatchMode(files) { } function applyPatch(pnpapi, opts) { - const defaultCache = {}; let enableNativeHooks = true; process.versions.pnp = String(pnpapi.VERSIONS.std); const moduleExports = require$$0__default.default; @@ -13864,62 +13863,13 @@ function applyPatch(pnpapi, opts) { } const originalModuleLoad = require$$0.Module._load; require$$0.Module._load = function(request, parent, isMain) { - if (!enableNativeHooks) - return originalModuleLoad.call(require$$0.Module, request, parent, isMain); - if (isBuiltinModule(request)) { - try { - enableNativeHooks = false; - return originalModuleLoad.call(require$$0.Module, request, parent, isMain); - } finally { - enableNativeHooks = true; - } - } - const parentApiPath = opts.manager.getApiPathFromParent(parent); - const parentApi = parentApiPath !== null ? opts.manager.getApiEntry(parentApiPath, true).instance : null; - if (parentApi === null) - return originalModuleLoad(request, parent, isMain); - if (request === `pnpapi`) - return parentApi; - const modulePath = require$$0.Module._resolveFilename(request, parent, isMain); - const isOwnedByRuntime = parentApi !== null ? parentApi.findPackageLocator(modulePath) !== null : false; - const moduleApiPath = isOwnedByRuntime ? parentApiPath : opts.manager.findApiPathFor(npath.dirname(modulePath)); - const entry = moduleApiPath !== null ? opts.manager.getApiEntry(moduleApiPath) : { instance: null, cache: defaultCache }; - const cacheEntry = entry.cache[modulePath]; - if (cacheEntry) { - if (cacheEntry.loaded === false && cacheEntry.isLoading !== true) { - try { - cacheEntry.isLoading = true; - if (isMain) { - process.mainModule = cacheEntry; - cacheEntry.id = `.`; - } - cacheEntry.load(modulePath); - } finally { - cacheEntry.isLoading = false; - } + if (request === `pnpapi`) { + const parentApiPath = opts.manager.getApiPathFromParent(parent); + if (parentApiPath) { + return opts.manager.getApiEntry(parentApiPath, true).instance; } - return cacheEntry.exports; } - const module = new require$$0.Module(modulePath, parent != null ? parent : void 0); - module.pnpApiPath = moduleApiPath; - reportRequiredFilesToWatchMode([modulePath]); - entry.cache[modulePath] = module; - if (isMain) { - process.mainModule = module; - module.id = `.`; - } - let hasThrown = true; - try { - module.isLoading = true; - module.load(modulePath); - hasThrown = false; - } finally { - module.isLoading = false; - if (hasThrown) { - delete require$$0.Module._cache[modulePath]; - } - } - return module.exports; + return originalModuleLoad.call(require$$0.Module, request, parent, isMain); }; function getIssuerSpecsFromPaths(paths) { return paths.map((path) => ({ @@ -13987,7 +13937,7 @@ function applyPatch(pnpapi, opts) { const parentDirectory = (parent == null ? void 0 : parent.filename) != null ? npath.dirname(parent.filename) : null; const absoluteRequest = npath.isAbsolute(request) ? request : parentDirectory !== null ? npath.resolve(parentDirectory, request) : null; if (absoluteRequest !== null) { - const apiPath = parentDirectory === npath.dirname(absoluteRequest) && (parent == null ? void 0 : parent.pnpApiPath) ? parent.pnpApiPath : opts.manager.findApiPathFor(absoluteRequest); + const apiPath = parent && parentDirectory === npath.dirname(absoluteRequest) ? opts.manager.getApiPathFromParent(parent) : opts.manager.findApiPathFor(absoluteRequest); if (apiPath !== null) { issuerSpecs.unshift({ apiPath, @@ -14146,118 +14096,6 @@ function hydrateRuntimeState(data, { basePath }) { }; } -/** - * @param {object} exports - * @param {Set} keys - */ -function loop(exports, keys) { - if (typeof exports === 'string') { - return exports; - } - - if (exports) { - let idx, tmp; - if (Array.isArray(exports)) { - for (idx=0; idx < exports.length; idx++) { - if (tmp = loop(exports[idx], keys)) return tmp; - } - } else { - for (idx in exports) { - if (keys.has(idx)) { - return loop(exports[idx], keys); - } - } - } - } -} - -/** - * @param {string} name The package name - * @param {string} entry The target entry, eg "." - * @param {number} [condition] Unmatched condition? - */ -function bail(name, entry, condition) { - throw new Error( - condition - ? `No known conditions for "${entry}" entry in "${name}" package` - : `Missing "${entry}" export in "${name}" package` - ); -} - -/** - * @param {string} name the package name - * @param {string} entry the target path/import - */ -function toName(name, entry) { - return entry === name ? '.' - : entry[0] === '.' ? entry - : entry.replace(new RegExp('^' + name + '\/'), './'); -} - -/** - * @param {object} pkg package.json contents - * @param {string} [entry] entry name or import path - * @param {object} [options] - * @param {boolean} [options.browser] - * @param {boolean} [options.require] - * @param {string[]} [options.conditions] - * @param {boolean} [options.unsafe] - */ -function resolve(pkg, entry='.', options={}) { - let { name, exports } = pkg; - - if (exports) { - let { browser, require, unsafe, conditions=[] } = options; - - let target = toName(name, entry); - if (target[0] !== '.') target = './' + target; - - if (typeof exports === 'string') { - return target === '.' ? exports : bail(name, target); - } - - let allows = new Set(['default', ...conditions]); - unsafe || allows.add(require ? 'require' : 'import'); - unsafe || allows.add(browser ? 'browser' : 'node'); - - let key, tmp, isSingle=false; - - for (key in exports) { - isSingle = key[0] !== '.'; - break; - } - - if (isSingle) { - return target === '.' - ? loop(exports, allows) || bail(name, target, 1) - : bail(name, target); - } - - if (tmp = exports[target]) { - return loop(tmp, allows) || bail(name, target, 1); - } - - for (key in exports) { - tmp = key[key.length - 1]; - if (tmp === '/' && target.startsWith(key)) { - return (tmp = loop(exports[key], allows)) - ? (tmp + target.substring(key.length)) - : bail(name, target, 1); - } - if (tmp === '*' && target.startsWith(key.slice(0, -1))) { - // do not trigger if no *content* to inject - if (target.substring(key.length - 1).length > 0) { - return (tmp = loop(exports[key], allows)) - ? tmp.replace('*', target.substring(key.length - 1)) - : bail(name, target, 1); - } - } - } - - return bail(name, target); - } -} - const ArrayIsArray = Array.isArray; const JSONStringify = JSON.stringify; const ObjectGetOwnPropertyNames = Object.getOwnPropertyNames; @@ -14318,6 +14156,15 @@ const ERR_INVALID_PACKAGE_CONFIG = createErrorType( }, Error ); +const ERR_PACKAGE_PATH_NOT_EXPORTED = createErrorType( + "ERR_PACKAGE_PATH_NOT_EXPORTED", + (pkgPath, subpath, base = void 0) => { + if (subpath === ".") + return `No "exports" main defined in ${pkgPath}package.json${base ? ` imported from ${base}` : ""}`; + return `Package subpath '${subpath}' is not defined by "exports" in ${pkgPath}package.json${base ? ` imported from ${base}` : ""}`; + }, + Error +); function filterOwnProperties(source, keys) { const filtered = /* @__PURE__ */ Object.create(null); @@ -14637,12 +14484,121 @@ function patternKeyCompare(a, b) { return 1; return 0; } -function packageImportsResolve({ - name, +function isConditionalExportsMainSugar(exports, packageJSONUrl, base) { + if (typeof exports === "string" || ArrayIsArray(exports)) + return true; + if (typeof exports !== "object" || exports === null) + return false; + const keys = ObjectGetOwnPropertyNames(exports); + let isConditionalSugar = false; + let i = 0; + for (let j = 0; j < keys.length; j++) { + const key = keys[j]; + const curIsConditionalSugar = key === "" || key[0] !== "."; + if (i++ === 0) { + isConditionalSugar = curIsConditionalSugar; + } else if (isConditionalSugar !== curIsConditionalSugar) { + throw new ERR_INVALID_PACKAGE_CONFIG( + url.fileURLToPath(packageJSONUrl), + base, + `"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 isConditionalSugar; +} +function throwExportsNotFound(subpath, packageJSONUrl, base) { + throw new ERR_PACKAGE_PATH_NOT_EXPORTED( + url.fileURLToPath(new URL(".", packageJSONUrl)), + subpath, + base && url.fileURLToPath(base) + ); +} +const emittedPackageWarnings = /* @__PURE__ */ new Set(); +function emitTrailingSlashPatternDeprecation(match, pjsonUrl, base) { + const pjsonPath = url.fileURLToPath(pjsonUrl); + if (emittedPackageWarnings.has(pjsonPath + "|" + match)) + return; + emittedPackageWarnings.add(pjsonPath + "|" + match); + process.emitWarning( + `Use of deprecated trailing slash pattern mapping "${match}" in the "exports" field module resolution of the package at ${pjsonPath}${base ? ` imported from ${url.fileURLToPath(base)}` : ""}. Mapping specifiers ending in "/" is no longer supported.`, + "DeprecationWarning", + "DEP0155" + ); +} +function packageExportsResolve({ + packageJSONUrl, + packageSubpath, + exports, base, - conditions, - readFileSyncFn + conditions }) { + if (isConditionalExportsMainSugar(exports, packageJSONUrl, base)) + exports = { ".": exports }; + if (ObjectPrototypeHasOwnProperty(exports, packageSubpath) && !StringPrototypeIncludes(packageSubpath, "*") && !StringPrototypeEndsWith(packageSubpath, "/")) { + const target = exports[packageSubpath]; + const resolveResult = resolvePackageTarget( + packageJSONUrl, + target, + "", + packageSubpath, + base, + false, + false, + conditions + ); + if (resolveResult == null) { + throwExportsNotFound(packageSubpath, packageJSONUrl, base); + } + return resolveResult; + } + let bestMatch = ""; + let bestMatchSubpath; + const keys = ObjectGetOwnPropertyNames(exports); + for (let i = 0; i < keys.length; i++) { + const key = keys[i]; + const patternIndex = StringPrototypeIndexOf(key, "*"); + if (patternIndex !== -1 && StringPrototypeStartsWith( + packageSubpath, + StringPrototypeSlice(key, 0, patternIndex) + )) { + if (StringPrototypeEndsWith(packageSubpath, "/")) + emitTrailingSlashPatternDeprecation( + packageSubpath, + packageJSONUrl, + base + ); + const patternTrailer = StringPrototypeSlice(key, patternIndex + 1); + if (packageSubpath.length >= key.length && StringPrototypeEndsWith(packageSubpath, patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && StringPrototypeLastIndexOf(key, "*") === patternIndex) { + bestMatch = key; + bestMatchSubpath = StringPrototypeSlice( + packageSubpath, + patternIndex, + packageSubpath.length - patternTrailer.length + ); + } + } + } + if (bestMatch) { + const target = exports[bestMatch]; + const resolveResult = resolvePackageTarget( + packageJSONUrl, + target, + bestMatchSubpath, + bestMatch, + base, + true, + false, + conditions + ); + if (resolveResult == null) { + throwExportsNotFound(packageSubpath, packageJSONUrl, base); + } + return resolveResult; + } + throwExportsNotFound(packageSubpath, packageJSONUrl, base); +} +function packageImportsResolve({ name, base, conditions, readFileSyncFn }) { if (name === "#" || StringPrototypeStartsWith(name, "#/") || StringPrototypeEndsWith(name, "/")) { const reason = "is not a valid internal imports specifier name"; throw new ERR_INVALID_MODULE_SPECIFIER(name, reason, url.fileURLToPath(base)); @@ -15110,12 +15066,11 @@ function makeApi(runtimeState, opts) { return false; } const defaultExportsConditions = /* @__PURE__ */ new Set([ - `default`, `node`, `require`, ...getOptionValue(`--conditions`) ]); - function applyNodeExportsResolution(unqualifiedPath, conditions = defaultExportsConditions) { + function applyNodeExportsResolution(unqualifiedPath, conditions = defaultExportsConditions, issuer) { const locator = findPackageLocator(ppath.join(unqualifiedPath, `internal.js`), { resolveIgnored: true, includeDiscardFromLookup: true @@ -15131,6 +15086,8 @@ function makeApi(runtimeState, opts) { if (!opts.fakeFs.existsSync(manifestPath)) return null; const pkgJson = JSON.parse(opts.fakeFs.readFileSync(manifestPath, `utf8`)); + if (pkgJson.exports == null) + return null; let subpath = ppath.contains(packageLocation, unqualifiedPath); if (subpath === null) { throw makeError( @@ -15138,25 +15095,25 @@ function makeApi(runtimeState, opts) { `unqualifiedPath doesn't contain the packageLocation (this is probably an internal error)` ); } - if (!isRelativeRegexp.test(subpath)) + if (subpath !== `.` && !isRelativeRegexp.test(subpath)) subpath = `./${subpath}`; - let resolvedExport; try { - resolvedExport = resolve(pkgJson, ppath.normalize(subpath), { - conditions, - unsafe: true + const resolvedExport = packageExportsResolve({ + packageJSONUrl: url.pathToFileURL(npath.fromPortablePath(manifestPath)), + packageSubpath: subpath, + exports: pkgJson.exports, + base: issuer ? url.pathToFileURL(npath.fromPortablePath(issuer)) : null, + conditions }); + return npath.toPortablePath(url.fileURLToPath(resolvedExport)); } catch (error) { throw makeError( ErrorCode.EXPORTS_RESOLUTION_FAILED, error.message, { unqualifiedPath: getPathForDisplay(unqualifiedPath), locator, pkgJson, subpath: getPathForDisplay(subpath), conditions }, - `ERR_PACKAGE_PATH_NOT_EXPORTED` + error.code ); } - if (typeof resolvedExport === `string`) - return ppath.join(packageLocation, resolvedExport); - return null; } function applyNodeExtensionResolution(unqualifiedPath, candidates, { extensions }) { let stat; @@ -15533,10 +15490,10 @@ Required by: ${issuerLocator.name}@${issuerLocator.reference} (via ${issuerForDi } return ppath.normalize(unqualifiedPath); } - function resolveUnqualifiedExport(request, unqualifiedPath, conditions = defaultExportsConditions) { + function resolveUnqualifiedExport(request, unqualifiedPath, conditions = defaultExportsConditions, issuer) { if (isStrictRegExp.test(request)) return unqualifiedPath; - const unqualifiedExportPath = applyNodeExportsResolution(unqualifiedPath, conditions); + const unqualifiedExportPath = applyNodeExportsResolution(unqualifiedPath, conditions, issuer); if (unqualifiedExportPath) { return ppath.normalize(unqualifiedExportPath); } else { @@ -15623,7 +15580,7 @@ ${candidates.map((candidate) => `Not found: ${getPathForDisplay(candidate)} if (unqualifiedPath === null) return null; const isIssuerIgnored = () => issuer !== null ? isPathIgnored(issuer) : false; - const remappedPath = (!considerBuiltins || !isBuiltinModule(request)) && !isIssuerIgnored() ? resolveUnqualifiedExport(request, unqualifiedPath, conditions) : unqualifiedPath; + const remappedPath = (!considerBuiltins || !isBuiltinModule(request)) && !isIssuerIgnored() ? resolveUnqualifiedExport(request, unqualifiedPath, conditions, issuer) : unqualifiedPath; return resolveUnqualified(remappedPath, { extensions }); } catch (error) { if (Object.prototype.hasOwnProperty.call(error, `pnpCode`)) @@ -15701,7 +15658,6 @@ function makeManager(pnpapi, opts) { const initialApiStats = opts.fakeFs.statSync(npath.toPortablePath(initialApiPath)); const apiMetadata = /* @__PURE__ */ new Map([ [initialApiPath, { - cache: require$$0.Module._cache, instance: pnpapi, stats: initialApiStats, lastRefreshCheck: Date.now() @@ -15733,7 +15689,6 @@ function makeManager(pnpapi, opts) { } } else { apiMetadata.set(pnpApiPath, apiEntry = { - cache: {}, instance: loadApiInstance(pnpApiPath), stats: opts.fakeFs.statSync(pnpApiPath), lastRefreshCheck: Date.now() @@ -15803,19 +15758,16 @@ ${controlSegment} } while (curr !== PortablePath.root); return addToCacheAndReturn(start, curr, null); } + const moduleToApiPathCache = /* @__PURE__ */ new WeakMap(); function getApiPathFromParent(parent) { if (parent == null) return initialApiPath; - if (typeof parent.pnpApiPath === `undefined`) { - if (parent.filename !== null) { - return parent.pnpApiPath = findApiPathFor(parent.filename); - } else { - return initialApiPath; - } - } - if (parent.pnpApiPath !== null) - return parent.pnpApiPath; - return null; + let apiPath = moduleToApiPathCache.get(parent); + if (typeof apiPath !== `undefined`) + return apiPath; + apiPath = parent.filename ? findApiPathFor(parent.filename) : null; + moduleToApiPathCache.set(parent, apiPath); + return apiPath; } return { getApiPathFromParent, diff --git a/.yarn/cache/get-func-name-npm-2.0.0-afbf363765-8d82e69f3e.zip b/.yarn/cache/get-func-name-npm-2.0.0-afbf363765-8d82e69f3e.zip deleted file mode 100644 index 7374eae..0000000 Binary files a/.yarn/cache/get-func-name-npm-2.0.0-afbf363765-8d82e69f3e.zip and /dev/null differ diff --git a/.yarn/cache/get-func-name-npm-2.0.2-409dbe3703-3f62f4c236.zip b/.yarn/cache/get-func-name-npm-2.0.2-409dbe3703-3f62f4c236.zip new file mode 100644 index 0000000..d80affc Binary files /dev/null and b/.yarn/cache/get-func-name-npm-2.0.2-409dbe3703-3f62f4c236.zip differ diff --git a/yarn.lock b/yarn.lock index f2a73af..1c46eac 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2295,9 +2295,9 @@ __metadata: linkType: hard "get-func-name@npm:^2.0.0": - version: 2.0.0 - resolution: "get-func-name@npm:2.0.0" - checksum: 8d82e69f3e7fab9e27c547945dfe5cc0c57fc0adf08ce135dddb01081d75684a03e7a0487466f478872b341d52ac763ae49e660d01ab83741f74932085f693c3 + version: 2.0.2 + resolution: "get-func-name@npm:2.0.2" + checksum: 3f62f4c23647de9d46e6f76d2b3eafe58933a9b3830c60669e4180d6c601ce1b4aa310ba8366143f55e52b139f992087a9f0647274e8745621fa2af7e0acf13b languageName: node linkType: hard