node/lib/internal/modules/esm/load.js
Bradley Farias ceadb473e6 esm: support https remotely and http locally under flag
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>
2022-02-09 19:47:12 -08:00

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,
};