Skip to content
Open
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
19 changes: 19 additions & 0 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -4517,6 +4517,23 @@
Passing a non-extractable [`CryptoKey`][] to [`KeyObject.from()`][] is
deprecated and will throw an error in a future version.

### DEP0205: `module.register()`

<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/62401
description: Runtime deprecation.
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/62395

Check warning on line 4528 in doc/api/deprecations.md

View workflow job for this annotation

GitHub Actions / lint-pr-url

pr-url doesn't match the URL of the current PR.
description: Documentation-only deprecation.
-->

Type: Runtime

[`module.register()`][] is deprecated. Use [`module.registerHooks()`][]
instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add small paragraph that exaplain why and what is the gap between theses api mainly one is only async and the other can do both

[DEP0142]: #dep0142-repl_builtinlibs
[NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
[RFC 6066]: https://tools.ietf.org/html/rfc6066#section-3
Expand Down Expand Up @@ -4621,6 +4638,8 @@
[`message.trailersDistinct`]: http.md#messagetrailersdistinct
[`message.trailers`]: http.md#messagetrailers
[`module.createRequire()`]: module.md#modulecreaterequirefilename
[`module.register()`]: module.md#moduleregisterspecifier-parenturl-options
[`module.registerHooks()`]: module.md#moduleregisterhooksoptions
[`os.networkInterfaces()`]: os.md#osnetworkinterfaces
[`os.tmpdir()`]: os.md#ostmpdir
[`process.env`]: process.md#processenv
Expand Down
10 changes: 9 additions & 1 deletion doc/api/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,15 @@
added:
- v20.6.0
- v18.19.0
deprecated: REPLACEME
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/62401
description: Runtime deprecation (DEP0205).
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/62395

Check warning on line 187 in doc/api/module.md

View workflow job for this annotation

GitHub Actions / lint-pr-url

pr-url doesn't match the URL of the current PR.
description: Documentation-only deprecation (DEP0205). Use
`module.registerHooks()` instead.
- version:
- v23.6.1
- v22.13.1
Expand All @@ -193,7 +201,7 @@
description: Add support for WHATWG URL instances.
-->

> Stability: 1.1 - Active development
> Stability: 0 - Deprecated: Use [`module.registerHooks()`][] instead.

* `specifier` {string|URL} Customization hooks to be registered; this should be
the same string that would be passed to `import()`, except that if it is
Expand Down
13 changes: 12 additions & 1 deletion lib/internal/modules/esm/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ const {
} = require('internal/errors').codes;
const { getOptionValue } = require('internal/options');
const { isURL, pathToFileURL } = require('internal/url');
const { kEmptyObject } = require('internal/util');
const {
getDeprecationWarningEmitter,
kEmptyObject,
} = require('internal/util');
const {
compileSourceTextModule,
SourceTextModuleTypes: { kUser },
Expand Down Expand Up @@ -955,7 +958,15 @@ function isCascadedLoaderInitialized() {
* });
* ```
*/
const emitRegisterDeprecation = getDeprecationWarningEmitter(
'DEP0205',
'`module.register()` is deprecated. Use `module.registerHooks()` instead.',
undefined,
false,
);

function register(specifier, parentURL = undefined, options) {
emitRegisterDeprecation();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
emitRegisterDeprecation();
emitRegisterDeprecation();

separate core logic & deprecation by space

if (parentURL != null && typeof parentURL === 'object' && !isURL(parentURL)) {
options = parentURL;
parentURL = options.parentURL;
Expand Down
2 changes: 1 addition & 1 deletion test/doctool/test-doc-api-json.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,5 @@ for await (const dirent of await fs.opendir(new URL('../../out/doc/api/', import
assert.partialDeepStrictEqual(allExpectedKeys, findAllKeys(json));
}

assert.strictEqual(numberOfDeprecatedSections, 44); // Increase this number every time a new API is deprecated.
assert.strictEqual(numberOfDeprecatedSections, 45); // Increase this number every time a new API is deprecated.
assert.strictEqual(numberOfRemovedAPIs, 46); // Increase this number every time a section is marked as removed.
60 changes: 60 additions & 0 deletions test/es-module/test-esm-register-deprecation.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { spawnPromisified } from '../common/index.mjs';
import * as fixtures from '../common/fixtures.mjs';

import assert from 'node:assert';
import { execPath } from 'node:process';
import { describe, it } from 'node:test';

const urlToRegister = fixtures.fileURL('es-module-loaders', 'loader-resolve-passthru.mjs');
const urlToRegisterEscaped = JSON.stringify(urlToRegister.href);


describe('module.register() deprecation (DEP0205)', { concurrency: !process.env.TEST_PARALLEL }, () => {
it('emits DEP0205 when module.register() is called', async () => {
const { code, stderr } = await spawnPromisified(execPath, [
'--input-type=module',
'--eval',
`import { register } from 'node:module'; register(${urlToRegisterEscaped});`,
]);

assert.match(stderr, /\[DEP0205\]/);
assert.strictEqual(code, 0);
});

it('only emits the warning once per process', async () => {
const { code, stderr } = await spawnPromisified(execPath, [
'--input-type=module',
'--eval',
`import { register } from 'node:module';
register(${urlToRegisterEscaped});
register(${urlToRegisterEscaped});`,
]);

assert.strictEqual(stderr.split('[DEP0205]').length - 1, 1);
assert.strictEqual(code, 0);
});

it('does not emit when --no-deprecation is set', async () => {
const { code, stderr } = await spawnPromisified(execPath, [
'--no-deprecation',
'--input-type=module',
'--eval',
`import { register } from 'node:module'; register(${urlToRegisterEscaped});`,
]);

assert.doesNotMatch(stderr, /DEP0205/);
assert.strictEqual(code, 0);
});

it('throws when --throw-deprecation is set', async () => {
const { code, stderr } = await spawnPromisified(execPath, [
'--throw-deprecation',
'--input-type=module',
'--eval',
`import { register } from 'node:module'; register(${urlToRegisterEscaped});`,
]);

assert.match(stderr, /DEP0205/);
assert.notStrictEqual(code, 0);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { spawnSyncAndAssert } from '../common/child_process.js';
spawnSyncAndAssert(
execPath,
[
'--no-deprecation',
'--no-experimental-require-module',
'--import',
fixtures.fileURL('es-module-loaders/builtin-named-exports.mjs'),
Expand Down
Loading