From ca20f5931dca00b844906d2aa2c6c4f248229389 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Thu, 20 Apr 2023 01:52:05 +0200 Subject: [PATCH] esm: remove support for deprecated hooks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Those have been deprecated for a while, it's time. PR-URL: https://github.com/nodejs/node/pull/47580 Backport-PR-URL: https://github.com/nodejs/node/pull/50669 Reviewed-By: Jacob Smith Reviewed-By: Mohammed Keyvanzadeh Reviewed-By: Michaƫl Zasso Reviewed-By: Geoffrey Booth Reviewed-By: Yagiz Nizipli Reviewed-By: James M Snell --- lib/internal/modules/esm/hooks.js | 37 ------------------- .../test-esm-loader-obsolete-hooks.mjs | 28 -------------- .../es-module-loaders/hooks-obsolete.mjs | 22 ----------- 3 files changed, 87 deletions(-) delete mode 100644 test/es-module/test-esm-loader-obsolete-hooks.mjs delete mode 100644 test/fixtures/es-module-loaders/hooks-obsolete.mjs diff --git a/lib/internal/modules/esm/hooks.js b/lib/internal/modules/esm/hooks.js index 8ab54bdbde9396..76239c2e6fb104 100644 --- a/lib/internal/modules/esm/hooks.js +++ b/lib/internal/modules/esm/hooks.js @@ -1,7 +1,6 @@ 'use strict'; const { - ArrayPrototypeJoin, ArrayPrototypePush, FunctionPrototypeCall, Int32Array, @@ -658,45 +657,9 @@ function pluckHooks({ globalPreload, resolve, load, - // obsolete hooks: - dynamicInstantiate, - getFormat, - getGlobalPreloadCode, - getSource, - transformSource, }) { - const obsoleteHooks = []; const acceptedHooks = { __proto__: null }; - if (getGlobalPreloadCode) { - globalPreload ??= getGlobalPreloadCode; - - process.emitWarning( - 'Loader hook "getGlobalPreloadCode" has been renamed to "globalPreload"', - ); - } - if (dynamicInstantiate) { - ArrayPrototypePush(obsoleteHooks, 'dynamicInstantiate'); - } - if (getFormat) { - ArrayPrototypePush(obsoleteHooks, 'getFormat'); - } - if (getSource) { - ArrayPrototypePush(obsoleteHooks, 'getSource'); - } - if (transformSource) { - ArrayPrototypePush(obsoleteHooks, 'transformSource'); - } - - if (obsoleteHooks.length) { - process.emitWarning( - `Obsolete loader hook(s) supplied and will be ignored: ${ - ArrayPrototypeJoin(obsoleteHooks, ', ') - }`, - 'DeprecationWarning', - ); - } - if (globalPreload) { acceptedHooks.globalPreload = globalPreload; } diff --git a/test/es-module/test-esm-loader-obsolete-hooks.mjs b/test/es-module/test-esm-loader-obsolete-hooks.mjs deleted file mode 100644 index fa0baef8a216b7..00000000000000 --- a/test/es-module/test-esm-loader-obsolete-hooks.mjs +++ /dev/null @@ -1,28 +0,0 @@ -import { spawnPromisified } from '../common/index.mjs'; -import { fileURL, path } from '../common/fixtures.mjs'; -import { match, notStrictEqual } from 'node:assert'; -import { execPath } from 'node:process'; -import { describe, it } from 'node:test'; - - -describe('ESM: deprecation warnings for obsolete hooks', { concurrency: true }, () => { - it(async () => { - const { code, stderr } = await spawnPromisified(execPath, [ - '--no-warnings', - '--throw-deprecation', - '--experimental-loader', - fileURL('es-module-loaders', 'hooks-obsolete.mjs').href, - path('print-error-message.js'), - ]); - - // DeprecationWarning: Obsolete loader hook(s) supplied and will be ignored: - // dynamicInstantiate, getFormat, getSource, transformSource - match(stderr, /DeprecationWarning:/); - match(stderr, /dynamicInstantiate/); - match(stderr, /getFormat/); - match(stderr, /getSource/); - match(stderr, /transformSource/); - - notStrictEqual(code, 0); - }); -}); diff --git a/test/fixtures/es-module-loaders/hooks-obsolete.mjs b/test/fixtures/es-module-loaders/hooks-obsolete.mjs deleted file mode 100644 index bb10ef8ef4b29a..00000000000000 --- a/test/fixtures/es-module-loaders/hooks-obsolete.mjs +++ /dev/null @@ -1,22 +0,0 @@ -export function dynamicInstantiate() {} -export function getFormat() {} -export function getSource() {} -export function transformSource() {} - - -export function resolve(specifier, context, next) { - if (specifier === 'whatever') return { - url: specifier, - }; - - return next(specifier); -} - -export function load(url, context, next) { - if (url === 'whatever') return { - format: 'module', - source: '', - }; - - return next(url); -}