From 834187b187a72914a7f5f06903ce8e643cdbe5d2 Mon Sep 17 00:00:00 2001 From: Ethan Arrowood Date: Fri, 10 Nov 2023 10:13:59 -0700 Subject: [PATCH] src: add `--disable-warnings` option --- doc/api/cli.md | 57 ++++++++++ lib/internal/process/warning.js | 10 ++ src/node_options.cc | 3 + src/node_options.h | 1 + test/fixtures/disable-warnings-worker.js | 3 + test/fixtures/disable-warnings.js | 11 ++ test/parallel/test-process-warnings.mjs | 131 +++++++++++++++++++++++ 7 files changed, 216 insertions(+) create mode 100644 test/fixtures/disable-warnings-worker.js create mode 100644 test/fixtures/disable-warnings.js create mode 100644 test/parallel/test-process-warnings.mjs diff --git a/doc/api/cli.md b/doc/api/cli.md index 1f5136ce69442f..46827e0a2f3b3b 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -443,6 +443,59 @@ Affects the default output directory of: * [`--heap-prof-dir`][] * [`--redirect-warnings`][] +### `--disable-warnings=code-or-type` + + + +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-warnings=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-warnings=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`