Skip to content

Commit 13e7aa7

Browse files
committed
feat(astro): add prefixer to non-api routes in builder
1 parent d645af0 commit 13e7aa7

File tree

4 files changed

+177
-2
lines changed

4 files changed

+177
-2
lines changed

packages/astro/src/builder.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { mkdir, readFile, writeFile } from 'node:fs/promises';
1+
import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
22
import { join, resolve } from 'node:path';
33
import { BaseBuilder, type AstroConfig } from '@workflow/builders';
44

@@ -16,6 +16,12 @@ async function normalizeRequestConverter(request) {
1616
}
1717
`;
1818

19+
const DEBUG_FILES = [
20+
'flow.js.debug.json',
21+
'manifest.debug.json',
22+
'step.js.debug.json',
23+
];
24+
1925
export class AstroBuilder extends BaseBuilder {
2026
constructor(config?: Partial<AstroConfig>) {
2127
const workingDir = config?.workingDir || process.cwd();
@@ -58,6 +64,13 @@ export class AstroBuilder extends BaseBuilder {
5864
await this.buildStepsRoute(options);
5965
await this.buildWorkflowsRoute(options);
6066
await this.buildWebhookRoute({ workflowGeneratedDir });
67+
68+
// Astro requires non-api routes to be prefixed with _ (debug files)
69+
for (const file of DEBUG_FILES) {
70+
const filePath = join(workflowGeneratedDir, file);
71+
const prefixedFilePath = join(workflowGeneratedDir, `_${file}`);
72+
await rename(filePath, prefixedFilePath);
73+
}
6174
}
6275

6376
private async buildStepsRoute({

pnpm-lock.yaml

Lines changed: 151 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

workbench/astro/astro.config.mjs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
// @ts-check
21
import { defineConfig } from 'astro/config';
32
import { workflowPlugin } from 'workflow/astro';
3+
import node from '@astrojs/node';
4+
import vercel from '@astrojs/vercel';
5+
6+
// Node adapter needed for ci tests
7+
const adapter = process.env.VERCEL_DEPLOYMENT_ID
8+
? vercel()
9+
: node({
10+
mode: 'standalone',
11+
});
412

513
// https://astro.build/config
614
export default defineConfig({
715
vite: { plugins: [workflowPlugin()] },
16+
adapter: adapter,
817
});

workbench/astro/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
"astro": "astro"
1313
},
1414
"dependencies": {
15+
"@astrojs/node": "9.5.0",
16+
"@astrojs/vercel": "^9.0.0",
1517
"astro": "^5.15.6",
1618
"nitro": "catalog:",
1719
"workflow": "workspace:*"

0 commit comments

Comments
 (0)