chore: bump node to v22.13.1 (main) (#45307)
* chore: bump node in DEPS to v22.13.1 * chore: fixup GN build file * https://github.com/nodejs/node/pull/55529 * https://github.com/nodejs/node/pull/55798 * https://github.com/nodejs/node/pull/55530 * module: simplify --inspect-brk handling https://github.com/nodejs/node/pull/55679 * src: fix outdated js2c.cc references https://github.com/nodejs/node/pull/56133 * crypto: include openssl/rand.h explicitly https://github.com/nodejs/node/pull/55425 * build: use variable for crypto dep path https://github.com/nodejs/node/pull/55928 * crypto: fix RSA_PKCS1_PADDING error message https://github.com/nodejs/node/pull/55629 * build: use variable for simdutf path https://github.com/nodejs/node/pull/56196 * test,crypto: make crypto tests work with BoringSSL https://github.com/nodejs/node/pull/55491 * fix: suppress clang -Wdeprecated-declarations in libuv https://github.com/libuv/libuv/pull/4486 * deps: update libuv to 1.49.1 https://github.com/nodejs/node/pull/55114 * test: make test-node-output-v8-warning more flexible https://github.com/nodejs/node/pull/55401 * [v22.x] Revert "v8: enable maglev on supported architectures" https://github.com/nodejs/node/pull/54384 * fix: potential WIN32_LEAN_AND_MEAN redefinition https://github.com/c-ares/c-ares/pull/869 * deps: update nghttp2 to 1.64.0 https://github.com/nodejs/node/pull/55559 * src: provide workaround for container-overflow https://github.com/nodejs/node/pull/55591 * build: use variable for simdutf path https://github.com/nodejs/node/pull/56196 * chore: fixup patch indices * fixup! module: simplify --inspect-brk handling * lib: fix fs.readdir recursive async https://github.com/nodejs/node/pull/56041 * lib: avoid excluding symlinks in recursive fs.readdir with filetypes https://github.com/nodejs/node/pull/55714/ This doesn't currently play well with ASAR - this should be fixed in a follow up * test: disable CJS permission test for config.main This has diverged as a result of our revert of src,lb: reducing C++ calls of esm legacy main resolve * fixup! lib: fix fs.readdir recursive async * deps: update libuv to 1.49.1 https://github.com/nodejs/node/pull/55114 --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
parent
ecd5d0a3a4
commit
93f4a93e12
42 changed files with 431 additions and 824 deletions
|
@ -24,6 +24,8 @@ const nextTick = (functionToCall: Function, args: any[] = []) => {
|
|||
process.nextTick(() => functionToCall(...args));
|
||||
};
|
||||
|
||||
const binding = internalBinding('fs');
|
||||
|
||||
// Cache asar archive objects.
|
||||
const cachedArchives = new Map<string, NodeJS.AsarArchive>();
|
||||
|
||||
|
@ -705,7 +707,137 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
|
|||
};
|
||||
|
||||
type ReaddirOptions = { encoding: BufferEncoding | null; withFileTypes?: false, recursive?: false } | undefined | null;
|
||||
type ReaddirCallback = (err: NodeJS.ErrnoException | null, files: string[]) => void;
|
||||
type ReaddirCallback = (err: NodeJS.ErrnoException | null, files?: string[]) => void;
|
||||
|
||||
const processReaddirResult = (args: any) => (args.context.withFileTypes ? handleDirents(args) : handleFilePaths(args));
|
||||
|
||||
function handleDirents ({ result, currentPath, context }: { result: any[], currentPath: string, context: any }) {
|
||||
const length = result[0].length;
|
||||
for (let i = 0; i < length; i++) {
|
||||
const resultPath = path.join(currentPath, result[0][i]);
|
||||
const info = splitPath(resultPath);
|
||||
|
||||
let type = result[1][i];
|
||||
if (info.isAsar) {
|
||||
const archive = getOrCreateArchive(info.asarPath);
|
||||
if (!archive) return;
|
||||
const stats = archive.stat(info.filePath);
|
||||
if (!stats) continue;
|
||||
type = stats.type;
|
||||
}
|
||||
|
||||
const dirent = getDirent(currentPath, result[0][i], type);
|
||||
const stat = internalBinding('fs').internalModuleStat(binding, resultPath);
|
||||
|
||||
context.readdirResults.push(dirent);
|
||||
if (dirent.isDirectory() || stat === 1) {
|
||||
context.pathsQueue.push(path.join(dirent.path, dirent.name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handleFilePaths ({ result, currentPath, context }: { result: string[], currentPath: string, context: any }) {
|
||||
for (let i = 0; i < result.length; i++) {
|
||||
const resultPath = path.join(currentPath, result[i]);
|
||||
const relativeResultPath = path.relative(context.basePath, resultPath);
|
||||
const stat = internalBinding('fs').internalModuleStat(binding, resultPath);
|
||||
context.readdirResults.push(relativeResultPath);
|
||||
|
||||
if (stat === 1) {
|
||||
context.pathsQueue.push(resultPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function readdirRecursive (basePath: string, options: ReaddirOptions, callback: ReaddirCallback) {
|
||||
const context = {
|
||||
withFileTypes: Boolean(options!.withFileTypes),
|
||||
encoding: options!.encoding,
|
||||
basePath,
|
||||
readdirResults: [],
|
||||
pathsQueue: [basePath]
|
||||
};
|
||||
|
||||
let i = 0;
|
||||
|
||||
function read (pathArg: string) {
|
||||
const req = new binding.FSReqCallback();
|
||||
req.oncomplete = (err: any, result: string) => {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (result === undefined) {
|
||||
callback(null, context.readdirResults);
|
||||
return;
|
||||
}
|
||||
|
||||
processReaddirResult({
|
||||
result,
|
||||
currentPath: pathArg,
|
||||
context
|
||||
});
|
||||
|
||||
if (i < context.pathsQueue.length) {
|
||||
read(context.pathsQueue[i++]);
|
||||
} else {
|
||||
callback(null, context.readdirResults);
|
||||
}
|
||||
};
|
||||
|
||||
const pathInfo = splitPath(pathArg);
|
||||
if (pathInfo.isAsar) {
|
||||
let readdirResult;
|
||||
const { asarPath, filePath } = pathInfo;
|
||||
|
||||
const archive = getOrCreateArchive(asarPath);
|
||||
if (!archive) {
|
||||
const error = createError(AsarError.INVALID_ARCHIVE, { asarPath });
|
||||
nextTick(callback, [error]);
|
||||
return;
|
||||
}
|
||||
|
||||
readdirResult = archive.readdir(filePath);
|
||||
if (!readdirResult) {
|
||||
const error = createError(AsarError.NOT_FOUND, { asarPath, filePath });
|
||||
nextTick(callback, [error]);
|
||||
return;
|
||||
}
|
||||
|
||||
// If we're in an asar dir, we need to ensure the result is in the same format as the
|
||||
// native call to readdir withFileTypes i.e. an array of arrays.
|
||||
if (context.withFileTypes) {
|
||||
readdirResult = [
|
||||
[...readdirResult], readdirResult.map((p: string) => {
|
||||
return internalBinding('fs').internalModuleStat(binding, path.join(pathArg, p));
|
||||
})
|
||||
];
|
||||
}
|
||||
|
||||
processReaddirResult({
|
||||
result: readdirResult,
|
||||
currentPath: pathArg,
|
||||
context
|
||||
});
|
||||
|
||||
if (i < context.pathsQueue.length) {
|
||||
read(context.pathsQueue[i++]);
|
||||
} else {
|
||||
callback(null, context.readdirResults);
|
||||
}
|
||||
} else {
|
||||
binding.readdir(
|
||||
pathArg,
|
||||
context.encoding,
|
||||
context.withFileTypes,
|
||||
req
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
read(context.pathsQueue[i++]);
|
||||
}
|
||||
|
||||
const { readdir } = fs;
|
||||
fs.readdir = function (pathArgument: string, options: ReaddirOptions, callback: ReaddirCallback) {
|
||||
|
@ -720,7 +852,7 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
|
|||
}
|
||||
|
||||
if (options?.recursive) {
|
||||
nextTick(callback!, [null, readdirSyncRecursive(pathArgument, options)]);
|
||||
readdirRecursive(pathArgument, options, callback);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -771,7 +903,7 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
|
|||
}
|
||||
|
||||
if (options?.recursive) {
|
||||
return readdirRecursive(pathArgument, options);
|
||||
return readdirRecursivePromises(pathArgument, options);
|
||||
}
|
||||
|
||||
const pathInfo = splitPath(pathArgument);
|
||||
|
@ -868,8 +1000,6 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
|
|||
return readPackageJSON(realPath, isESM, base, specifier);
|
||||
};
|
||||
|
||||
const binding = internalBinding('fs');
|
||||
|
||||
const { internalModuleStat } = binding;
|
||||
internalBinding('fs').internalModuleStat = (receiver: unknown, pathArgument: string) => {
|
||||
const pathInfo = splitPath(pathArgument);
|
||||
|
@ -888,7 +1018,7 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
|
|||
};
|
||||
|
||||
const { kUsePromises } = binding;
|
||||
async function readdirRecursive (originalPath: string, options: ReaddirOptions) {
|
||||
async function readdirRecursivePromises (originalPath: string, options: ReaddirOptions) {
|
||||
const result: any[] = [];
|
||||
|
||||
const pathInfo = splitPath(originalPath);
|
||||
|
@ -992,11 +1122,13 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
|
|||
}
|
||||
|
||||
function readdirSyncRecursive (basePath: string, options: ReaddirOptions) {
|
||||
const withFileTypes = Boolean(options!.withFileTypes);
|
||||
const encoding = options!.encoding;
|
||||
|
||||
const readdirResults: string[] = [];
|
||||
const pathsQueue = [basePath];
|
||||
const context = {
|
||||
withFileTypes: Boolean(options!.withFileTypes),
|
||||
encoding: options!.encoding,
|
||||
basePath,
|
||||
readdirResults: [] as any,
|
||||
pathsQueue: [basePath]
|
||||
};
|
||||
|
||||
function read (pathArg: string) {
|
||||
let readdirResult;
|
||||
|
@ -1011,7 +1143,7 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
|
|||
if (!readdirResult) return;
|
||||
// If we're in an asar dir, we need to ensure the result is in the same format as the
|
||||
// native call to readdir withFileTypes i.e. an array of arrays.
|
||||
if (withFileTypes) {
|
||||
if (context.withFileTypes) {
|
||||
readdirResult = [
|
||||
[...readdirResult], readdirResult.map((p: string) => {
|
||||
return internalBinding('fs').internalModuleStat(binding, path.join(pathArg, p));
|
||||
|
@ -1021,52 +1153,27 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
|
|||
} else {
|
||||
readdirResult = binding.readdir(
|
||||
path.toNamespacedPath(pathArg),
|
||||
encoding,
|
||||
withFileTypes
|
||||
context.encoding,
|
||||
context.withFileTypes
|
||||
);
|
||||
}
|
||||
|
||||
if (readdirResult === undefined) return;
|
||||
|
||||
if (withFileTypes) {
|
||||
const length = readdirResult[0].length;
|
||||
for (let i = 0; i < length; i++) {
|
||||
const resultPath = path.join(pathArg, readdirResult[0][i]);
|
||||
const info = splitPath(resultPath);
|
||||
|
||||
let type = readdirResult[1][i];
|
||||
if (info.isAsar) {
|
||||
const archive = getOrCreateArchive(info.asarPath);
|
||||
if (!archive) return;
|
||||
const stats = archive.stat(info.filePath);
|
||||
if (!stats) continue;
|
||||
type = stats.type;
|
||||
}
|
||||
|
||||
const dirent = getDirent(pathArg, readdirResult[0][i], type);
|
||||
|
||||
readdirResults.push(dirent);
|
||||
if (dirent.isDirectory()) {
|
||||
pathsQueue.push(path.join(dirent.path, dirent.name));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (let i = 0; i < readdirResult.length; i++) {
|
||||
const resultPath = path.join(pathArg, readdirResult[i]);
|
||||
const relativeResultPath = path.relative(basePath, resultPath);
|
||||
const stat = internalBinding('fs').internalModuleStat(binding, resultPath);
|
||||
|
||||
readdirResults.push(relativeResultPath);
|
||||
if (stat === 1) pathsQueue.push(resultPath);
|
||||
}
|
||||
if (readdirResult === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
processReaddirResult({
|
||||
result: readdirResult,
|
||||
currentPath: pathArg,
|
||||
context
|
||||
});
|
||||
}
|
||||
|
||||
for (let i = 0; i < pathsQueue.length; i++) {
|
||||
read(pathsQueue[i]);
|
||||
for (let i = 0; i < context.pathsQueue.length; i++) {
|
||||
read(context.pathsQueue[i]);
|
||||
}
|
||||
|
||||
return readdirResults;
|
||||
return context.readdirResults;
|
||||
}
|
||||
|
||||
// Calling mkdir for directory inside asar archive should throw ENOTDIR
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue