Skip to content

Commit

Permalink
readableURIEncode
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Sep 16, 2023
1 parent 27c14d7 commit 45d517d
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/internal/modules/esm/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ require('internal/modules/cjs/loader');
const {
ArrayPrototypeJoin,
ArrayPrototypeMap,
encodeURI,
ArrayPrototypeReduce,
FunctionPrototypeCall,
JSONStringify,
ObjectSetPrototypeOf,
RegExpPrototypeSymbolReplace,
SafeWeakMap,
encodeURIComponent,
hardenRegExp,
} = primordials;

const {
Expand Down Expand Up @@ -520,10 +523,18 @@ function createModuleLoader(useCustomLoadersIfPresent = true) {
const userLoaderPaths = getOptionValue('--experimental-loader');
if (userLoaderPaths.length > 0) {
if (!emittedLoaderFlagWarning) {
const readableURIEncode = (string) => ArrayPrototypeReduce(
[
[/'/g, '%27'], // We need to URL-encode the single quote as it's the delimiter for the --import flag.
[/%22/g, '"'], // We can decode the double quotes to improve readability.
[/%2F/ig, '/'], // We can decode the slashes to improve readability.
],
(str, { 0: regex, 1: replacement }) => RegExpPrototypeSymbolReplace(hardenRegExp(regex), str, replacement),
encodeURIComponent(string));
process.emitWarning(
'`--experimental-loader` may be removed in the future; instead use `register()`:\n' +
`--import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; ${ArrayPrototypeJoin(
ArrayPrototypeMap(userLoaderPaths, (loader) => `register(${JSONStringify(encodeURI(loader))}, pathToFileURL("./"))`),
ArrayPrototypeMap(userLoaderPaths, (loader) => `register(${readableURIEncode(JSONStringify(loader))}, pathToFileURL("./"))`),
'; ',
)};'`,
'ExperimentalWarning',
Expand Down

0 comments on commit 45d517d

Please sign in to comment.