@shareai-lab/kode 1.1.13 → 1.1.14
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 +82 -77
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -1,95 +1,100 @@
|
|
|
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
|
const fs = require('fs');
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Windows Syntax Error Fix
|
|
9
|
+
*
|
|
10
|
+
* This script is designed to work around common Windows CLI syntax issues:
|
|
11
|
+
* 1. cmd.exe shell syntax limitations
|
|
12
|
+
* 2. Path separator issues (\ vs /)
|
|
13
|
+
* 3. spawn/exec command format differences
|
|
14
|
+
*
|
|
15
|
+
* For most Windows users, the compiled dist/ files should work directly
|
|
16
|
+
* without needing any additional tools like bun or tsx.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const isWindows = process.platform === 'win32';
|
|
8
20
|
const args = process.argv.slice(2);
|
|
21
|
+
|
|
22
|
+
// Windows-safe path construction
|
|
9
23
|
const cliPath = path.join(__dirname, 'src', 'entrypoints', 'cli.tsx');
|
|
10
24
|
const distEntrypoint = path.join(__dirname, 'dist', 'entrypoints', 'cli.js');
|
|
25
|
+
const yogaWasmPath = path.join(__dirname, 'yoga.wasm');
|
|
26
|
+
|
|
27
|
+
// Windows command execution with proper escaping
|
|
28
|
+
function runWindowsSafe(command, cmdArgs = [], env = {}) {
|
|
29
|
+
// Use cmd.exe for Windows to handle shell syntax properly
|
|
30
|
+
const options = {
|
|
31
|
+
stdio: 'inherit',
|
|
32
|
+
windowsHide: true,
|
|
33
|
+
shell: true,
|
|
34
|
+
env: {
|
|
35
|
+
...process.env,
|
|
36
|
+
...env,
|
|
37
|
+
YOGA_WASM_PATH: yogaWasmPath
|
|
38
|
+
}
|
|
39
|
+
};
|
|
11
40
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
41
|
+
try {
|
|
42
|
+
if (isWindows) {
|
|
43
|
+
// Use spawn with absolute paths to avoid shell interpretation issues
|
|
44
|
+
return spawn(command, cmdArgs, options);
|
|
45
|
+
} else {
|
|
46
|
+
return spawn(command, cmdArgs, options);
|
|
47
|
+
}
|
|
48
|
+
} catch (error) {
|
|
49
|
+
// Fallback to exec for better error handling
|
|
50
|
+
const fullCommand = isWindows ?
|
|
51
|
+
`"${command}" ${cmdArgs.map(arg => `"${arg}"`).join(' ')}` :
|
|
52
|
+
`${command} ${cmdArgs.join(' ')}`;
|
|
53
|
+
|
|
54
|
+
return spawn('cmd', ['/c', fullCommand], options);
|
|
25
55
|
}
|
|
26
|
-
} catch (_) {
|
|
27
|
-
// fallthrough to bun/tsx
|
|
28
56
|
}
|
|
29
57
|
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
function runWithBunOrTsx() {
|
|
34
|
-
// Try bun first
|
|
58
|
+
// Primary execution: Use compiled dist files (recommended for Windows)
|
|
59
|
+
function runWithNode() {
|
|
35
60
|
try {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
61
|
+
if (fs.existsSync(distEntrypoint)) {
|
|
62
|
+
// Use direct Node.js execution - most reliable for Windows
|
|
63
|
+
const child = runWindowsSafe(process.execPath, [distEntrypoint, ...args]);
|
|
64
|
+
|
|
65
|
+
child.on('exit', code => process.exit(code || 0));
|
|
66
|
+
child.on('error', (err) => {
|
|
67
|
+
console.error('❌ Node.js execution failed:', err.message);
|
|
68
|
+
process.exit(1);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
return true;
|
|
72
|
+
} else {
|
|
73
|
+
console.error('❌ Compiled files not found. Run: npm install -g @shareai-lab/kode');
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
} catch (err) {
|
|
77
|
+
console.error('❌ Unexpected error:', err.message);
|
|
78
|
+
process.exit(1);
|
|
50
79
|
}
|
|
51
|
-
|
|
52
|
-
runWithNodeTsx();
|
|
53
80
|
}
|
|
54
81
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
env: {
|
|
67
|
-
...process.env,
|
|
68
|
-
YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm'),
|
|
69
|
-
TSX_TSCONFIG_PATH: process.platform === 'win32' ? 'noop' : undefined
|
|
70
|
-
},
|
|
71
|
-
})
|
|
72
|
-
child2.on('error', () => {
|
|
73
|
-
console.error('\nError: tsx is required but not found.')
|
|
74
|
-
console.error('Please install tsx globally: npm install -g tsx')
|
|
75
|
-
process.exit(1)
|
|
76
|
-
})
|
|
77
|
-
child2.on('exit', (code2) => process.exit(code2 || 0))
|
|
78
|
-
}
|
|
82
|
+
// Simple error handler
|
|
83
|
+
function handleWindowsError(error) {
|
|
84
|
+
console.error('\n❌ Windows CLI Error');
|
|
85
|
+
console.error('Error:', error.message);
|
|
86
|
+
console.error('\n💡 Solutions for Windows:');
|
|
87
|
+
console.error('1. Install latest Node.js from nodejs.org');
|
|
88
|
+
console.error('2. Use Git Bash (recommended) or Windows Terminal');
|
|
89
|
+
console.error('3. Reinstall: npm install -g @shareai-lab/kode');
|
|
90
|
+
console.error('4. Use WSL (Windows Subsystem for Linux)');
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
79
93
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
env: {
|
|
84
|
-
...process.env,
|
|
85
|
-
YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm'),
|
|
86
|
-
TSX_TSCONFIG_PATH: process.platform === 'win32' ? 'noop' : undefined
|
|
87
|
-
},
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
child.on('error', () => runPathTsx())
|
|
91
|
-
child.on('exit', (code) => {
|
|
92
|
-
if (code && code !== 0) return runPathTsx()
|
|
93
|
-
process.exit(code || 0)
|
|
94
|
-
})
|
|
94
|
+
// Main execution - always use compiled dist files for Windows
|
|
95
|
+
if (isWindows) {
|
|
96
|
+
console.log('🪟 Windows detected - using optimized execution...');
|
|
95
97
|
}
|
|
98
|
+
|
|
99
|
+
// Always use the compiled version for better Windows compatibility
|
|
100
|
+
runWithNode();
|