Skip to content

Commit 31442b9

Browse files
aduh95RafaelGSS
authored andcommitted
esm: fix globalPreload warning
PR-URL: #49069 Fixes: #49026 Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Jacob Smith <jacob@frende.me>
1 parent 600c08d commit 31442b9

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
@@ -86,7 +86,6 @@ let importMetaInitializer;
8686

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

89-
let globalPreloadWarned = false;
9089
class Hooks {
9190
#chains = {
9291
/**
@@ -162,12 +161,9 @@ class Hooks {
162161
} = pluckHooks(exports);
163162

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

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,22 @@ describe('Loader hooks', { concurrency: true }, () => {
424424
const { stderr } = await spawnPromisified(execPath, [
425425
'--experimental-loader',
426426
'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(){}',
427439
fixtures.path('empty.js'),
428440
]);
429441

430-
assert.match(stderr, /`globalPreload` will be removed/);
442+
assert.doesNotMatch(stderr, /`globalPreload` is an experimental feature/);
431443
});
432444

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

0 commit comments

Comments
 (0)