Skip to content

Commit 1b14cb3

Browse files
authored
fix(web): terminal links keep route and pnpm paths in one piece (#30603)
1 parent 9bf7dcd commit 1b14cb3

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎apps/web/src/terminal-links.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,11 @@ describe("extractTerminalLinks", () => {
125125
String.raw`żółć\main.ts:12`,
126126
"src/cafe\u0301.ts:12",
127127
"src/𐐀.ts:12",
128-
])("keeps the complete Unicode relative path %s", (text) => {
128+
"src/app/[id]/page.tsx:3:10",
129+
"src/routes/(app)/+page.svelte:12:4",
130+
"node_modules/.pnpm/[email protected]/node_modules/react/index.js:12:5",
131+
"app/routes/posts.$id.tsx:5",
132+
])("keeps the complete relative path %s", (text) => {
129133
expect(extractTerminalLinks(`see ${text} for details`)).toEqual([
130134
{ kind: "path", text, start: 4, end: 4 + text.length },
131135
]);

‎apps/web/src/terminal-links.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ const URL_PATTERN = /https?:\/\/[^\s"'`<>]+/giu;
3131
const POWERSHELL_PROMPT_PATH_PATTERN = /^PS ((?:[A-Za-z]:[\\/]|\\\\|\/)[^>\r\n]*)>/u;
3232
// Bare paths start only at a segment boundary: hover detection runs this on
3333
// every frame, so separator-free output must not be rescanned at every suffix.
34+
// For the same reason `]` needs its `[`: trimming a long run of `]` is quadratic.
35+
// Parentheses count only before a slash, so `src/foo.ts(3,10)` stays a compiler location.
3436
const FILE_PATH_PATTERN =
35-
/(?:~[\\/]|\.{1,2}[\\/]|\/|[A-Za-z]:[\\/]|\\\\)[^\s"'`<>]+|(?<![\p{L}\p{M}\p{N}._-])[\p{L}\p{M}\p{N}._-]+(?:[\\/][\p{L}\p{M}\p{N}._-]+)+(?::\d+){0,2}/gu;
37+
/(?:~[\\/]|\.{1,2}[\\/]|\/|[A-Za-z]:[\\/]|\\\\)[^\s"'`<>]+|(?<![\p{L}\p{M}\p{N}._-])[\p{L}\p{M}\p{N}._-]+(?:[\\/](?:[\p{L}\p{M}\p{N}._$+@-]|\[{1,2}[\p{L}\p{M}\p{N}._-]+\]{1,2}|\([\p{L}\p{M}\p{N}._-]+\)(?=[\\/]))+)+(?::\d+){0,2}/gu;
3638
const QUOTED_FILE_PATH_PATTERN =
3739
/(["'`])(?<path>(?:~[\\/]|\.{1,2}[\\/]|\/|[A-Za-z]:[\\/]|\\\\|[\p{L}\p{M}\p{N}._ -]+[\\/])[^\r\n]*?|[\p{L}\p{M}\p{N}._ -]+\.[\p{L}\p{M}\p{N}_-]+(?::\d+){0,2})\1(?<position>(?::\d+){0,2})/gu;
3840
const TRAILING_PUNCTUATION_PATTERN = /[.,;!?]+$/;

0 commit comments

Comments
 (0)