@myrialabs/clopen 0.4.12 → 0.4.14

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.
package/backend/index.ts CHANGED
@@ -8,7 +8,12 @@ if (typeof globalThis.Bun === 'undefined') {
8
8
  process.exit(1);
9
9
  }
10
10
 
11
- // MUST be first import — cleans process.env before any other module reads it
11
+ // Note: the node:v8 isBuildingSnapshot shim (backend/utils/bun-compat.ts) is
12
+ // applied via Bun `preload` (bunfig.toml + --preload in bin/clopen.ts), NOT a
13
+ // plain import here — Bun does not guarantee side-effect import order ahead of
14
+ // the transitive mongodb/bson CJS import, so an import would run too late.
15
+
16
+ // MUST be first import — cleans process.env before any other module reads it.
12
17
  import { SERVER_ENV } from './utils/env';
13
18
 
14
19
  import { Elysia } from 'elysia';
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Bun compatibility shims — applied as a side effect at process startup.
3
+ *
4
+ * `node:v8` `startupSnapshot.isBuildingSnapshot()` is not implemented in Bun
5
+ * (calling it throws `ERR_NOT_IMPLEMENTED`). `bson` >= 7.3.0 invokes it inside a
6
+ * module-level `static {}` block, so importing `mongodb` crashes the process at
7
+ * load time on Bun — before Clopen can even start.
8
+ *
9
+ * We cannot reliably pin the transitive `bson` for end users: they install via
10
+ * `bun add -g @myrialabs/clopen`, where Clopen is a dependency rather than the
11
+ * root package, so its `overrides`/exact pins are ignored and Bun re-resolves
12
+ * `mongodb`'s `bson: "^7.2.0"` to the newest (broken) version. Instead we
13
+ * neutralize the missing API by replacing the throwing stub with a no-op that
14
+ * reports "not building a snapshot" — always true for a normally-running
15
+ * process, so `bson` skips its snapshot branch and loads cleanly.
16
+ *
17
+ * This file MUST be loaded via Bun's `--preload` / `bunfig.toml preload`, NOT a
18
+ * plain `import`. Bun does not guarantee that an earlier ESM side-effect import
19
+ * runs before a later CJS import is evaluated, so `import './bun-compat'` at the
20
+ * top of an entry still lets `mongodb`/`bson` load (and crash) first. `preload`
21
+ * is the only mechanism that reliably runs before the entry's import graph.
22
+ */
23
+
24
+ if (typeof globalThis.Bun !== 'undefined') {
25
+ const v8 = (process as { getBuiltinModule?: (name: string) => unknown }).getBuiltinModule?.('v8') as
26
+ | { startupSnapshot?: { isBuildingSnapshot?: () => boolean } }
27
+ | undefined;
28
+
29
+ if (v8?.startupSnapshot && typeof v8.startupSnapshot.isBuildingSnapshot === 'function') {
30
+ try {
31
+ v8.startupSnapshot.isBuildingSnapshot = () => false;
32
+ } catch {
33
+ // Property is non-writable in this runtime — best effort, nothing else to do.
34
+ }
35
+ }
36
+ }
package/bin/clopen.ts CHANGED
@@ -374,6 +374,9 @@ function ensureBuild() {
374
374
  }
375
375
 
376
376
  async function startServer(options: CLIOptions) {
377
+ // cwd is set to __dirname (package root) below so Bun picks up bunfig.toml,
378
+ // which preloads the node:v8 isBuildingSnapshot shim before the backend's
379
+ // import graph — see bunfig.toml and backend/utils/bun-compat.ts.
377
380
  const startScript = join(__dirname, 'scripts/start.ts');
378
381
 
379
382
  const env = { ...process.env, ...loadEnvFile(ENV_FILE) };
package/bunfig.toml ADDED
@@ -0,0 +1,4 @@
1
+ # Preload Bun compatibility shims before any entry's import graph is evaluated.
2
+ # Required because Bun does not guarantee ESM side-effect import order ahead of
3
+ # CJS imports — see backend/utils/bun-compat.ts (node:v8 isBuildingSnapshot / bson).
4
+ preload = ["./backend/utils/bun-compat.ts"]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myrialabs/clopen",
3
- "version": "0.4.12",
3
+ "version": "0.4.14",
4
4
  "description": "All-in-one web workspace for AI coding agents — Claude Code, OpenCode, Codex, Copilot, and Qwen Code — with chat, terminal, git, browser preview, database client, checkpoints, and real-time collaboration",
5
5
  "author": "Myria Labs",
6
6
  "license": "MIT",
@@ -54,6 +54,7 @@
54
54
  "shared",
55
55
  "dist",
56
56
  "tsconfig.json",
57
+ "bunfig.toml",
57
58
  ".env.example"
58
59
  ],
59
60
  "engines": {
@@ -109,7 +110,6 @@
109
110
  "@opencode-ai/sdk": "1.15.12",
110
111
  "@qwen-code/sdk": "0.1.7",
111
112
  "@sinclair/typebox": "0.34.48",
112
- "bson": "7.2.0",
113
113
  "bun-pty": "0.4.8",
114
114
  "dompurify": "3.4.9",
115
115
  "elysia": "1.4.27",
@@ -129,8 +129,5 @@
129
129
  "trustedDependencies": [
130
130
  "puppeteer",
131
131
  "sharp"
132
- ],
133
- "overrides": {
134
- "bson": "7.2.0"
135
- }
132
+ ]
136
133
  }