@shareai-lab/kode 1.1.2 → 1.1.6

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 +23 -34
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -1,26 +1,17 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const { spawn, execSync } = require('child_process');
3
+ const { spawn } = require('child_process');
4
4
  const path = require('path');
5
5
 
6
- // Prefer bun if available, otherwise use Node with local tsx CLI
6
+ // Prefer bun if available, otherwise use node with loader
7
7
  const args = process.argv.slice(2);
8
8
  const cliPath = path.join(__dirname, 'src', 'entrypoints', 'cli.tsx');
9
9
 
10
- // Auto-set UTF-8 code page on Windows cmd if not already UTF-8
11
- try {
12
- if (process.platform === 'win32' && process.env.KODE_NO_AUTO_CHCP !== '1') {
13
- const out = execSync('chcp', { encoding: 'utf8' });
14
- if (!/65001/.test(out)) {
15
- execSync('chcp 65001', { stdio: 'ignore' });
16
- }
17
- }
18
- } catch {}
19
-
20
10
  // Try bun first
21
11
  try {
12
+ const { execSync } = require('child_process');
22
13
  execSync('bun --version', { stdio: 'ignore' });
23
-
14
+
24
15
  // Bun is available
25
16
  const child = spawn('bun', ['run', cliPath, ...args], {
26
17
  stdio: 'inherit',
@@ -29,7 +20,7 @@ try {
29
20
  YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm')
30
21
  }
31
22
  });
32
-
23
+
33
24
  child.on('exit', (code) => process.exit(code || 0));
34
25
  child.on('error', () => {
35
26
  // Fallback to node if bun fails
@@ -41,36 +32,34 @@ try {
41
32
  }
42
33
 
43
34
  function runWithNode() {
44
- // Use local tsx installation (original PR behavior), with Windows-friendly resolution
35
+ // Use local tsx installation; if missing, try PATH-resolved tsx
45
36
  const binDir = path.join(__dirname, 'node_modules', '.bin')
46
37
  const tsxPath = process.platform === 'win32'
47
38
  ? path.join(binDir, 'tsx.cmd')
48
39
  : path.join(binDir, 'tsx')
49
40
 
50
- const trySpawn = (cmd, useShell) => {
51
- const child = spawn(cmd, [cliPath, ...args], {
41
+ const runPathTsx = () => {
42
+ const child2 = spawn('tsx', [cliPath, ...args], {
52
43
  stdio: 'inherit',
53
- shell: useShell || false,
44
+ shell: process.platform === 'win32',
54
45
  env: { ...process.env, YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm') },
55
46
  })
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
- }
47
+ child2.on('error', () => {
48
+ console.error('\nError: tsx is required but not found.')
49
+ console.error('Please install tsx globally: npm install -g tsx')
64
50
  process.exit(1)
65
51
  })
66
- child.on('exit', (code) => process.exit(code || 0))
52
+ child2.on('exit', (code2) => process.exit(code2 || 0))
67
53
  }
68
54
 
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
- }
55
+ const child = spawn(tsxPath, [cliPath, ...args], {
56
+ stdio: 'inherit',
57
+ env: { ...process.env, YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm') },
58
+ })
59
+
60
+ child.on('error', () => runPathTsx())
61
+ child.on('exit', (code) => {
62
+ if (code && code !== 0) return runPathTsx()
63
+ process.exit(code || 0)
64
+ })
76
65
  }
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.06",
4
4
  "bin": {
5
5
  "kode": "cli.js",
6
6
  "kwa": "cli.js",