diff --git a/scripts/bundle-a2ui.mjs b/scripts/bundle-a2ui.mjs index 085ea322075..3cf462e4c3b 100644 --- a/scripts/bundle-a2ui.mjs +++ b/scripts/bundle-a2ui.mjs @@ -67,6 +67,18 @@ export function getLocalRolldownCliCandidates(repoRoot = rootDir) { ]; } +export function compareNormalizedPaths(left, right) { + const normalizedLeft = normalizePath(left); + const normalizedRight = normalizePath(right); + if (normalizedLeft < normalizedRight) { + return -1; + } + if (normalizedLeft > normalizedRight) { + return 1; + } + return 0; +} + async function walkFiles(entryPath, files) { if (!isBundleHashInputPath(entryPath)) { return; @@ -106,7 +118,7 @@ async function computeHash() { await walkFiles(inputPath, files); } } - files.sort((left, right) => normalizePath(left).localeCompare(normalizePath(right))); + files.sort(compareNormalizedPaths); const hash = createHash("sha256"); for (const filePath of files) { diff --git a/test/scripts/bundle-a2ui.test.ts b/test/scripts/bundle-a2ui.test.ts index d40d4d4f2a1..1143b2e2e1e 100644 --- a/test/scripts/bundle-a2ui.test.ts +++ b/test/scripts/bundle-a2ui.test.ts @@ -1,6 +1,7 @@ import path from "node:path"; import { describe, expect, it } from "vitest"; import { + compareNormalizedPaths, getLocalRolldownCliCandidates, isBundleHashInputPath, } from "../../scripts/bundle-a2ui.mjs"; @@ -36,4 +37,15 @@ describe("scripts/bundle-a2ui.mjs", () => { path.join(repoRoot, "node_modules", "rolldown", "bin", "cli.mjs"), ); }); + + it("sorts hash inputs without locale-dependent collation", () => { + const paths = ["repo/Z.ts", "repo/a.ts", "repo/ä.ts", "repo/A.ts"]; + + expect([...paths].toSorted(compareNormalizedPaths)).toEqual([ + "repo/A.ts", + "repo/Z.ts", + "repo/a.ts", + "repo/ä.ts", + ]); + }); });