Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 36.4k
lib: allow skipping source maps in node_modules#56639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3,6 +3,7 @@ | ||
| const { | ||
| ArrayPrototypePush, | ||
| JSONParse, | ||
| ObjectFreeze, | ||
| RegExpPrototypeExec, | ||
| SafeMap, | ||
| StringPrototypeCodePointAt, | ||
| @@ -15,15 +16,15 @@ let debug = require('internal/util/debuglog').debuglog('source_map', (fn) => { | ||
| debug = fn; | ||
| }); | ||
| const { validateBoolean } = require('internal/validators'); | ||
| const { validateBoolean, validateObject } = require('internal/validators'); | ||
| const { | ||
| setSourceMapsEnabled: setSourceMapsNative, | ||
| } = internalBinding('errors'); | ||
| const { | ||
| defaultPrepareStackTrace, | ||
| setInternalPrepareStackTrace, | ||
| } = require('internal/errors'); | ||
| const { getLazy } = require('internal/util'); | ||
| const { getLazy, isUnderNodeModules, kEmptyObject } = require('internal/util'); | ||
| const getModuleSourceMapCache = getLazy(() => { | ||
| const { SourceMapCacheMap } = require('internal/source_map/source_map_cache_map'); | ||
| @@ -45,30 +46,48 @@ const { fileURLToPath, pathToFileURL, URL, URLParse } = require('internal/url'); | ||
| let SourceMap; | ||
| // This is configured with --enable-source-maps during pre-execution. | ||
| let sourceMapsEnabled = false; | ||
| function getSourceMapsEnabled() { | ||
| return sourceMapsEnabled; | ||
| let sourceMapsSupport = ObjectFreeze({ | ||
| __proto__: null, | ||
| enabled: false, | ||
| nodeModules: false, | ||
| generatedCode: false, | ||
legendecas marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| }); | ||
| function getSourceMapsSupport() { | ||
| // Return a read-only object. | ||
| return sourceMapsSupport; | ||
| } | ||
| /** | ||
| * Enables or disables source maps programmatically. | ||
| * @param {boolean} val | ||
| * @param {boolean} enabled | ||
| * @param {object} options | ||
| * @param {boolean} [options.nodeModules] | ||
| * @param {boolean} [options.generatedCode] | ||
| */ | ||
| function setSourceMapsEnabled(val) { | ||
| validateBoolean(val, 'val'); | ||
| function setSourceMapsSupport(enabled, options = kEmptyObject) { | ||
| validateBoolean(enabled, 'enabled'); | ||
| validateObject(options, 'options'); | ||
| const { nodeModules = false, generatedCode = false } = options; | ||
H4ad marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| validateBoolean(nodeModules, 'options.nodeModules'); | ||
| validateBoolean(generatedCode, 'options.generatedCode'); | ||
| setSourceMapsNative(val); | ||
| if (val) { | ||
| setSourceMapsNative(enabled); | ||
| if (enabled) { | ||
| const { | ||
| prepareStackTraceWithSourceMaps, | ||
| } = require('internal/source_map/prepare_stack_trace'); | ||
| setInternalPrepareStackTrace(prepareStackTraceWithSourceMaps); | ||
| } else if (sourceMapsEnabled !== undefined) { | ||
| // Reset prepare stack trace callback only when disabling source maps. | ||
| } else { | ||
| setInternalPrepareStackTrace(defaultPrepareStackTrace); | ||
| } | ||
| sourceMapsEnabled = val; | ||
| sourceMapsSupport = ObjectFreeze({ | ||
| __proto__: null, | ||
| enabled, | ||
| nodeModules: nodeModules, | ||
| generatedCode: generatedCode, | ||
| }); | ||
| } | ||
| /** | ||
| @@ -130,14 +149,18 @@ function extractSourceMapURLMagicComment(content) { | ||
| * @param {string | undefined} sourceMapURL - the source map url | ||
| */ | ||
| function maybeCacheSourceMap(filename, content, moduleInstance, isGeneratedSource, sourceURL, sourceMapURL) { | ||
| const sourceMapsEnabled = getSourceMapsEnabled(); | ||
| if (!(process.env.NODE_V8_COVERAGE || sourceMapsEnabled)) return; | ||
| const support = getSourceMapsSupport(); | ||
| if (!(process.env.NODE_V8_COVERAGE || support.enabled)) return; | ||
| const { normalizeReferrerURL } = require('internal/modules/helpers'); | ||
| filename = normalizeReferrerURL(filename); | ||
| if (filename === undefined) { | ||
| // This is most likely an invalid filename in sourceURL of [eval]-wrapper. | ||
| return; | ||
| } | ||
| if (!support.nodeModules && isUnderNodeModules(filename)) { | ||
| // Skip file under node_modules if not enabled. | ||
| return; | ||
| } | ||
| if (sourceMapURL === undefined) { | ||
| sourceMapURL = extractSourceMapURLMagicComment(content); | ||
| @@ -185,8 +208,8 @@ function maybeCacheSourceMap(filename, content, moduleInstance, isGeneratedSourc | ||
| * @param {string} content - the eval'd source code | ||
| */ | ||
| function maybeCacheGeneratedSourceMap(content) { | ||
| const sourceMapsEnabled = getSourceMapsEnabled(); | ||
| if (!(process.env.NODE_V8_COVERAGE || sourceMapsEnabled)) return; | ||
| const support = getSourceMapsSupport(); | ||
| if (!(process.env.NODE_V8_COVERAGE || support.enabled || support.generated)) return; | ||
| const sourceURL = extractSourceURLMagicComment(content); | ||
| if (sourceURL === null) { | ||
| @@ -352,6 +375,10 @@ function findSourceMap(sourceURL) { | ||
| return undefined; | ||
| } | ||
| if (!getSourceMapsSupport().nodeModules && isUnderNodeModules(sourceURL)) { | ||
| return undefined; | ||
| } | ||
| SourceMap ??= require('internal/source_map/source_map').SourceMap; | ||
| try { | ||
| if (RegExpPrototypeExec(kLeadingProtocol, sourceURL) === null) { | ||
| @@ -377,8 +404,8 @@ function findSourceMap(sourceURL) { | ||
| module.exports = { | ||
| findSourceMap, | ||
| getSourceMapsEnabled, | ||
| setSourceMapsEnabled, | ||
| getSourceMapsSupport, | ||
| setSourceMapsSupport, | ||
| maybeCacheSourceMap, | ||
| maybeCacheGeneratedSourceMap, | ||
| sourceMapCacheToObject, | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.