@shareai-lab/kode 1.1.2 → 1.1.3

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 +53 -51
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -3,7 +3,7 @@
3
3
  const { spawn, execSync } = require('child_process');
4
4
  const path = require('path');
5
5
 
6
- // Prefer bun if available, otherwise use Node with local tsx CLI
6
+ // Kode requires Bun for best reliability & speed on Windows
7
7
  const args = process.argv.slice(2);
8
8
  const cliPath = path.join(__dirname, 'src', 'entrypoints', 'cli.tsx');
9
9
 
@@ -17,60 +17,62 @@ try {
17
17
  }
18
18
  } catch {}
19
19
 
20
- // Try bun first
21
- try {
22
- execSync('bun --version', { stdio: 'ignore' });
23
-
24
- // Bun is available
20
+ function startWithBun() {
25
21
  const child = spawn('bun', ['run', cliPath, ...args], {
26
22
  stdio: 'inherit',
27
- env: {
28
- ...process.env,
29
- YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm')
30
- }
31
- });
32
-
33
- child.on('exit', (code) => process.exit(code || 0));
34
- child.on('error', () => {
35
- // Fallback to node if bun fails
36
- runWithNode();
37
- });
38
- } catch {
39
- // Bun not available, use node
40
- runWithNode();
23
+ shell: process.platform === 'win32',
24
+ env: { ...process.env, YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm') },
25
+ })
26
+ child.on('exit', code => process.exit(code || 0))
27
+ child.on('error', () => showBunInstructionsAndExit())
41
28
  }
42
29
 
43
- function runWithNode() {
44
- // Use local tsx installation (original PR behavior), with Windows-friendly resolution
45
- const binDir = path.join(__dirname, 'node_modules', '.bin')
46
- const tsxPath = process.platform === 'win32'
47
- ? path.join(binDir, 'tsx.cmd')
48
- : path.join(binDir, 'tsx')
49
-
50
- const trySpawn = (cmd, useShell) => {
51
- const child = spawn(cmd, [cliPath, ...args], {
52
- stdio: 'inherit',
53
- shell: useShell || false,
54
- env: { ...process.env, YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm') },
55
- })
56
- child.on('error', (err) => {
57
- // Final fallback: suggest install
58
- if (err && err.code === 'ENOENT') {
59
- console.error('\nError: tsx is required but not found.')
60
- console.error('Please run: npm install')
61
- } else {
62
- console.error('Failed to start Kode:', err && err.message ? err.message : err)
63
- }
64
- process.exit(1)
65
- })
66
- child.on('exit', (code) => process.exit(code || 0))
30
+ function showBunInstructionsAndExit() {
31
+ console.error('')
32
+ console.error('Kode requires Bun for optimal startup and compatibility.')
33
+ console.error('Install Bun, then install Kode with Bun, and run Kode:')
34
+ console.error('')
35
+ if (process.platform === 'win32') {
36
+ console.error('Windows (PowerShell, recommended):')
37
+ console.error(' winget install --id=Oven-sh.Bun -e')
38
+ console.error(' # 如果未安装 winget,可用 PowerShell 安装脚本:')
39
+ console.error(' powershell -ExecutionPolicy Bypass -NoLogo -NoProfile -Command "iwr https://bun.sh/install.ps1 -UseBasicParsing | iex"')
40
+ console.error(' # 若脚本受限:Set-ExecutionPolicy RemoteSigned -Scope CurrentUser')
41
+ console.error(' # bun 未自动加入 PATH,可执行:')
42
+ console.error(' setx PATH "%USERPROFILE%\\.bun\\bin;%PATH%"')
43
+ console.error('')
44
+ console.error('安装完成后:')
45
+ console.error(' bun --version')
46
+ console.error(' bun add -g @shareai-lab/kode@latest')
47
+ console.error(' kode')
48
+ } else if (process.platform === 'darwin') {
49
+ console.error('macOS:')
50
+ console.error(' brew tap oven-sh/bun && brew install bun')
51
+ console.error(' # 或者')
52
+ console.error(' curl -fsSL https://bun.sh/install | bash')
53
+ console.error(' # zsh: echo "export PATH=\"$HOME/.bun/bin:$PATH\"" >> ~/.zshrc && source ~/.zshrc')
54
+ console.error('')
55
+ console.error('安装完成后:')
56
+ console.error(' bun --version')
57
+ console.error(' bun add -g @shareai-lab/kode@latest')
58
+ console.error(' kode')
59
+ } else {
60
+ console.error('Linux:')
61
+ console.error(' curl -fsSL https://bun.sh/install | bash')
62
+ console.error(' echo "export PATH=\"$HOME/.bun/bin:$PATH\"" >> ~/.bashrc && source ~/.bashrc')
63
+ console.error('')
64
+ console.error('安装完成后:')
65
+ console.error(' bun --version')
66
+ console.error(' bun add -g @shareai-lab/kode@latest')
67
+ console.error(' kode')
67
68
  }
69
+ console.error('')
70
+ process.exit(1)
71
+ }
68
72
 
69
- try {
70
- // Prefer absolute path to local .bin
71
- trySpawn(tsxPath, false)
72
- } catch {
73
- // If that fails (e.g., npm hoisted .bin), try PATH-resolved "tsx" (shell on Windows)
74
- trySpawn('tsx', process.platform === 'win32')
75
- }
73
+ try {
74
+ execSync('bun --version', { stdio: 'ignore' })
75
+ startWithBun()
76
+ } catch {
77
+ showBunInstructionsAndExit()
76
78
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shareai-lab/kode",
3
- "version": "1.1.02",
3
+ "version": "1.1.03",
4
4
  "bin": {
5
5
  "kode": "cli.js",
6
6
  "kwa": "cli.js",