From e5f6de4edbdfe2ae2f6e975511a5a571633e2fd6 Mon Sep 17 00:00:00 2001 From: Pascal Schilp Date: Wed, 4 May 2022 14:27:51 +0200 Subject: [PATCH] feat: expose pages (#3286) * feat: expose pages * chore: changeset * fix: build --- .changeset/mean-donkeys-sin.md | 5 +++++ packages/astro/src/@types/astro.ts | 4 +++- packages/astro/src/core/build/static-build.ts | 4 ++-- packages/astro/src/integrations/index.ts | 5 ++++- 4 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 .changeset/mean-donkeys-sin.md diff --git a/.changeset/mean-donkeys-sin.md b/.changeset/mean-donkeys-sin.md new file mode 100644 index 000000000..41967d94f --- /dev/null +++ b/.changeset/mean-donkeys-sin.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Adds pages param to the astro:build:setup integration hook diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 4a19d0443..2848760d2 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -14,6 +14,7 @@ import type { AstroConfigSchema } from '../core/config'; import type { AstroComponentFactory, Metadata } from '../runtime/server'; import type { ViteConfigWithSSR } from '../core/create-vite'; import type { SerializedSSRManifest } from '../core/app/types'; +import type { PageBuildData } from '../core/build/types'; export type { SSRManifest } from '../core/app/types'; export interface AstroBuiltinProps { @@ -912,8 +913,9 @@ export interface AstroIntegration { 'astro:build:start'?: (options: { buildConfig: BuildConfig }) => void | Promise; 'astro:build:setup'?: (options: { vite: ViteConfigWithSSR; + pages: Map; target: 'client' | 'server'; - }) => void; + }) => void | Promise; 'astro:build:done'?: (options: { pages: { pathname: string }[]; dir: URL; diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index b06f3c4f1..a5f4d102b 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -167,7 +167,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp resolve: viteConfig.resolve, } as ViteConfigWithSSR; - await runHookBuildSetup({ config: astroConfig, vite: viteBuildConfig, target: 'server' }); + await runHookBuildSetup({ config: astroConfig, pages: internals.pagesByComponent, vite: viteBuildConfig, target: 'server' }); // TODO: use vite.mergeConfig() here? return await vite.build(viteBuildConfig); @@ -232,7 +232,7 @@ async function clientBuild( base: astroConfig.base, } as ViteConfigWithSSR; - await runHookBuildSetup({ config: astroConfig, vite: viteBuildConfig, target: 'client' }); + await runHookBuildSetup({ config: astroConfig, pages: internals.pagesByComponent, vite: viteBuildConfig, target: 'client' }); const buildResult = await vite.build(viteBuildConfig); info(opts.logging, null, dim(`Completed in ${getTimeStat(timer, performance.now())}.\n`)); diff --git a/packages/astro/src/integrations/index.ts b/packages/astro/src/integrations/index.ts index 611106ca5..1abbbae3b 100644 --- a/packages/astro/src/integrations/index.ts +++ b/packages/astro/src/integrations/index.ts @@ -1,6 +1,7 @@ import type { AddressInfo } from 'net'; import type { ViteDevServer } from 'vite'; import type { SerializedSSRManifest } from '../core/app/types'; +import type { PageBuildData } from '../core/build/types'; import { AstroConfig, AstroRenderer, BuildConfig, RouteData } from '../@types/astro.js'; import { mergeConfig } from '../core/config.js'; import ssgAdapter from '../adapter-ssg/index.js'; @@ -123,15 +124,17 @@ export async function runHookBuildStart({ export async function runHookBuildSetup({ config, vite, + pages, target, }: { config: AstroConfig; vite: ViteConfigWithSSR; + pages: Map; target: 'server' | 'client'; }) { for (const integration of config.integrations) { if (integration.hooks['astro:build:setup']) { - await integration.hooks['astro:build:setup']({ vite, target }); + await integration.hooks['astro:build:setup']({ vite, pages, target }); } } }