mirror of
https://github.com/nodejs/node.git
synced 2025-05-09 03:18:24 +00:00

PR-URL: https://github.com/nodejs/node/pull/42252 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Rich Trott <rtrott@gmail.com>
54 lines
1.1 KiB
JavaScript
54 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
const {
|
|
RegExpPrototypeTest,
|
|
} = primordials;
|
|
const { getOptionValue } = require('internal/options');
|
|
|
|
|
|
const experimentalWasmModules = getOptionValue('--experimental-wasm-modules');
|
|
|
|
const extensionFormatMap = {
|
|
'__proto__': null,
|
|
'.cjs': 'commonjs',
|
|
'.js': 'module',
|
|
'.json': 'json',
|
|
'.mjs': 'module',
|
|
};
|
|
|
|
const legacyExtensionFormatMap = {
|
|
'__proto__': null,
|
|
'.cjs': 'commonjs',
|
|
'.js': 'commonjs',
|
|
'.json': 'commonjs',
|
|
'.mjs': 'module',
|
|
'.node': 'commonjs',
|
|
};
|
|
|
|
if (experimentalWasmModules) {
|
|
extensionFormatMap['.wasm'] = legacyExtensionFormatMap['.wasm'] = 'wasm';
|
|
}
|
|
|
|
function mimeToFormat(mime) {
|
|
if (
|
|
RegExpPrototypeTest(
|
|
/\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?/i,
|
|
mime
|
|
)
|
|
) return 'module';
|
|
if (mime === 'application/json') return 'json';
|
|
if (experimentalWasmModules && mime === 'application/wasm') return 'wasm';
|
|
return null;
|
|
}
|
|
|
|
function getLegacyExtensionFormat(ext) {
|
|
return legacyExtensionFormatMap[ext];
|
|
}
|
|
|
|
module.exports = {
|
|
extensionFormatMap,
|
|
getLegacyExtensionFormat,
|
|
legacyExtensionFormatMap,
|
|
mimeToFormat,
|
|
};
|