@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.
Files changed (2) hide show
  1. package/cli.js +25 -12
  2. 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 + tsx preload
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 runWithTsxImport() {
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', () => runWithTsxCLI())
63
+ child.on('error', () => onErrorFailOver ? onErrorFailOver() : fail())
64
64
  child.on('exit', code => {
65
- if (code && code !== 0) return runWithTsxCLI()
65
+ if (code && code !== 0) return onErrorFailOver ? onErrorFailOver() : fail()
66
66
  process.exit(code || 0)
67
67
  })
68
68
  }
69
69
 
70
- function runWithTsxCLI() {
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 => process.exit(code || 0))
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 (process.platform === 'win32') {
88
- // On Windows, use Node --import tsx with proper file:// URLs
89
- runWithTsxImport()
100
+ if (hasBun()) {
101
+ runWithBun()
102
+ } else if (process.platform === 'win32') {
103
+ runWindowsNoBun()
90
104
  } else {
91
- if (hasBun()) runWithBun()
92
- else runWithTsxImport()
105
+ runPosixNoBun()
93
106
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shareai-lab/kode",
3
- "version": "1.0.101",
3
+ "version": "1.0.102",
4
4
  "bin": {
5
5
  "kode": "cli.js",
6
6
  "kwa": "cli.js",