| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b8d145d commit 9e8beff
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -212,7 +212,6 @@ const keyStrRegExp = /^[a-zA-Z_][a-zA-Z_0-9]*$/; | |||
| 212 | 212 | const numberRegExp = /^(0|[1-9][0-9]*)$/; | |
| 213 | 213 | ||
| 214 | 214 | const coreModuleRegExp = /^ {4}at (?:[^/\\(]+ \(|)node:(.+):\d+:\d+\)?$/; | |
| 215 | - const nodeModulesRegExp = /[/\\]node_modules[/\\](.+?)(?=[/\\])/g; | ||
| 216 | 215 | ||
| 217 | 216 | const classRegExp = /^(\s+[^(]*?)\s*{/; | |
| 218 | 217 | // eslint-disable-next-line node-core/no-unescaped-regexp-dot | |
@@ -1339,16 +1338,45 @@ function removeDuplicateErrorKeys(ctx, keys, err, stack) { | |||
| 1339 | 1338 | ||
| 1340 | 1339 | function markNodeModules(ctx, line) { | |
| 1341 | 1340 | let tempLine = ''; | |
| 1342 | - let nodeModule; | ||
| 1343 | - let pos = 0; | ||
| 1344 | - while ((nodeModule = nodeModulesRegExp.exec(line)) !== null) { | ||
| 1345 | - // '/node_modules/'.length === 14 | ||
| 1346 | - tempLine += StringPrototypeSlice(line, pos, nodeModule.index + 14); | ||
| 1347 | - tempLine += ctx.stylize(nodeModule[1], 'module'); | ||
| 1348 | - pos = nodeModule.index + nodeModule[0].length; | ||
| 1349 | - } | ||
| 1350 | - if (pos !== 0) { | ||
| 1351 | - line = tempLine + StringPrototypeSlice(line, pos); | ||
| 1341 | + let lastPos = 0; | ||
| 1342 | + let searchFrom = 0; | ||
| 1343 | + | ||
| 1344 | + while (true) { | ||
| 1345 | + const nodeModulePosition = StringPrototypeIndexOf(line, 'node_modules', searchFrom); | ||
| 1346 | + if (nodeModulePosition === -1) { | ||
| 1347 | + break; | ||
| 1348 | + } | ||
| 1349 | + | ||
| 1350 | + // Ensure it's a path segment: must have a path separator before and after | ||
| 1351 | + const separator = line[nodeModulePosition - 1]; | ||
| 1352 | + const after = line[nodeModulePosition + 12]; // 'node_modules'.length === 12 | ||
| 1353 | + | ||
| 1354 | + if ((after !== '/' && after !== '\\') || (separator !== '/' && separator !== '\\')) { | ||
| 1355 | + // Not a proper segment; continue searching | ||
| 1356 | + searchFrom = nodeModulePosition + 1; | ||
| 1357 | + continue; | ||
| 1358 | + } | ||
| 1359 | + | ||
| 1360 | + const moduleStart = nodeModulePosition + 13; // Include trailing separator | ||
| 1361 | + | ||
| 1362 | + // Append up to and including '/node_modules/' | ||
| 1363 | + tempLine += StringPrototypeSlice(line, lastPos, moduleStart); | ||
| 1364 | + | ||
| 1365 | + let moduleEnd = StringPrototypeIndexOf(line, separator, moduleStart); | ||
| 1366 | + if (line[moduleStart] === '@') { | ||
| 1367 | + // Namespaced modules have an extra slash: @namespace/package | ||
| 1368 | + moduleEnd = StringPrototypeIndexOf(line, separator, moduleEnd + 1); | ||
| 1369 | + } | ||
| 1370 | + | ||
| 1371 | + const nodeModule = StringPrototypeSlice(line, moduleStart, moduleEnd); | ||
| 1372 | + tempLine += ctx.stylize(nodeModule, 'module'); | ||
| 1373 | + | ||
| 1374 | + lastPos = moduleEnd; | ||
| 1375 | + searchFrom = moduleEnd; | ||
| 1376 | + } | ||
| 1377 | + | ||
| 1378 | + if (lastPos !== 0) { | ||
| 1379 | + line = tempLine + StringPrototypeSlice(line, lastPos); | ||
| 1352 | 1380 | } | |
| 1353 | 1381 | return line; | |
| 1354 | 1382 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2833,7 +2833,7 @@ assert.strictEqual( | |||
| 2833 | 2833 | // Use a fake stack to verify the expected colored outcome. | |
| 2834 | 2834 | const stack = [ | |
| 2835 | 2835 | 'Error: CWD is grayed out, even cwd that are percent encoded!', | |
| 2836 | - ' at A.<anonymous> (/test/node_modules/foo/node_modules/bar/baz.js:2:7)', | ||
| 2836 | + ' at A.<anonymous> (/test/node_modules/foo/node_modules/@namespace/bar/baz.js:2:7)', | ||
| 2837 | 2837 | ' at Module._compile (node:internal/modules/cjs/loader:827:30)', | |
| 2838 | 2838 | ' at Fancy (node:vm:697:32)', | |
| 2839 | 2839 | // This file is not an actual Node.js core file. | |
@@ -2858,7 +2858,7 @@ assert.strictEqual( | |||
| 2858 | 2858 | } | |
| 2859 | 2859 | const escapedCWD = util.inspect(process.cwd()).slice(1, -1); | |
| 2860 | 2860 | util.inspect(err, { colors: true }).split('\n').forEach((line, i) => { | |
| 2861 | - let expected = stack[i].replace(/node_modules\/([^/]+)/gi, (_, m) => { | ||
| 2861 | + let expected = stack[i].replace(/node_modules\/(@[^/]+\/[^/]+|[^/]+)/gi, (_, m) => { | ||
| 2862 | 2862 | return `node_modules/\u001b[4m${m}\u001b[24m`; | |
| 2863 | 2863 | }).replaceAll(new RegExp(`(\\(?${escapedCWD}(\\\\|/))`, 'gi'), (_, m) => { | |
| 2864 | 2864 | return `\x1B[90m${m}\x1B[39m`; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments