Skip to content
Draft
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
6 changes: 6 additions & 0 deletions .changeset/guard-astro-sveltekit-writes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@workflow/astro': patch
'@workflow/sveltekit': patch
---

Stop rewriting generated files whose content is unchanged, so a no-op rebuild no longer invalidates them in the dev server.
12 changes: 8 additions & 4 deletions packages/astro/src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
NORMALIZE_REQUEST_CODE,
resolveProjectRoot,
VercelBuildOutputAPIBuilder,
writeFileIfChanged,
} from '@workflow/builders';

const WORKFLOW_ROUTES = [
Expand Down Expand Up @@ -54,7 +55,7 @@ export class LocalBuilder extends BaseBuilder {

// Add .gitignore to exclude generated files from version control
if (process.env.VERCEL_DEPLOYMENT_ID === undefined) {
await writeFile(join(workflowGeneratedDir, '.gitignore'), '*');
await writeFileIfChanged(join(workflowGeneratedDir, '.gitignore'), '*');
}

// Clean up stale V1 step route (may persist via Vercel build cache)
Expand Down Expand Up @@ -90,7 +91,10 @@ export const POST = async ({request}) => {

export const prerender = false;`
);
await writeFile(workflowsRouteFile, workflowsRouteContent);
// These files are generated into the Astro pages directory, which Vite
// watches in dev, so an identical rewrite would still invalidate the
// module and force a redundant recompile.
await writeFileIfChanged(workflowsRouteFile, workflowsRouteContent);

await this.buildWebhookRoute({ workflowGeneratedDir });

Expand All @@ -105,7 +109,7 @@ export const prerender = false;`
// Expose manifest as a public HTTP route when WORKFLOW_PUBLIC_MANIFEST=1
// Astro maps `foo.json.js` to the URL `/foo.json`
if (this.shouldExposePublicManifest && manifestJson) {
await writeFile(
await writeFileIfChanged(
join(workflowGeneratedDir, 'manifest.json.js'),
`export function GET() {
return new Response(${JSON.stringify(manifestJson)}, {
Expand Down Expand Up @@ -169,7 +173,7 @@ export const OPTIONS = createHandler('OPTIONS');
export const prerender = false;`
);

await writeFile(webhookRouteFile, webhookRouteContent);
await writeFileIfChanged(webhookRouteFile, webhookRouteContent);
}
}

Expand Down
30 changes: 14 additions & 16 deletions packages/sveltekit/src/builder.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import { constants } from 'node:fs';
import {
access,
copyFile,
mkdir,
readFile,
rm,
stat,
writeFile,
} from 'node:fs/promises';
import { access, mkdir, readFile, rm, stat } from 'node:fs/promises';
import { createRequire } from 'node:module';
import { dirname, join, resolve } from 'node:path';
import { pathToFileURL } from 'node:url';
Expand All @@ -17,6 +9,7 @@ import {
NORMALIZE_REQUEST_CODE,
resolveProjectRoot,
type SvelteKitConfig,
writeFileIfChanged,
} from '@workflow/builders';

const SVELTEKIT_VIRTUAL_MODULES = [
Expand Down Expand Up @@ -70,7 +63,7 @@ export class SvelteKitBuilder extends BaseBuilder {

// Add .gitignore to exclude generated files from version control
if (process.env.VERCEL_DEPLOYMENT_ID === undefined) {
await writeFile(join(workflowGeneratedDir, '.gitignore'), '*');
await writeFileIfChanged(join(workflowGeneratedDir, '.gitignore'), '*');
}

// Clean up stale V1 step route directory (may persist via Vercel build cache)
Expand Down Expand Up @@ -110,7 +103,10 @@ export const POST = async ({request}) => {
return workflowEntrypoint(workflowCode${options})(normalRequest);
}`
);
await writeFile(workflowsRouteFile, workflowsRouteContent);
// These files are generated into the SvelteKit routes directory, which
// Vite watches in dev, so an identical rewrite would still invalidate the
// module and force a redundant recompile.
await writeFileIfChanged(workflowsRouteFile, workflowsRouteContent);

await this.buildWebhookRoute({ workflowGeneratedDir });

Expand All @@ -131,11 +127,13 @@ export const POST = async ({request}) => {
);
await mkdir(staticManifestDir, { recursive: true });
if (process.env.VERCEL_DEPLOYMENT_ID === undefined) {
await writeFile(join(staticManifestDir, '.gitignore'), '*');
await writeFileIfChanged(join(staticManifestDir, '.gitignore'), '*');
}
await copyFile(
join(workflowGeneratedDir, 'manifest.json'),
join(staticManifestDir, 'manifest.json')
// Written from the same string rather than copied, so an unchanged
// manifest leaves the static copy untouched too.
await writeFileIfChanged(
join(staticManifestDir, 'manifest.json'),
manifestJson
);
}
}
Expand Down Expand Up @@ -193,7 +191,7 @@ export const HEAD = createSvelteKitHandler('HEAD');
export const OPTIONS = createSvelteKitHandler('OPTIONS');`
);

await writeFile(webhookRouteFile, webhookRouteContent);
await writeFileIfChanged(webhookRouteFile, webhookRouteContent);
}

private async loadRoutesDirectory(): Promise<string> {
Expand Down
Loading