@0ctx/cli 0.1.2

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.
Files changed (3) hide show
  1. package/build.mjs +74 -0
  2. package/dist/index.js +6416 -0
  3. package/package.json +47 -0
package/build.mjs ADDED
@@ -0,0 +1,74 @@
1
+ /**
2
+ * esbuild bundle script for @0ctx/cli
3
+ *
4
+ * Produces a single self-contained dist/index.js that compiles and inlines
5
+ * all workspace packages (@0ctx/core, @0ctx/daemon, @0ctx/mcp) directly
6
+ * from their TypeScript source — no separate tsc pre-build needed.
7
+ *
8
+ * External (kept as runtime node_modules deps):
9
+ * - better-sqlite3 — native Node addon (.node binary)
10
+ * - cross-keychain — uses @napi-rs/keyring native addon optionally
11
+ */
12
+
13
+ // esbuild is installed at the monorepo root — Node's module resolution walks
14
+ // up from packages/cli/ and finds it in ../../node_modules automatically.
15
+ import esbuild from 'esbuild';
16
+ import { mkdirSync, existsSync } from 'fs';
17
+ import { resolve, dirname } from 'path';
18
+ import { fileURLToPath } from 'url';
19
+
20
+ const __dirname = dirname(fileURLToPath(import.meta.url));
21
+ const root = resolve(__dirname, '../..');
22
+
23
+ const dist = resolve(__dirname, 'dist');
24
+ if (!existsSync(dist)) mkdirSync(dist);
25
+
26
+ // ── Workspace package aliases ────────────────────────────────────────────────
27
+ // Point @0ctx/* imports directly at TypeScript source so esbuild compiles and
28
+ // bundles them without needing a separate tsc step first.
29
+ //
30
+ // Sub-path imports like `@0ctx/mcp/dist/bootstrap` are also aliased so the
31
+ // /dist/ path segment (used in the published package) maps to the src/ file.
32
+
33
+ const alias = {
34
+ // Top-level package entries
35
+ '@0ctx/core': resolve(root, 'packages/core/src/index.ts'),
36
+ '@0ctx/daemon': resolve(root, 'packages/daemon/src/index.ts'),
37
+ '@0ctx/mcp': resolve(root, 'packages/mcp/src/index.ts'),
38
+
39
+ // Sub-path imports used by CLI (from packages/cli/src/index.ts)
40
+ '@0ctx/mcp/dist/bootstrap': resolve(root, 'packages/mcp/src/bootstrap.ts'),
41
+ '@0ctx/mcp/dist/client': resolve(root, 'packages/mcp/src/client.ts'),
42
+ };
43
+
44
+ console.log('→ Bundling @0ctx/cli (esbuild)...');
45
+
46
+ await esbuild.build({
47
+ entryPoints: [resolve(__dirname, 'src/index.ts')],
48
+ bundle: true,
49
+ platform: 'node',
50
+ target: 'node18',
51
+ format: 'cjs',
52
+ outfile: resolve(__dirname, 'dist/index.js'),
53
+
54
+ // Workspace packages resolved above via alias
55
+ alias,
56
+
57
+ // Native addons that cannot be inlined — must remain in node_modules
58
+ external: [
59
+ 'better-sqlite3',
60
+ 'cross-keychain',
61
+ '@napi-rs/keyring',
62
+ ],
63
+
64
+ // Inline source-map for better stack traces without extra files
65
+ sourcemap: 'inline',
66
+
67
+ // Note: esbuild 0.27+ preserves the shebang from src/index.ts automatically.
68
+ // Do NOT add a banner here — it would produce a duplicate shebang and a
69
+ // "SyntaxError: Invalid or unexpected token" when running with `node`.
70
+
71
+ logLevel: 'info',
72
+ });
73
+
74
+ console.log('✓ dist/index.js ready');