@shareai-lab/kode 1.0.103 → 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 +56 -92
- package/package.json +1 -1
- package/src/package.json +0 -3
package/cli.js
CHANGED
|
@@ -1,112 +1,76 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const { spawn } = require('child_process');
|
|
3
|
+
const { spawn, execSync } = require('child_process');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
|
|
6
|
-
// Prefer
|
|
6
|
+
// Prefer bun if available, otherwise use Node with local tsx CLI
|
|
7
7
|
const args = process.argv.slice(2);
|
|
8
8
|
const cliPath = path.join(__dirname, 'src', 'entrypoints', 'cli.tsx');
|
|
9
9
|
|
|
10
|
-
//
|
|
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
|
-
// Enforce minimum Node version based on package.json engines.node
|
|
10
|
+
// Auto-set UTF-8 code page on Windows cmd if not already UTF-8
|
|
17
11
|
try {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (tooOld) {
|
|
24
|
-
console.error('Error: Node.js ' + req + ' is required. Please upgrade Node.')
|
|
25
|
-
process.exit(1)
|
|
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
|
+
}
|
|
26
17
|
}
|
|
27
18
|
} catch {}
|
|
28
19
|
|
|
29
|
-
//
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
20
|
+
// Try bun first
|
|
21
|
+
try {
|
|
22
|
+
execSync('bun --version', { stdio: 'ignore' });
|
|
23
|
+
|
|
24
|
+
// Bun is available
|
|
25
|
+
const child = spawn('bun', ['run', cliPath, ...args], {
|
|
26
|
+
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();
|
|
35
41
|
}
|
|
36
42
|
|
|
37
|
-
function
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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], {
|
|
42
52
|
stdio: 'inherit',
|
|
43
|
-
shell:
|
|
53
|
+
shell: useShell || false,
|
|
44
54
|
env: { ...process.env, YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm') },
|
|
45
55
|
})
|
|
46
|
-
|
|
47
|
-
|
|
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))
|
|
48
67
|
}
|
|
49
|
-
child.on('error', () => (process.platform === 'win32' ? runWindowsNoBun() : runPosixNoBun()))
|
|
50
|
-
child.on('exit', code => {
|
|
51
|
-
if (code && code !== 0) return process.platform === 'win32' ? runWindowsNoBun() : runPosixNoBun()
|
|
52
|
-
process.exit(code || 0)
|
|
53
|
-
})
|
|
54
|
-
}
|
|
55
68
|
|
|
56
|
-
function spawnTsxImport(onErrorFailOver) {
|
|
57
|
-
let importArg = 'tsx'
|
|
58
69
|
try {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const child = spawn(process.execPath, [...baseArgs, '--import', importArg, cliPath, ...args], {
|
|
66
|
-
stdio: 'inherit',
|
|
67
|
-
env: { ...process.env, YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm') },
|
|
68
|
-
})
|
|
69
|
-
child.on('error', () => onErrorFailOver ? onErrorFailOver() : fail())
|
|
70
|
-
child.on('exit', code => {
|
|
71
|
-
if (code && code !== 0) return onErrorFailOver ? onErrorFailOver() : fail()
|
|
72
|
-
process.exit(code || 0)
|
|
73
|
-
})
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function spawnTsxCLI(onErrorFailOver) {
|
|
77
|
-
if (!tsxCliPath) return fail()
|
|
78
|
-
const child = spawn(process.execPath, [tsxCliPath, cliPath, ...args], {
|
|
79
|
-
stdio: 'inherit',
|
|
80
|
-
env: { ...process.env, YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm') },
|
|
81
|
-
})
|
|
82
|
-
child.on('error', () => onErrorFailOver ? onErrorFailOver() : fail())
|
|
83
|
-
child.on('exit', code => {
|
|
84
|
-
if (code && code !== 0) return onErrorFailOver ? onErrorFailOver() : fail()
|
|
85
|
-
process.exit(code || 0)
|
|
86
|
-
})
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function runWindowsNoBun() {
|
|
90
|
-
// Best order on Windows: tsx CLI -> Node --import tsx
|
|
91
|
-
spawnTsxCLI(() => spawnTsxImport(() => fail()))
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function runPosixNoBun() {
|
|
95
|
-
// Best order on non-Windows: Node --import tsx -> tsx CLI
|
|
96
|
-
spawnTsxImport(() => spawnTsxCLI(() => fail()))
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function fail() {
|
|
100
|
-
console.error('')
|
|
101
|
-
console.error('Failed to start Kode.')
|
|
102
|
-
console.error('If you see top-level await/CJS errors on Windows, ensure tsx is available and up-to-date.')
|
|
103
|
-
process.exit(1)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (hasBun()) {
|
|
107
|
-
runWithBun()
|
|
108
|
-
} else if (process.platform === 'win32') {
|
|
109
|
-
runWindowsNoBun()
|
|
110
|
-
} else {
|
|
111
|
-
runPosixNoBun()
|
|
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
|
+
}
|
|
112
76
|
}
|
package/package.json
CHANGED
package/src/package.json
DELETED