Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixup! esm: fallback to getSource when load returns nullish source
  • Loading branch information
aduh95 committed Nov 21, 2023
commit 11c610a4827f1aaa4d3d97124dec5b542f21d4de
9 changes: 7 additions & 2 deletions lib/internal/modules/esm/translators.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,13 @@ const { internalCompileFunction } = require('internal/vm');

// Lazy-loading to avoid circular dependencies.
let getSourceSync;
/**
* @param {Parameters<typeof import('./load').getSourceSync>[0]} url
* @returns {ReturnType<typeof import('./load').getSourceSync>}
*/
function getSource(url) {
Comment thread
aduh95 marked this conversation as resolved.
getSourceSync ??= require('internal/modules/esm/load').getSourceSync;
return getSourceSync(url).source;
return getSourceSync(url);
}

/** @type {import('deps/cjs-module-lexer/lexer.js').parse} */
Expand Down Expand Up @@ -283,7 +287,8 @@ function createCJSModuleWrap(url, source, isMain, loadCJS = loadCJSModule) {
debug(`Translating CJSModule ${url}`);

const filename = StringPrototypeStartsWith(url, 'file://') ? fileURLToPath(url) : url;
source = stringify(source ?? getSource(new URL(url)));
// In case the source was not provided by the `load` step, we need fetch it now.
source = stringify(source ?? getSource(new URL(url)).source);

const { exportNames, module } = cjsPreparseModuleExports(filename, source);
cjsCache.set(url, module);
Expand Down