mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
this commit solves a regression introduced with PR-40980. if a resolve call results in a script with .mjs extension the is automatically set to . This avoids the case where an additional in the same directory as the .mjs file would declare the to commonjs PR-URL: https://github.com/nodejs/node/pull/41218 Refs: https://github.com/nodejs/node/pull/40980 Refs: https://github.com/yargs/yargs/issues/2068 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
44 lines
848 B
JavaScript
44 lines
848 B
JavaScript
'use strict';
|
|
|
|
const { defaultGetFormat } = require('internal/modules/esm/get_format');
|
|
const { defaultGetSource } = require('internal/modules/esm/get_source');
|
|
const { validateAssertions } = require('internal/modules/esm/assert');
|
|
|
|
/**
|
|
* Node.js default load hook.
|
|
* @param {string} url
|
|
* @param {object} context
|
|
* @returns {object}
|
|
*/
|
|
async function defaultLoad(url, context) {
|
|
let {
|
|
format,
|
|
source,
|
|
} = context;
|
|
const { importAssertions } = context;
|
|
|
|
if (format == null) {
|
|
format = defaultGetFormat(url);
|
|
}
|
|
|
|
validateAssertions(url, format, importAssertions);
|
|
|
|
if (
|
|
format === 'builtin' ||
|
|
format === 'commonjs'
|
|
) {
|
|
source = null;
|
|
} else if (source == null) {
|
|
source = await defaultGetSource(url, { format });
|
|
}
|
|
|
|
return {
|
|
format,
|
|
source,
|
|
};
|
|
}
|
|
|
|
module.exports = {
|
|
defaultLoad,
|
|
};
|