GeezerVison is showing github.com — lib: add api to detect whether source-maps are enabled · nodejs/node@17246be
File treeExpand file treeCollapse file tree Open diff view settings test/fixtures/source-map/output
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: doc/api/process.md +13Lines changed: 13 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -3458,6 +3458,19 @@ throw an error. | 3458 | 3458 | Using this function is mutually exclusive with using the deprecated | 3459 | 3459 | [`domain`][] built-in module. | 3460 | 3460 |
| | 3461 | +## `process.sourceMapsEnabled` | | 3462 | +
| | 3463 | +<!-- YAML | | 3464 | +added: REPLACEME | | 3465 | +--> | | 3466 | +
| | 3467 | +> Stability: 1 - Experimental | | 3468 | +
| | 3469 | +* {boolean} | | 3470 | +
| | 3471 | +The `process.sourceMapsEnabled` property returns whether the | | 3472 | +[Source Map v3][Source Map] support for stack traces is enabled. | | 3473 | +
| 3461 | 3474 | ## `process.stderr` | 3462 | 3475 |
| 3463 | 3476 | * {Stream} | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/bootstrap/node.js +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -359,13 +359,22 @@ process.emitWarning = emitWarning; | 359 | 359 |
| 360 | 360 | { | 361 | 361 | const { | | 362 | + getSourceMapsEnabled, | 362 | 363 | setSourceMapsEnabled, | 363 | 364 | maybeCacheGeneratedSourceMap, | 364 | 365 | } = require('internal/source_map/source_map_cache'); | 365 | 366 | const { | 366 | 367 | setMaybeCacheGeneratedSourceMap, | 367 | 368 | } = internalBinding('errors'); | 368 | 369 |
| | 370 | + ObjectDefineProperty(process, 'sourceMapsEnabled', { | | 371 | + __proto__: null, | | 372 | + enumerable: true, | | 373 | + configurable: true, | | 374 | + get() { | | 375 | + return getSourceMapsEnabled(); | | 376 | + }, | | 377 | + }); | 369 | 378 | process.setSourceMapsEnabled = setSourceMapsEnabled; | 370 | 379 | // The C++ land calls back to maybeCacheGeneratedSourceMap() | 371 | 380 | // when code is generated by user with eval() or new Function() | |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/source-map/output/source_map_disabled_by_api.js +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 |
| 3 | 3 | 'use strict'; | 4 | 4 | require('../../../common'); | | 5 | +const assert = require('assert'); | 5 | 6 | Error.stackTraceLimit = 5; | 6 | 7 |
| | 8 | +assert.strictEqual(process.sourceMapsEnabled, true); | 7 | 9 | process.setSourceMapsEnabled(false); | | 10 | +assert.strictEqual(process.sourceMapsEnabled, false); | 8 | 11 |
| 9 | 12 | try { | 10 | 13 | require('../enclosing-call-site-min.js'); | @@ -17,6 +20,7 @@ delete require.cache[require | 17 | 20 |
| 18 | 21 | // Re-enable. | 19 | 22 | process.setSourceMapsEnabled(true); | | 23 | +assert.strictEqual(process.sourceMapsEnabled, true); | 20 | 24 |
| 21 | 25 | try { | 22 | 26 | require('../enclosing-call-site-min.js'); | |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/source-map/output/source_map_enabled_by_api.js +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | 'use strict'; | 2 | 2 | require('../../../common'); | | 3 | +const assert = require('assert'); | 3 | 4 | Error.stackTraceLimit = 5; | 4 | 5 |
| | 6 | +assert.strictEqual(process.sourceMapsEnabled, false); | 5 | 7 | process.setSourceMapsEnabled(true); | | 8 | +assert.strictEqual(process.sourceMapsEnabled, true); | 6 | 9 |
| 7 | 10 | try { | 8 | 11 | require('../enclosing-call-site-min.js'); | @@ -14,6 +17,7 @@ delete require.cache[require | 14 | 17 | .resolve('../enclosing-call-site-min.js')]; | 15 | 18 |
| 16 | 19 | process.setSourceMapsEnabled(false); | | 20 | +assert.strictEqual(process.sourceMapsEnabled, false); | 17 | 21 |
| 18 | 22 | try { | 19 | 23 | require('../enclosing-call-site-min.js'); | |
|