From e9fd52fe780ab4a325cd52838225dcf180ff54fe Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Sun, 16 Mar 2025 22:25:39 +0000 Subject: [PATCH] repl: deprecate `repl.builtinModules` Co-authored-by: Antoine du Hamel --- doc/api/deprecations.md | 18 ++++++++++++++++++ doc/api/repl.md | 6 +++++- lib/repl.js | 14 +++++++++++--- test/parallel/test-repl-options.js | 3 +++ 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 6fa684a37855c4..0984ad249da215 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -3879,6 +3879,24 @@ Type: Runtime When an `args` array is passed to [`child_process.execFile`][] or [`child_process.spawn`][] with the option `{ shell: true }`, the values are not escaped, only space-separated, which can lead to shell injection. +### DEP0191: `repl.builtinModules` + + + +Type: Documentation-only (supports [`--pending-deprecation`][]) + +The `node:repl` module exports a `builtinModules` property that contains an array +of built-in modules. This was incomplete and matched the already deprecated +`repl._builtinLibs` ([DEP0142][]) instead it's better to rely +upon `require('node:module').builtinModules`. + +[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 [RFC 8247 Section 2.4]: https://www.rfc-editor.org/rfc/rfc8247#section-2.4 diff --git a/doc/api/repl.md b/doc/api/repl.md index a134c493a54812..3550055cda49e6 100644 --- a/doc/api/repl.md +++ b/doc/api/repl.md @@ -646,11 +646,14 @@ with REPL instances programmatically. +> Stability: 0 - Deprecated. Use [`module.builtinModules`][] instead. + * {string\[]} -A list of the names of all Node.js modules, e.g., `'http'`. +A list of the names of some Node.js modules, e.g., `'http'`. ## `repl.start([options])` @@ -908,6 +911,7 @@ avoiding open network interfaces. [`ERR_INVALID_REPL_INPUT`]: errors.md#err_invalid_repl_input [`curl(1)`]: https://curl.haxx.se/docs/manpage.html [`domain`]: domain.md +[`module.builtinModules`]: module.md#modulebuiltinmodules [`process.setUncaughtExceptionCaptureCallback()`]: process.md#processsetuncaughtexceptioncapturecallbackfn [`readline.InterfaceCompleter`]: readline.md#use-of-the-completer-function [`repl.ReplServer`]: #class-replserver diff --git a/lib/repl.js b/lib/repl.js index e61a24bb041c7e..0a5a9187ddce3f 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -1858,9 +1858,17 @@ module.exports = { ObjectDefineProperty(module.exports, 'builtinModules', { __proto__: null, - get: () => _builtinLibs, - set: (val) => _builtinLibs = val, - enumerable: true, + get: pendingDeprecation ? deprecate( + () => _builtinLibs, + 'repl.builtinModules is deprecated. Check module.builtinModules instead', + 'DEP0191', + ) : () => _builtinLibs, + set: pendingDeprecation ? deprecate( + (val) => _builtinLibs = val, + 'repl.builtinModules is deprecated. Check module.builtinModules instead', + 'DEP0191', + ) : (val) => _builtinLibs = val, + enumerable: false, configurable: true, }); diff --git a/test/parallel/test-repl-options.js b/test/parallel/test-repl-options.js index faaf461165ef8f..8b4ba71f11aa95 100644 --- a/test/parallel/test-repl-options.js +++ b/test/parallel/test-repl-options.js @@ -29,12 +29,15 @@ const repl = require('repl'); const cp = require('child_process'); assert.strictEqual(repl.repl, undefined); + repl._builtinLibs; // eslint-disable-line no-unused-expressions +repl.builtinModules; // eslint-disable-line no-unused-expressions common.expectWarning({ DeprecationWarning: { DEP0142: 'repl._builtinLibs is deprecated. Check module.builtinModules instead', + DEP0191: 'repl.builtinModules is deprecated. Check module.builtinModules instead', DEP0141: 'repl.inputStream and repl.outputStream are deprecated. ' + 'Use repl.input and repl.output instead', }