Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esm: fix globalPreload warning #49069

Merged
merged 4 commits into from
Aug 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions lib/internal/modules/esm/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ let importMetaInitializer;

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

let globalPreloadWarned = false;
class Hooks {
#chains = {
/**
Expand Down Expand Up @@ -162,12 +161,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
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,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