From 6200057d7d1e9aa229b275b18c75da83788725f0 Mon Sep 17 00:00:00 2001 From: azhar Date: Sat, 7 Nov 2026 13:59:31 +0700 Subject: [PATCH 1/9] test(web): PR file order resolves alias imports of dotted modules Co-Authored-By: Claude Fable 5.1 --- .../pullRequest/pullRequestFileOrder.logic.test.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.test.ts b/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.test.ts index 899aff44f1934..4d43f1b26c226 100644 --- a/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.test.ts +++ b/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.test.ts @@ -55,6 +55,19 @@ describe("orderDiffFiles", () => { ]); }); + it("falls back to the whole dotted module name, not its first segment", () => { + expect( + order([file("src/a.ts", ['import { b } from "~/z/b.logic";']), file("z/b.logic.ts")]), + ).toEqual(["z/b.logic.ts", "src/a.ts"]); + expect( + order([ + file("src/a.ts", ['import { b } from "~/z/b.logic";']), + file("z/b.logic.ts"), + file("other/b.ts"), + ]), + ).toEqual(["other/b.ts", "z/b.logic.ts", "src/a.ts"]); + }); + it("ignores an ambiguous last segment rather than guessing", () => { expect( order([ From b422806d49444644712cbafa1e8c4df6f5ade240 Mon Sep 17 00:00:00 2001 From: azhar Date: Sat, 7 Nov 2026 14:00:08 +0700 Subject: [PATCH 2/9] fix(web): PR file order follows alias imports of dotted modules An import such as ~/z/b.logic resolves through the last-segment fallback, which stripped a second dot segment and looked up b instead of b.logic. The dependency was missed, or matched an unrelated b.ts in the same diff. Module-map keys and lookups now strip only module extensions. Co-Authored-By: Claude Fable 5.1 --- .../pullRequest/pullRequestFileOrder.logic.ts | 46 ++++++++++++------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.ts b/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.ts index 737206d96e508..8f906691b22f3 100644 --- a/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.ts @@ -56,6 +56,17 @@ function baseName(path: string): string { return stripExtension(path.split("/").at(-1) ?? ""); } +// Import specifiers omit module extensions but keep dotted names such as `b.logic`, so module-map +// keys strip only the extensions an import could omit. +function stripModuleExtension(path: string): string { + const extension = MODULE_EXTENSIONS.find((candidate) => path.endsWith(candidate)); + return extension === undefined ? path : path.slice(0, -extension.length); +} + +function moduleName(path: string): string { + return stripModuleExtension(path.split("/").at(-1) ?? ""); +} + function resolveRelative(fromPath: string, specifier: string): string { const segments = fromPath.split("/").slice(0, -1); for (const part of specifier.split("/")) { @@ -72,7 +83,7 @@ function importedPaths( path: string, lines: ReadonlyArray, byModulePath: ReadonlyMap, - byBaseName: ReadonlyMap, + byModuleName: ReadonlyMap, ): ReadonlySet { const imported = new Set(); for (const line of lines) { @@ -80,17 +91,13 @@ function importedPaths( let match = IMPORT_SPECIFIER.exec(line); while (match !== null) { const specifier = match[1] ?? ""; - const withExtension = specifier.startsWith(".") - ? resolveRelative(path, specifier) - : specifier; - // Module-map keys omit extensions, which can differ from disk. - const extension = MODULE_EXTENSIONS.find((candidate) => withExtension.endsWith(candidate)); - const resolved = - extension === undefined ? withExtension : withExtension.slice(0, -extension.length); + const resolved = stripModuleExtension( + specifier.startsWith(".") ? resolveRelative(path, specifier) : specifier, + ); const target = byModulePath.get(resolved) ?? byModulePath.get(`${resolved}/index`) ?? - byBaseName.get(baseName(resolved)); + byModuleName.get(moduleName(resolved)); if (target !== undefined && target !== path) imported.add(target); match = IMPORT_SPECIFIER.exec(line); } @@ -140,22 +147,27 @@ export function orderDiffFiles( const sourcePaths = [...byPath.keys()].filter((path) => tiers.get(path) === "source"); const byModulePath = new Map(); - const ambiguousBaseNames = new Set(); - const byBaseName = new Map(); + const ambiguousModuleNames = new Set(); + const byModuleName = new Map(); for (const path of sourcePaths) { - byModulePath.set(stripExtension(path), path); - const base = baseName(path); - if (byBaseName.has(base)) ambiguousBaseNames.add(base); - byBaseName.set(base, path); + byModulePath.set(stripModuleExtension(path), path); + const name = moduleName(path); + if (byModuleName.has(name)) ambiguousModuleNames.add(name); + byModuleName.set(name, path); } - for (const base of ambiguousBaseNames) byBaseName.delete(base); + for (const name of ambiguousModuleNames) byModuleName.delete(name); const imports = new Map>(); for (const path of sourcePaths) { const file = byPath.get(path)!; imports.set( path, - importedPaths(path, [...file.additionLines, ...file.deletionLines], byModulePath, byBaseName), + importedPaths( + path, + [...file.additionLines, ...file.deletionLines], + byModulePath, + byModuleName, + ), ); } const orderedSource = orderByImports(sourcePaths, imports); From 9660e526e9b17f5c5642aa9a4445d7f4a70b96af Mon Sep 17 00:00:00 2001 From: azhar Date: Sat, 7 Nov 2026 14:20:40 +0700 Subject: [PATCH 3/9] test(web): PR file order keeps resolving imports with a bundler query Co-Authored-By: Claude Fable 5.1 --- .../pullRequest/pullRequestFileOrder.logic.test.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.test.ts b/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.test.ts index 4d43f1b26c226..e478a3383dd97 100644 --- a/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.test.ts +++ b/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.test.ts @@ -85,6 +85,18 @@ describe("orderDiffFiles", () => { ]); }); + it("resolves a specifier carrying a bundler query such as ?worker", () => { + expect( + order([file("src/a.js", ['import Worker from "./z.js?worker";']), file("src/z.js")]), + ).toEqual(["src/z.js", "src/a.js"]); + expect( + order([ + file("src/a.ts", ['import url from "~/lib/b.logic?url#hash";']), + file("lib/b.logic.ts"), + ]), + ).toEqual(["lib/b.logic.ts", "src/a.ts"]); + }); + it("reads require and bare imports too", () => { expect( order([ From a752321fc9d5c413dfac88f34cc7dff6c3acf18e Mon Sep 17 00:00:00 2001 From: azhar Date: Sat, 7 Nov 2026 14:21:16 +0700 Subject: [PATCH 4/9] fix(web): PR file order strips bundler queries before resolving imports Vite imports such as ./z.js?worker matched before only because the old last-segment fallback cut from the last dot. Cutting the query and fragment first keeps that dependency and lets it resolve by path. Co-Authored-By: Claude Fable 5.1 --- .../src/components/pullRequest/pullRequestFileOrder.logic.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.ts b/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.ts index 8f906691b22f3..ee248a4f768ac 100644 --- a/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.ts @@ -90,7 +90,8 @@ function importedPaths( IMPORT_SPECIFIER.lastIndex = 0; let match = IMPORT_SPECIFIER.exec(line); while (match !== null) { - const specifier = match[1] ?? ""; + // Bundler queries such as `?worker` or `?url` name the same file. + const specifier = (match[1] ?? "").replace(/[?#].*$/, ""); const resolved = stripModuleExtension( specifier.startsWith(".") ? resolveRelative(path, specifier) : specifier, ); From 03b8ad80605be7ab96fb8b1c08fc59a0b469ec9a Mon Sep 17 00:00:00 2001 From: azhar Date: Sat, 7 Nov 2026 14:32:36 +0700 Subject: [PATCH 5/9] test(web): PR file order keeps # package subpath imports Co-Authored-By: Claude Fable 5.1 --- .../pullRequest/pullRequestFileOrder.logic.test.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.test.ts b/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.test.ts index e478a3383dd97..009f054a38193 100644 --- a/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.test.ts +++ b/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.test.ts @@ -90,13 +90,16 @@ describe("orderDiffFiles", () => { order([file("src/a.js", ['import Worker from "./z.js?worker";']), file("src/z.js")]), ).toEqual(["src/z.js", "src/a.js"]); expect( - order([ - file("src/a.ts", ['import url from "~/lib/b.logic?url#hash";']), - file("lib/b.logic.ts"), - ]), + order([file("src/a.ts", ['import url from "~/lib/b.logic?url";']), file("lib/b.logic.ts")]), ).toEqual(["lib/b.logic.ts", "src/a.ts"]); }); + it("keeps the leading # of a package subpath import", () => { + expect( + order([file("src/a.ts", ['import { z } from "#internal/z";']), file("src/z.ts")]), + ).toEqual(["src/z.ts", "src/a.ts"]); + }); + it("reads require and bare imports too", () => { expect( order([ From c0927114dd4c86b04bd42cb64d5fc5cf2e041d8a Mon Sep 17 00:00:00 2001 From: azhar Date: Sat, 7 Nov 2026 14:32:57 +0700 Subject: [PATCH 6/9] fix(web): PR file order strips only the query from an import specifier A leading # starts a package subpath import such as #internal/z, so cutting at # emptied the specifier. Import specifiers carry no fragment, so only the ?query is removed. Co-Authored-By: Claude Fable 5.1 --- .../src/components/pullRequest/pullRequestFileOrder.logic.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.ts b/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.ts index ee248a4f768ac..4e688c3a6a1eb 100644 --- a/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.ts @@ -91,7 +91,7 @@ function importedPaths( let match = IMPORT_SPECIFIER.exec(line); while (match !== null) { // Bundler queries such as `?worker` or `?url` name the same file. - const specifier = (match[1] ?? "").replace(/[?#].*$/, ""); + const specifier = (match[1] ?? "").replace(/\?.*$/, ""); const resolved = stripModuleExtension( specifier.startsWith(".") ? resolveRelative(path, specifier) : specifier, ); From f1f95e7b18c7ea200c04787409242bc97cc2580e Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 15 Nov 2026 04:43:17 +0000 Subject: [PATCH 7/9] test(web): fold the # subpath import case into the bundler query test Co-Authored-By: Claude Opus 5.5 --- .../pullRequest/pullRequestFileOrder.logic.test.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.test.ts b/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.test.ts index 009f054a38193..11ceeff4de1eb 100644 --- a/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.test.ts +++ b/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.test.ts @@ -85,16 +85,13 @@ describe("orderDiffFiles", () => { ]); }); - it("resolves a specifier carrying a bundler query such as ?worker", () => { + it("strips a bundler query such as ?worker but keeps a # subpath import", () => { expect( order([file("src/a.js", ['import Worker from "./z.js?worker";']), file("src/z.js")]), ).toEqual(["src/z.js", "src/a.js"]); expect( order([file("src/a.ts", ['import url from "~/lib/b.logic?url";']), file("lib/b.logic.ts")]), ).toEqual(["lib/b.logic.ts", "src/a.ts"]); - }); - - it("keeps the leading # of a package subpath import", () => { expect( order([file("src/a.ts", ['import { z } from "#internal/z";']), file("src/z.ts")]), ).toEqual(["src/z.ts", "src/a.ts"]); From 90dbbba23a62e11e98aea4d1e89b8ff0ae7e558a Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 15 Nov 2026 04:49:33 +0000 Subject: [PATCH 8/9] test(web): alias query assertion fails when the import does not resolve Co-Authored-By: Claude Opus 5.5 --- .../components/pullRequest/pullRequestFileOrder.logic.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.test.ts b/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.test.ts index 11ceeff4de1eb..8afa4b657c146 100644 --- a/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.test.ts +++ b/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.test.ts @@ -90,8 +90,8 @@ describe("orderDiffFiles", () => { order([file("src/a.js", ['import Worker from "./z.js?worker";']), file("src/z.js")]), ).toEqual(["src/z.js", "src/a.js"]); expect( - order([file("src/a.ts", ['import url from "~/lib/b.logic?url";']), file("lib/b.logic.ts")]), - ).toEqual(["lib/b.logic.ts", "src/a.ts"]); + order([file("a.ts", ['import url from "~/lib/b.logic?url";']), file("lib/b.logic.ts")]), + ).toEqual(["lib/b.logic.ts", "a.ts"]); expect( order([file("src/a.ts", ['import { z } from "#internal/z";']), file("src/z.ts")]), ).toEqual(["src/z.ts", "src/a.ts"]); From ecc1185ae12bcdc91c40e168cc26ad5944284809 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 15 Nov 2026 05:00:43 +0000 Subject: [PATCH 9/9] fix(web): PR file order resolves .mts and .cts modules Module-map keys strip only known module extensions, so .mts and .cts sources kept their extension and no import reached them. Longer extensions come first because .mts also ends in .ts. Co-Authored-By: Claude Opus 5.5 --- .../pullRequest/pullRequestFileOrder.logic.test.ts | 11 +++++++++++ .../pullRequest/pullRequestFileOrder.logic.ts | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.test.ts b/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.test.ts index 8afa4b657c146..0626e463d751a 100644 --- a/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.test.ts +++ b/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.test.ts @@ -48,6 +48,17 @@ describe("orderDiffFiles", () => { ).toEqual(["src/lib/index.ts", "src/a.ts"]); }); + it("resolves .mts and .cts modules from NodeNext and extensionless specifiers", () => { + expect(order([file("a.mts", ['import { z } from "./z.mjs";']), file("z.mts")])).toEqual([ + "z.mts", + "a.mts", + ]); + expect(order([file("a.ts", ['import { z } from "./z";']), file("z.cts")])).toEqual([ + "z.cts", + "a.ts", + ]); + }); + it("falls back to the specifier's last segment when the path does not line up", () => { expect(order([file("src/a.ts", ['import { b } from "~/lib/b";']), file("lib/b.ts")])).toEqual([ "lib/b.ts", diff --git a/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.ts b/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.ts index 4e688c3a6a1eb..41ee82ebdf85e 100644 --- a/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestFileOrder.logic.ts @@ -22,7 +22,8 @@ const GENERATED_DIRECTORIES = new Set([ "vendor", ]); const TEST_DIRECTORIES = new Set(["__tests__", "tests", "test"]); -const MODULE_EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"]; +// `.mts` also ends in `.ts`, so longer extensions come first. +const MODULE_EXTENSIONS = [".mts", ".cts", ".mjs", ".cjs", ".tsx", ".jsx", ".ts", ".js"]; function diffFileTier(path: string): DiffFileTier { const segments = path.split("/");