GeezerVison is showing github.com — esm: fix `globalPreload` warning · nodejs/node@31442b9
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 |
|---|
@@ -86,7 +86,6 @@ let importMetaInitializer; | 86 | 86 |
| 87 | 87 | // [2] `validate...()`s throw the wrong error | 88 | 88 |
| 89 | | -let globalPreloadWarned = false; | 90 | 89 | class Hooks { | 91 | 90 | #chains = { | 92 | 91 | /** | @@ -162,12 +161,9 @@ class Hooks { | 162 | 161 | } = pluckHooks(exports); | 163 | 162 |
| 164 | 163 | if (globalPreload && !initialize) { | 165 | | - if (globalPreloadWarned === false) { | 166 | | - globalPreloadWarned = true; | 167 | | - emitExperimentalWarning( | 168 | | - '`globalPreload` will be removed in a future version. Please use `initialize` instead.', | 169 | | - ); | 170 | | - } | | 164 | + emitExperimentalWarning( | | 165 | + '`globalPreload` is planned for removal in favor of `initialize`. `globalPreload`', | | 166 | + ); | 171 | 167 | ArrayPrototypePush(this.#chains.globalPreload, { __proto__: null, fn: globalPreload, url }); | 172 | 168 | } | 173 | 169 | 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 |
|---|
@@ -424,10 +424,22 @@ describe('Loader hooks', { concurrency: true }, () => { | 424 | 424 | const { stderr } = await spawnPromisified(execPath, [ | 425 | 425 | '--experimental-loader', | 426 | 426 | 'data:text/javascript,export function globalPreload(){}', | | 427 | + '--experimental-loader', | | 428 | + 'data:text/javascript,export function globalPreload(){return""}', | | 429 | + fixtures.path('empty.js'), | | 430 | + ]); | | 431 | + | | 432 | + assert.strictEqual(stderr.match(/`globalPreload` is an experimental feature/g).length, 1); | | 433 | + }); | | 434 | + | | 435 | + it('should not emit deprecation warning when initialize is supplied', async () => { | | 436 | + const { stderr } = await spawnPromisified(execPath, [ | | 437 | + '--experimental-loader', | | 438 | + 'data:text/javascript,export function globalPreload(){}export function initialize(){}', | 427 | 439 | fixtures.path('empty.js'), | 428 | 440 | ]); | 429 | 441 |
| 430 | | - assert.match(stderr, /`globalPreload` will be removed/); | | 442 | + assert.doesNotMatch(stderr, /`globalPreload` is an experimental feature/); | 431 | 443 | }); | 432 | 444 |
| 433 | 445 | it('should handle globalPreload returning undefined', async () => { | |
|