From 58ee15905b0f062d980e8a8dcbe93b2220028662 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Wed, 6 Mar 2024 12:45:16 +0100 Subject: [PATCH] chore: fix fs overrides for asar (#41525) fix: fs overrides for asar Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr --- ...de_entrypoint_to_be_a_builtin_module.patch | 4 ++-- ...in_esm_loaders_to_apply_asar_patches.patch | 20 ++++++++++++++++++- ...g_c_calls_of_esm_legacy_main_resolve.patch | 13 ++++++++++-- ...dder_overriding_of_internal_fs_calls.patch | 18 +++++++++-------- 4 files changed, 42 insertions(+), 13 deletions(-) diff --git a/patches/node/chore_allow_the_node_entrypoint_to_be_a_builtin_module.patch b/patches/node/chore_allow_the_node_entrypoint_to_be_a_builtin_module.patch index 6955eeada118..4d17a2946cb5 100644 --- a/patches/node/chore_allow_the_node_entrypoint_to_be_a_builtin_module.patch +++ b/patches/node/chore_allow_the_node_entrypoint_to_be_a_builtin_module.patch @@ -8,10 +8,10 @@ they use themselves as the entry point. We should try to upstream some form of this. diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js -index 1f3b719048f2477de183e2856b9b8eee8502f708..21116088c101f4679b5a5f41762ce710368e69ed 100644 +index dbbb454c3fc8a7774c1d190713e88862fda50f22..7a326e925a5769b8ea8e512e30fa655768beae3f 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js -@@ -1351,6 +1351,13 @@ Module.prototype._compile = function(content, filename) { +@@ -1350,6 +1350,13 @@ Module.prototype._compile = function(content, filename) { if (getOptionValue('--inspect-brk') && process._eval == null) { if (!resolvedArgv) { // We enter the repl if we're not given a filename argument. diff --git a/patches/node/fix_lazyload_fs_in_esm_loaders_to_apply_asar_patches.patch b/patches/node/fix_lazyload_fs_in_esm_loaders_to_apply_asar_patches.patch index 7cbce3398de7..b2c21b6e80b4 100644 --- a/patches/node/fix_lazyload_fs_in_esm_loaders_to_apply_asar_patches.patch +++ b/patches/node/fix_lazyload_fs_in_esm_loaders_to_apply_asar_patches.patch @@ -38,7 +38,7 @@ index 6a15fcae677b3bda58fc85f705862bbcd9feec9d..449131b9af99744c08d62d73f8d124ce const match = RegExpPrototypeExec(DATA_URL_PATTERN, url.pathname); if (!match) { diff --git a/lib/internal/modules/esm/resolve.js b/lib/internal/modules/esm/resolve.js -index 66ecfbcdd4fb2c9986e2d4619a381337839979fe..102165af37a42ca0394ec0d4efc21d3b03efe5eb 100644 +index 66ecfbcdd4fb2c9986e2d4619a381337839979fe..06d23dac1d0f591893643ed2c32711eb2b5c0675 100644 --- a/lib/internal/modules/esm/resolve.js +++ b/lib/internal/modules/esm/resolve.js @@ -24,7 +24,7 @@ const { @@ -50,6 +50,15 @@ index 66ecfbcdd4fb2c9986e2d4619a381337839979fe..102165af37a42ca0394ec0d4efc21d3b const { getOptionValue } = require('internal/options'); // Do not eagerly grab .manifest, it may be in TDZ const policy = getOptionValue('--experimental-policy') ? +@@ -250,7 +250,7 @@ function finalizeResolution(resolved, base, preserveSymlinks) { + throw err; + } + +- const stats = internalModuleStat(toNamespacedPath(StringPrototypeEndsWith(path, '/') ? ++ const stats = internalFsBinding.internalModuleStat(toNamespacedPath(StringPrototypeEndsWith(path, '/') ? + StringPrototypeSlice(path, -1) : path)); + + // Check for stats.isDirectory() @@ -266,7 +266,7 @@ function finalizeResolution(resolved, base, preserveSymlinks) { } @@ -59,6 +68,15 @@ index 66ecfbcdd4fb2c9986e2d4619a381337839979fe..102165af37a42ca0394ec0d4efc21d3b [internalFS.realpathCacheKey]: realpathCache, }); const { search, hash } = resolved; +@@ -825,7 +825,7 @@ function packageResolve(specifier, base, conditions) { + let packageJSONPath = fileURLToPath(packageJSONUrl); + let lastPath; + do { +- const stat = internalModuleStat(toNamespacedPath(StringPrototypeSlice(packageJSONPath, 0, ++ const stat = internalFsBinding.internalModuleStat(toNamespacedPath(StringPrototypeSlice(packageJSONPath, 0, + packageJSONPath.length - 13))); + // Check for !stat.isDirectory() + if (stat !== 1) { diff --git a/lib/internal/modules/esm/translators.js b/lib/internal/modules/esm/translators.js index e5fea28126b1b810cd3e1e5a13c0fdc97b6b71f5..cea066d1073a31573e134d584f1991e7a06b1036 100644 --- a/lib/internal/modules/esm/translators.js diff --git a/patches/node/fix_revert_src_lb_reducing_c_calls_of_esm_legacy_main_resolve.patch b/patches/node/fix_revert_src_lb_reducing_c_calls_of_esm_legacy_main_resolve.patch index ced296ea5319..ef4ff1250ea1 100644 --- a/patches/node/fix_revert_src_lb_reducing_c_calls_of_esm_legacy_main_resolve.patch +++ b/patches/node/fix_revert_src_lb_reducing_c_calls_of_esm_legacy_main_resolve.patch @@ -15,7 +15,7 @@ to recognize asar files. This reverts commit 9cf2e1f55b8446a7cde23699d00a3be73aa0c8f1. diff --git a/lib/internal/modules/esm/resolve.js b/lib/internal/modules/esm/resolve.js -index 102165af37a42ca0394ec0d4efc21d3b03efe5eb..cb8341f7378f16d4c0cc5368047a893704147842 100644 +index 06d23dac1d0f591893643ed2c32711eb2b5c0675..585437ce6a5382cd8657e02e4f3bcefc92206d7b 100644 --- a/lib/internal/modules/esm/resolve.js +++ b/lib/internal/modules/esm/resolve.js @@ -36,10 +36,9 @@ const preserveSymlinksMain = getOptionValue('--preserve-symlinks-main'); @@ -30,6 +30,15 @@ index 102165af37a42ca0394ec0d4efc21d3b03efe5eb..cb8341f7378f16d4c0cc5368047a8937 const { ERR_INPUT_TYPE_NOT_ALLOWED, ERR_INVALID_ARG_TYPE, +@@ -58,7 +57,7 @@ const { Module: CJSModule } = require('internal/modules/cjs/loader'); + const { getPackageScopeConfig } = require('internal/modules/esm/package_config'); + const { getConditionsSet } = require('internal/modules/esm/utils'); + const packageJsonReader = require('internal/modules/package_json_reader'); +-const { internalModuleStat } = internalBinding('fs'); ++const internalFsBinding = internalBinding('fs'); + + /** + * @typedef {import('internal/modules/esm/package_config.js').PackageConfig} PackageConfig @@ -161,34 +160,13 @@ function emitLegacyIndexDeprecation(url, packageJSONUrl, base, main) { const realpathCache = new SafeMap(); @@ -67,7 +76,7 @@ index 102165af37a42ca0394ec0d4efc21d3b03efe5eb..cb8341f7378f16d4c0cc5368047a8937 + * @returns {boolean} + */ +function fileExists(url) { -+ return internalModuleStat(toNamespacedPath(toPathIfFileURL(url))) === 0; ++ return internalFsBinding.internalModuleStat(toNamespacedPath(toPathIfFileURL(url))) === 0; +} /** diff --git a/patches/node/refactor_allow_embedder_overriding_of_internal_fs_calls.patch b/patches/node/refactor_allow_embedder_overriding_of_internal_fs_calls.patch index dd6cc69c2d7a..6584bc3d7a71 100644 --- a/patches/node/refactor_allow_embedder_overriding_of_internal_fs_calls.patch +++ b/patches/node/refactor_allow_embedder_overriding_of_internal_fs_calls.patch @@ -22,18 +22,19 @@ index 7a773d5208e250abd8b0efb6dde66c45060bbee4..45e38ca0a122e3b1c5d8d59865f9610c const binding = internalBinding('builtins'); diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js -index d4b70bab5e89300bfe6305263d556c986380e2e0..1f3b719048f2477de183e2856b9b8eee8502f708 100644 +index d4b70bab5e89300bfe6305263d556c986380e2e0..dbbb454c3fc8a7774c1d190713e88862fda50f22 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js -@@ -96,6 +96,7 @@ const assert = require('internal/assert'); +@@ -95,7 +95,7 @@ const { containsModuleSyntax } = internalBinding('contextify'); + const assert = require('internal/assert'); const fs = require('fs'); const path = require('path'); - const { internalModuleStat } = internalBinding('fs'); +-const { internalModuleStat } = internalBinding('fs'); +const internalFsBinding = internalBinding('fs'); const { safeGetenv } = internalBinding('credentials'); const { privateSymbols: { -@@ -195,7 +196,7 @@ function stat(filename) { +@@ -195,7 +195,7 @@ function stat(filename) { const result = statCache.get(filename); if (result !== undefined) { return result; } } @@ -43,18 +44,19 @@ index d4b70bab5e89300bfe6305263d556c986380e2e0..1f3b719048f2477de183e2856b9b8eee // Only set cache when `internalModuleStat(filename)` succeeds. statCache.set(filename, result); diff --git a/lib/internal/modules/package_json_reader.js b/lib/internal/modules/package_json_reader.js -index 88c079d10d116107aa34dc9281f64c799c48c0b5..146e2e49dc46c7f5302638f75cca4af548509d77 100644 +index 88c079d10d116107aa34dc9281f64c799c48c0b5..069f922612777f226127dc44f4091eed30416925 100644 --- a/lib/internal/modules/package_json_reader.js +++ b/lib/internal/modules/package_json_reader.js -@@ -13,6 +13,7 @@ const { +@@ -12,7 +12,7 @@ const { + const { ERR_INVALID_PACKAGE_CONFIG, } = require('internal/errors').codes; - const { internalModuleReadJSON } = internalBinding('fs'); +-const { internalModuleReadJSON } = internalBinding('fs'); +const internalFsBinding = internalBinding('fs'); const { resolve, sep, toNamespacedPath } = require('path'); const permission = require('internal/process/permission'); const { kEmptyObject } = require('internal/util'); -@@ -53,7 +54,7 @@ function read(jsonPath, { base, specifier, isESM } = kEmptyObject) { +@@ -53,7 +53,7 @@ function read(jsonPath, { base, specifier, isESM } = kEmptyObject) { const { 0: string, 1: containsKeys,