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:
翠 / green authored and GitHub committed 2023-08-17 08:42:12 +00:00
1 parent b4a2be457c
commit 6bb400f8ec
4 files changed
+30

No files matched your search

+9
View File
@@ -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()