agent-canvas 0.1.11 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,22 +33,28 @@ export async function compilePlan(jsx: string, projectRoot?: string): Promise<Co
33
33
  try {
34
34
  writeFileSync(tmpFile, source);
35
35
 
36
- const result = await Bun.build({
37
- entrypoints: [tmpFile],
38
- format: "esm",
39
- external: ["react", "react-dom", "#canvas/components", "#canvas/runtime"],
40
- });
41
-
42
- if (!result.success) {
43
- const errors = result.logs
44
- .filter((l) => l.level === "error")
45
- .map((l) => l.message)
46
- .join("\n");
47
- return { ok: false, error: errors || "Compilation failed" };
48
- }
36
+ try {
37
+ const result = await Bun.build({
38
+ entrypoints: [tmpFile],
39
+ format: "esm",
40
+ external: ["react", "react-dom", "#canvas/components", "#canvas/runtime"],
41
+ });
42
+
43
+ if (!result.success) {
44
+ const errors = result.logs
45
+ .filter((l) => l.level === "error")
46
+ .map((l) => l.message)
47
+ .join("\n");
48
+ return { ok: false, error: errors || "Compilation failed" };
49
+ }
49
50
 
50
- const js = await result.outputs[0].text();
51
- return { ok: true, js };
51
+ const js = await result.outputs[0].text();
52
+ return { ok: true, js };
53
+ } catch {
54
+ // Bun.build() can throw "Unknown Error, TODO" in long-running processes
55
+ // when its internal bundler state gets corrupted. Fall back to subprocess.
56
+ return await compilePlanSubprocess(tmpFile);
57
+ }
52
58
  } catch (e: any) {
53
59
  return { ok: false, error: e.message };
54
60
  } finally {
@@ -56,6 +62,28 @@ export async function compilePlan(jsx: string, projectRoot?: string): Promise<Co
56
62
  }
57
63
  }
58
64
 
65
+ async function compilePlanSubprocess(tmpFile: string): Promise<CompileResult> {
66
+ const outFile = `${tmpFile}.out.js`;
67
+ const proc = Bun.spawn(
68
+ ["bun", "build", tmpFile, "--format=esm",
69
+ "--external=react", "--external=react-dom",
70
+ "--external=#canvas/components", "--external=#canvas/runtime",
71
+ "--outfile", outFile],
72
+ { stdout: "pipe", stderr: "pipe" },
73
+ );
74
+ const exitCode = await proc.exited;
75
+ if (exitCode !== 0) {
76
+ const stderr = await new Response(proc.stderr).text();
77
+ return { ok: false, error: stderr || "Compilation failed" };
78
+ }
79
+ try {
80
+ const js = readFileSync(outFile, "utf-8");
81
+ return { ok: true, js };
82
+ } finally {
83
+ try { unlinkSync(outFile); } catch {}
84
+ }
85
+ }
86
+
59
87
  /**
60
88
  * Find <Markdown file="..." /> tags and inject __content with the file contents
61
89
  * resolved at compile time.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-canvas",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "Interactive visual canvas for Claude Code — rich annotatable documents in the browser",
5
5
  "bin": {
6
6
  "agent-canvas": "bin/agent-canvas.js"