Skip to content

Commit 3364cf9

Browse files
committed
Reuse the runtime helper in Astro init
Use the shared package-manager-to-runtime helper in the Astro initializer instead of duplicating the runtime mapping inline. This keeps the template selection logic aligned with the existing utility used elsewhere in the init package. Assisted-by: OpenCode:gpt-5.4
1 parent 04550b6 commit 3364cf9

1 file changed

Lines changed: 58 additions & 56 deletions

File tree

packages/init/src/webframeworks/astro.ts

Lines changed: 58 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,73 +2,75 @@ import { PACKAGE_MANAGER } from "../const.ts";
22
import { PACKAGE_VERSION, readTemplate } from "../lib.ts";
33
import type { PackageManager, WebFrameworkDescription } from "../types.ts";
44
import { defaultDenoDependencies, defaultDevDependencies } from "./const.ts";
5-
import { getInstruction } from "./utils.ts";
5+
import { getInstruction, packageManagerToRuntime } from "./utils.ts";
66

77
const astroDescription: WebFrameworkDescription = {
88
label: "Astro",
99
packageManagers: PACKAGE_MANAGER,
1010
defaultPort: 4321,
11-
init: async ({ packageManager: pm }) => ({
12-
command: Array.from(getAstroInitCommand(pm)),
13-
dependencies: pm === "deno"
14-
? {
15-
...defaultDenoDependencies,
16-
"@deno/astro-adapter": "npm:@deno/astro-adapter@^0.3.2",
17-
"@fedify/astro": PACKAGE_VERSION,
18-
}
19-
: pm === "bun"
20-
? {
21-
"@fedify/astro": PACKAGE_VERSION,
22-
"@nurodev/astro-bun": "^2.1.2",
23-
}
24-
: {
25-
"@astrojs/node": "^9.5.4",
26-
"@fedify/astro": PACKAGE_VERSION,
27-
},
28-
devDependencies: {
29-
...defaultDevDependencies,
30-
...(pm !== "deno"
31-
? { typescript: "^5.9.3", "@types/node": "^22.17.0" }
32-
: {}),
33-
},
34-
federationFile: "src/federation.ts",
35-
loggingFile: "src/logging.ts",
36-
files: {
37-
[`astro.config.ts`]: await readTemplate(
38-
`astro/astro.config.${
39-
pm === "deno" ? "deno" : pm === "bun" ? "bun" : "node"
40-
}.ts`,
41-
),
42-
"src/middleware.ts": await readTemplate("astro/src/middleware.ts"),
43-
...(pm !== "deno"
44-
? {
45-
"eslint.config.ts": await readTemplate("defaults/eslint.config.ts"),
46-
}
47-
: {}),
48-
},
49-
compilerOptions: undefined,
50-
tasks: {
51-
...(pm === "deno"
11+
init: async ({ packageManager: pm }) => {
12+
const runtime = packageManagerToRuntime(pm);
13+
14+
return ({
15+
command: Array.from(getAstroInitCommand(pm)),
16+
dependencies: pm === "deno"
5217
? {
53-
dev: "deno run -A npm:astro dev",
54-
build: "deno run -A npm:astro build",
55-
preview: "deno run -A npm:astro preview",
18+
...defaultDenoDependencies,
19+
"@deno/astro-adapter": "npm:@deno/astro-adapter@^0.3.2",
20+
"@fedify/astro": PACKAGE_VERSION,
5621
}
5722
: pm === "bun"
5823
? {
59-
dev: "bunx astro dev",
60-
build: "bunx astro build",
61-
preview: "bun ./dist/server/entry.mjs",
24+
"@fedify/astro": PACKAGE_VERSION,
25+
"@nurodev/astro-bun": "^2.1.2",
6226
}
6327
: {
64-
dev: "astro dev",
65-
build: "astro build",
66-
preview: "astro preview",
67-
}),
68-
...(pm !== "deno" ? { lint: "eslint ." } : {}),
69-
},
70-
instruction: getInstruction(pm, 4321),
71-
}),
28+
"@astrojs/node": "^9.5.4",
29+
"@fedify/astro": PACKAGE_VERSION,
30+
},
31+
devDependencies: {
32+
...defaultDevDependencies,
33+
...(pm !== "deno"
34+
? { typescript: "^5.9.3", "@types/node": "^22.17.0" }
35+
: {}),
36+
},
37+
federationFile: "src/federation.ts",
38+
loggingFile: "src/logging.ts",
39+
files: {
40+
[`astro.config.ts`]: await readTemplate(
41+
`astro/astro.config.${runtime}.ts`,
42+
),
43+
"src/middleware.ts": await readTemplate("astro/src/middleware.ts"),
44+
...(pm !== "deno"
45+
? {
46+
"eslint.config.ts": await readTemplate("defaults/eslint.config.ts"),
47+
}
48+
: {}),
49+
},
50+
compilerOptions: undefined,
51+
tasks: {
52+
...(pm === "deno"
53+
? {
54+
dev: "deno run -A npm:astro dev",
55+
build: "deno run -A npm:astro build",
56+
preview: "deno run -A npm:astro preview",
57+
}
58+
: pm === "bun"
59+
? {
60+
dev: "bunx astro dev",
61+
build: "bunx astro build",
62+
preview: "bun ./dist/server/entry.mjs",
63+
}
64+
: {
65+
dev: "astro dev",
66+
build: "astro build",
67+
preview: "astro preview",
68+
}),
69+
...(pm !== "deno" ? { lint: "eslint ." } : {}),
70+
},
71+
instruction: getInstruction(pm, 4321),
72+
});
73+
},
7274
};
7375

7476
export default astroDescription;

0 commit comments

Comments
 (0)