Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run astro:config:done hook before generating route manifest #12936

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
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
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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the reordering of hooks is for this to work right? Just to make sure I understand, we don't want to infer the build output if the adapter locks it. Is that right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. This code will only work as a fallback


// 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
Loading