@shareai-lab/kode 1.1.1 → 1.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.
- package/cli.js +40 -20
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -7,6 +7,16 @@ const path = require('path');
|
|
|
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
|
+
|
|
10
20
|
// Try bun first
|
|
11
21
|
try {
|
|
12
22
|
execSync('bun --version', { stdio: 'ignore' });
|
|
@@ -31,26 +41,36 @@ try {
|
|
|
31
41
|
}
|
|
32
42
|
|
|
33
43
|
function runWithNode() {
|
|
34
|
-
// Use local tsx installation
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
...process.env,
|
|
40
|
-
YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm')
|
|
41
|
-
}
|
|
42
|
-
});
|
|
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')
|
|
43
49
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
process.
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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))
|
|
67
|
+
}
|
|
54
68
|
|
|
55
|
-
|
|
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
|
+
}
|
|
56
76
|
}
|