Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions app/scripts/build-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,25 @@ async function collectBuildInputs(
include: (path) => hasSourceExtension(path),
skipDirectory: (path) => basename(path) === "node_modules",
});
// The app bundles modules from `shared/` too (attachment limits, handoff markers), so a change
// there has to rebuild it just as a change under `app/src` does.
const sharedFiles = await collectFiles(join(resolvedRoot, "shared"), {
prefix: "shared",
include: (path) => hasSourceExtension(path),
skipDirectory: (path) => basename(path) === "node_modules",
});
const tenantFiles = await collectFiles(tenantDir, {
prefix: `tenant/${slashPath(relative(resolvedRoot, tenantDir))}`,
include: (path) => hasSourceExtension(path),
skipDirectory: (path) => basename(path) === "node_modules",
});

return [...explicitFiles, ...sourceFiles, ...tenantFiles].sort(
(left, right) => left.path.localeCompare(right.path),
);
return [
...explicitFiles,
...sourceFiles,
...sharedFiles,
...tenantFiles,
].sort((left, right) => left.path.localeCompare(right.path));
}

export async function buildCacheKey(
Expand Down
10 changes: 10 additions & 0 deletions app/tests/build-cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ async function withProject(
await mkdir(join(appDir, "src/lib/generated"), { recursive: true });
await mkdir(join(appDir, "dist"), { recursive: true });
await mkdir(join(rootDir, "examples/brand"), { recursive: true });
await mkdir(join(rootDir, "shared"), { recursive: true });
await writeFile(join(rootDir, "package.json"), '{"version":"1.2.3"}\n');
await writeFile(join(rootDir, "bun.lock"), "lock-a\n");
await writeFile(join(appDir, "package.json"), '{"version":"0.0.0"}\n');
Expand All @@ -36,6 +37,10 @@ async function withProject(
"export const appConfig = { brand: { tenantId: 'a' } };\n",
);
await writeFile(join(rootDir, "examples/brand/brand.yaml"), "name: A\n");
await writeFile(
join(rootDir, "shared/attachments.ts"),
"export const MAX_ATTACHMENTS_PER_MESSAGE = 8;\n",
);
await writeFile(join(appDir, "dist/index.html"), "<html></html>\n");
await callback({ rootDir, appDir });
} finally {
Expand Down Expand Up @@ -76,6 +81,11 @@ describe("production build cache", () => {
["root package version", "package.json", '{"version":"1.2.4"}\n'],
["app package manifest", "app/package.json", '{"version":"0.0.1"}\n'],
["tenant branding", "examples/brand/brand.yaml", "name: B\n"],
[
"a shared module the app imports",
"shared/attachments.ts",
"export const MAX_ATTACHMENTS_PER_MESSAGE = 10;\n",
],
] as const)(
"rejects a build when %s changes",
async (_name, path, contents) => {
Expand Down
Loading