mirror of
https://github.com/nodejs/node.git
synced 2025-05-07 15:35:41 +00:00

PR-URL: https://github.com/nodejs/node/pull/46629 Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
42 lines
854 B
JavaScript
42 lines
854 B
JavaScript
'use strict';
|
|
|
|
const {
|
|
RegExpPrototypeExec,
|
|
} = primordials;
|
|
const { getOptionValue } = require('internal/options');
|
|
|
|
const experimentalWasmModules = getOptionValue('--experimental-wasm-modules');
|
|
|
|
const extensionFormatMap = {
|
|
'__proto__': null,
|
|
'.cjs': 'commonjs',
|
|
'.js': 'module',
|
|
'.json': 'json',
|
|
'.mjs': 'module',
|
|
};
|
|
|
|
if (experimentalWasmModules) {
|
|
extensionFormatMap['.wasm'] = 'wasm';
|
|
}
|
|
|
|
/**
|
|
* @param {string} mime
|
|
* @returns {string | null}
|
|
*/
|
|
function mimeToFormat(mime) {
|
|
if (
|
|
RegExpPrototypeExec(
|
|
/\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?/i,
|
|
mime,
|
|
) !== null
|
|
) return 'module';
|
|
if (mime === 'application/json') return 'json';
|
|
if (experimentalWasmModules && mime === 'application/wasm') return 'wasm';
|
|
return null;
|
|
}
|
|
|
|
module.exports = {
|
|
extensionFormatMap,
|
|
mimeToFormat,
|
|
};
|