Skip to content

Commit

Permalink
Run astro:config:done hook before generating route manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Jan 8, 2025
1 parent d486836 commit eca2174
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/wild-eels-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Runs `astro:config:done` hook first before generating the internal route manifest
2 changes: 1 addition & 1 deletion packages/astro/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export function getViteConfig(
const { astroConfig: config } = await resolveConfig(inlineAstroConfig, cmd);
let settings = await createSettings(config, userViteConfig.root);
settings = await runHookConfigSetup({ settings, command: cmd, logger });
await runHookConfigDone({ settings, logger });
const manifest = await createRouteManifest({ settings }, logger);
const devSSRManifest = createDevelopmentManifest(settings);
const viteConfig = await createVite(
Expand All @@ -66,7 +67,6 @@ export function getViteConfig(
},
{ settings, command: cmd, logger, mode, sync: false, manifest, ssrManifest: devSSRManifest },
);
await runHookConfigDone({ settings, logger });
return mergeConfig(viteConfig, userViteConfig);
};
}
3 changes: 1 addition & 2 deletions packages/astro/src/core/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,10 @@ class AstroBuilder {
command: 'build',
logger: logger,
});
await runHookConfigDone({ settings: this.settings, logger: logger, command: 'build' });

this.manifest = await createRouteManifest({ settings: this.settings }, this.logger);

await runHookConfigDone({ settings: this.settings, logger: logger, command: 'build' });

// If we're building for the server, we need to ensure that an adapter is installed.
// If the adapter installed does not support a server output, an error will be thrown when the adapter is added, so no need to check here.
if (!this.settings.config.adapter && this.settings.buildOutput === 'server') {
Expand Down
3 changes: 1 addition & 2 deletions packages/astro/src/core/dev/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export async function createContainer({
logger: logger,
isRestart,
});
await runHookConfigDone({ settings, logger, command: 'dev' });

const {
base,
Expand Down Expand Up @@ -85,8 +86,6 @@ export async function createContainer({
const manifest = await createRouteManifest({ settings, fsMod: fs }, logger, { dev: true });
const devSSRManifest = createDevelopmentManifest(settings);

await runHookConfigDone({ settings, logger, command: 'dev' });

warnMissingAdapter(logger, settings);

const mode = inlineConfig?.mode ?? 'development';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/preview/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ export default async function preview(inlineConfig: AstroInlineConfig): Promise<
command: 'preview',
logger: logger,
});
await runHookConfigDone({ settings: settings, logger: logger, command: 'preview' });

// Create a route manifest so we can know if the build output is a static site or not
await createRouteManifest({ settings: settings, cwd: inlineConfig.root }, logger);

await runHookConfigDone({ settings: settings, logger: logger, command: 'preview' });

if (settings.buildOutput === 'static') {
if (!fs.existsSync(settings.config.outDir)) {
Expand Down
4 changes: 3 additions & 1 deletion packages/astro/src/core/routing/manifest/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,9 @@ export async function createRouteManifest(
...[...filteredFiledBasedRoutes, ...injectedRoutes, ...redirectRoutes].sort(routeComparator),
];

settings.buildOutput = getPrerenderDefault(config) ? 'static' : 'server';
// NOTE: `buildOutput` may already be set by `runHookConfigDone` if the adapter only
// support server build output
settings.buildOutput ??= getPrerenderDefault(config) ? 'static' : 'server';

// Check the prerender option for each route
const limit = pLimit(10);
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/core/sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ export default async function sync(
settings,
logger,
});
const manifest = await createRouteManifest({ settings, fsMod: fs }, logger);

await runHookConfigDone({ settings, logger });

const manifest = await createRouteManifest({ settings, fsMod: fs }, logger);

return await syncInternal({
settings,
logger,
Expand Down

0 comments on commit eca2174

Please sign in to comment.