mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00

Remove V8 flag for import assertions, enabling support for the syntax; require the import assertion syntax for imports of JSON. Support import assertions in user loaders. Use both resolved module URL and import assertion type as the key for caching modules. Co-authored-by: Geoffrey Booth <webadmin@geoffreybooth.com> PR-URL: https://github.com/nodejs/node/pull/40250 Reviewed-By: Bradley Farias <bradley.meck@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
44 lines
938 B
JavaScript
44 lines
938 B
JavaScript
'use strict';
|
|
|
|
const { defaultGetFormat } = require('internal/modules/esm/get_format');
|
|
const { defaultGetSource } = require('internal/modules/esm/get_source');
|
|
const { translators } = require('internal/modules/esm/translators');
|
|
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 || !translators.has(format)) {
|
|
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,
|
|
};
|