Files
bunext/dist/functions/bundler/dispose-bundler-contexts.js
2026-10-16 16:54:55 +01:00

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) { }
}
}