@shareai-lab/kode 1.0.103 → 1.1.1
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 +43 -99
- package/package.json +1 -1
- package/src/package.json +0 -3
package/cli.js
CHANGED
|
@@ -1,112 +1,56 @@
|
|
|
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
|
+
// Try bun first
|
|
17
11
|
try {
|
|
18
|
-
|
|
19
|
-
const m = req.match(/(\d+)\.(\d+)\.(\d+)/)
|
|
20
|
-
const [maj, min, pat] = process.versions.node.split('.').map(Number)
|
|
21
|
-
const [rMaj, rMin, rPat] = m ? m.slice(1).map(Number) : [20, 18, 1]
|
|
22
|
-
const tooOld = (maj < rMaj) || (maj === rMaj && (min < rMin || (min === rMin && pat < rPat)))
|
|
23
|
-
if (tooOld) {
|
|
24
|
-
console.error('Error: Node.js ' + req + ' is required. Please upgrade Node.')
|
|
25
|
-
process.exit(1)
|
|
26
|
-
}
|
|
27
|
-
} catch {}
|
|
28
|
-
|
|
29
|
-
// Find packaged Bun binary or fall back to system Bun
|
|
30
|
-
function hasBun() {
|
|
31
|
-
try {
|
|
32
|
-
require('child_process').execSync('bun --version', { stdio: 'ignore' })
|
|
33
|
-
return true
|
|
34
|
-
} catch { return false }
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function runWithBun() {
|
|
38
|
-
const bunCmd = 'bun'
|
|
39
|
-
let child
|
|
40
|
-
try {
|
|
41
|
-
child = spawn(bunCmd, ['run', cliPath, ...args], {
|
|
42
|
-
stdio: 'inherit',
|
|
43
|
-
shell: process.platform === 'win32',
|
|
44
|
-
env: { ...process.env, YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm') },
|
|
45
|
-
})
|
|
46
|
-
} catch {
|
|
47
|
-
return process.platform === 'win32' ? runWindowsNoBun() : runPosixNoBun()
|
|
48
|
-
}
|
|
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
|
-
}
|
|
12
|
+
execSync('bun --version', { stdio: 'ignore' });
|
|
55
13
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
try {
|
|
59
|
-
if (tsxImportPath) {
|
|
60
|
-
const { pathToFileURL } = require('node:url')
|
|
61
|
-
importArg = pathToFileURL(tsxImportPath).href
|
|
62
|
-
}
|
|
63
|
-
} catch {}
|
|
64
|
-
const baseArgs = ['--no-warnings=ExperimentalWarning', '--enable-source-maps']
|
|
65
|
-
const child = spawn(process.execPath, [...baseArgs, '--import', importArg, cliPath, ...args], {
|
|
14
|
+
// Bun is available
|
|
15
|
+
const child = spawn('bun', ['run', cliPath, ...args], {
|
|
66
16
|
stdio: 'inherit',
|
|
67
|
-
env: {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
17
|
+
env: {
|
|
18
|
+
...process.env,
|
|
19
|
+
YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm')
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
child.on('exit', (code) => process.exit(code || 0));
|
|
24
|
+
child.on('error', () => {
|
|
25
|
+
// Fallback to node if bun fails
|
|
26
|
+
runWithNode();
|
|
27
|
+
});
|
|
28
|
+
} catch {
|
|
29
|
+
// Bun not available, use node
|
|
30
|
+
runWithNode();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function runWithNode() {
|
|
34
|
+
// Use local tsx installation
|
|
35
|
+
const tsxPath = path.join(__dirname, 'node_modules', '.bin', 'tsx');
|
|
36
|
+
const child = spawn(tsxPath, [cliPath, ...args], {
|
|
79
37
|
stdio: 'inherit',
|
|
80
|
-
env: {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
}
|
|
38
|
+
env: {
|
|
39
|
+
...process.env,
|
|
40
|
+
YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm')
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
child.on('error', (err) => {
|
|
45
|
+
if (err && err.code === 'ENOENT') {
|
|
46
|
+
console.error('\nError: tsx is required but not found.');
|
|
47
|
+
console.error('Please run: npm install');
|
|
48
|
+
process.exit(1);
|
|
49
|
+
} else {
|
|
50
|
+
console.error('Failed to start Kode:', err && err.message ? err.message : err);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
105
54
|
|
|
106
|
-
|
|
107
|
-
runWithBun()
|
|
108
|
-
} else if (process.platform === 'win32') {
|
|
109
|
-
runWindowsNoBun()
|
|
110
|
-
} else {
|
|
111
|
-
runPosixNoBun()
|
|
55
|
+
child.on('exit', (code) => process.exit(code || 0));
|
|
112
56
|
}
|
package/package.json
CHANGED
package/src/package.json
DELETED