@shareai-lab/kode 1.0.101 → 1.0.102
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 +25 -12
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const { spawn } = require('child_process');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
|
|
6
|
-
// Prefer Bun if available for speed; otherwise use Node
|
|
6
|
+
// Prefer Bun if available for speed; otherwise use Node/tsx in best order per platform
|
|
7
7
|
const args = process.argv.slice(2);
|
|
8
8
|
const cliPath = path.join(__dirname, 'src', 'entrypoints', 'cli.tsx');
|
|
9
9
|
|
|
@@ -47,7 +47,7 @@ function runWithBun() {
|
|
|
47
47
|
})
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
function
|
|
50
|
+
function spawnTsxImport(onErrorFailOver) {
|
|
51
51
|
let importArg = 'tsx'
|
|
52
52
|
try {
|
|
53
53
|
if (tsxImportPath) {
|
|
@@ -60,21 +60,34 @@ function runWithTsxImport() {
|
|
|
60
60
|
stdio: 'inherit',
|
|
61
61
|
env: { ...process.env, YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm') },
|
|
62
62
|
})
|
|
63
|
-
child.on('error', () =>
|
|
63
|
+
child.on('error', () => onErrorFailOver ? onErrorFailOver() : fail())
|
|
64
64
|
child.on('exit', code => {
|
|
65
|
-
if (code && code !== 0) return
|
|
65
|
+
if (code && code !== 0) return onErrorFailOver ? onErrorFailOver() : fail()
|
|
66
66
|
process.exit(code || 0)
|
|
67
67
|
})
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
function
|
|
70
|
+
function spawnTsxCLI(onErrorFailOver) {
|
|
71
71
|
if (!tsxCliPath) return fail()
|
|
72
72
|
const child = spawn(process.execPath, [tsxCliPath, cliPath, ...args], {
|
|
73
73
|
stdio: 'inherit',
|
|
74
74
|
env: { ...process.env, YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm') },
|
|
75
75
|
})
|
|
76
|
-
child.on('error', () => fail())
|
|
77
|
-
child.on('exit', code =>
|
|
76
|
+
child.on('error', () => onErrorFailOver ? onErrorFailOver() : fail())
|
|
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()))
|
|
78
91
|
}
|
|
79
92
|
|
|
80
93
|
function fail() {
|
|
@@ -84,10 +97,10 @@ function fail() {
|
|
|
84
97
|
process.exit(1)
|
|
85
98
|
}
|
|
86
99
|
|
|
87
|
-
if (
|
|
88
|
-
|
|
89
|
-
|
|
100
|
+
if (hasBun()) {
|
|
101
|
+
runWithBun()
|
|
102
|
+
} else if (process.platform === 'win32') {
|
|
103
|
+
runWindowsNoBun()
|
|
90
104
|
} else {
|
|
91
|
-
|
|
92
|
-
else runWithTsxImport()
|
|
105
|
+
runPosixNoBun()
|
|
93
106
|
}
|