Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bail not being defined for the vite builder #19405

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions code/lib/builder-vite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,25 @@ function iframeMiddleware(options: ExtendedOptions, server: ViteDevServer): Requ
};
}

let server: ViteDevServer;

export async function bail(e?: Error): Promise<void> {
try {
return await server.close();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: In theory server can be undefined here - although I can't see if it can in practice right now.

To be defensive I'd change the type to be let server: ViteDevServer | undefined; and add optional chaining when using it.

Copy link
Member

@IanVS IanVS Oct 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you want that in order to avoid the console warning? (this is in a try/catch.) I think it might be nice to show it, so we know what's happening, but it's also not super actionable, so I could go either way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm good point, I actually have no strong preference.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered this but I chose to leave it unguarded so that it would throw and error.

} catch (err) {
console.warn('unable to close vite server');
}

throw e;
}

export const start: ViteBuilder['start'] = async ({
startTime,
options,
router,
server: devServer,
}) => {
const server = await createViteServer(options as ExtendedOptions, devServer);
server = await createViteServer(options as ExtendedOptions, devServer);

// Just mock this endpoint (which is really Webpack-specific) so we don't get spammed with 404 in browser devtools
// TODO: we should either show some sort of progress from Vite, or just try to disable the whole Loader in the Manager UI.
Expand All @@ -75,16 +87,6 @@ export const start: ViteBuilder['start'] = async ({
router.use(iframeMiddleware(options as ExtendedOptions, server));
router.use(server.middlewares);

async function bail(e?: Error): Promise<void> {
try {
return await server.close();
} catch (err) {
console.warn('unable to close vite server');
}

throw e;
}

return {
bail,
stats: { toJson: () => null },
Expand Down