@shareai-lab/kode 1.0.102 → 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 +42 -92
- package/package.json +1 -1
- package/src/package.json +0 -3
package/cli.js
CHANGED
|
@@ -1,106 +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
|
-
}
|
|
12
|
+
execSync('bun --version', { stdio: 'ignore' });
|
|
36
13
|
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
const child = spawn(bunCmd, ['run', cliPath, ...args], {
|
|
14
|
+
// Bun is available
|
|
15
|
+
const child = spawn('bun', ['run', cliPath, ...args], {
|
|
40
16
|
stdio: 'inherit',
|
|
41
|
-
env: {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
child.on('exit', code => {
|
|
45
|
-
if (code && code !== 0) return runWithTsxImport()
|
|
46
|
-
process.exit(code || 0)
|
|
47
|
-
})
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function spawnTsxImport(onErrorFailOver) {
|
|
51
|
-
let importArg = 'tsx'
|
|
52
|
-
try {
|
|
53
|
-
if (tsxImportPath) {
|
|
54
|
-
const { pathToFileURL } = require('node:url')
|
|
55
|
-
importArg = pathToFileURL(tsxImportPath).href
|
|
17
|
+
env: {
|
|
18
|
+
...process.env,
|
|
19
|
+
YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm')
|
|
56
20
|
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
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], {
|
|
60
37
|
stdio: 'inherit',
|
|
61
|
-
env: {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
child.on('exit', code => {
|
|
78
|
-
if (code && code !== 0) return onErrorFailOver ? onErrorFailOver() : fail()
|
|
79
|
-
process.exit(code || 0)
|
|
80
|
-
})
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function runWindowsNoBun() {
|
|
84
|
-
// Best order on Windows: tsx CLI -> Node --import tsx
|
|
85
|
-
spawnTsxCLI(() => spawnTsxImport(() => fail()))
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function runPosixNoBun() {
|
|
89
|
-
// Best order on non-Windows: Node --import tsx -> tsx CLI
|
|
90
|
-
spawnTsxImport(() => spawnTsxCLI(() => fail()))
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function fail() {
|
|
94
|
-
console.error('')
|
|
95
|
-
console.error('Failed to start Kode.')
|
|
96
|
-
console.error('If you see top-level await/CJS errors on Windows, ensure tsx is available and up-to-date.')
|
|
97
|
-
process.exit(1)
|
|
98
|
-
}
|
|
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
|
+
});
|
|
99
54
|
|
|
100
|
-
|
|
101
|
-
runWithBun()
|
|
102
|
-
} else if (process.platform === 'win32') {
|
|
103
|
-
runWindowsNoBun()
|
|
104
|
-
} else {
|
|
105
|
-
runPosixNoBun()
|
|
55
|
+
child.on('exit', (code) => process.exit(code || 0));
|
|
106
56
|
}
|
package/package.json
CHANGED
package/src/package.json
DELETED