Skip to content

Commit f8d12b8

Browse files
committed
Source map node internals with ignoreList
This hides the node internals automatically but still lets them be visible when expanded.
1 parent 67ec4a3 commit f8d12b8

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

fixtures/flight/server/region.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,22 @@ if (process.env.NODE_ENV === 'development') {
206206

207207
const sourceMap = nodeModule.findSourceMap(requestedFilePath);
208208
let map;
209-
// There are two ways to return a source map depending on what we observe in error.stack.
210-
// A real app will have a similar choice to make for which strategy to pick.
211-
if (!sourceMap || !isCompiledOutput) {
209+
if (requestedFilePath.startsWith('node:')) {
210+
// This is a node internal. We don't include any source code for this but we still
211+
// generate a source map for it so that we can add it to an ignoreList automatically.
212+
map = {
213+
version: 3,
214+
sources: [requestedFilePath],
215+
sourcesContent: ['// Node Internals'],
216+
mappings: 'AAAA',
217+
ignoreList: [0],
218+
sourceRoot: '',
219+
};
220+
} else if (!sourceMap || !isCompiledOutput) {
212221
// If a file doesn't have a source map, such as this file, then we generate a blank
213222
// source map that just contains the original content and segments pointing to the
214-
// original lines.
215-
// Similarly
223+
// original lines. If a line number points to uncompiled output, like if source mapping
224+
// was already applied we also use this path.
216225
const sourceContent = await readFile(requestedFilePath, 'utf8');
217226
const lines = sourceContent.split('\n').length;
218227
map = {
@@ -224,6 +233,10 @@ if (process.env.NODE_ENV === 'development') {
224233
// generated for each parsed segment or add a segment for each column.
225234
mappings: 'AAAA' + ';AACA'.repeat(lines - 1),
226235
sourceRoot: '',
236+
// Add any node_modules to the ignore list automatically.
237+
ignoreList: requestedFilePath.includes('node_modules')
238+
? [0]
239+
: undefined,
227240
};
228241
} else {
229242
// We always set prepareStackTrace before reading the stack so that we get the stack

0 commit comments

Comments
 (0)