@qoder-ai/qodercli 0.2.2-beta.7 → 0.2.2-beta.9

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/bin/run.js +49 -21
  2. package/package.json +6 -6
package/bin/run.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- const { spawn } = require('child_process');
2
+ const { spawnSync } = require('child_process');
3
3
  const path = require('path');
4
4
  const fs = require('fs');
5
5
 
@@ -7,26 +7,47 @@ const platform = process.platform;
7
7
  const arch = process.arch;
8
8
  const target = `${platform}-${arch}`;
9
9
  const pkgName = `@qoder-ai/qodercli-${target}`;
10
+ const subPkgDir = pkgName.split('/')[1]; // e.g. "qodercli-win32-x64"
10
11
 
11
12
  // 查找平台子包中的二进制
12
13
  const BINARY_NAME = platform === 'win32' ? 'qodercli.exe' : 'qodercli';
13
14
 
14
- // 尝试多种路径:
15
- // 1. node_modules 中的子包(npm install 场景)
16
- // 2. 同级目录(开发/调试场景)
15
+ // __dirname = .../node_modules/@qoder-ai/qodercli/bin/
16
+ // npm global install 结构:
17
+ // prefix/node_modules/@qoder-ai/qodercli/ (主包)
18
+ // prefix/node_modules/@qoder-ai/qodercli-win32-x64/ (子包, 同级)
19
+ // npm local install 结构:
20
+ // project/node_modules/@qoder-ai/qodercli/
21
+ // project/node_modules/@qoder-ai/qodercli-win32-x64/ (hoisted)
22
+ // 或 project/node_modules/@qoder-ai/qodercli/node_modules/@qoder-ai/qodercli-win32-x64/ (nested)
23
+
17
24
  const candidates = [
25
+ // 同级 scope 目录下 (global + hoisted local)
26
+ path.join(__dirname, '..', '..', subPkgDir, 'bin', BINARY_NAME),
27
+ // nested in main package's node_modules
18
28
  path.join(__dirname, '..', 'node_modules', pkgName, 'bin', BINARY_NAME),
19
- path.join(__dirname, '..', '..', pkgName.split('/')[1], 'bin', BINARY_NAME),
29
+ // 3 levels up (some pnpm/yarn structures)
20
30
  path.join(__dirname, '..', '..', '..', 'node_modules', pkgName, 'bin', BINARY_NAME),
21
- path.join(__dirname, target, BINARY_NAME),
31
+ // npm global on Windows may place under node_modules directly
32
+ path.join(__dirname, '..', '..', '..', subPkgDir, 'bin', BINARY_NAME),
33
+ // resolve from require (most reliable for complex layouts)
22
34
  ];
23
35
 
36
+ // Also try require.resolve to find the sub-package
37
+ try {
38
+ const subPkgJson = require.resolve(`${pkgName}/package.json`, { paths: [path.join(__dirname, '..')] });
39
+ const subPkgBin = path.join(path.dirname(subPkgJson), 'bin', BINARY_NAME);
40
+ candidates.push(subPkgBin);
41
+ } catch {}
42
+
24
43
  let binPath = null;
25
44
  for (const p of candidates) {
26
- if (fs.existsSync(p)) {
27
- binPath = p;
28
- break;
29
- }
45
+ try {
46
+ if (fs.existsSync(p)) {
47
+ binPath = p;
48
+ break;
49
+ }
50
+ } catch {}
30
51
  }
31
52
 
32
53
  if (!binPath) {
@@ -34,24 +55,31 @@ if (!binPath) {
34
55
  console.error('');
35
56
  console.error(`The platform-specific package "${pkgName}" does not appear to be installed.`);
36
57
  console.error('');
37
- console.error('This usually means:');
38
- console.error(' 1. Your platform is not supported, or');
39
- console.error(' 2. The optional dependency was not installed (try: npm install --include=optional)');
58
+ console.error('__dirname:', __dirname);
59
+ console.error('Searched paths:');
60
+ candidates.forEach(p => console.error(` - ${p} [${fs.existsSync(p) ? 'EXISTS' : 'NOT FOUND'}]`));
61
+ console.error('');
62
+ // List what's actually in the scope directory
63
+ const scopeDir = path.join(__dirname, '..', '..');
64
+ try {
65
+ console.error('Contents of scope dir (' + scopeDir + '):');
66
+ fs.readdirSync(scopeDir).forEach(f => console.error(' ' + f));
67
+ } catch (e) { console.error(' (cannot read: ' + e.message + ')'); }
40
68
  console.error('');
41
69
  console.error('Supported platforms: darwin-arm64, darwin-x64, linux-x64, linux-arm64, win32-x64');
70
+ console.error('Try: npm install -g @qoder-ai/qodercli --include=optional');
42
71
  process.exit(1);
43
72
  }
44
73
 
45
- const child = spawn(binPath, process.argv.slice(2), {
74
+ // Use spawnSync for reliable cross-platform behavior
75
+ const result = spawnSync(binPath, process.argv.slice(2), {
46
76
  stdio: 'inherit',
47
77
  windowsHide: false,
48
78
  });
49
79
 
50
- child.on('close', (code) => {
51
- process.exit(code !== null ? code : 1);
52
- });
53
-
54
- child.on('error', (error) => {
55
- console.error('Failed to execute qodercli:', error.message);
80
+ if (result.error) {
81
+ console.error('Failed to execute qodercli:', result.error.message);
56
82
  process.exit(1);
57
- });
83
+ }
84
+
85
+ process.exit(result.status !== null ? result.status : 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qoder-ai/qodercli",
3
- "version": "0.2.2-beta.7",
3
+ "version": "0.2.2-beta.9",
4
4
  "description": "QoderCLI - AI-powered coding assistant",
5
5
  "private": false,
6
6
  "publishConfig": { "access": "public" },
@@ -8,11 +8,11 @@
8
8
  "files": ["bin/", "README.md", "LICENSE"],
9
9
  "engines": { "node": ">=14" },
10
10
  "optionalDependencies": {
11
- "@qoder-ai/qodercli-darwin-arm64": "0.2.2-beta.7",
12
- "@qoder-ai/qodercli-darwin-x64": "0.2.2-beta.7",
13
- "@qoder-ai/qodercli-linux-x64": "0.2.2-beta.7",
14
- "@qoder-ai/qodercli-linux-arm64": "0.2.2-beta.7",
15
- "@qoder-ai/qodercli-win32-x64": "0.2.2-beta.7"
11
+ "@qoder-ai/qodercli-darwin-arm64": "0.2.2-beta.9",
12
+ "@qoder-ai/qodercli-darwin-x64": "0.2.2-beta.9",
13
+ "@qoder-ai/qodercli-linux-x64": "0.2.2-beta.9",
14
+ "@qoder-ai/qodercli-linux-arm64": "0.2.2-beta.9",
15
+ "@qoder-ai/qodercli-win32-x64": "0.2.2-beta.9"
16
16
  },
17
17
  "keywords": ["qoder", "ai", "cli", "coding", "assistant", "terminal"],
18
18
  "author": "Qoder AI",