GeezerVison is showing github.com — src: add --pending-deprecation and NODE_PENDING_DEPRECATION · nodejs/node@a16b570
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: doc/api/cli.md +28Lines changed: 28 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -137,6 +137,20 @@ added: v0.11.14 | 137 | 137 |
| 138 | 138 | Throw errors for deprecations. | 139 | 139 |
| | 140 | +### `--pending-deprecation` | | 141 | +<!-- YAML | | 142 | +added: REPLACEME | | 143 | +--> | | 144 | + | | 145 | +Emit pending deprecation warnings. | | 146 | + | | 147 | +*Note*: Pending deprecations are generally identical to a runtime deprecation | | 148 | +with the notable exception that they are turned *off* by default and will not | | 149 | +be emitted unless either the `--pending-deprecation` command line flag, or the | | 150 | +`NODE_PENDING_DEPRECATION=1` environment variable, is set. Pending deprecations | | 151 | +are used to provide a kind of selective "early warning" mechanism that | | 152 | +developers may leverage to detect deprecated API usage. | | 153 | + | 140 | 154 | ### `--no-warnings` | 141 | 155 | <!-- YAML | 142 | 156 | added: v6.0.0 | @@ -383,6 +397,20 @@ added: v7.5.0 | 383 | 397 |
| 384 | 398 | When set to `1`, process warnings are silenced. | 385 | 399 |
| | 400 | +### `NODE_PENDING_DEPRECATION=1` | | 401 | +<!-- YAML | | 402 | +added: REPLACEME | | 403 | +--> | | 404 | + | | 405 | +When set to `1`, emit pending deprecation warnings. | | 406 | + | | 407 | +*Note*: Pending deprecations are generally identical to a runtime deprecation | | 408 | +with the notable exception that they are turned *off* by default and will not | | 409 | +be emitted unless either the `--pending-deprecation` command line flag, or the | | 410 | +`NODE_PENDING_DEPRECATION=1` environment variable, is set. Pending deprecations | | 411 | +are used to provide a kind of selective "early warning" mechanism that | | 412 | +developers may leverage to detect deprecated API usage. | | 413 | + | 386 | 414 | ### `NODE_PRESERVE_SYMLINKS=1` | 387 | 415 | <!-- YAML | 388 | 416 | added: v7.1.0 | |
Collapse file Copy file name to clipboardExpand all lines: doc/node.1 +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -115,6 +115,10 @@ Print stack traces for deprecations. | 115 | 115 | .BR \-\-throw\-deprecation | 116 | 116 | Throw errors for deprecations. | 117 | 117 |
| | 118 | +.TP | | 119 | +.BR \-\-pending\-deprecation | | 120 | +Emit pending deprecation warnings. | | 121 | + | 118 | 122 | .TP | 119 | 123 | .BR \-\-no\-warnings | 120 | 124 | Silence all process warnings (including deprecations). | @@ -259,6 +263,10 @@ When set to \fI1\fR, process warnings are silenced. | 259 | 263 | .BR NODE_PATH =\fIpath\fR[:\fI...\fR] | 260 | 264 | \':\'\-separated list of directories prefixed to the module search path. | 261 | 265 |
| | 266 | +.TP | | 267 | +.BR NODE_PENDING_DEPRECATION = \fI1\fR | | 268 | +When set to \fI1\fR, emit pending deprecation warnings. | | 269 | + | 262 | 270 | .TP | 263 | 271 | .BR NODE_REPL_HISTORY =\fIfile\fR | 264 | 272 | Path to the file used to store the persistent REPL history. The default path | |
Collapse file Copy file name to clipboardExpand all lines: src/node.cc +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -209,6 +209,10 @@ bool trace_warnings = false; | 209 | 209 | // that is used by lib/module.js | 210 | 210 | bool config_preserve_symlinks = false; | 211 | 211 |
| | 212 | +// Set by ParseArgs when --pending-deprecation or NODE_PENDING_DEPRECATION | | 213 | +// is used. | | 214 | +bool config_pending_deprecation = false; | | 215 | + | 212 | 216 | // Set in node.cc by ParseArgs when --redirect-warnings= is used. | 213 | 217 | std::string config_warning_file; // NOLINT(runtime/string) | 214 | 218 |
| @@ -3768,6 +3772,8 @@ static void ParseArgs(int* argc, | 3768 | 3772 | short_circuit = true; | 3769 | 3773 | } else if (strcmp(arg, "--zero-fill-buffers") == 0) { | 3770 | 3774 | zero_fill_all_buffers = true; | | 3775 | + } else if (strcmp(arg, "--pending-deprecation") == 0) { | | 3776 | + config_pending_deprecation = true; | 3771 | 3777 | } else if (strcmp(arg, "--v8-options") == 0) { | 3772 | 3778 | new_v8_argv[new_v8_argc] = "--help"; | 3773 | 3779 | new_v8_argc += 1; | @@ -4187,6 +4193,12 @@ void Init(int* argc, | 4187 | 4193 | V8::SetFlagsFromString(NODE_V8_OPTIONS, sizeof(NODE_V8_OPTIONS) - 1); | 4188 | 4194 | #endif | 4189 | 4195 |
| | 4196 | + { | | 4197 | + std::string text; | | 4198 | + config_pending_deprecation = | | 4199 | + SafeGetenv("NODE_PENDING_DEPRECATION", &text) && text[0] == '1'; | | 4200 | + } | | 4201 | + | 4190 | 4202 | // Allow for environment set preserving symlinks. | 4191 | 4203 | { | 4192 | 4204 | std::string text; | |
Collapse file Copy file name to clipboardExpand all lines: src/node_config.cc +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -49,6 +49,9 @@ static void InitConfig(Local<Object> target, | 49 | 49 | if (config_preserve_symlinks) | 50 | 50 | READONLY_BOOLEAN_PROPERTY("preserveSymlinks"); | 51 | 51 |
| | 52 | + if (config_pending_deprecation) | | 53 | + READONLY_BOOLEAN_PROPERTY("pendingDeprecation"); | | 54 | + | 52 | 55 | if (!config_warning_file.empty()) { | 53 | 56 | Local<String> name = OneByteString(env->isolate(), "warningFile"); | 54 | 57 | Local<String> value = String::NewFromUtf8(env->isolate(), | |
Collapse file Copy file name to clipboardExpand all lines: src/node_internals.h +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -76,6 +76,10 @@ extern bool config_expose_internals; | 76 | 76 | // it to stderr. | 77 | 77 | extern std::string config_warning_file; // NOLINT(runtime/string) | 78 | 78 |
| | 79 | +// Set in node.cc by ParseArgs when --pending-deprecation or | | 80 | +// NODE_PENDING_DEPRECATION is used | | 81 | +extern bool config_pending_deprecation; | | 82 | + | 79 | 83 | // Tells whether it is safe to call v8::Isolate::GetCurrent(). | 80 | 84 | extern bool v8_initialized; | 81 | 85 |
| |
Collapse file Copy file name to clipboard +45Lines changed: 45 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use strict'; | | 2 | + | | 3 | +// Tests that --pending-deprecation and NODE_PENDING_DEPRECATION both | | 4 | +// set the process.binding('config').pendingDeprecation flag that is | | 5 | +// used to determine if pending deprecation messages should be shown. | | 6 | +// The test is performed by launching two child processes that run | | 7 | +// this same test script with different arguments. If those exit with | | 8 | +// code 0, then the test passes. If they don't, it fails. | | 9 | + | | 10 | +const common = require('../common'); | | 11 | + | | 12 | +const assert = require('assert'); | | 13 | +const config = process.binding('config'); | | 14 | +const fork = require('child_process').fork; | | 15 | + | | 16 | +function message(name) { | | 17 | + return `${name} did not set the process.binding('config').` + | | 18 | + 'pendingDeprecation flag.'; | | 19 | +} | | 20 | + | | 21 | +switch (process.argv[2]) { | | 22 | + case 'env': | | 23 | + case 'switch': | | 24 | + assert.strictEqual(config.pendingDeprecation, true); | | 25 | + break; | | 26 | + default: | | 27 | + // Verify that the flag is off by default. | | 28 | + assert.strictEqual(config.pendingDeprecation, undefined); | | 29 | + | | 30 | + // Test the --pending-deprecation command line switch. | | 31 | + fork(__filename, ['switch'], { | | 32 | + execArgv: ['--pending-deprecation'], | | 33 | + silent: true | | 34 | + }).on('exit', common.mustCall((code) => { | | 35 | + assert.strictEqual(code, 0, message('--pending-deprecation')); | | 36 | + })); | | 37 | + | | 38 | + // Test the NODE_PENDING_DEPRECATION environment var. | | 39 | + fork(__filename, ['env'], { | | 40 | + env: {NODE_PENDING_DEPRECATION: 1}, | | 41 | + silent: true | | 42 | + }).on('exit', common.mustCall((code) => { | | 43 | + assert.strictEqual(code, 0, message('NODE_PENDING_DEPRECATION')); | | 44 | + })); | | 45 | +} |
|