fix: node 22 module filename resolution in win32 (#49) by @faulpeltz

This commit is contained in:
faulpeltz 2024-09-24 09:51:37 +02:00 committed by GitHub
parent 9beb2509cd
commit e436d74e4c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -327,17 +327,23 @@ index 0000000000..a697294fdf
+ }());
+}());
diff --git node/lib/internal/modules/cjs/loader.js node/lib/internal/modules/cjs/loader.js
index 451b7c2195..203be65195 100644
index 451b7c2195..7733dfb3d6 100644
--- node/lib/internal/modules/cjs/loader.js
+++ node/lib/internal/modules/cjs/loader.js
@@ -234,7 +234,10 @@ function stat(filename) {
@@ -229,12 +229,16 @@ function wrapModuleLoad(request, parent, isMain) {
* @param {string} filename Absolute path to the file
*/
function stat(filename) {
+ const origFilename = filename;
filename = path.toNamespacedPath(filename);
if (statCache !== null) {
const result = statCache.get(filename);
if (result !== undefined) { return result; }
}
- const result = internalFsBinding.internalModuleStat(filename);
+ const fs = require('fs');
+ const result = fs.existsSync(filename) ?
+ (fs.statSync(filename).isDirectory() ? 1 : 0) : -1;
+ const result = fs.existsSync(origFilename) ?
+ (fs.statSync(origFilename).isDirectory() ? 1 : 0) : -1;
+
if (statCache !== null && result >= 0) {
// Only set cache when `internalModuleStat(filename)` succeeds.