From 988542cd7289baa9906632cb95552ce2f4cc7e26 Mon Sep 17 00:00:00 2001 From: Ethan Arrowood Date: Tue, 21 Nov 2023 13:30:02 -0700 Subject: [PATCH] src: add `--disable-warning` option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Geoffrey Booth Co-authored-by: Antoine du Hamel PR-URL: https://github.com/nodejs/node/pull/50661 Fixes: https://github.com/nodejs/node/issues/30810 Fixes: https://github.com/nodejs/node/issues/47478 Fixes: https://github.com/nodejs/node/issues/46862 Fixes: https://github.com/nodejs/node/issues/40940 Reviewed-By: Geoffrey Booth Reviewed-By: James M Snell Reviewed-By: Benjamin Gruenbaum Reviewed-By: Vinícius Lourenço Claro Cardoso Reviewed-By: Antoine du Hamel Reviewed-By: Yagiz Nizipli Reviewed-By: Matteo Collina Reviewed-By: Richard Lau --- doc/api/cli.md | 55 ++++++++ lib/internal/process/warning.js | 18 +++ src/node_options.cc | 4 + src/node_options.h | 1 + test/fixtures/disable-warning-worker.js | 4 + test/fixtures/disable-warning.js | 15 +++ test/parallel/test-process-warnings.mjs | 163 ++++++++++++++++++++++++ 7 files changed, 260 insertions(+) create mode 100644 test/fixtures/disable-warning-worker.js create mode 100644 test/fixtures/disable-warning.js create mode 100644 test/parallel/test-process-warnings.mjs diff --git a/doc/api/cli.md b/doc/api/cli.md index 3e982d39707c4d..5c36e2baa1d411 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -443,6 +443,57 @@ Affects the default output directory of: * [`--heap-prof-dir`][] * [`--redirect-warnings`][] +### `--disable-warning=code-or-type` + +> Stability: 1.1 - Active development + + + +Disable specific process warnings by `code` or `type`. + +Warnings emitted from [`process.emitWarning()`][emit_warning] may contain a +`code` and a `type`. This option will not-emit warnings that have a matching +`code` or `type`. + +List of [deprecation warnings][]. + +The Node.js core warning types are: `DeprecationWarning` and +`ExperimentalWarning` + +For example, the following script will not emit +[DEP0025 `require('node:sys')`][DEP0025 warning] when executed with +`node --disable-warning=DEP0025`: + +```mjs +import sys from 'node:sys'; +``` + +```cjs +const sys = require('node:sys'); +``` + +For example, the following script will emit the +[DEP0025 `require('node:sys')`][DEP0025 warning], but not any Experimental +Warnings (such as +[ExperimentalWarning: `vm.measureMemory` is an experimental feature][] +in <=v21) when executed with `node --disable-warning=ExperimentalWarnings`: + +```mjs +import sys from 'node:sys'; +import vm from 'node:vm'; + +vm.measureMemory(); +``` + +```cjs +const sys = require('node:sys'); +const vm = require('node:vm'); + +vm.measureMemory(); +``` + ### `--disable-proto=mode`