From 8685506174962329fb7a76367ea3cf32ea0aa48c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Seery?= Date: Thu, 12 May 2022 13:55:29 -0300 Subject: [PATCH] fix: vite types (#3352) * Re-export vite types and added them to zod schema * Removed casted typed * Changeset --- .changeset/quick-gorillas-kick.md | 5 +++++ packages/astro/src/@types/astro.ts | 6 +++++- packages/astro/src/core/build/static-build.ts | 4 ++-- packages/astro/src/core/config.ts | 6 ++++-- 4 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 .changeset/quick-gorillas-kick.md diff --git a/.changeset/quick-gorillas-kick.md b/.changeset/quick-gorillas-kick.md new file mode 100644 index 0000000000..7d080ec798 --- /dev/null +++ b/.changeset/quick-gorillas-kick.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Export `ViteUserConfig` type diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 050223b53f..b51d97f65d 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -255,6 +255,10 @@ type ServerConfig = { port?: number; }; +export interface ViteUserConfig extends vite.UserConfig { + ssr?: vite.SSROptions; +} + /** * Astro User Config * Docs: https://docs.astro.build/reference/configuration-reference/ @@ -652,7 +656,7 @@ export interface AstroUserConfig { * } * ``` */ - vite?: vite.UserConfig & { ssr?: vite.SSROptions }; + vite?: ViteUserConfig; experimental?: { /** diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index 8b55e83bf1..1fac3c00d5 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -120,7 +120,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp const ssr = isBuildingToSSR(astroConfig); const out = ssr ? opts.buildConfig.server : astroConfig.outDir; - const viteBuildConfig = { + const viteBuildConfig: ViteConfigWithSSR = { logLevel: 'error', mode: 'production', css: viteConfig.css, @@ -165,7 +165,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp base: astroConfig.base, ssr: viteConfig.ssr, resolve: viteConfig.resolve, - } as ViteConfigWithSSR; + }; await runHookBuildSetup({ config: astroConfig, diff --git a/packages/astro/src/core/config.ts b/packages/astro/src/core/config.ts index c868425f9c..27550c313d 100644 --- a/packages/astro/src/core/config.ts +++ b/packages/astro/src/core/config.ts @@ -1,4 +1,4 @@ -import type { AstroConfig, AstroUserConfig, CLIFlags } from '../@types/astro'; +import type { AstroConfig, AstroUserConfig, CLIFlags, ViteUserConfig } from '../@types/astro'; import type { Arguments as Flags } from 'yargs-parser'; import type * as Postcss from 'postcss'; import type { ILanguageRegistration, IThemeRegistration, Theme } from 'shiki'; @@ -182,7 +182,9 @@ export const AstroConfigSchema = z.object({ .default([]), }) .default({}), - vite: z.any().optional().default({}), + vite: z + .custom((data) => data instanceof Object && !Array.isArray(data)) + .default({}), experimental: z .object({ ssr: z.boolean().optional().default(false),