Builds errors bugfix

This commit is contained in:
2026-10-16 16:54:55 +01:00
parent af12852fb9
commit 8a981c854a
8 changed files with 50 additions and 6 deletions
+2
View File
@@ -5,6 +5,7 @@ import { rmSync, writeFileSync } from "fs";
import bunextInit from "../../functions/bunext-init"; import bunextInit from "../../functions/bunext-init";
import { v4 } from "uuid"; import { v4 } from "uuid";
import { updatePageLastmodRecord } from "../../utils/page-lastmod-record"; import { updatePageLastmodRecord } from "../../utils/page-lastmod-record";
import disposeBundlerContexts from "../../functions/bundler/dispose-bundler-contexts";
const { HYDRATION_DST_DIR, BUNX_CWD_PAGES_REWRITE_DIR, BUNDLER_CTX_MAP_JSON, SSR_BUNDLER_CTX_MAP_JSON, BUNX_CWD_MODULE_CACHE_DIR, BUILD_INFO_JSON, } = grabDirNames(); const { HYDRATION_DST_DIR, BUNX_CWD_PAGES_REWRITE_DIR, BUNDLER_CTX_MAP_JSON, SSR_BUNDLER_CTX_MAP_JSON, BUNX_CWD_MODULE_CACHE_DIR, BUILD_INFO_JSON, } = grabDirNames();
export default function () { export default function () {
return new Command("build") return new Command("build")
@@ -21,6 +22,7 @@ export default function () {
catch (error) { } catch (error) { }
global.BUNEXT_SKIPPED_BROWSER_MODULES = new Set(); global.BUNEXT_SKIPPED_BROWSER_MODULES = new Set();
await bunextInit({ build_only: true }); await bunextInit({ build_only: true });
await disposeBundlerContexts({ stop_service: true });
// A failed bundle must fail the command: CI and scripts rely on // A failed bundle must fail the command: CI and scripts rely on
// the exit code instead of grepping logs. // the exit code instead of grepping logs.
if (global.BUNEXT_BUILD_FAILED) { if (global.BUNEXT_BUILD_FAILED) {
+10 -1
View File
@@ -1,6 +1,15 @@
type Params = {
/**
* Also stop esbuild's service process. Only safe when no other esbuild
* call can be in flight (e.g. before exiting, or right after the startup
* build). The service restarts on the next esbuild call.
*/
stop_service?: boolean;
};
/** /**
* Disposes the hydration and SSR esbuild contexts, releasing the incremental * Disposes the hydration and SSR esbuild contexts, releasing the incremental
* build state esbuild keeps in memory for them. The bundlers re-create the * build state esbuild keeps in memory for them. The bundlers re-create the
* contexts on their next run. * contexts on their next run.
*/ */
export default function disposeBundlerContexts(): Promise<void>; export default function disposeBundlerContexts(params?: Params): Promise<void>;
export {};
+11 -1
View File
@@ -1,9 +1,10 @@
import * as esbuild from "esbuild";
/** /**
* Disposes the hydration and SSR esbuild contexts, releasing the incremental * Disposes the hydration and SSR esbuild contexts, releasing the incremental
* build state esbuild keeps in memory for them. The bundlers re-create the * build state esbuild keeps in memory for them. The bundlers re-create the
* contexts on their next run. * contexts on their next run.
*/ */
export default async function disposeBundlerContexts() { export default async function disposeBundlerContexts(params) {
try { try {
await global.BUNEXT_BUNDLER_CTX?.dispose(); await global.BUNEXT_BUNDLER_CTX?.dispose();
} }
@@ -14,4 +15,13 @@ export default async function disposeBundlerContexts() {
} }
catch (error) { } catch (error) { }
global.BUNEXT_SSR_BUNDLER_CTX = undefined; 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) { }
}
} }
+1 -1
View File
@@ -89,7 +89,7 @@ export default async function bunextInit(params) {
await allPagesESBuildContextBundler({ start: true }); await allPagesESBuildContextBundler({ start: true });
// The server only needs the artifact maps; don't keep // The server only needs the artifact maps; don't keep
// esbuild's build state alive for the rest of the process. // esbuild's build state alive for the rest of the process.
await disposeBundlerContexts(); await disposeBundlerContexts({ stop_service: true });
} }
cron(); cron();
} }
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@moduletrace/bunext", "name": "@moduletrace/bunext",
"version": "1.3.2", "version": "1.3.3",
"main": "dist/index.js", "main": "dist/index.js",
"module": "index.ts", "module": "index.ts",
"dependencies": { "dependencies": {
+3
View File
@@ -6,6 +6,7 @@ import bunextInit from "../../functions/bunext-init";
import type { BuildDataType } from "../../types"; import type { BuildDataType } from "../../types";
import { v4 } from "uuid"; import { v4 } from "uuid";
import { updatePageLastmodRecord } from "../../utils/page-lastmod-record"; import { updatePageLastmodRecord } from "../../utils/page-lastmod-record";
import disposeBundlerContexts from "../../functions/bundler/dispose-bundler-contexts";
const { const {
HYDRATION_DST_DIR, HYDRATION_DST_DIR,
@@ -33,6 +34,8 @@ export default function () {
await bunextInit({ build_only: true }); await bunextInit({ build_only: true });
await disposeBundlerContexts({ stop_service: true });
// A failed bundle must fail the command: CI and scripts rely on // A failed bundle must fail the command: CI and scripts rely on
// the exit code instead of grepping logs. // the exit code instead of grepping logs.
if (global.BUNEXT_BUILD_FAILED) { if (global.BUNEXT_BUILD_FAILED) {
@@ -1,9 +1,20 @@
import * as esbuild from "esbuild";
type Params = {
/**
* Also stop esbuild's service process. Only safe when no other esbuild
* call can be in flight (e.g. before exiting, or right after the startup
* build). The service restarts on the next esbuild call.
*/
stop_service?: boolean;
};
/** /**
* Disposes the hydration and SSR esbuild contexts, releasing the incremental * Disposes the hydration and SSR esbuild contexts, releasing the incremental
* build state esbuild keeps in memory for them. The bundlers re-create the * build state esbuild keeps in memory for them. The bundlers re-create the
* contexts on their next run. * contexts on their next run.
*/ */
export default async function disposeBundlerContexts() { export default async function disposeBundlerContexts(params?: Params) {
try { try {
await global.BUNEXT_BUNDLER_CTX?.dispose(); await global.BUNEXT_BUNDLER_CTX?.dispose();
} catch (error) {} } catch (error) {}
@@ -13,4 +24,13 @@ export default async function disposeBundlerContexts() {
await global.BUNEXT_SSR_BUNDLER_CTX?.dispose(); await global.BUNEXT_SSR_BUNDLER_CTX?.dispose();
} catch (error) {} } catch (error) {}
global.BUNEXT_SSR_BUNDLER_CTX = undefined; 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) {}
}
} }
+1 -1
View File
@@ -165,7 +165,7 @@ export default async function bunextInit(params?: Params) {
await allPagesESBuildContextBundler({ start: true }); await allPagesESBuildContextBundler({ start: true });
// The server only needs the artifact maps; don't keep // The server only needs the artifact maps; don't keep
// esbuild's build state alive for the rest of the process. // esbuild's build state alive for the rest of the process.
await disposeBundlerContexts(); await disposeBundlerContexts({ stop_service: true });
} }
cron(); cron();