@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.
Files changed (2) hide show
  1. package/cli.js +82 -77
  2. 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
- // Prefer dist (pure Node) if available, otherwise try bun, then node+tsx
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
- // 1) Run compiled dist with Node if present (Windows-friendly, no bun/tsx needed)
13
- try {
14
- if (fs.existsSync(distEntrypoint)) {
15
- const child = spawn(process.execPath, [distEntrypoint, ...args], {
16
- stdio: 'inherit',
17
- env: {
18
- ...process.env,
19
- YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm'),
20
- },
21
- });
22
- child.on('exit', code => process.exit(code || 0));
23
- child.on('error', () => runWithBunOrTsx());
24
- return;
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
- // 2) Otherwise, try bun first, then fall back to node+tsx
31
- runWithBunOrTsx();
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
- const { execSync } = require('child_process');
37
- execSync('bun --version', { stdio: 'ignore' });
38
- const child = spawn('bun', ['run', cliPath, ...args], {
39
- stdio: 'inherit',
40
- env: {
41
- ...process.env,
42
- YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm'),
43
- },
44
- });
45
- child.on('exit', code => process.exit(code || 0));
46
- child.on('error', () => runWithNodeTsx());
47
- return;
48
- } catch {
49
- // ignore and try tsx path
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
- function runWithNodeTsx() {
56
- // Use local tsx installation; if missing, try PATH-resolved tsx
57
- const binDir = path.join(__dirname, 'node_modules', '.bin')
58
- const tsxPath = process.platform === 'win32'
59
- ? path.join(binDir, 'tsx.cmd')
60
- : path.join(binDir, 'tsx')
61
-
62
- const runPathTsx = () => {
63
- const child2 = spawn('tsx', [cliPath, ...args], {
64
- stdio: 'inherit',
65
- shell: process.platform === 'win32',
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
- const child = spawn(tsxPath, [cliPath, ...args], {
81
- stdio: 'inherit',
82
- shell: process.platform === 'win32',
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();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shareai-lab/kode",
3
- "version": "1.1.13",
3
+ "version": "1.1.14",
4
4
  "bin": {
5
5
  "kode": "dist/index.js",
6
6
  "kwa": "dist/index.js",