esm: fix globalPreload warning

PR-URL: https://github.com/nodejs/node/pull/49069
Backport-PR-URL: https://github.com/nodejs/node/pull/50669
Fixes: https://github.com/nodejs/node/issues/49026
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Jacob Smith <jacob@frende.me>
This commit is contained in:
Antoine du Hamel authored and Michaël Zasso committed 2023-11-23 10:46:11 +01:00
1 parent c1a84398b4
commit 01ca6d277d
2 files changed
+16 -8

No files matched your search

+3 -7
View File
@@ -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) {
+13 -1
View File
@@ -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.match(stderr, /`globalPreload` will be removed/);
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.doesNotMatch(stderr, /`globalPreload` is an experimental feature/);
});
it('should handle globalPreload returning undefined', async () => {