Skip to content

Commit 05ed2aa

Browse files
author
Austin Crim
authored
Web frameworks - Fix Astro config loading (#6213)
* change config loading depending on version * compare correct version * update changelog * remove fs * extract configPath
1 parent 5cc75d7 commit 05ed2aa

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
- Fixed Astro web framework bug when loading configuration for version `2.9.7` and above. (#6213)
12
- Increase Next.js config bundle timeout to 60 seconds (#6214)

src/frameworks/astro/index.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,13 @@ import { copy, existsSync } from "fs-extra";
33
import { join } from "path";
44
import { BuildResult, Discovery, FrameworkType, SupportLevel } from "../interfaces";
55
import { FirebaseError } from "../../error";
6-
import {
7-
readJSON,
8-
simpleProxy,
9-
warnIfCustomBuildScript,
10-
findDependency,
11-
getNodeModuleBin,
12-
} from "../utils";
13-
import { getBootstrapScript, getConfig } from "./utils";
6+
import { readJSON, simpleProxy, warnIfCustomBuildScript, getNodeModuleBin } from "../utils";
7+
import { getAstroVersion, getBootstrapScript, getConfig } from "./utils";
148

159
export const name = "Astro";
1610
export const support = SupportLevel.Experimental;
1711
export const type = FrameworkType.MetaFramework;
1812

19-
function getAstroVersion(cwd: string): string | undefined {
20-
return findDependency("astro", { cwd, depth: 0, omitDev: false })?.version;
21-
}
22-
2313
export async function discover(dir: string): Promise<Discovery | undefined> {
2414
if (!existsSync(join(dir, "package.json"))) return;
2515
if (!getAstroVersion(dir)) return;

src/frameworks/astro/utils.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { dirname, join, relative } from "path";
2+
import { findDependency } from "../utils";
3+
import { gte } from "semver";
24

35
const { dynamicImport } = require(true && "../../dynamicImport");
46

@@ -10,15 +12,30 @@ export function getBootstrapScript() {
1012

1113
export async function getConfig(cwd: string) {
1214
const astroDirectory = dirname(require.resolve("astro/package.json", { paths: [cwd] }));
13-
const { openConfig }: typeof import("astro/dist/core/config/config") = await dynamicImport(
14-
join(astroDirectory, "dist", "core", "config", "config.js")
15-
);
16-
const logging: any = undefined; // TODO figure out the types here
17-
const { astroConfig: config } = await openConfig({ cmd: "build", cwd, logging });
15+
const version = getAstroVersion(cwd);
16+
17+
let config;
18+
const configPath = join(astroDirectory, "dist", "core", "config", "config.js");
19+
if (gte(version!, "2.9.7")) {
20+
const { resolveConfig } = await dynamicImport(configPath);
21+
const { astroConfig } = await resolveConfig({ root: cwd }, "build");
22+
config = astroConfig;
23+
} else {
24+
const { openConfig }: typeof import("astro/dist/core/config/config") = await dynamicImport(
25+
configPath
26+
);
27+
const logging: any = undefined; // TODO figure out the types here
28+
const { astroConfig } = await openConfig({ cmd: "build", cwd, logging });
29+
config = astroConfig;
30+
}
1831
return {
1932
outDir: relative(cwd, config.outDir.pathname),
2033
publicDir: relative(cwd, config.publicDir.pathname),
2134
output: config.output,
2235
adapter: config.adapter,
2336
};
2437
}
38+
39+
export function getAstroVersion(cwd: string): string | undefined {
40+
return findDependency("astro", { cwd, depth: 0, omitDev: false })?.version;
41+
}

0 commit comments

Comments
 (0)