@shareai-lab/kode 1.0.82 → 1.0.85
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 +52 -23
- package/package.json +2 -2
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, otherwise use node with loader
|
|
6
|
+
// Prefer bun if available, otherwise use node with tsx (ESM --import, fallback to --loader)
|
|
7
7
|
const args = process.argv.slice(2);
|
|
8
8
|
const cliPath = path.join(__dirname, 'src', 'entrypoints', 'cli.tsx');
|
|
9
9
|
|
|
@@ -32,26 +32,55 @@ try {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
function runWithNode() {
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
process.exit(
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
35
|
+
const nodeVersion = process.versions.node.split('.').map(Number)
|
|
36
|
+
const [major, minor] = nodeVersion
|
|
37
|
+
const supportsImport = major > 20 || (major === 20 && minor >= 6) || major >= 21
|
|
38
|
+
|
|
39
|
+
const baseArgs = ['--no-warnings=ExperimentalWarning', '--enable-source-maps']
|
|
40
|
+
|
|
41
|
+
const tryWithLoader = () => {
|
|
42
|
+
const child = spawn(process.execPath, [...baseArgs, '--loader', 'tsx', cliPath, ...args], {
|
|
43
|
+
stdio: 'inherit',
|
|
44
|
+
env: { ...process.env, YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm') },
|
|
45
|
+
})
|
|
46
|
+
child.on('error', () => tryWithTsxBinary())
|
|
47
|
+
child.on('exit', code => {
|
|
48
|
+
if (code && code !== 0) return tryWithTsxBinary()
|
|
49
|
+
process.exit(code || 0)
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const tryWithTsxBinary = () => {
|
|
54
|
+
const tsxPath = path.join(__dirname, 'node_modules', '.bin', 'tsx')
|
|
55
|
+
const child = spawn(tsxPath, [cliPath, ...args], {
|
|
56
|
+
stdio: 'inherit',
|
|
57
|
+
env: { ...process.env, YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm') },
|
|
58
|
+
})
|
|
59
|
+
child.on('error', err => {
|
|
60
|
+
if (err.code === 'ENOENT') {
|
|
61
|
+
console.error('')
|
|
62
|
+
console.error('Error: tsx is required but not found.')
|
|
63
|
+
console.error('Please run: npm install')
|
|
64
|
+
process.exit(1)
|
|
65
|
+
} else {
|
|
66
|
+
console.error('Failed to start Kode:', err.message)
|
|
67
|
+
process.exit(1)
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
child.on('exit', code => process.exit(code || 0))
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (supportsImport) {
|
|
74
|
+
const child = spawn(process.execPath, [...baseArgs, '--import', 'tsx', cliPath, ...args], {
|
|
75
|
+
stdio: 'inherit',
|
|
76
|
+
env: { ...process.env, YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm') },
|
|
77
|
+
})
|
|
78
|
+
child.on('error', () => tryWithLoader())
|
|
79
|
+
child.on('exit', code => {
|
|
80
|
+
if (code && code !== 0) return tryWithLoader()
|
|
81
|
+
process.exit(code || 0)
|
|
82
|
+
})
|
|
83
|
+
} else {
|
|
84
|
+
tryWithLoader()
|
|
85
|
+
}
|
|
57
86
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shareai-lab/kode",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.85",
|
|
4
4
|
"bin": {
|
|
5
5
|
"kode": "cli.js",
|
|
6
6
|
"kwa": "cli.js",
|
|
7
7
|
"kd": "cli.js"
|
|
8
8
|
},
|
|
9
9
|
"engines": {
|
|
10
|
-
"node": ">=18.
|
|
10
|
+
"node": ">=20.18.1"
|
|
11
11
|
},
|
|
12
12
|
"main": "cli.js",
|
|
13
13
|
"author": "ShareAI-lab <ai-lab@foxmail.com>",
|