@shareai-lab/kode 1.0.93 → 1.0.94

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 +61 -17
  2. package/package.json +1 -2
package/cli.js CHANGED
@@ -3,7 +3,7 @@
3
3
  const { spawn } = require('child_process');
4
4
  const path = require('path');
5
5
 
6
- // Prefer packaged Bun runtime to execute TS/TSX directly (simple + cross-platform)
6
+ // Prefer Bun if available for speed; otherwise use Node + tsx
7
7
  const args = process.argv.slice(2);
8
8
  const cliPath = path.join(__dirname, 'src', 'entrypoints', 'cli.tsx');
9
9
 
@@ -23,23 +23,67 @@ try {
23
23
  } catch {}
24
24
 
25
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
26
+ function hasBun() {
27
+ try {
28
+ require('child_process').execSync('bun --version', { stdio: 'ignore' })
29
+ return true
30
+ } catch { return false }
31
31
  }
32
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 => {
33
+ function runWithBun() {
34
+ const bunCmd = process.platform === 'win32' ? 'bun.cmd' : 'bun'
35
+ const child = spawn(bunCmd, ['run', cliPath, ...args], {
36
+ stdio: 'inherit',
37
+ env: { ...process.env, YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm') },
38
+ })
39
+ child.on('error', () => runWithTsxCLI())
40
+ child.on('exit', code => {
41
+ if (code && code !== 0) return runWithTsxCLI()
42
+ process.exit(code || 0)
43
+ })
44
+ }
45
+
46
+ function runWithTsxImport() {
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 baseArgs = ['--no-warnings=ExperimentalWarning', '--enable-source-maps']
55
+ const child = spawn(process.execPath, [...baseArgs, '--import', importArg, cliPath, ...args], {
56
+ stdio: 'inherit',
57
+ env: { ...process.env, YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm') },
58
+ })
59
+ child.on('error', () => runWithTsxCLI())
60
+ child.on('exit', code => {
61
+ if (code && code !== 0) return runWithTsxCLI()
62
+ process.exit(code || 0)
63
+ })
64
+ }
65
+
66
+ function runWithTsxCLI() {
67
+ if (!tsxCliPath) return fail()
68
+ const child = spawn(process.execPath, [tsxCliPath, cliPath, ...args], {
69
+ stdio: 'inherit',
70
+ env: { ...process.env, YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm') },
71
+ })
72
+ child.on('error', () => fail())
73
+ child.on('exit', code => process.exit(code || 0))
74
+ }
75
+
76
+ function fail() {
39
77
  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')
78
+ console.error('Failed to start Kode.')
79
+ console.error('Try installing Bun: npm i -g bun, or ensure tsx is available.')
43
80
  process.exit(1)
44
- })
45
- child.on('exit', code => process.exit(code || 0))
81
+ }
82
+
83
+ if (process.platform === 'win32') {
84
+ // On Windows, tsx CLI is the most reliable
85
+ runWithTsxCLI()
86
+ } else {
87
+ if (hasBun()) runWithBun()
88
+ else runWithTsxImport()
89
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shareai-lab/kode",
3
- "version": "1.0.93",
3
+ "version": "1.0.94",
4
4
  "bin": {
5
5
  "kode": "cli.js",
6
6
  "kwa": "cli.js",
@@ -46,7 +46,6 @@
46
46
  "@img/sharp-win32-x64": "^0.33.5"
47
47
  },
48
48
  "dependencies": {
49
- "bun": "^1.1.34",
50
49
  "@anthropic-ai/bedrock-sdk": "^0.12.6",
51
50
  "@anthropic-ai/sdk": "^0.39.0",
52
51
  "@anthropic-ai/vertex-sdk": "^0.7.0",