Skip to content

Commit 67db69c

Browse files
kevin9327claudedavidmckayv
authored
Rebuild the app when a shared module it bundles changes (#594)
The build cache behind `bun run serve` keyed app/dist on app/src, the lockfile, the manifests, the Vite config and the tenant package, but not on shared/, which the app bundles too: the attachment limits and the handoff markers are imported from there. A change to shared/ alone left the old build in place while the server ran the new code. Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: David McKay <david@copilotkit.ai>
1 parent e9e0e72 commit 67db69c

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

app/scripts/build-cache.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,25 @@ async function collectBuildInputs(
171171
include: (path) => hasSourceExtension(path),
172172
skipDirectory: (path) => basename(path) === "node_modules",
173173
});
174+
// The app bundles modules from `shared/` too (attachment limits, handoff markers), so a change
175+
// there has to rebuild it just as a change under `app/src` does.
176+
const sharedFiles = await collectFiles(join(resolvedRoot, "shared"), {
177+
prefix: "shared",
178+
include: (path) => hasSourceExtension(path),
179+
skipDirectory: (path) => basename(path) === "node_modules",
180+
});
174181
const tenantFiles = await collectFiles(tenantDir, {
175182
prefix: `tenant/${slashPath(relative(resolvedRoot, tenantDir))}`,
176183
include: (path) => hasSourceExtension(path),
177184
skipDirectory: (path) => basename(path) === "node_modules",
178185
});
179186

180-
return [...explicitFiles, ...sourceFiles, ...tenantFiles].sort(
181-
(left, right) => left.path.localeCompare(right.path),
182-
);
187+
return [
188+
...explicitFiles,
189+
...sourceFiles,
190+
...sharedFiles,
191+
...tenantFiles,
192+
].sort((left, right) => left.path.localeCompare(right.path));
183193
}
184194

185195
export async function buildCacheKey(

app/tests/build-cache.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ async function withProject(
2525
await mkdir(join(appDir, "src/lib/generated"), { recursive: true });
2626
await mkdir(join(appDir, "dist"), { recursive: true });
2727
await mkdir(join(rootDir, "examples/brand"), { recursive: true });
28+
await mkdir(join(rootDir, "shared"), { recursive: true });
2829
await writeFile(join(rootDir, "package.json"), '{"version":"1.2.3"}\n');
2930
await writeFile(join(rootDir, "bun.lock"), "lock-a\n");
3031
await writeFile(join(appDir, "package.json"), '{"version":"0.0.0"}\n');
@@ -36,6 +37,10 @@ async function withProject(
3637
"export const appConfig = { brand: { tenantId: 'a' } };\n",
3738
);
3839
await writeFile(join(rootDir, "examples/brand/brand.yaml"), "name: A\n");
40+
await writeFile(
41+
join(rootDir, "shared/attachments.ts"),
42+
"export const MAX_ATTACHMENTS_PER_MESSAGE = 8;\n",
43+
);
3944
await writeFile(join(appDir, "dist/index.html"), "<html></html>\n");
4045
await callback({ rootDir, appDir });
4146
} finally {
@@ -76,6 +81,11 @@ describe("production build cache", () => {
7681
["root package version", "package.json", '{"version":"1.2.4"}\n'],
7782
["app package manifest", "app/package.json", '{"version":"0.0.1"}\n'],
7883
["tenant branding", "examples/brand/brand.yaml", "name: B\n"],
84+
[
85+
"a shared module the app imports",
86+
"shared/attachments.ts",
87+
"export const MAX_ATTACHMENTS_PER_MESSAGE = 10;\n",
88+
],
7989
] as const)(
8090
"rejects a build when %s changes",
8191
async (_name, path, contents) => {

0 commit comments

Comments
 (0)