Skip to content

Commit a737d76

Browse files
committed
vfs: remove duplicated module resolution logic from setup.js
Remove ~550 lines of duplicated module resolution functions that reimplemented canonical Node.js resolver behavior (extension trying, package exports resolution, bare specifier walking, directory entry resolution, format detection). The canonical resolvers already consult VFS through the loader overrides installed by installModuleLoaderOverrides(), making the Module.registerHooks() resolve/load hooks redundant. Also add clearStatCache() to the CJS loader, called on VFS unmount to prevent stale stat cache entries from causing incorrect resolution after a VFS is deregistered.
1 parent 386ec3e commit a737d76

File tree

3 files changed

+28
-701
lines changed

3 files changed

+28
-701
lines changed

lib/internal/modules/cjs/loader.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ const kFormat = Symbol('kFormat');
113113

114114
// Set first due to cycle with ESM loader functions.
115115
module.exports = {
116+
clearStatCache,
116117
kModuleSource,
117118
kModuleExport,
118119
kModuleExportNames,
@@ -229,6 +230,16 @@ let requireDepth = 0;
229230
let isPreloading = false;
230231
let statCache = null;
231232

233+
/**
234+
* Clear the stat cache. Called when VFS instances are unmounted
235+
* to prevent stale stat results from being returned.
236+
*/
237+
function clearStatCache() {
238+
if (statCache !== null) {
239+
statCache = new SafeMap();
240+
}
241+
}
242+
232243
/**
233244
* Internal method to add tracing capabilities for Module._load.
234245
*

0 commit comments

Comments
 (0)