Merge pull request #20243 from storybookjs/20242-handle-bail-better

Vite: Make the bail function work if the server fails to start
This commit is contained in:
Michael Shilman 2022-12-14 20:16:03 +08:00 committed by GitHub
commit f4f79893b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 19 deletions

View File

@ -69,14 +69,8 @@ function iframeMiddleware(options: ExtendedOptions, server: ViteDevServer): Requ
let server: ViteDevServer;
export async function bail(e?: Error): Promise<void> {
try {
return await server.close();
} catch (err) {
console.warn('unable to close vite server');
}
throw e;
export async function bail(): Promise<void> {
return server?.close();
}
export const start: ViteBuilder['start'] = async ({

View File

@ -3,19 +3,16 @@
import { createViteServer } from './vite-server';
let server: ViteDevServer;
export async function bail(): Promise<void> {
return server?.close();
}
export const start: ViteBuilder['start'] = async ({ options, server: devServer }) => {
// Remainder implementation goes here
const server = await createViteServer(options as ExtendedOptions, devServer);
async function bail(e?: Error): Promise<void> {
try {
return await server.close();
} catch (err) {
console.warn('unable to close the server');
}
throw e;
}
server = await createViteServer(options as ExtendedOptions, devServer);
return {
bail,
totalTime: process.hrtime(startTime),