fs: restore fs patchability in ESM loader by joyeecheung · Pull Request #62835 · nodejs/node · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/internal/modules/esm/load.js
8 changes: 6 additions & 2 deletions lib/internal/modules/esm/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const {
const assert = require('internal/assert');
const internalFS = require('internal/fs/utils');
const { BuiltinModule } = require('internal/bootstrap/realm');
const { realpathSync } = require('fs');
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');
Expand Down Expand Up @@ -273,7 +273,11 @@ function finalizeResolution(resolved, base, preserveSymlinks) {
}

if (!preserveSymlinks) {
const real = realpathSync(path, {
// If you are reading this code to figure out how to patch Node.js module loading
// behavior - DO NOT depend on the patchability in new code: Node.js
// internals may stop going through the JavaScript fs module entirely.
// Prefer module.registerHooks() or other more formal fs hooks released in the future.
const real = fs.realpathSync(path, {
[internalFS.realpathCacheKey]: realpathCache,
});
const { search, hash } = resolved;
Expand Down
8 changes: 6 additions & 2 deletions lib/internal/modules/esm/translators.js
Loading