Skip to content

Commit

Permalink
esm: fix globalPreload warning
Browse files Browse the repository at this point in the history
PR-URL: #49069
Backport-PR-URL: #50669
Fixes: #49026
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Jacob Smith <jacob@frende.me>
  • Loading branch information
aduh95 authored and targos committed Nov 23, 2023
1 parent c1a8439 commit 01ca6d2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
10 changes: 3 additions & 7 deletions lib/internal/modules/esm/hooks.js
Expand Up @@ -85,7 +85,6 @@ let importMetaInitializer;

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

let globalPreloadWarned = false;
class Hooks {
#chains = {
/**
Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 13 additions & 1 deletion test/es-module/test-esm-loader-hooks.mjs
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 01ca6d2

Please sign in to comment.