| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,6 +31,7 @@ const { | |||
| 31 | 31 | ERR_UNKNOWN_MODULE_FORMAT | |
| 32 | 32 | } = require('internal/errors').codes; | |
| 33 | 33 | const { pathToFileURL, isURLInstance, URL } = require('internal/url'); | |
| 34 | + const { emitExperimentalWarning } = require('internal/util'); | ||
| 34 | 35 | const { | |
| 35 | 36 | isAnyArrayBuffer, | |
| 36 | 37 | isArrayBufferView, | |
@@ -53,6 +54,13 @@ const { | |||
| 53 | 54 | fetchModule, | |
| 54 | 55 | } = require('internal/modules/esm/fetch_module'); | |
| 55 | 56 | ||
| 57 | + | ||
| 58 | + /** | ||
| 59 | + * Prevent the specifier resolution warning from being printed twice | ||
| 60 | + */ | ||
| 61 | + let emittedSpecifierResolutionWarning = false; | ||
| 62 | + | ||
| 63 | + | ||
| 56 | 64 | /** | |
| 57 | 65 | * An ESMLoader instance is used as the main entry point for loading ES modules. | |
| 58 | 66 | * Currently, this is a singleton -- there is only one used for loading | |
@@ -107,6 +115,22 @@ class ESMLoader { | |||
| 107 | 115 | */ | |
| 108 | 116 | translators = translators; | |
| 109 | 117 | ||
| 118 | + constructor() { | ||
| 119 | + if (getOptionValue('--experimental-loader')) { | ||
| 120 | + emitExperimentalWarning('Custom ESM Loaders'); | ||
| 121 | + } | ||
| 122 | + if (getOptionValue('--experimental-network-imports')) { | ||
| 123 | + emitExperimentalWarning('Network Imports'); | ||
| 124 | + } | ||
| 125 | + if (getOptionValue('--experimental-specifier-resolution') === 'node' && !emittedSpecifierResolutionWarning) { | ||
| 126 | + process.emitWarning( | ||
| 127 | + 'The Node.js specifier resolution flag is experimental. It could change or be removed at any time.', | ||
| 128 | + 'ExperimentalWarning' | ||
| 129 | + ); | ||
| 130 | + emittedSpecifierResolutionWarning = true; | ||
| 131 | + } | ||
| 132 | + } | ||
| 133 | + | ||
| 110 | 134 | static pluckHooks({ | |
| 111 | 135 | globalPreload, | |
| 112 | 136 | resolve, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -363,7 +363,6 @@ function resolveDirectoryEntry(search) { | |||
| 363 | 363 | } | |
| 364 | 364 | ||
| 365 | 365 | const encodedSepRegEx = /%2F|%5C/i; | |
| 366 | - let experimentalSpecifierResolutionWarned = false; | ||
| 367 | 366 | /** | |
| 368 | 367 | * @param {URL} resolved | |
| 369 | 368 | * @param {string | URL | undefined} base | |
@@ -378,13 +377,6 @@ function finalizeResolution(resolved, base, preserveSymlinks) { | |||
| 378 | 377 | ||
| 379 | 378 | let path = fileURLToPath(resolved); | |
| 380 | 379 | if (getOptionValue('--experimental-specifier-resolution') === 'node') { | |
| 381 | - if (!experimentalSpecifierResolutionWarned) { | ||
| 382 | - process.emitWarning( | ||
| 383 | - 'The Node.js specifier resolution flag is experimental. It could change or be removed at any time.', | ||
| 384 | - 'ExperimentalWarning'); | ||
| 385 | - experimentalSpecifierResolutionWarned = true; | ||
| 386 | - } | ||
| 387 | - | ||
| 388 | 380 | let file = resolveExtensionsWithTryExactName(resolved); | |
| 389 | 381 | ||
| 390 | 382 | // Directory | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -55,9 +55,6 @@ async function initializeLoader() { | |||
| 55 | 55 | ||
| 56 | 56 | if (!customLoaders.length) return; | |
| 57 | 57 | ||
| 58 | - const { emitExperimentalWarning } = require('internal/util'); | ||
| 59 | - emitExperimentalWarning('--experimental-loader'); | ||
| 60 | - | ||
| 61 | 58 | let cwd; | |
| 62 | 59 | try { | |
| 63 | 60 | cwd = process.cwd() + '/'; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,32 @@ | |||
| 1 | + import { mustCall } from '../common/index.mjs'; | ||
| 2 | + import { fileURL } from '../common/fixtures.mjs'; | ||
| 3 | + import { match, strictEqual } from 'assert'; | ||
| 4 | + import { spawn } from 'child_process'; | ||
| 5 | + import { execPath } from 'process'; | ||
| 6 | + | ||
| 7 | + // Verify experimental warnings are printed | ||
| 8 | + for ( | ||
| 9 | + const [experiment, arg] of [ | ||
| 10 | + [/Custom ESM Loaders/, `--experimental-loader=${fileURL('es-module-loaders', 'hooks-custom.mjs')}`], | ||
| 11 | + [/Network Imports/, '--experimental-network-imports'], | ||
| 12 | + [/specifier resolution/, '--experimental-specifier-resolution=node'], | ||
| 13 | + ] | ||
| 14 | + ) { | ||
| 15 | + const input = `import ${JSON.stringify(fileURL('es-module-loaders', 'module-named-exports.mjs'))}`; | ||
| 16 | + const child = spawn(execPath, [ | ||
| 17 | + arg, | ||
| 18 | + '--input-type=module', | ||
| 19 | + '--eval', | ||
| 20 | + input, | ||
| 21 | + ]); | ||
| 22 | + | ||
| 23 | + let stderr = ''; | ||
| 24 | + child.stderr.setEncoding('utf8'); | ||
| 25 | + child.stderr.on('data', (data) => { stderr += data; }); | ||
| 26 | + child.on('close', mustCall((code, signal) => { | ||
| 27 | + strictEqual(code, 0); | ||
| 28 | + strictEqual(signal, null); | ||
| 29 | + match(stderr, /ExperimentalWarning/); | ||
| 30 | + match(stderr, experiment); | ||
| 31 | + })); | ||
| 32 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments