Skip to content

Commit b5663af

Browse files
committed
fixup! module: handle null source from async loader hooks in sync hooks
1 parent dce8de1 commit b5663af

File tree

5 files changed

+7
-8
lines changed

5 files changed

+7
-8
lines changed

lib/internal/modules/cjs/loader.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,9 +1794,7 @@ function loadSource(mod, filename, formatFromNode) {
17941794

17951795
const defaultLoad = getDefaultLoad(mod[kURL], filename);
17961796
const loadResult = loadWithHooks(mod[kURL], mod[kFormat], /* importAttributes */ undefined,
1797-
getCjsConditionsArray(),
1798-
defaultLoad,
1799-
validateLoadStrict);
1797+
getCjsConditionsArray(), defaultLoad, validateLoadStrict);
18001798
// Reset the module properties with load hook results.
18011799
if (loadResult.format !== undefined) {
18021800
mod[kFormat] = loadResult.format;

lib/internal/modules/customization_hooks.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ function validateLoadStrict(url, context, result) {
275275
}
276276

277277
function validateLoadSloppy(url, context, result) {
278-
validateSourceSloppy(url, context, result);
278+
validateSourcePermissive(url, context, result);
279279
validateFormat(url, context, result);
280280
return result;
281281
}
@@ -299,11 +299,12 @@ function validateSourceStrict(url, context, result) {
299299
}
300300
}
301301

302-
function validateSourceSloppy(url, context, result) {
302+
function validateSourcePermissive(url, context, result) {
303303
const { source, format } = result;
304304
if (format === 'commonjs' && source == null) {
305305
// Accommodate the quirk in defaultLoad used by asynchronous loader hooks
306306
// which sets source to null for commonjs.
307+
// See: https://github.com/nodejs/node/issues/57327#issuecomment-2701382020
307308
return;
308309
}
309310
validateSourceStrict(url, context, result);

lib/internal/modules/esm/translators.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ translators.set('commonjs', function commonjsStrategy(url, translateContext, par
344344
}
345345

346346
// For backward-compatibility, it's possible to return a nullish value for
347-
// CJS source associated with a file: URL - that usually means the source is not
347+
// CJS source associated with a `file:` URL - that usually means the source is not
348348
// customized (is loaded by default load) or the hook author wants it to be reloaded
349349
// through CJS routine. In this case, the source is obtained by calling the
350350
// monkey-patchable CJS loader.

test/common/tmpdir.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const testRoot = process.env.NODE_TEST_DIR ?
3838
// Using a `.` prefixed name, which is the convention for "hidden" on POSIX,
3939
// gets tools to ignore it by default or by simple rules, especially eslint.
4040
const tmpdirName = '.tmp.' +
41-
(process.env.TEST_SERIAL_ID || process.env.TEST_THREAD_ID || '0');
41+
(process.env.TEST_SERIAL_ID || process.env.TEST_THREAD_ID || '0');
4242
let tmpPath = path.join(testRoot, tmpdirName);
4343

4444
let firstRefresh = true;

test/parallel/test-single-executable-blob-config-errors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ const { spawnSyncAndAssert } = require('../common/child_process');
105105
cwd: tmpdir.path,
106106
}, {
107107
status: 1,
108-
stderr: /"disableExperimentalSEAWarning" field of .*invalid-disableExperimentalSEAWarning\.json is not a Boolean/
108+
stderr: /"disableExperimentalSEAWarning" field of .*invalid-disableExperimentalSEAWarning\UN.json is not a Boolean/
109109
});
110110
}
111111

0 commit comments

Comments
 (0)