Skip to content

Commit 6321e08

Browse files
committed
fixup! vfs: integrate with CJS and ESM module loaders
Restore the "DO NOT depend on the patchability" warnings in esm/load.js and esm/resolve.js that were dropped along with the fs imports. The warning still applies; it now also points at node:vfs as one of the formal hook mechanisms callers should reach for instead. Addresses review feedback from @jsumners-nr in #63653
1 parent b51fe1f commit 6321e08

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

lib/internal/modules/esm/load.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ function getSourceSync(url, context) {
3434
const responseURL = href;
3535
let source;
3636
if (protocol === 'file:') {
37+
// If you are reading this code to figure out how to patch Node.js module
38+
// loading behavior - DO NOT depend on the patchability in new code: Node.js
39+
// internals may stop going through the JavaScript fs module entirely.
40+
// Prefer module.registerHooks(), node:vfs, or other more formal fs hooks
41+
// released in the future. loaderReadFile is the toggleable hook used by
42+
// node:vfs and is not part of the public API.
3743
source = loaderReadFile(url);
3844
} else if (protocol === 'data:') {
3945
const result = dataURLProcessor(url);

lib/internal/modules/esm/resolve.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@ function finalizeResolution(resolved, base, preserveSymlinks) {
267267
}
268268

269269
if (!preserveSymlinks) {
270+
// If you are reading this code to figure out how to patch Node.js module
271+
// loading behavior - DO NOT depend on the patchability in new code: Node.js
272+
// internals may stop going through the JavaScript fs module entirely.
273+
// Prefer module.registerHooks(), node:vfs, or other more formal fs hooks
274+
// released in the future. toRealPath is the toggleable hook used by
275+
// node:vfs and is not part of the public API.
270276
const real = toRealPath(path);
271277
const { search, hash } = resolved;
272278
resolved =

0 commit comments

Comments
 (0)