@shareai-lab/kode 1.0.92 → 1.0.93

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 (2) hide show
  1. package/cli.js +21 -76
  2. package/package.json +2 -1
package/cli.js CHANGED
@@ -3,16 +3,10 @@
3
3
  const { spawn } = require('child_process');
4
4
  const path = require('path');
5
5
 
6
- // Prefer Bun for dev; otherwise use Node + tsx (ESM --import)
6
+ // Prefer packaged Bun runtime to execute TS/TSX directly (simple + cross-platform)
7
7
  const args = process.argv.slice(2);
8
8
  const cliPath = path.join(__dirname, 'src', 'entrypoints', 'cli.tsx');
9
9
 
10
- // Resolve tsx from this package directory (avoid CWD-based resolution on Windows/global installs)
11
- let tsxImportPath = null;
12
- let tsxCliPath = null;
13
- try { tsxImportPath = require.resolve('tsx', { paths: [__dirname] }); } catch {}
14
- try { tsxCliPath = require.resolve('tsx/cli', { paths: [__dirname] }); } catch {}
15
-
16
10
  // Enforce minimum Node version based on package.json engines.node
17
11
  try {
18
12
  const req = "${enginesNode}"
@@ -28,73 +22,24 @@ try {
28
22
  }
29
23
  } catch {}
30
24
 
31
- // Try Bun first
32
- try {
33
- const { execSync } = require('child_process');
34
- execSync('bun --version', { stdio: 'ignore' });
35
- const child = spawn('bun', ['run', cliPath, ...args], {
36
- stdio: 'inherit',
37
- env: { ...process.env, YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm') },
38
- });
39
- child.on('exit', (code) => process.exit(code || 0));
40
- child.on('error', () => runWithNode());
41
- } catch { runWithNode(); }
42
-
43
- function runWithNode() {
44
- const baseArgs = ['--no-warnings=ExperimentalWarning', '--enable-source-maps']
45
-
46
- const tryWithImport = () => {
47
- let importArg = 'tsx'
48
- try {
49
- if (tsxImportPath) {
50
- const { pathToFileURL } = require('node:url')
51
- importArg = pathToFileURL(tsxImportPath).href
52
- }
53
- } catch {}
54
- const child = spawn(process.execPath, [...baseArgs, '--import', importArg, cliPath, ...args], {
55
- stdio: 'inherit',
56
- env: { ...process.env, YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm') },
57
- })
58
- child.on('error', () => failWithTsxHint())
59
- child.on('exit', code => {
60
- if (code && code !== 0) return failWithTsxHint()
61
- process.exit(code || 0)
62
- })
63
- }
64
-
65
- const tryWithTsxBinary = () => {
66
- if (!tsxCliPath) return failWithTsxHint()
67
- const child = spawn(process.execPath, [tsxCliPath, cliPath, ...args], {
68
- stdio: 'inherit',
69
- env: { ...process.env, YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm') },
70
- })
71
- child.on('error', () => failWithTsxHint())
72
- child.on('exit', code => {
73
- if (code && code !== 0) return failWithTsxHint()
74
- process.exit(code || 0)
75
- })
76
- }
77
-
78
- function failWithTsxHint() {
79
- console.error('')
80
- console.error('Failed to launch with Node + tsx.')
81
- console.error('Try reinstalling: npm i -g @shareai-lab/kode (ensures bundled tsx).')
82
- console.error('Or install Bun and run: bun run kode')
83
- process.exit(1)
84
- }
85
-
86
- // Windows prefers tsx CLI due to top-level await in CJS transforms
87
- if (process.platform === 'win32') {
88
- tryWithTsxBinary()
89
- } else {
90
- // Non-Windows: try import-based first, then fallback
91
- let attempted = false
92
- const child = spawn(process.execPath, [...baseArgs, '--eval', ''], { stdio: 'ignore' })
93
- child.on('error', () => {})
94
- child.on('exit', () => {
95
- if (attempted) return
96
- attempted = true
97
- tryWithImport()
98
- })
99
- }
25
+ // Find packaged Bun binary or fall back to system Bun
26
+ function findBunPath() {
27
+ const binName = process.platform === 'win32' ? 'bun.cmd' : 'bun'
28
+ const localBin = path.join(__dirname, 'node_modules', '.bin', binName)
29
+ try { require('fs').accessSync(localBin); return localBin } catch {}
30
+ return binName
100
31
  }
32
+
33
+ const bunPath = findBunPath()
34
+ const child = spawn(bunPath, [cliPath, ...args], {
35
+ stdio: 'inherit',
36
+ env: { ...process.env, YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm') },
37
+ })
38
+ child.on('error', err => {
39
+ console.error('')
40
+ console.error('Failed to start Kode using Bun runtime.')
41
+ console.error('Please install Bun or ensure it is accessible:')
42
+ console.error(' npm install -g bun')
43
+ process.exit(1)
44
+ })
45
+ child.on('exit', code => process.exit(code || 0))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shareai-lab/kode",
3
- "version": "1.0.92",
3
+ "version": "1.0.93",
4
4
  "bin": {
5
5
  "kode": "cli.js",
6
6
  "kwa": "cli.js",
@@ -46,6 +46,7 @@
46
46
  "@img/sharp-win32-x64": "^0.33.5"
47
47
  },
48
48
  "dependencies": {
49
+ "bun": "^1.1.34",
49
50
  "@anthropic-ai/bedrock-sdk": "^0.12.6",
50
51
  "@anthropic-ai/sdk": "^0.39.0",
51
52
  "@anthropic-ai/vertex-sdk": "^0.7.0",