@@ -6,11 +6,14 @@ require('internal/modules/cjs/loader');
6
6
const {
7
7
ArrayPrototypeJoin,
8
8
ArrayPrototypeMap,
9
- encodeURI ,
9
+ ArrayPrototypeReduce ,
10
10
FunctionPrototypeCall,
11
11
JSONStringify,
12
12
ObjectSetPrototypeOf,
13
+ RegExpPrototypeSymbolReplace,
13
14
SafeWeakMap,
15
+ encodeURIComponent,
16
+ hardenRegExp,
14
17
} = primordials ;
15
18
16
19
const {
@@ -520,10 +523,18 @@ function createModuleLoader(useCustomLoadersIfPresent = true) {
520
523
const userLoaderPaths = getOptionValue ( '--experimental-loader' ) ;
521
524
if ( userLoaderPaths . length > 0 ) {
522
525
if ( ! emittedLoaderFlagWarning ) {
526
+ const readableURIEncode = ( string ) => ArrayPrototypeReduce (
527
+ [
528
+ [ / ' / g, '%27' ] , // We need to URL-encode the single quote as it's the delimiter for the --import flag.
529
+ [ / % 2 2 / g, '"' ] , // We can decode the double quotes to improve readability.
530
+ [ / % 2 F / ig, '/' ] , // We can decode the slashes to improve readability.
531
+ ] ,
532
+ ( str , { 0 : regex , 1 : replacement } ) => RegExpPrototypeSymbolReplace ( hardenRegExp ( regex ) , str , replacement ) ,
533
+ encodeURIComponent ( string ) ) ;
523
534
process . emitWarning (
524
535
'`--experimental-loader` may be removed in the future; instead use `register()`:\n' +
525
536
`--import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; ${ ArrayPrototypeJoin (
526
- ArrayPrototypeMap ( userLoaderPaths , ( loader ) => `register(${ JSONStringify ( encodeURI ( loader ) ) } , pathToFileURL("./"))` ) ,
537
+ ArrayPrototypeMap ( userLoaderPaths , ( loader ) => `register(${ readableURIEncode ( JSONStringify ( loader ) ) } , pathToFileURL("./"))` ) ,
527
538
'; ' ,
528
539
) } ;'`,
529
540
'ExperimentalWarning' ,
0 commit comments