diff --git a/lib/internal/modules/esm/hooks.js b/lib/internal/modules/esm/hooks.js index e4ee2db18a0899..abba6b51a05939 100644 --- a/lib/internal/modules/esm/hooks.js +++ b/lib/internal/modules/esm/hooks.js @@ -85,7 +85,6 @@ let importMetaInitializer; // [2] `validate...()`s throw the wrong error -let globalPreloadWarned = false; class Hooks { #chains = { /** @@ -161,12 +160,9 @@ class Hooks { } = pluckHooks(exports); if (globalPreload && !initialize) { - if (globalPreloadWarned === false) { - globalPreloadWarned = true; - emitExperimentalWarning( - '`globalPreload` will be removed in a future version. Please use `initialize` instead.', - ); - } + emitExperimentalWarning( + '`globalPreload` is planned for removal in favor of `initialize`. `globalPreload`', + ); ArrayPrototypePush(this.#chains.globalPreload, { __proto__: null, fn: globalPreload, url }); } if (resolve) { diff --git a/test/es-module/test-esm-loader-hooks.mjs b/test/es-module/test-esm-loader-hooks.mjs index 4684f813a16dce..633e4d07b3744c 100644 --- a/test/es-module/test-esm-loader-hooks.mjs +++ b/test/es-module/test-esm-loader-hooks.mjs @@ -372,10 +372,22 @@ describe('Loader hooks', { concurrency: true }, () => { const { stderr } = await spawnPromisified(execPath, [ '--experimental-loader', 'data:text/javascript,export function globalPreload(){}', + '--experimental-loader', + 'data:text/javascript,export function globalPreload(){return""}', + fixtures.path('empty.js'), + ]); + + assert.strictEqual(stderr.match(/`globalPreload` is an experimental feature/g).length, 1); + }); + + it('should not emit deprecation warning when initialize is supplied', async () => { + const { stderr } = await spawnPromisified(execPath, [ + '--experimental-loader', + 'data:text/javascript,export function globalPreload(){}export function initialize(){}', fixtures.path('empty.js'), ]); - assert.match(stderr, /`globalPreload` will be removed/); + assert.doesNotMatch(stderr, /`globalPreload` is an experimental feature/); }); it('should handle globalPreload returning undefined', async () => {