mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
lib: add api to detect whether source-maps are enabled
Add `process.sourceMapsEnabled` to detect whether source-maps are enabled. Fixes: https://github.com/nodejs/node/issues/46304 PR-URL: https://github.com/nodejs/node/pull/46391 Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
This commit is contained in:
1 parent
b4a2be457c
commit
6bb400f8ec
4 files changed
+30
No files matched your search
@@ -3517,6 +3517,19 @@ throw an error.
|
||||
Using this function is mutually exclusive with using the deprecated
|
||||
[`domain`][] built-in module.
|
||||
|
||||
## `process.sourceMapsEnabled`
|
||||
|
||||
<!-- YAML
|
||||
added: REPLACEME
|
||||
-->
|
||||
|
||||
> Stability: 1 - Experimental
|
||||
|
||||
* {boolean}
|
||||
|
||||
The `process.sourceMapsEnabled` property returns whether the
|
||||
[Source Map v3][Source Map] support for stack traces is enabled.
|
||||
|
||||
## `process.stderr`
|
||||
|
||||
* {Stream}
|
||||
|
||||
@@ -326,6 +326,7 @@ process.emitWarning = emitWarning;
|
||||
|
||||
{
|
||||
const {
|
||||
getSourceMapsEnabled,
|
||||
setSourceMapsEnabled,
|
||||
maybeCacheGeneratedSourceMap,
|
||||
} = require('internal/source_map/source_map_cache');
|
||||
@@ -333,6 +334,14 @@ process.emitWarning = emitWarning;
|
||||
setMaybeCacheGeneratedSourceMap,
|
||||
} = internalBinding('errors');
|
||||
|
||||
ObjectDefineProperty(process, 'sourceMapsEnabled', {
|
||||
__proto__: null,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
get() {
|
||||
return getSourceMapsEnabled();
|
||||
},
|
||||
});
|
||||
process.setSourceMapsEnabled = setSourceMapsEnabled;
|
||||
// The C++ land calls back to maybeCacheGeneratedSourceMap()
|
||||
// when code is generated by user with eval() or new Function()
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
|
||||
'use strict';
|
||||
require('../../../common');
|
||||
const assert = require('assert');
|
||||
Error.stackTraceLimit = 5;
|
||||
|
||||
assert.strictEqual(process.sourceMapsEnabled, true);
|
||||
process.setSourceMapsEnabled(false);
|
||||
assert.strictEqual(process.sourceMapsEnabled, false);
|
||||
|
||||
try {
|
||||
require('../enclosing-call-site-min.js');
|
||||
@@ -17,6 +20,7 @@ delete require.cache[require
|
||||
|
||||
// Re-enable.
|
||||
process.setSourceMapsEnabled(true);
|
||||
assert.strictEqual(process.sourceMapsEnabled, true);
|
||||
|
||||
try {
|
||||
require('../enclosing-call-site-min.js');
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
'use strict';
|
||||
require('../../../common');
|
||||
const assert = require('assert');
|
||||
Error.stackTraceLimit = 5;
|
||||
|
||||
assert.strictEqual(process.sourceMapsEnabled, false);
|
||||
process.setSourceMapsEnabled(true);
|
||||
assert.strictEqual(process.sourceMapsEnabled, true);
|
||||
|
||||
try {
|
||||
require('../enclosing-call-site-min.js');
|
||||
@@ -14,6 +17,7 @@ delete require.cache[require
|
||||
.resolve('../enclosing-call-site-min.js')];
|
||||
|
||||
process.setSourceMapsEnabled(false);
|
||||
assert.strictEqual(process.sourceMapsEnabled, false);
|
||||
|
||||
try {
|
||||
require('../enclosing-call-site-min.js');
|
||||
|
||||
Reference in new issue
Block a user