* A loader instance is used as the main entry point for loading ES modules. Currently, this is a singleton; there is * only one used for loading the main module and everything in its dependency graph, though separate instances of this * class might be instantiated as part of bootstrap for other pu
(asyncLoaderHooks)
| 867 | * @returns {ModuleLoader} |
| 868 | */ |
| 869 | function createModuleLoader(asyncLoaderHooks) { |
| 870 | // Don't spawn a new loader hook worker if we are already in a loader hook worker to avoid infinite recursion. |
| 871 | if (shouldSpawnLoaderHookWorker()) { |
| 872 | assert(asyncLoaderHooks === undefined, 'asyncLoaderHooks should only be provided on the loader hook thread itself'); |
| 873 | const userLoaderPaths = getOptionValue('--experimental-loader'); |
| 874 | if (userLoaderPaths.length > 0) { |
| 875 | if (!emittedLoaderFlagWarning) { |
| 876 | const readableURIEncode = (string) => ArrayPrototypeReduce( |
| 877 | [ |
| 878 | [/'/g, '%27'], // We need to URL-encode the single quote as it's the delimiter for the --import flag. |
| 879 | [/%22/g, '"'], // We can decode the double quotes to improve readability. |
| 880 | [/%2F/ig, '/'], // We can decode the slashes to improve readability. |
| 881 | ], |
| 882 | (str, { 0: regex, 1: replacement }) => RegExpPrototypeSymbolReplace(hardenRegExp(regex), str, replacement), |
| 883 | encodeURIComponent(string)); |
| 884 | process.emitWarning( |
| 885 | '`--experimental-loader` may be removed in the future; instead use `register()`:\n' + |
| 886 | `--import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; ${ArrayPrototypeJoin( |
| 887 | ArrayPrototypeMap(userLoaderPaths, (loader) => `register(${readableURIEncode(JSONStringify(loader))}, pathToFileURL("./"))`), |
| 888 | '; ', |
| 889 | )};'`, |
| 890 | 'ExperimentalWarning', |
| 891 | ); |
| 892 | emittedLoaderFlagWarning = true; |
| 893 | } |
| 894 | const { AsyncLoaderHooksProxiedToLoaderHookWorker } = require('internal/modules/esm/hooks'); |
| 895 | asyncLoaderHooks = new AsyncLoaderHooksProxiedToLoaderHookWorker(); |
| 896 | } |
| 897 | } |
| 898 | |
| 899 | return new ModuleLoader(asyncLoaderHooks); |
| 900 | } |
| 901 | |
| 902 | let allowImportMetaResolveParentURL; |
| 903 | /** |
no test coverage detected
searching dependent graphs…