From e74bcf794e8a04d493982a358c80cb08a3303c0e Mon Sep 17 00:00:00 2001 From: StefanStojanovic Date: Fri, 8 Dec 2023 14:07:36 +0100 Subject: [PATCH] module,win: fix long path resolve Fixes: https://github.com/nodejs/node/issues/50753 --- src/node_file.cc | 6 ++++++ src/node_modules.cc | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/src/node_file.cc b/src/node_file.cc index e426319daf7856..0f1c2f9416acc3 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -2916,6 +2916,9 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo& args) { for (int i = 0; i < legacy_main_extensions_with_main_end; i++) { file_path = *initial_file_path + std::string(legacy_main_extensions[i]); +#ifdef _WIN32 + file_path = "\\\\?\\" + file_path; +#endif switch (FilePathIsFile(env, file_path)) { case BindingData::FilePathIsFileReturnType::kIsFile: @@ -2953,6 +2956,9 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo& args) { i < legacy_main_extensions_package_fallback_end; i++) { file_path = *initial_file_path + std::string(legacy_main_extensions[i]); +#ifdef _WIN32 + file_path = "\\\\?\\" + file_path; +#endif switch (FilePathIsFile(env, file_path)) { case BindingData::FilePathIsFileReturnType::kIsFile: diff --git a/src/node_modules.cc b/src/node_modules.cc index 9217b94852e33b..2dc209ffd34829 100644 --- a/src/node_modules.cc +++ b/src/node_modules.cc @@ -256,8 +256,13 @@ void BindingData::ReadPackageJSON(const FunctionCallbackInfo& args) { permission::PermissionScope::kFileSystemRead, path.ToStringView()); +#ifdef _WIN32 + auto package_json = GetPackageJSON( + realm, "\\\\?\\" + path.ToString(), is_esm ? &error_context : nullptr); +#else auto package_json = GetPackageJSON(realm, path.ToString(), is_esm ? &error_context : nullptr); +#endif if (package_json == nullptr) { return; }