Skip to content

Commit 01ca6d2

Browse files
aduh95targos
authored andcommitted
esm: fix globalPreload warning
PR-URL: #49069 Backport-PR-URL: #50669 Fixes: #49026 Reviewed-By: Chemi Atlow <[email protected]> Reviewed-By: Jacob Smith <[email protected]>
1 parent c1a8439 commit 01ca6d2

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

lib/internal/modules/esm/hooks.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ let importMetaInitializer;
8585

8686
// [2] `validate...()`s throw the wrong error
8787

88-
let globalPreloadWarned = false;
8988
class Hooks {
9089
#chains = {
9190
/**
@@ -161,12 +160,9 @@ class Hooks {
161160
} = pluckHooks(exports);
162161

163162
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+
);
170166
ArrayPrototypePush(this.#chains.globalPreload, { __proto__: null, fn: globalPreload, url });
171167
}
172168
if (resolve) {

test/es-module/test-esm-loader-hooks.mjs

+13-1
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,22 @@ describe('Loader hooks', { concurrency: true }, () => {
372372
const { stderr } = await spawnPromisified(execPath, [
373373
'--experimental-loader',
374374
'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(){}',
375387
fixtures.path('empty.js'),
376388
]);
377389

378-
assert.match(stderr, /`globalPreload` will be removed/);
390+
assert.doesNotMatch(stderr, /`globalPreload` is an experimental feature/);
379391
});
380392

381393
it('should handle globalPreload returning undefined', async () => {

0 commit comments

Comments
 (0)