This commit is contained in:
parent
9584bb9e28
commit
28f90a2986
106
.pnp.loader.mjs
generated
106
.pnp.loader.mjs
generated
@ -1,9 +1,12 @@
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
|
||||
import fs from 'fs';
|
||||
import { URL as URL$1, fileURLToPath, pathToFileURL } from 'url';
|
||||
import path from 'path';
|
||||
import { createHash } from 'crypto';
|
||||
import { EOL } from 'os';
|
||||
import moduleExports, { isBuiltin } from 'module';
|
||||
import esmModule, { createRequire, isBuiltin } from 'module';
|
||||
import assert from 'assert';
|
||||
|
||||
const SAFE_TIME = 456789e3;
|
||||
@ -283,6 +286,7 @@ async function copySymlink(prelayout, postlayout, destinationFs, destination, de
|
||||
}
|
||||
|
||||
class FakeFS {
|
||||
pathUtils;
|
||||
constructor(pathUtils) {
|
||||
this.pathUtils = pathUtils;
|
||||
}
|
||||
@ -830,6 +834,12 @@ class ProxiedFS extends FakeFS {
|
||||
rmdirSync(p, opts) {
|
||||
return this.baseFs.rmdirSync(this.mapToBase(p), opts);
|
||||
}
|
||||
async rmPromise(p, opts) {
|
||||
return this.baseFs.rmPromise(this.mapToBase(p), opts);
|
||||
}
|
||||
rmSync(p, opts) {
|
||||
return this.baseFs.rmSync(this.mapToBase(p), opts);
|
||||
}
|
||||
async linkPromise(existingP, newP) {
|
||||
return this.baseFs.linkPromise(this.mapToBase(existingP), this.mapToBase(newP));
|
||||
}
|
||||
@ -885,6 +895,7 @@ class ProxiedFS extends FakeFS {
|
||||
watch(p, a, b) {
|
||||
return this.baseFs.watch(
|
||||
this.mapToBase(p),
|
||||
// @ts-expect-error
|
||||
a,
|
||||
b
|
||||
);
|
||||
@ -892,6 +903,7 @@ class ProxiedFS extends FakeFS {
|
||||
watchFile(p, a, b) {
|
||||
return this.baseFs.watchFile(
|
||||
this.mapToBase(p),
|
||||
// @ts-expect-error
|
||||
a,
|
||||
b
|
||||
);
|
||||
@ -915,6 +927,7 @@ function direntToPortable(dirent) {
|
||||
return portableDirent;
|
||||
}
|
||||
class NodeFS extends BasePortableFakeFS {
|
||||
realFs;
|
||||
constructor(realFs = fs) {
|
||||
super();
|
||||
this.realFs = realFs;
|
||||
@ -1211,6 +1224,18 @@ class NodeFS extends BasePortableFakeFS {
|
||||
rmdirSync(p, opts) {
|
||||
return this.realFs.rmdirSync(npath.fromPortablePath(p), opts);
|
||||
}
|
||||
async rmPromise(p, opts) {
|
||||
return await new Promise((resolve, reject) => {
|
||||
if (opts) {
|
||||
this.realFs.rm(npath.fromPortablePath(p), opts, this.makeCallback(resolve, reject));
|
||||
} else {
|
||||
this.realFs.rm(npath.fromPortablePath(p), this.makeCallback(resolve, reject));
|
||||
}
|
||||
});
|
||||
}
|
||||
rmSync(p, opts) {
|
||||
return this.realFs.rmSync(npath.fromPortablePath(p), opts);
|
||||
}
|
||||
async linkPromise(existingP, newP) {
|
||||
return await new Promise((resolve, reject) => {
|
||||
this.realFs.link(npath.fromPortablePath(existingP), npath.fromPortablePath(newP), this.makeCallback(resolve, reject));
|
||||
@ -1298,6 +1323,7 @@ class NodeFS extends BasePortableFakeFS {
|
||||
watch(p, a, b) {
|
||||
return this.realFs.watch(
|
||||
npath.fromPortablePath(p),
|
||||
// @ts-expect-error
|
||||
a,
|
||||
b
|
||||
);
|
||||
@ -1305,6 +1331,7 @@ class NodeFS extends BasePortableFakeFS {
|
||||
watchFile(p, a, b) {
|
||||
return this.realFs.watchFile(
|
||||
npath.fromPortablePath(p),
|
||||
// @ts-expect-error
|
||||
a,
|
||||
b
|
||||
);
|
||||
@ -1327,10 +1354,7 @@ const NUMBER_REGEXP = /^[0-9]+$/;
|
||||
const VIRTUAL_REGEXP = /^(\/(?:[^/]+\/)*?(?:\$\$virtual|__virtual__))((?:\/((?:[^/]+-)?[a-f0-9]+)(?:\/([^/]+))?)?((?:\/.*)?))$/;
|
||||
const VALID_COMPONENT = /^([^/]+-)?[a-f0-9]+$/;
|
||||
class VirtualFS extends ProxiedFS {
|
||||
constructor({ baseFs = new NodeFS() } = {}) {
|
||||
super(ppath);
|
||||
this.baseFs = baseFs;
|
||||
}
|
||||
baseFs;
|
||||
static makeVirtualPath(base, component, to) {
|
||||
if (ppath.basename(base) !== `__virtual__`)
|
||||
throw new Error(`Assertion failed: Virtual folders must be named "__virtual__"`);
|
||||
@ -1360,6 +1384,10 @@ class VirtualFS extends ProxiedFS {
|
||||
const subpath = match[5] || `.`;
|
||||
return VirtualFS.resolveVirtual(ppath.join(target, backstep, subpath));
|
||||
}
|
||||
constructor({ baseFs = new NodeFS() } = {}) {
|
||||
super(ppath);
|
||||
this.baseFs = baseFs;
|
||||
}
|
||||
getExtractHint(hints) {
|
||||
return this.baseFs.getExtractHint(hints);
|
||||
}
|
||||
@ -1403,6 +1431,8 @@ const URL = Number(process.versions.node.split('.', 1)[0]) < 20 ? URL$1 : global
|
||||
const [major, minor] = process.versions.node.split(`.`).map((value) => parseInt(value, 10));
|
||||
const WATCH_MODE_MESSAGE_USES_ARRAYS = major > 19 || major === 19 && minor >= 2 || major === 18 && minor >= 13;
|
||||
const HAS_LAZY_LOADED_TRANSLATORS = major === 20 && minor < 6 || major === 19 && minor >= 3;
|
||||
const SUPPORTS_IMPORT_ATTRIBUTES = major >= 21 || major === 20 && minor >= 10 || major === 18 && minor >= 20;
|
||||
const SUPPORTS_IMPORT_ATTRIBUTES_ONLY = major >= 22;
|
||||
|
||||
function readPackageScope(checkPath) {
|
||||
const rootSeparatorIndex = checkPath.indexOf(npath.sep);
|
||||
@ -1493,10 +1523,21 @@ async function load$1(urlString, context, nextLoad) {
|
||||
const format = getFileFormat(filePath);
|
||||
if (!format)
|
||||
return nextLoad(urlString, context, nextLoad);
|
||||
if (format === `json` && context.importAssertions?.type !== `json`) {
|
||||
const err = new TypeError(`[ERR_IMPORT_ASSERTION_TYPE_MISSING]: Module "${urlString}" needs an import assertion of type "json"`);
|
||||
err.code = `ERR_IMPORT_ASSERTION_TYPE_MISSING`;
|
||||
throw err;
|
||||
if (format === `json`) {
|
||||
if (SUPPORTS_IMPORT_ATTRIBUTES_ONLY) {
|
||||
if (context.importAttributes?.type !== `json`) {
|
||||
const err = new TypeError(`[ERR_IMPORT_ATTRIBUTE_MISSING]: Module "${urlString}" needs an import attribute of "type: json"`);
|
||||
err.code = `ERR_IMPORT_ATTRIBUTE_MISSING`;
|
||||
throw err;
|
||||
}
|
||||
} else {
|
||||
const type = `importAttributes` in context ? context.importAttributes?.type : context.importAssertions?.type;
|
||||
if (type !== `json`) {
|
||||
const err = new TypeError(`[ERR_IMPORT_ASSERTION_TYPE_MISSING]: Module "${urlString}" needs an import ${SUPPORTS_IMPORT_ATTRIBUTES ? `attribute` : `assertion`} of type "json"`);
|
||||
err.code = `ERR_IMPORT_ASSERTION_TYPE_MISSING`;
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (process.env.WATCH_REPORT_DEPENDENCIES && process.send) {
|
||||
const pathToSend = pathToFileURL(
|
||||
@ -1743,8 +1784,7 @@ function resolvePackageTargetString(target, subpath, match, packageJSONUrl, base
|
||||
const packagePath = new URL(".", packageJSONUrl).pathname;
|
||||
if (!StringPrototypeStartsWith(resolvedPath, packagePath))
|
||||
throwInvalidPackageTarget(match, target, packageJSONUrl, internal, base);
|
||||
if (subpath === "")
|
||||
return resolved;
|
||||
if (subpath === "") return resolved;
|
||||
if (RegExpPrototypeExec(invalidSegmentRegEx, subpath) !== null) {
|
||||
const request = pattern ? StringPrototypeReplace(match, "*", () => subpath) : match + subpath;
|
||||
throwInvalidSubpath(request, packageJSONUrl, internal, base);
|
||||
@ -1758,8 +1798,7 @@ function resolvePackageTargetString(target, subpath, match, packageJSONUrl, base
|
||||
}
|
||||
function isArrayIndex(key) {
|
||||
const keyNum = +key;
|
||||
if (`${keyNum}` !== key)
|
||||
return false;
|
||||
if (`${keyNum}` !== key) return false;
|
||||
return keyNum >= 0 && keyNum < 4294967295;
|
||||
}
|
||||
function resolvePackageTarget(packageJSONUrl, target, subpath, packageSubpath, base, pattern, internal, conditions) {
|
||||
@ -1836,8 +1875,7 @@ function resolvePackageTarget(packageJSONUrl, target, subpath, packageSubpath, b
|
||||
internal,
|
||||
conditions
|
||||
);
|
||||
if (resolveResult === void 0)
|
||||
continue;
|
||||
if (resolveResult === void 0) continue;
|
||||
return resolveResult;
|
||||
}
|
||||
}
|
||||
@ -1858,18 +1896,12 @@ function patternKeyCompare(a, b) {
|
||||
const bPatternIndex = StringPrototypeIndexOf(b, "*");
|
||||
const baseLenA = aPatternIndex === -1 ? a.length : aPatternIndex + 1;
|
||||
const baseLenB = bPatternIndex === -1 ? b.length : bPatternIndex + 1;
|
||||
if (baseLenA > baseLenB)
|
||||
return -1;
|
||||
if (baseLenB > baseLenA)
|
||||
return 1;
|
||||
if (aPatternIndex === -1)
|
||||
return 1;
|
||||
if (bPatternIndex === -1)
|
||||
return -1;
|
||||
if (a.length > b.length)
|
||||
return -1;
|
||||
if (b.length > a.length)
|
||||
return 1;
|
||||
if (baseLenA > baseLenB) return -1;
|
||||
if (baseLenB > baseLenA) return 1;
|
||||
if (aPatternIndex === -1) return 1;
|
||||
if (bPatternIndex === -1) return -1;
|
||||
if (a.length > b.length) return -1;
|
||||
if (b.length > a.length) return 1;
|
||||
return 0;
|
||||
}
|
||||
function packageImportsResolve({ name, base, conditions, readFileSyncFn }) {
|
||||
@ -1941,6 +1973,13 @@ function packageImportsResolve({ name, base, conditions, readFileSyncFn }) {
|
||||
throwImportNotDefined(name, packageJSONUrl, base);
|
||||
}
|
||||
|
||||
let findPnpApi = esmModule.findPnpApi;
|
||||
if (!findPnpApi) {
|
||||
const require = createRequire(import.meta.url);
|
||||
const pnpApi = require(`./.pnp.cjs`);
|
||||
pnpApi.setup();
|
||||
findPnpApi = esmModule.findPnpApi;
|
||||
}
|
||||
const pathRegExp = /^(?![a-zA-Z]:[\\/]|\\\\|\.{0,2}(?:\/|$))((?:node:)?(?:@[^/]+\/)?[^/]+)\/*(.*|)$/;
|
||||
const isRelativeRegexp = /^\.{0,2}\//;
|
||||
function tryReadFile(filePath) {
|
||||
@ -1968,7 +2007,6 @@ async function resolvePrivateRequest(specifier, issuer, context, nextResolve) {
|
||||
}
|
||||
}
|
||||
async function resolve$1(originalSpecifier, context, nextResolve) {
|
||||
const { findPnpApi } = moduleExports;
|
||||
if (!findPnpApi || isBuiltin(originalSpecifier))
|
||||
return nextResolve(originalSpecifier, context, nextResolve);
|
||||
let specifier = originalSpecifier;
|
||||
@ -2004,6 +2042,7 @@ async function resolve$1(originalSpecifier, context, nextResolve) {
|
||||
try {
|
||||
result = pnpapi.resolveRequest(specifier, issuer, {
|
||||
conditions: new Set(conditions),
|
||||
// TODO: Handle --experimental-specifier-resolution=node
|
||||
extensions: allowLegacyResolve ? void 0 : []
|
||||
});
|
||||
} catch (err) {
|
||||
@ -2034,6 +2073,9 @@ if (!HAS_LAZY_LOADED_TRANSLATORS) {
|
||||
try {
|
||||
return fs.readFileSync(args[0], {
|
||||
encoding: `utf8`,
|
||||
// @ts-expect-error - The docs says it needs to be a string but
|
||||
// links to https://nodejs.org/dist/latest-v20.x/docs/api/fs.html#file-system-flags
|
||||
// which says it can be a number which matches the implementation.
|
||||
flag: args[1]
|
||||
});
|
||||
} catch {
|
||||
@ -2061,6 +2103,14 @@ if (!HAS_LAZY_LOADED_TRANSLATORS) {
|
||||
stats.ino,
|
||||
stats.size,
|
||||
stats.blocks
|
||||
// atime sec
|
||||
// atime ns
|
||||
// mtime sec
|
||||
// mtime ns
|
||||
// ctime sec
|
||||
// ctime ns
|
||||
// birthtime sec
|
||||
// birthtime ns
|
||||
]);
|
||||
} catch {
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user