| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f64d0de commit a2d2003
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -250,7 +250,6 @@ const keyStrRegExp = /^[a-zA-Z_][a-zA-Z_0-9]*$/; | |||
| 250 | 250 | const numberRegExp = /^(0|[1-9][0-9]*)$/; | |
| 251 | 251 | ||
| 252 | 252 | const coreModuleRegExp = /^ {4}at (?:[^/\\(]+ \(|)node:(.+):\d+:\d+\)?$/; | |
| 253 | - const nodeModulesRegExp = /[/\\]node_modules[/\\](.+?)(?=[/\\])/g; | ||
| 254 | 253 | ||
| 255 | 254 | const classRegExp = /^(\s+[^(]*?)\s*{/; | |
| 256 | 255 | // eslint-disable-next-line node-core/no-unescaped-regexp-dot | |
@@ -1423,16 +1422,45 @@ function removeDuplicateErrorKeys(ctx, keys, err, stack) { | |||
| 1423 | 1422 | ||
| 1424 | 1423 | function markNodeModules(ctx, line) { | |
| 1425 | 1424 | let tempLine = ''; | |
| 1426 | - let nodeModule; | ||
| 1427 | - let pos = 0; | ||
| 1428 | - while ((nodeModule = nodeModulesRegExp.exec(line)) !== null) { | ||
| 1429 | - // '/node_modules/'.length === 14 | ||
| 1430 | - tempLine += StringPrototypeSlice(line, pos, nodeModule.index + 14); | ||
| 1431 | - tempLine += ctx.stylize(nodeModule[1], 'module'); | ||
| 1432 | - pos = nodeModule.index + nodeModule[0].length; | ||
| 1433 | - } | ||
| 1434 | - if (pos !== 0) { | ||
| 1435 | - line = tempLine + StringPrototypeSlice(line, pos); | ||
| 1425 | + let lastPos = 0; | ||
| 1426 | + let searchFrom = 0; | ||
| 1427 | + | ||
| 1428 | + while (true) { | ||
| 1429 | + const nodeModulePosition = StringPrototypeIndexOf(line, 'node_modules', searchFrom); | ||
| 1430 | + if (nodeModulePosition === -1) { | ||
| 1431 | + break; | ||
| 1432 | + } | ||
| 1433 | + | ||
| 1434 | + // Ensure it's a path segment: must have a path separator before and after | ||
| 1435 | + const separator = line[nodeModulePosition - 1]; | ||
| 1436 | + const after = line[nodeModulePosition + 12]; // 'node_modules'.length === 12 | ||
| 1437 | + | ||
| 1438 | + if ((after !== '/' && after !== '\\') || (separator !== '/' && separator !== '\\')) { | ||
| 1439 | + // Not a proper segment; continue searching | ||
| 1440 | + searchFrom = nodeModulePosition + 1; | ||
| 1441 | + continue; | ||
| 1442 | + } | ||
| 1443 | + | ||
| 1444 | + const moduleStart = nodeModulePosition + 13; // Include trailing separator | ||
| 1445 | + | ||
| 1446 | + // Append up to and including '/node_modules/' | ||
| 1447 | + tempLine += StringPrototypeSlice(line, lastPos, moduleStart); | ||
| 1448 | + | ||
| 1449 | + let moduleEnd = StringPrototypeIndexOf(line, separator, moduleStart); | ||
| 1450 | + if (line[moduleStart] === '@') { | ||
| 1451 | + // Namespaced modules have an extra slash: @namespace/package | ||
| 1452 | + moduleEnd = StringPrototypeIndexOf(line, separator, moduleEnd + 1); | ||
| 1453 | + } | ||
| 1454 | + | ||
| 1455 | + const nodeModule = StringPrototypeSlice(line, moduleStart, moduleEnd); | ||
| 1456 | + tempLine += ctx.stylize(nodeModule, 'module'); | ||
| 1457 | + | ||
| 1458 | + lastPos = moduleEnd; | ||
| 1459 | + searchFrom = moduleEnd; | ||
| 1460 | + } | ||
| 1461 | + | ||
| 1462 | + if (lastPos !== 0) { | ||
| 1463 | + line = tempLine + StringPrototypeSlice(line, lastPos); | ||
| 1436 | 1464 | } | |
| 1437 | 1465 | return line; | |
| 1438 | 1466 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2835,7 +2835,7 @@ assert.strictEqual( | |||
| 2835 | 2835 | // Use a fake stack to verify the expected colored outcome. | |
| 2836 | 2836 | const stack = [ | |
| 2837 | 2837 | 'Error: CWD is grayed out, even cwd that are percent encoded!', | |
| 2838 | - ' at A.<anonymous> (/test/node_modules/foo/node_modules/bar/baz.js:2:7)', | ||
| 2838 | + ' at A.<anonymous> (/test/node_modules/foo/node_modules/@namespace/bar/baz.js:2:7)', | ||
| 2839 | 2839 | ' at Module._compile (node:internal/modules/cjs/loader:827:30)', | |
| 2840 | 2840 | ' at Fancy (node:vm:697:32)', | |
| 2841 | 2841 | // This file is not an actual Node.js core file. | |
@@ -2860,7 +2860,7 @@ assert.strictEqual( | |||
| 2860 | 2860 | } | |
| 2861 | 2861 | const escapedCWD = util.inspect(process.cwd()).slice(1, -1); | |
| 2862 | 2862 | util.inspect(err, { colors: true }).split('\n').forEach((line, i) => { | |
| 2863 | - let expected = stack[i].replace(/node_modules\/([^/]+)/gi, (_, m) => { | ||
| 2863 | + let expected = stack[i].replace(/node_modules\/(@[^/]+\/[^/]+|[^/]+)/gi, (_, m) => { | ||
| 2864 | 2864 | return `node_modules/\u001b[4m${m}\u001b[24m`; | |
| 2865 | 2865 | }).replaceAll(new RegExp(`(\\(?${escapedCWD}(\\\\|/))`, 'gi'), (_, m) => { | |
| 2866 | 2866 | return `\x1B[90m${m}\x1B[39m`; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments