Skip to content

Commit c4dcd3e

Browse files
committed
fix(workbench): tighten bundle chunk matching
1 parent 427d741 commit c4dcd3e

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

apps/workbench/build/workbench-chunking.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ function normalizeModuleId(id: string) {
1414

1515
export function matchesNodeModulePackage(id: string, packageName: string) {
1616
const normalizedId = normalizeModuleId(id);
17-
return (
18-
normalizedId.includes(`/node_modules/${packageName}/`) ||
19-
normalizedId.includes(`/node_modules/${packageName}`)
20-
);
17+
const packageRoot = `/node_modules/${packageName}`;
18+
const packageIndex = normalizedId.indexOf(packageRoot);
19+
if (packageIndex === -1) {
20+
return false;
21+
}
22+
23+
const remainder = normalizedId.slice(packageIndex + packageRoot.length);
24+
return remainder === "" || remainder.startsWith("/") || remainder.startsWith("?");
2125
}
2226

2327
export function resolveWorkbenchManualChunk(id: string) {

apps/workbench/src/__tests__/workbench-chunking.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ describe("workbench chunking", () => {
3232
).toBeUndefined();
3333
});
3434

35+
it("does not let package prefixes override more specific chunk groups", () => {
36+
expect(
37+
resolveWorkbenchManualChunk(
38+
"/repo/apps/workbench/node_modules/three-stdlib/math/CurveModifier.js",
39+
),
40+
).toBe("vendor-r3f");
41+
});
42+
3543
it("leaves unrelated modules ungrouped", () => {
3644
expect(
3745
resolveWorkbenchManualChunk(

0 commit comments

Comments
 (0)