@andyqiu/codeforge 0.6.1 → 0.6.2

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/bin/codeforge.mjs CHANGED
@@ -95,20 +95,42 @@ function parseArgs(argv) {
95
95
  // ────────────────────────────────────────────────────────────────────
96
96
  // opencode installer:薄壳,统一调 install.mjs(Node ESM 跨平台)
97
97
  // ADR:unify-install-to-node-mjs
98
+ // 自举兼容:优先找 install.mjs(v0.6+),fallback 到 install.sh(v0.5 过渡期)
99
+ // 用于 upgrade 命令:旧版 CLI 调新包时,新包里只有 install.mjs
98
100
  // ────────────────────────────────────────────────────────────────────
101
+ function resolveInstallerScript() {
102
+ const mjsScript = path.join(REPO_ROOT, "install.mjs")
103
+ if (existsSync(mjsScript)) return { script: mjsScript, useNode: true }
104
+ const shScript = path.join(REPO_ROOT, "install.sh")
105
+ if (existsSync(shScript)) return { script: shScript, useNode: false }
106
+ return null
107
+ }
108
+
99
109
  function installOpencode({ scope, dryRun, extraArgs, quiet = false, verbose = false }) {
100
- const script = path.join(REPO_ROOT, "install.mjs")
101
- if (!existsSync(script)) {
102
- err(`installer 脚本不存在:${script}`)
110
+ const resolved = resolveInstallerScript()
111
+ if (!resolved) {
112
+ err(`installer 脚本不存在:${path.join(REPO_ROOT, "install.mjs")}`)
103
113
  return 2
104
114
  }
105
- const args = [script]
106
- if (scope === "global") args.push("--global")
107
- if (dryRun) args.push("--dry-run")
108
- if (verbose) args.push("--verbose")
109
- if (extraArgs) args.push(...extraArgs)
110
- if (!quiet) log(`opencode: node ${args.join(" ")}`)
111
- const r = spawnSync(process.execPath, args, { stdio: quiet ? "pipe" : "inherit", cwd: REPO_ROOT })
115
+ const { script, useNode } = resolved
116
+ let cmd, args
117
+ if (useNode) {
118
+ cmd = process.execPath
119
+ args = [script]
120
+ if (scope === "global") args.push("--global")
121
+ if (dryRun) args.push("--dry-run")
122
+ if (verbose) args.push("--verbose")
123
+ if (extraArgs) args.push(...extraArgs)
124
+ } else {
125
+ // fallback:旧版包里只有 install.sh(v0.5 过渡期)
126
+ cmd = "bash"
127
+ args = [script]
128
+ if (scope === "global") args.push("--global")
129
+ if (dryRun) args.push("--dry-run")
130
+ if (extraArgs) args.push(...extraArgs)
131
+ }
132
+ if (!quiet) log(`opencode: ${useNode ? "node" : "bash"} ${args.join(" ")}`)
133
+ const r = spawnSync(cmd, args, { stdio: quiet ? "pipe" : "inherit", cwd: REPO_ROOT })
112
134
  if (quiet && r.status !== 0) {
113
135
  if (r.stderr) process.stderr.write(r.stderr)
114
136
  if (r.stdout) process.stderr.write(r.stdout)
@@ -117,11 +139,21 @@ function installOpencode({ scope, dryRun, extraArgs, quiet = false, verbose = fa
117
139
  }
118
140
 
119
141
  function uninstallOpencode({ scope }) {
120
- const script = path.join(REPO_ROOT, "install.mjs")
142
+ const resolved = resolveInstallerScript()
143
+ if (!resolved) {
144
+ err(`installer 脚本不存在:${path.join(REPO_ROOT, "install.mjs")}`)
145
+ return 2
146
+ }
147
+ const { script, useNode } = resolved
148
+ if (!useNode && process.platform === "win32") {
149
+ err("Windows 下旧版 install.sh 不支持,请重新安装:npm install -g @andyqiu/codeforge")
150
+ return 2
151
+ }
152
+ const cmd = useNode ? process.execPath : "bash"
121
153
  const args = [script, "--uninstall"]
122
154
  if (scope === "global") args.push("--global")
123
- log(`opencode uninstall: node ${args.join(" ")}`)
124
- const r = spawnSync(process.execPath, args, { stdio: "inherit", cwd: REPO_ROOT })
155
+ log(`opencode uninstall: ${useNode ? "node" : "bash"} ${args.join(" ")}`)
156
+ const r = spawnSync(cmd, args, { stdio: "inherit", cwd: REPO_ROOT })
125
157
  return r.status ?? 1
126
158
  }
127
159
 
@@ -311,9 +343,6 @@ async function cmdUpgrade(args) {
311
343
  log(`当前版本:${currentVersion} → 最新版本:${latestVersion}`)
312
344
  }
313
345
 
314
- hr()
315
- log(`正在升级...`)
316
-
317
346
  const npmCmd = "npm"
318
347
  // 有明确版本号时用精确版本,绕过 @latest dist-tag 缓存
319
348
  const installTarget = latestVersion
package/dist/index.js CHANGED
@@ -19759,7 +19759,7 @@ import * as zlib from "node:zlib";
19759
19759
  // lib/version-injected.ts
19760
19760
  function getInjectedVersion() {
19761
19761
  try {
19762
- const v = "0.6.1";
19762
+ const v = "0.6.2";
19763
19763
  if (typeof v === "string" && /^\d+\.\d+\.\d+/.test(v)) {
19764
19764
  return v;
19765
19765
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andyqiu/codeforge",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "CodeForge — opencode 的零侵入扩展包",
5
5
  "type": "module",
6
6
  "private": false,