TypeScript
fix(web): terminal links keep route and pnpm paths in one piece (#30603)
tiliakoos1b14cb3d8cbe
diff --git a/apps/web/src/terminal-links.test.ts b/apps/web/src/terminal-links.test.tsindex dafb07f3544..cc239b39c9e 100644--- a/apps/web/src/terminal-links.test.ts+++ b/apps/web/src/terminal-links.test.ts@@ -125,7 +125,11 @@ describe("extractTerminalLinks", () => {String.raw`żółć\main.ts:12`,"src/cafe\u0301.ts:12","src/𐐀.ts:12",- ])("keeps the complete Unicode relative path %s", (text) => {+ "src/app/[id]/page.tsx:3:10",+ "src/routes/(app)/+page.svelte:12:4",+ "node_modules/.pnpm/[email protected]/node_modules/react/index.js:12:5",+ "app/routes/posts.$id.tsx:5",+ ])("keeps the complete relative path %s", (text) => {expect(extractTerminalLinks(`see ${text} for details`)).toEqual([{ kind: "path", text, start: 4, end: 4 + text.length },]);diff --git a/apps/web/src/terminal-links.ts b/apps/web/src/terminal-links.tsindex 68bd4c8d5a8..114219e721e 100644--- a/apps/web/src/terminal-links.ts+++ b/apps/web/src/terminal-links.ts@@ -31,8 +31,10 @@ const URL_PATTERN = /https?:\/\/[^\s"'`<>]+/giu;const POWERSHELL_PROMPT_PATH_PATTERN = /^PS ((?:[A-Za-z]:[\\/]|\\\\|\/)[^>\r\n]*)>/u;// Bare paths start only at a segment boundary: hover detection runs this on// every frame, so separator-free output must not be rescanned at every suffix.+// For the same reason `]` needs its `[`: trimming a long run of `]` is quadratic.+// Parentheses count only before a slash, so `src/foo.ts(3,10)` stays a compiler location.const FILE_PATH_PATTERN =- /(?:~[\\/]|\.{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;+ /(?:~[\\/]|\.{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;const QUOTED_FILE_PATH_PATTERN =/(["'`])(?<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;const TRAILING_PUNCTUATION_PATTERN = /[.,;!?]+$/;