Handle errors better

This commit is contained in:
2026-04-09 18:01:29 +01:00
parent eb0721f94b
commit f3b087a1f3
10 changed files with 91 additions and 15 deletions
@@ -1,4 +1,4 @@
import type { Plugin } from "esbuild";
import { type Plugin } from "esbuild";
import type { PageFiles } from "../../../types";
type Params = {
entryToPage: Map<string, PageFiles & {
@@ -1,20 +1,24 @@
import {} from "esbuild";
import { log } from "../../../utils/log";
import grabArtifactsFromBundledResults from "../grab-artifacts-from-bundled-result";
let buildStart = 0;
let build_starts = 0;
const MAX_BUILD_STARTS = 10;
const MAX_BUILD_STARTS = 2;
export default function esbuildCTXArtifactTracker({ entryToPage, post_build_fn, }) {
const artifactTracker = {
name: "artifact-tracker",
setup(build) {
build.onStart(() => {
build.onStart(async () => {
build_starts++;
buildStart = performance.now();
if (build_starts == MAX_BUILD_STARTS) {
const error_msg = `Build Failed. Please check all your components and imports.`;
log.error(error_msg);
global.BUNDLER_CTX_DISPOSED = true;
global.RECOMPILING = false;
global.IS_SERVER_COMPONENT = false;
await global.BUNDLER_CTX?.dispose();
global.BUNDLER_CTX = undefined;
}
});
build.onEnd((result) => {
@@ -28,6 +32,20 @@ export default function esbuildCTXArtifactTracker({ entryToPage, post_build_fn,
// }
return;
}
// if (result.errors.length) {
// console.error(
// esbuild.formatMessagesSync(result.errors, {
// kind: "error",
// }),
// );
// }
// if (result.warnings.length) {
// console.warn(
// esbuild.formatMessagesSync(result.warnings, {
// kind: "warning",
// }),
// );
// }
const artifacts = grabArtifactsFromBundledResults({
result,
entryToPage,