GeezerVison is showing github.com — esm: fix `globalPreload` warning · nodejs/node@01ca6d2
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/modules/esm/hooks.js +3-7Lines changed: 3 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -85,7 +85,6 @@ let importMetaInitializer; | 85 | 85 |
| 86 | 86 | // [2] `validate...()`s throw the wrong error | 87 | 87 |
| 88 | | -let globalPreloadWarned = false; | 89 | 88 | class Hooks { | 90 | 89 | #chains = { | 91 | 90 | /** | @@ -161,12 +160,9 @@ class Hooks { | 161 | 160 | } = pluckHooks(exports); | 162 | 161 |
| 163 | 162 | if (globalPreload && !initialize) { | 164 | | - if (globalPreloadWarned === false) { | 165 | | - globalPreloadWarned = true; | 166 | | - emitExperimentalWarning( | 167 | | - '`globalPreload` will be removed in a future version. Please use `initialize` instead.', | 168 | | - ); | 169 | | - } | | 163 | + emitExperimentalWarning( | | 164 | + '`globalPreload` is planned for removal in favor of `initialize`. `globalPreload`', | | 165 | + ); | 170 | 166 | ArrayPrototypePush(this.#chains.globalPreload, { __proto__: null, fn: globalPreload, url }); | 171 | 167 | } | 172 | 168 | if (resolve) { | |
Collapse file Copy file name to clipboardExpand all lines: test/es-module/test-esm-loader-hooks.mjs +13-1Lines changed: 13 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -372,10 +372,22 @@ describe('Loader hooks', { concurrency: true }, () => { | 372 | 372 | const { stderr } = await spawnPromisified(execPath, [ | 373 | 373 | '--experimental-loader', | 374 | 374 | 'data:text/javascript,export function globalPreload(){}', | | 375 | + '--experimental-loader', | | 376 | + 'data:text/javascript,export function globalPreload(){return""}', | | 377 | + fixtures.path('empty.js'), | | 378 | + ]); | | 379 | + | | 380 | + assert.strictEqual(stderr.match(/`globalPreload` is an experimental feature/g).length, 1); | | 381 | + }); | | 382 | + | | 383 | + it('should not emit deprecation warning when initialize is supplied', async () => { | | 384 | + const { stderr } = await spawnPromisified(execPath, [ | | 385 | + '--experimental-loader', | | 386 | + 'data:text/javascript,export function globalPreload(){}export function initialize(){}', | 375 | 387 | fixtures.path('empty.js'), | 376 | 388 | ]); | 377 | 389 |
| 378 | | - assert.match(stderr, /`globalPreload` will be removed/); | | 390 | + assert.doesNotMatch(stderr, /`globalPreload` is an experimental feature/); | 379 | 391 | }); | 380 | 392 |
| 381 | 393 | it('should handle globalPreload returning undefined', async () => { | |
|