|
@@ -1,9 +1,9 @@
|
|
|
import fs from 'fs';
|
|
|
import { URL as URL$1, fileURLToPath, pathToFileURL } from 'url';
|
|
|
import path from 'path';
|
|
|
-import moduleExports, { Module } from 'module';
|
|
|
import { createHash } from 'crypto';
|
|
|
import { EOL } from 'os';
|
|
|
+import moduleExports, { isBuiltin } from 'module';
|
|
|
import assert from 'assert';
|
|
|
|
|
|
const SAFE_TIME = 456789e3;
|
|
@@ -16,14 +16,16 @@ const PortablePath = {
|
|
|
const npath = Object.create(path);
|
|
|
const ppath = Object.create(path.posix);
|
|
|
npath.cwd = () => process.cwd();
|
|
|
-ppath.cwd = () => toPortablePath(process.cwd());
|
|
|
-ppath.resolve = (...segments) => {
|
|
|
- if (segments.length > 0 && ppath.isAbsolute(segments[0])) {
|
|
|
- return path.posix.resolve(...segments);
|
|
|
- } else {
|
|
|
- return path.posix.resolve(ppath.cwd(), ...segments);
|
|
|
- }
|
|
|
-};
|
|
|
+ppath.cwd = process.platform === `win32` ? () => toPortablePath(process.cwd()) : process.cwd;
|
|
|
+if (process.platform === `win32`) {
|
|
|
+ ppath.resolve = (...segments) => {
|
|
|
+ if (segments.length > 0 && ppath.isAbsolute(segments[0])) {
|
|
|
+ return path.posix.resolve(...segments);
|
|
|
+ } else {
|
|
|
+ return path.posix.resolve(ppath.cwd(), ...segments);
|
|
|
+ }
|
|
|
+ };
|
|
|
+}
|
|
|
const contains = function(pathUtils, from, to) {
|
|
|
from = pathUtils.normalize(from);
|
|
|
to = pathUtils.normalize(to);
|
|
@@ -37,17 +39,13 @@ const contains = function(pathUtils, from, to) {
|
|
|
return null;
|
|
|
}
|
|
|
};
|
|
|
-npath.fromPortablePath = fromPortablePath;
|
|
|
-npath.toPortablePath = toPortablePath;
|
|
|
npath.contains = (from, to) => contains(npath, from, to);
|
|
|
ppath.contains = (from, to) => contains(ppath, from, to);
|
|
|
const WINDOWS_PATH_REGEXP = /^([a-zA-Z]:.*)$/;
|
|
|
const UNC_WINDOWS_PATH_REGEXP = /^\/\/(\.\/)?(.*)$/;
|
|
|
const PORTABLE_PATH_REGEXP = /^\/([a-zA-Z]:.*)$/;
|
|
|
const UNC_PORTABLE_PATH_REGEXP = /^\/unc\/(\.dot\/)?(.*)$/;
|
|
|
-function fromPortablePath(p) {
|
|
|
- if (process.platform !== `win32`)
|
|
|
- return p;
|
|
|
+function fromPortablePathWin32(p) {
|
|
|
let portablePathMatch, uncPortablePathMatch;
|
|
|
if (portablePathMatch = p.match(PORTABLE_PATH_REGEXP))
|
|
|
p = portablePathMatch[1];
|
|
@@ -57,9 +55,7 @@ function fromPortablePath(p) {
|
|
|
return p;
|
|
|
return p.replace(/\//g, `\\`);
|
|
|
}
|
|
|
-function toPortablePath(p) {
|
|
|
- if (process.platform !== `win32`)
|
|
|
- return p;
|
|
|
+function toPortablePathWin32(p) {
|
|
|
p = p.replace(/\\/g, `/`);
|
|
|
let windowsPathMatch, uncWindowsPathMatch;
|
|
|
if (windowsPathMatch = p.match(WINDOWS_PATH_REGEXP))
|
|
@@ -68,6 +64,10 @@ function toPortablePath(p) {
|
|
|
p = `/unc/${uncWindowsPathMatch[1] ? `.dot/` : ``}${uncWindowsPathMatch[2]}`;
|
|
|
return p;
|
|
|
}
|
|
|
+const toPortablePath = process.platform === `win32` ? toPortablePathWin32 : (p) => p;
|
|
|
+const fromPortablePath = process.platform === `win32` ? fromPortablePathWin32 : (p) => p;
|
|
|
+npath.fromPortablePath = fromPortablePath;
|
|
|
+npath.toPortablePath = toPortablePath;
|
|
|
function convertPath(targetPathUtils, sourcePath) {
|
|
|
return targetPathUtils === npath ? fromPortablePath(sourcePath) : toPortablePath(sourcePath);
|
|
|
}
|
|
@@ -902,6 +902,12 @@ class ProxiedFS extends FakeFS {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+function direntToPortable(dirent) {
|
|
|
+ const portableDirent = dirent;
|
|
|
+ if (typeof dirent.path === `string`)
|
|
|
+ portableDirent.path = npath.toPortablePath(dirent.path);
|
|
|
+ return portableDirent;
|
|
|
+}
|
|
|
class NodeFS extends BasePortableFakeFS {
|
|
|
constructor(realFs = fs) {
|
|
|
super();
|
|
@@ -1228,15 +1234,31 @@ class NodeFS extends BasePortableFakeFS {
|
|
|
async readdirPromise(p, opts) {
|
|
|
return await new Promise((resolve, reject) => {
|
|
|
if (opts) {
|
|
|
- this.realFs.readdir(npath.fromPortablePath(p), opts, this.makeCallback(resolve, reject));
|
|
|
+ if (opts.recursive && process.platform === `win32`) {
|
|
|
+ if (opts.withFileTypes) {
|
|
|
+ this.realFs.readdir(npath.fromPortablePath(p), opts, this.makeCallback((results) => resolve(results.map(direntToPortable)), reject));
|
|
|
+ } else {
|
|
|
+ this.realFs.readdir(npath.fromPortablePath(p), opts, this.makeCallback((results) => resolve(results.map(npath.toPortablePath)), reject));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.realFs.readdir(npath.fromPortablePath(p), opts, this.makeCallback(resolve, reject));
|
|
|
+ }
|
|
|
} else {
|
|
|
- this.realFs.readdir(npath.fromPortablePath(p), this.makeCallback((value) => resolve(value), reject));
|
|
|
+ this.realFs.readdir(npath.fromPortablePath(p), this.makeCallback(resolve, reject));
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
readdirSync(p, opts) {
|
|
|
if (opts) {
|
|
|
- return this.realFs.readdirSync(npath.fromPortablePath(p), opts);
|
|
|
+ if (opts.recursive && process.platform === `win32`) {
|
|
|
+ if (opts.withFileTypes) {
|
|
|
+ return this.realFs.readdirSync(npath.fromPortablePath(p), opts).map(direntToPortable);
|
|
|
+ } else {
|
|
|
+ return this.realFs.readdirSync(npath.fromPortablePath(p), opts).map(npath.toPortablePath);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return this.realFs.readdirSync(npath.fromPortablePath(p), opts);
|
|
|
+ }
|
|
|
} else {
|
|
|
return this.realFs.readdirSync(npath.fromPortablePath(p));
|
|
|
}
|
|
@@ -1372,10 +1394,8 @@ class VirtualFS extends ProxiedFS {
|
|
|
|
|
|
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 > 19 || major === 19 && minor >= 3;
|
|
|
+const HAS_LAZY_LOADED_TRANSLATORS = major === 20 && minor < 6 || major === 19 && minor >= 3;
|
|
|
|
|
|
-const builtinModules = new Set(Module.builtinModules || Object.keys(process.binding(`natives`)));
|
|
|
-const isBuiltinModule = (request) => request.startsWith(`node:`) || builtinModules.has(request);
|
|
|
function readPackageScope(checkPath) {
|
|
|
const rootSeparatorIndex = checkPath.indexOf(npath.sep);
|
|
|
let separatorIndex;
|
|
@@ -1963,7 +1983,7 @@ async function resolvePrivateRequest(specifier, issuer, context, nextResolve) {
|
|
|
}
|
|
|
async function resolve$1(originalSpecifier, context, nextResolve) {
|
|
|
const { findPnpApi } = moduleExports;
|
|
|
- if (!findPnpApi || isBuiltinModule(originalSpecifier))
|
|
|
+ if (!findPnpApi || isBuiltin(originalSpecifier))
|
|
|
return nextResolve(originalSpecifier, context, nextResolve);
|
|
|
let specifier = originalSpecifier;
|
|
|
const url = tryParseURL(specifier, isRelativeRegexp.test(specifier) ? context.parentURL : void 0);
|
|
@@ -2022,31 +2042,46 @@ async function resolve$1(originalSpecifier, context, nextResolve) {
|
|
|
|
|
|
if (!HAS_LAZY_LOADED_TRANSLATORS) {
|
|
|
const binding = process.binding(`fs`);
|
|
|
- const originalfstat = binding.fstat;
|
|
|
- const ZIP_MASK = 4278190080;
|
|
|
- const ZIP_MAGIC = 704643072;
|
|
|
- binding.fstat = function(...args) {
|
|
|
- const [fd, useBigint, req] = args;
|
|
|
- if ((fd & ZIP_MASK) === ZIP_MAGIC && useBigint === false && req === void 0) {
|
|
|
+ const originalReadFile = binding.readFileUtf8 || binding.readFileSync;
|
|
|
+ if (originalReadFile) {
|
|
|
+ binding[originalReadFile.name] = function(...args) {
|
|
|
try {
|
|
|
- const stats = fs.fstatSync(fd);
|
|
|
- return new Float64Array([
|
|
|
- stats.dev,
|
|
|
- stats.mode,
|
|
|
- stats.nlink,
|
|
|
- stats.uid,
|
|
|
- stats.gid,
|
|
|
- stats.rdev,
|
|
|
- stats.blksize,
|
|
|
- stats.ino,
|
|
|
- stats.size,
|
|
|
- stats.blocks
|
|
|
- ]);
|
|
|
+ return fs.readFileSync(args[0], {
|
|
|
+ encoding: `utf8`,
|
|
|
+ flag: args[1]
|
|
|
+ });
|
|
|
} catch {
|
|
|
}
|
|
|
- }
|
|
|
- return originalfstat.apply(this, args);
|
|
|
- };
|
|
|
+ return originalReadFile.apply(this, args);
|
|
|
+ };
|
|
|
+ } else {
|
|
|
+ const binding2 = process.binding(`fs`);
|
|
|
+ const originalfstat = binding2.fstat;
|
|
|
+ const ZIP_MASK = 4278190080;
|
|
|
+ const ZIP_MAGIC = 704643072;
|
|
|
+ binding2.fstat = function(...args) {
|
|
|
+ const [fd, useBigint, req] = args;
|
|
|
+ if ((fd & ZIP_MASK) === ZIP_MAGIC && useBigint === false && req === void 0) {
|
|
|
+ try {
|
|
|
+ const stats = fs.fstatSync(fd);
|
|
|
+ return new Float64Array([
|
|
|
+ stats.dev,
|
|
|
+ stats.mode,
|
|
|
+ stats.nlink,
|
|
|
+ stats.uid,
|
|
|
+ stats.gid,
|
|
|
+ stats.rdev,
|
|
|
+ stats.blksize,
|
|
|
+ stats.ino,
|
|
|
+ stats.size,
|
|
|
+ stats.blocks
|
|
|
+ ]);
|
|
|
+ } catch {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return originalfstat.apply(this, args);
|
|
|
+ };
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
const resolve = resolve$1;
|