mirror of
https://github.com/nodejs/node.git
synced 2025-05-15 12:45:25 +00:00

Co-authored-by: Jacob Smith <3012099+JakobJingleheimer@users.noreply.github.com> Co-authored-by: James M Snell <jasnell@gmail.com> Co-authored-by: Jordan Harband <ljharb@gmail.com> Co-authored-by: James Sumners <james@sumners.email> PR-URL: https://github.com/nodejs/node/pull/36328 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
44 lines
860 B
JavaScript
44 lines
860 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) {
|
|
const { importAssertions } = context;
|
|
let {
|
|
format,
|
|
source,
|
|
} = context;
|
|
|
|
if (format == null) {
|
|
format = await defaultGetFormat(url, context);
|
|
}
|
|
|
|
validateAssertions(url, format, importAssertions);
|
|
|
|
if (
|
|
format === 'builtin' ||
|
|
format === 'commonjs'
|
|
) {
|
|
source = null;
|
|
} else if (source == null) {
|
|
source = await defaultGetSource(url, context);
|
|
}
|
|
|
|
return {
|
|
format,
|
|
source,
|
|
};
|
|
}
|
|
|
|
module.exports = {
|
|
defaultLoad,
|
|
};
|