mirror of
https://github.com/electron/electron.git
synced 2026-01-07 22:54:25 -05:00
* chore: upgrade Node.js to v24.10.0 * chore: fixup crypto patch * chore: fixup crypto test patch * src: prepare for v8 sandboxing https://github.com/nodejs/node/pull/58376 * esm: fix module.exports export on CJS modules https://github.com/nodejs/node/pull/57366 * chore: fixup lazyload fs patch * esm: Source Phase Imports for WebAssembly https://github.com/nodejs/node/pull/56919 * module: remove --experimental-default-type https://github.com/nodejs/node/pull/56092 * lib,src: refactor assert to load error source from memory https://github.com/nodejs/node/pull/59751 * src: add source location to v8::TaskRunner https://github.com/nodejs/node/pull/54077 * src: remove dependency on wrapper-descriptor-based CppHeap https://github.com/nodejs/node/pull/54077 * src: do not use soon-to-be-deprecated V8 API https://github.com/nodejs/node/pull/53174 * src: stop using deprecated fields of v8::FastApiCallbackOptions https://github.com/nodejs/node/pull/54077 * test: update v8-stats test for V8 12.6 https://github.com/nodejs/node/pull/54077 * esm: unflag --experimental-wasm-modules https://github.com/nodejs/node/pull/57038 * test: adapt assert tests to stack trace changes https://github.com/nodejs/node/pull/58070 * src,test: unregister the isolate after disposal and before freeing https://github.com/nodejs/node/pull/58070 * src: use cppgc to manage ContextifyContext https://github.com/nodejs/node/pull/56522 * src: replace uses of FastApiTypedArray https://github.com/nodejs/node/pull/58070 * module: integrate TypeScript into compile cache https://github.com/nodejs/node/pull/56629 * deps: update ada to 3.2.7 https://github.com/nodejs/node/pull/59336 * src: make minor cleanups in encoding_binding.cc https://github.com/nodejs/node/pull/57448 * src: switch from `Get/SetPrototype` to `Get/SetPrototypeV2` https://github.com/nodejs/node/pull/55453 * src: use non-deprecated Get/SetPrototype methods https://github.com/nodejs/node/pull/59671 * src: simplify string_bytes with views https://github.com/nodejs/node/pull/54876 * src: improve utf8 string generation performance https://github.com/nodejs/node/pull/54873 * src: use non-deprecated Utf8LengthV2() method https://github.com/nodejs/node/pull/58070 * src: use non-deprecated WriteUtf8V2() method https://github.com/nodejs/node/pull/58070 * src: refactor WriteUCS2 and remove flags argument https://github.com/nodejs/node/pull/58163 * src: use String::WriteV2() in TwoByteValue https://github.com/nodejs/node/pull/58164 * node-api: use WriteV2 in napi_get_value_string_utf16 https://github.com/nodejs/node/pull/58165 * node-api: use WriteOneByteV2 in napi_get_value_string_latin1 https://github.com/nodejs/node/pull/58325 * src: migrate WriteOneByte to WriteOneByteV2 https://github.com/nodejs/node/pull/59634 * fs: introduce dirent\.parentPath https://github.com/nodejs/node/pull/50976 * src: avoid copy by using std::views::keys https://github.com/nodejs/node/pull/56080 * chore: fixup patch indices * fix: errant use of context->GetIsolate() * fix: tweak BoringSSL compat patch for new changes * fix: add back missing isolate dtor declaration * fixup! esm: fix module.exports export on CJS modules * cli: remove --no-experimental-fetch flag https://github.com/nodejs/node/pull/52611/files * esm: Source Phase Imports for WebAssembly https://github.com/nodejs/node/pull/56919 * fixup! src: prepare for v8 sandboxing * chore: bump @types/node to v24 * chore: fix const assignment in crypto test * fix: sandbox pointer patch issues * chore: rework source phase import patch * src: add percentage support to --max-old-space-size https://github.com/nodejs/node/pull/59082 * chore: fixup crypto tests * chore: HostImportModuleWithPhaseDynamically todo * fix: cjs esm failures * fix: v8::Object::Wrappable issues -b72a615754-490bac2496-4896a0dd69* chore: remove deleted specs * src: use v8::ExternalMemoryAccounter https://github.com/nodejs/node/pull/58070 * fs: port SonicBoom module to fs module as FastUtf8Stream https://github.com/nodejs/node/pull/58897 * chore: tweak sandboxed pr patch * test: disable parallel/test-os-checked-function * test: use WHATWG URL instead of url.parse * fix: OPENSSL_secure_zalloc doesn't work in BoringSSL * chore: fix accidental extra line * 7017517: [defer-import-eval] Parse import defer syntax https://chromium-review.googlesource.com/c/v8/v8/+/7017517
130 lines
6.3 KiB
Diff
130 lines
6.3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Shelley Vohr <shelley.vohr@gmail.com>
|
|
Date: Sat, 17 Feb 2024 22:17:13 -0800
|
|
Subject: fix: allow passing fileExists fn to legacyMainResolve
|
|
|
|
This switch to native legacyMainResolve doesn't take asar into account, and can
|
|
cause errors when a project using ESM and asar tries to load a dependency which
|
|
uses commonJS.
|
|
|
|
We can fix this by allowing the C++ implementation of legacyMainResolve to use
|
|
a fileExists function that does take Asar into account.
|
|
|
|
diff --git a/lib/internal/modules/esm/resolve.js b/lib/internal/modules/esm/resolve.js
|
|
index 72cc9444ca93ef7a1526e23314693aeaf5f173b0..79684dd7e8d1629b19be01ebf97e43e503dec581 100644
|
|
--- a/lib/internal/modules/esm/resolve.js
|
|
+++ b/lib/internal/modules/esm/resolve.js
|
|
@@ -28,14 +28,13 @@ const { BuiltinModule } = require('internal/bootstrap/realm');
|
|
const fs = require('fs');
|
|
const { getOptionValue } = require('internal/options');
|
|
// Do not eagerly grab .manifest, it may be in TDZ
|
|
-const { sep, posix: { relative: relativePosixPath }, resolve } = require('path');
|
|
+const { sep, posix: { relative: relativePosixPath }, toNamespacedPath, resolve } = require('path');
|
|
const preserveSymlinks = getOptionValue('--preserve-symlinks');
|
|
const preserveSymlinksMain = getOptionValue('--preserve-symlinks-main');
|
|
const inputTypeFlag = getOptionValue('--input-type');
|
|
-const { URL, pathToFileURL, fileURLToPath, isURL, URLParse } = require('internal/url');
|
|
+const { URL, pathToFileURL, fileURLToPath, isURL, URLParse, toPathIfFileURL } = require('internal/url');
|
|
const { getCWDURL, setOwnProperty } = require('internal/util');
|
|
const { canParse: URLCanParse } = internalBinding('url');
|
|
-const { legacyMainResolve: FSLegacyMainResolve } = internalBinding('fs');
|
|
const {
|
|
ERR_INPUT_TYPE_NOT_ALLOWED,
|
|
ERR_INVALID_ARG_TYPE,
|
|
@@ -183,6 +182,11 @@ const legacyMainResolveExtensionsIndexes = {
|
|
kResolvedByPackageAndNode: 9,
|
|
};
|
|
|
|
+function fileExists(url) {
|
|
+ const namespaced = toNamespacedPath(toPathIfFileURL(url));
|
|
+ return internalFsBinding.internalModuleStat(namespaced) === 0;
|
|
+}
|
|
+
|
|
/**
|
|
* Legacy CommonJS main resolution:
|
|
* 1. let M = pkg_url + (json main field)
|
|
@@ -201,7 +205,7 @@ function legacyMainResolve(packageJSONUrl, packageConfig, base) {
|
|
|
|
const baseStringified = isURL(base) ? base.href : base;
|
|
|
|
- const resolvedOption = FSLegacyMainResolve(pkgPath, packageConfig.main, baseStringified);
|
|
+ const resolvedOption = internalFsBinding.legacyMainResolve(pkgPath, packageConfig.main, baseStringified, fileExists);
|
|
|
|
const maybeMain = resolvedOption <= legacyMainResolveExtensionsIndexes.kResolvedByMainIndexNode ?
|
|
packageConfig.main || './' : '';
|
|
diff --git a/src/node_file.cc b/src/node_file.cc
|
|
index 00f369e9691e184f9e5f226ce4216bd5b1d353ae..d73dac2ee3f1cf1cac6845fae0f702c9fba8fcef 100644
|
|
--- a/src/node_file.cc
|
|
+++ b/src/node_file.cc
|
|
@@ -3623,13 +3623,25 @@ static void CpSyncCopyDir(const FunctionCallbackInfo<Value>& args) {
|
|
}
|
|
|
|
BindingData::FilePathIsFileReturnType BindingData::FilePathIsFile(
|
|
- Environment* env, const std::string& file_path) {
|
|
+ Environment* env, const std::string& file_path, v8::Local<v8::Function> is_file_function) {
|
|
THROW_IF_INSUFFICIENT_PERMISSIONS(
|
|
env,
|
|
permission::PermissionScope::kFileSystemRead,
|
|
file_path,
|
|
BindingData::FilePathIsFileReturnType::kThrowInsufficientPermissions);
|
|
|
|
+ if (!is_file_function.IsEmpty()) {
|
|
+ v8::Local<v8::Value> argv[] = {v8::String::NewFromUtf8(
|
|
+ env->isolate(), file_path.c_str(), v8::NewStringType::kNormal)
|
|
+ .ToLocalChecked()};
|
|
+ MaybeLocal<Value> maybe_is_file = is_file_function->Call(env->context(), v8::Undefined(env->isolate()), 1, argv);
|
|
+ if (!maybe_is_file.IsEmpty()) {
|
|
+ bool is_file = maybe_is_file.ToLocalChecked()->BooleanValue(env->isolate());
|
|
+ return is_file ? BindingData::FilePathIsFileReturnType::kIsFile
|
|
+ : BindingData::FilePathIsFileReturnType::kIsNotFile;
|
|
+ }
|
|
+ }
|
|
+
|
|
uv_fs_t req;
|
|
|
|
int rc = uv_fs_stat(env->event_loop(), &req, file_path.c_str(), nullptr);
|
|
@@ -3687,6 +3699,11 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
|
|
std::optional<std::string> initial_file_path;
|
|
std::string file_path;
|
|
|
|
+ v8::Local<v8::Function> is_file_function;
|
|
+ if (args.Length() >= 3 && args[3]->IsFunction()) {
|
|
+ is_file_function = args[3].As<v8::Function>();
|
|
+ }
|
|
+
|
|
if (args.Length() >= 2 && args[1]->IsString()) {
|
|
auto package_config_main = Utf8Value(isolate, args[1]).ToString();
|
|
|
|
@@ -3707,7 +3724,7 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
|
|
BufferValue buff_file_path(isolate, local_file_path);
|
|
ToNamespacedPath(env, &buff_file_path);
|
|
|
|
- switch (FilePathIsFile(env, buff_file_path.ToString())) {
|
|
+ switch (FilePathIsFile(env, buff_file_path.ToString(), is_file_function)) {
|
|
case BindingData::FilePathIsFileReturnType::kIsFile:
|
|
return args.GetReturnValue().Set(i);
|
|
case BindingData::FilePathIsFileReturnType::kIsNotFile:
|
|
@@ -3744,7 +3761,7 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
|
|
BufferValue buff_file_path(isolate, local_file_path);
|
|
ToNamespacedPath(env, &buff_file_path);
|
|
|
|
- switch (FilePathIsFile(env, buff_file_path.ToString())) {
|
|
+ switch (FilePathIsFile(env, buff_file_path.ToString(), is_file_function)) {
|
|
case BindingData::FilePathIsFileReturnType::kIsFile:
|
|
return args.GetReturnValue().Set(i);
|
|
case BindingData::FilePathIsFileReturnType::kIsNotFile:
|
|
diff --git a/src/node_file.h b/src/node_file.h
|
|
index 224fa6f7ade375cb673c8adcc95927fa04f9c248..343c6bec67e6cf70ffb91b87e7837dbaf6071cee 100644
|
|
--- a/src/node_file.h
|
|
+++ b/src/node_file.h
|
|
@@ -101,7 +101,8 @@ class BindingData : public SnapshotableObject {
|
|
InternalFieldInfo* internal_field_info_ = nullptr;
|
|
|
|
static FilePathIsFileReturnType FilePathIsFile(Environment* env,
|
|
- const std::string& file_path);
|
|
+ const std::string& file_path,
|
|
+ v8::Local<v8::Function> is_file_function = v8::Local<v8::Function>());
|
|
};
|
|
|
|
// structure used to store state during a complex operation, e.g., mkdirp.
|