Skip to content

Commit 5bcd76e

Browse files
authored
Refactor ViteConfigWithSSR type (#4952)
1 parent 1668816 commit 5bcd76e

File tree

7 files changed

+20
-20
lines changed

7 files changed

+20
-20
lines changed

.changeset/moody-gifts-press.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Refactor ViteConfigWithSSR type

packages/astro/src/@types/astro.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import type { SerializedSSRManifest } from '../core/app/types';
1616
import type { PageBuildData } from '../core/build/types';
1717
import type { AstroConfigSchema } from '../core/config';
1818
import type { AstroCookies } from '../core/cookies';
19-
import type { ViteConfigWithSSR } from '../core/create-vite';
2019
import type { AstroComponentFactory, Metadata } from '../runtime/server';
2120
export type {
2221
MarkdownHeading,
@@ -1161,10 +1160,10 @@ export interface AstroIntegration {
11611160
'astro:build:ssr'?: (options: { manifest: SerializedSSRManifest }) => void | Promise<void>;
11621161
'astro:build:start'?: (options: { buildConfig: BuildConfig }) => void | Promise<void>;
11631162
'astro:build:setup'?: (options: {
1164-
vite: ViteConfigWithSSR;
1163+
vite: vite.InlineConfig;
11651164
pages: Map<string, PageBuildData>;
11661165
target: 'client' | 'server';
1167-
updateConfig: (newConfig: ViteConfigWithSSR) => void;
1166+
updateConfig: (newConfig: vite.InlineConfig) => void;
11681167
}) => void | Promise<void>;
11691168
'astro:build:generated'?: (options: { dir: URL }) => void | Promise<void>;
11701169
'astro:build:done'?: (options: {

packages/astro/src/core/build/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import type { LogOptions } from '../logger/core';
55
import fs from 'fs';
66
import * as colors from 'kleur/colors';
77
import { performance } from 'perf_hooks';
8+
import * as vite from 'vite';
89
import {
910
runHookBuildDone,
1011
runHookBuildStart,
1112
runHookConfigDone,
1213
runHookConfigSetup,
1314
} from '../../integrations/index.js';
14-
import { createVite, ViteConfigWithSSR } from '../create-vite.js';
15+
import { createVite } from '../create-vite.js';
1516
import { fixViteErrorMessage } from '../errors.js';
1617
import { debug, info, levels, timerMessage } from '../logger/core.js';
1718
import { apply as applyPolyfill } from '../polyfill.js';
@@ -84,7 +85,7 @@ class AstroBuilder {
8485
}
8586

8687
/** Run the build logic. build() is marked private because usage should go through ".run()" */
87-
private async build({ viteConfig }: { viteConfig: ViteConfigWithSSR }) {
88+
private async build({ viteConfig }: { viteConfig: vite.InlineConfig }) {
8889
const buildConfig: BuildConfig = {
8990
client: new URL('./client/', this.settings.config.outDir),
9091
server: new URL('./server/', this.settings.config.outDir),

packages/astro/src/core/build/static-build.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { prependForwardSlash } from '../../core/path.js';
99
import { emptyDir, isModeServerWithNoAdapter, removeDir } from '../../core/util.js';
1010
import { runHookBuildSetup } from '../../integrations/index.js';
1111
import { PAGE_SCRIPT_ID } from '../../vite-plugin-scripts/index.js';
12-
import type { ViteConfigWithSSR } from '../create-vite';
1312
import { info } from '../logger/core.js';
1413
import { getOutDirWithinCwd } from './common.js';
1514
import { generatePages } from './generate.js';
@@ -114,7 +113,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp
114113
const ssr = settings.config.output === 'server';
115114
const out = ssr ? opts.buildConfig.server : getOutDirWithinCwd(settings.config.outDir);
116115

117-
const viteBuildConfig: ViteConfigWithSSR = {
116+
const viteBuildConfig: vite.InlineConfig = {
118117
...viteConfig,
119118
mode: viteConfig.mode || 'production',
120119
logLevel: opts.viteConfig.logLevel ?? 'error',
@@ -192,7 +191,7 @@ async function clientBuild(
192191

193192
info(opts.logging, null, `\n${bgGreen(black(' building client '))}`);
194193

195-
const viteBuildConfig = {
194+
const viteBuildConfig: vite.InlineConfig = {
196195
...viteConfig,
197196
mode: viteConfig.mode || 'production',
198197
logLevel: 'info',
@@ -226,7 +225,7 @@ async function clientBuild(
226225
],
227226
envPrefix: 'PUBLIC_',
228227
base: settings.config.base,
229-
} as ViteConfigWithSSR;
228+
} ;
230229

231230
await runHookBuildSetup({
232231
config: settings.config,

packages/astro/src/core/build/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { InlineConfig } from 'vite';
12
import type {
23
AstroSettings,
34
BuildConfig,
@@ -7,7 +8,6 @@ import type {
78
RuntimeMode,
89
SSRLoadedRenderer,
910
} from '../../@types/astro';
10-
import type { ViteConfigWithSSR } from '../create-vite';
1111
import type { LogOptions } from '../logger/core';
1212
import type { RouteCache } from '../render/route-cache';
1313

@@ -34,7 +34,7 @@ export interface StaticBuildOptions {
3434
origin: string;
3535
pageNames: string[];
3636
routeCache: RouteCache;
37-
viteConfig: ViteConfigWithSSR;
37+
viteConfig: InlineConfig;
3838
}
3939

4040
export interface SingleFileBuiltModule {

packages/astro/src/core/create-vite.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ import astroScriptsPageSSRPlugin from '../vite-plugin-scripts/page-ssr.js';
2121
import { createCustomViteLogger } from './errors.js';
2222
import { resolveDependency } from './util.js';
2323

24-
// note: ssr is still an experimental API hence the type omission from `vite`
25-
export type ViteConfigWithSSR = vite.InlineConfig & { ssr?: vite.SSROptions };
26-
2724
interface CreateViteOptions {
2825
settings: AstroSettings;
2926
logging: LogOptions;
@@ -58,12 +55,12 @@ function getSsrNoExternalDeps(projectRoot: URL): string[] {
5855

5956
/** Return a common starting point for all Vite actions */
6057
export async function createVite(
61-
commandConfig: ViteConfigWithSSR,
58+
commandConfig: vite.InlineConfig,
6259
{ settings, logging, mode }: CreateViteOptions
63-
): Promise<ViteConfigWithSSR> {
60+
): Promise<vite.InlineConfig> {
6461
const thirdPartyAstroPackages = await getAstroPackages(settings);
6562
// Start with the Vite configuration that Astro core needs
66-
const commonConfig: ViteConfigWithSSR = {
63+
const commonConfig: vite.InlineConfig = {
6764
cacheDir: fileURLToPath(new URL('./node_modules/.vite/', settings.config.root)), // using local caches allows Astro to be used in monorepos, etc.
6865
clearScreen: false, // we want to control the output, not Vite
6966
logLevel: 'warn', // log warnings and errors only

packages/astro/src/integrations/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { bold } from 'kleur/colors';
22
import type { AddressInfo } from 'net';
3-
import type { ViteDevServer } from 'vite';
3+
import type { InlineConfig, ViteDevServer } from 'vite';
44
import {
55
AstroConfig,
66
AstroRenderer,
@@ -12,7 +12,6 @@ import {
1212
import type { SerializedSSRManifest } from '../core/app/types';
1313
import type { PageBuildData } from '../core/build/types';
1414
import { mergeConfig } from '../core/config/config.js';
15-
import type { ViteConfigWithSSR } from '../core/create-vite.js';
1615
import { info, LogOptions } from '../core/logger/core.js';
1716

1817
async function withTakingALongTimeMsg<T>({
@@ -224,7 +223,7 @@ export async function runHookBuildSetup({
224223
logging,
225224
}: {
226225
config: AstroConfig;
227-
vite: ViteConfigWithSSR;
226+
vite: InlineConfig;
228227
pages: Map<string, PageBuildData>;
229228
target: 'server' | 'client';
230229
logging: LogOptions;

0 commit comments

Comments
 (0)