@ttpos/cli 0.3.3 → 0.3.4

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/ttpos.js +13 -3
  2. package/package.json +5 -5
package/bin/ttpos.js CHANGED
@@ -3,6 +3,8 @@
3
3
  // @ttpos/cli 入口:按平台解析 optionalDependencies 里的真二进制并执行。
4
4
  // 不用 postinstall 换二进制:--ignore-scripts 下会静默坏掉,且触发安装告警。
5
5
  const { spawnSync } = require("child_process");
6
+ const fs = require("fs");
7
+ const path = require("path");
6
8
 
7
9
  const PLATFORM_PACKAGES = {
8
10
  "darwin-arm64": "@ttpos/cli-darwin-arm64",
@@ -19,10 +21,18 @@ if (!pkg) {
19
21
  process.exit(1);
20
22
  }
21
23
 
24
+ // 只在本包所在目录向上找 node_modules。不用 require.resolve:它还会查 NODE_PATH
25
+ // 和 ~/.node_modules,平台包缺失时可能运行到别人放在那里的程序。
22
26
  let bin;
23
- try {
24
- bin = require.resolve(`${pkg}/bin/ttpos`);
25
- } catch {
27
+ for (let dir = __dirname; ; dir = path.dirname(dir)) {
28
+ const candidate = path.join(dir, "node_modules", pkg, "bin", "ttpos");
29
+ if (fs.existsSync(candidate)) {
30
+ bin = candidate;
31
+ break;
32
+ }
33
+ if (dir === path.dirname(dir)) break;
34
+ }
35
+ if (!bin) {
26
36
  console.error(`ttpos: 找不到平台包 ${pkg}。`);
27
37
  console.error("可能原因: 安装时带了 --omit=optional,或 lockfile 是在其他平台生成的。");
28
38
  console.error(`修复: 重新执行 npm install,或改用安装脚本: https://github.com/ZonEaseTech/ttpos-cli#安装`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttpos/cli",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "TTPOS 只读运维 CLI(安装后提供 ttpos 命令)",
5
5
  "license": "UNLICENSED",
6
6
  "repository": { "type": "git", "url": "git+https://github.com/ZonEaseTech/ttpos-cli.git" },
@@ -8,10 +8,10 @@
8
8
  "engines": { "node": ">=18" },
9
9
  "files": ["bin/ttpos.js", "README.md"],
10
10
  "optionalDependencies": {
11
- "@ttpos/cli-linux-x64": "0.3.3",
12
- "@ttpos/cli-linux-arm64": "0.3.3",
13
- "@ttpos/cli-darwin-x64": "0.3.3",
14
- "@ttpos/cli-darwin-arm64": "0.3.3"
11
+ "@ttpos/cli-linux-x64": "0.3.4",
12
+ "@ttpos/cli-linux-arm64": "0.3.4",
13
+ "@ttpos/cli-darwin-x64": "0.3.4",
14
+ "@ttpos/cli-darwin-arm64": "0.3.4"
15
15
  },
16
16
  "publishConfig": { "access": "public" }
17
17
  }