28 lines
876 B
JavaScript
28 lines
876 B
JavaScript
import * as esbuild from "esbuild";
|
|
/**
|
|
* Disposes the hydration and SSR esbuild contexts, releasing the incremental
|
|
* build state esbuild keeps in memory for them. The bundlers re-create the
|
|
* contexts on their next run.
|
|
*/
|
|
export default async function disposeBundlerContexts(params) {
|
|
try {
|
|
await global.BUNEXT_BUNDLER_CTX?.dispose();
|
|
}
|
|
catch (error) { }
|
|
global.BUNEXT_BUNDLER_CTX = undefined;
|
|
try {
|
|
await global.BUNEXT_SSR_BUNDLER_CTX?.dispose();
|
|
}
|
|
catch (error) { }
|
|
global.BUNEXT_SSR_BUNDLER_CTX = undefined;
|
|
if (params?.stop_service) {
|
|
// Exiting while the service is still running can leave it orphaned
|
|
// with an unanswered ping, which crashes it with "all goroutines are
|
|
// asleep - deadlock!".
|
|
try {
|
|
await esbuild.stop();
|
|
}
|
|
catch (error) { }
|
|
}
|
|
}
|