Move astro/config into src and typecheck (#5013)

* Move astro/config into src and typecheck

* Adding a changeset
This commit is contained in:
Matthew Phillips 2022-10-07 10:30:08 -04:00 committed by GitHub
parent 92b27e9c92
commit ffbe4e71e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 43 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fixes getViteConfig from astro/config

View file

@ -1,43 +1,4 @@
export function defineConfig(config) {
return config;
}
export function getViteConfig(inlineConfig) {
// Return an async Vite config getter which exposes a resolved `mode` and `command`
return async ({ mode, command }) => {
// Vite `command` is `serve | build`, but Astro uses `dev | build`
const cmd = command === 'serve' ? 'dev' : command;
// Use dynamic import to avoid pulling in deps unless used
const [
{ mergeConfig },
{ nodeLogDestination },
{ openConfig },
{ createVite },
{ runHookConfigSetup, runHookConfigDone },
] = await Promise.all([
import('vite'),
import('./dist/core/logger/node.js'),
import('./dist/core/config.js'),
import('./dist/core/create-vite.js'),
import('./dist/integrations/index.js'),
]);
const logging = {
dest: nodeLogDestination,
level: 'info',
};
const { astroConfig: config } = await openConfig({
cmd,
logging,
});
await runHookConfigSetup({ config, command: cmd });
const viteConfig = await createVite(
{
mode,
},
{ astroConfig: config, logging: logging, mode }
);
await runHookConfigDone({ config });
return mergeConfig(viteConfig, inlineConfig);
};
}
export {
defineConfig,
getViteConfig
} from './dist/config/index.js';

View file

@ -0,0 +1,53 @@
import type { AstroUserConfig } from '../@types/astro';
import type { UserConfig } from 'vite';
import type { LogOptions } from '../core/logger/core';
export function defineConfig(config: AstroUserConfig) {
return config;
}
export function getViteConfig(inlineConfig: UserConfig) {
// Return an async Vite config getter which exposes a resolved `mode` and `command`
return async ({ mode, command }: { mode: string; command: 'serve' | 'build' }) => {
// Vite `command` is `serve | build`, but Astro uses `dev | build`
const cmd = command === 'serve' ? 'dev' : command;
// Use dynamic import to avoid pulling in deps unless used
const [
{ mergeConfig },
{ nodeLogDestination },
{ openConfig, createSettings, loadTSConfig },
{ createVite },
{ runHookConfigSetup, runHookConfigDone },
] = await Promise.all([
import('vite'),
import('../core/logger/node.js'),
import('../core/config/index.js'),
import('../core/create-vite.js'),
import('../integrations/index.js'),
]);
const logging: LogOptions = {
dest: nodeLogDestination,
level: 'info',
};
const { astroConfig: config } = await openConfig({
cmd,
logging,
});
const initialTsConfig = loadTSConfig(inlineConfig.root)
const settings = createSettings({
config,
tsConfig: initialTsConfig?.config,
tsConfigPath: initialTsConfig?.path,
});
await runHookConfigSetup({ settings, command: cmd, logging });
const viteConfig = await createVite(
{
mode,
},
{ settings, logging: logging, mode }
);
await runHookConfigDone({ settings, logging });
return mergeConfig(viteConfig, inlineConfig);
};
}