@capyclaw/publisher 0.1.6 → 0.1.7
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/package.json +1 -1
- package/server/impl.mjs +32 -2
package/package.json
CHANGED
package/server/impl.mjs
CHANGED
|
@@ -153,8 +153,38 @@ export function pkgOf(dir) {
|
|
|
153
153
|
|
|
154
154
|
/* ────────────────────────── npm 调用(每次调用一个 context) ────────────────────────── */
|
|
155
155
|
|
|
156
|
-
/** npm 直调(node npm-cli.js,不走 shell):含空格的临时/用户目录不会被拆词。
|
|
157
|
-
|
|
156
|
+
/** npm 直调(node npm-cli.js,不走 shell):含空格的临时/用户目录不会被拆词。
|
|
157
|
+
*
|
|
158
|
+
* 为什么不能只看 process.execPath 旁边:宿主可能是 Electron(DeepSeek Harness.exe),
|
|
159
|
+
* 其旁没有 node_modules/npm。旧实现此时回退 `spawn('npm', …, {shell:true})`,
|
|
160
|
+
* 而 Windows 的 cmd.exe 把 `^` 当转义符吃掉——`gateway@^0.1.0` 变成 `gateway@0.1.0`,
|
|
161
|
+
* npm view 精确版查无 → E404,顺序闸误判「依赖不可解析」。所以必须稳健定位 npm-cli.js,
|
|
162
|
+
* 始终走 node 直调(无 shell),让 ^ / & 等范围字符原样传给 npm。 */
|
|
163
|
+
function resolveNpmCli() {
|
|
164
|
+
const candidates = [
|
|
165
|
+
path.join(path.dirname(process.execPath), 'node_modules', 'npm', 'bin', 'npm-cli.js'),
|
|
166
|
+
]
|
|
167
|
+
/* npm 自身运行时注入的 cli 路径(若本进程恰由 npm 拉起)。 */
|
|
168
|
+
if (process.env.npm_execpath) candidates.push(process.env.npm_execpath)
|
|
169
|
+
/* 沿 PATH 找 npm shim(npm.cmd / npm),其同目录的 node_modules/npm 即 npm 安装处。 */
|
|
170
|
+
const shimNames = process.platform === 'win32' ? ['npm.cmd', 'npm.exe', 'npm'] : ['npm']
|
|
171
|
+
for (const dir of (process.env.PATH || '').split(path.delimiter)) {
|
|
172
|
+
if (!dir) continue
|
|
173
|
+
for (const shim of shimNames) {
|
|
174
|
+
try {
|
|
175
|
+
if (fs.existsSync(path.join(dir, shim))) {
|
|
176
|
+
candidates.push(path.join(dir, 'node_modules', 'npm', 'bin', 'npm-cli.js'))
|
|
177
|
+
break
|
|
178
|
+
}
|
|
179
|
+
} catch { /* 不可读目录跳过 */ }
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
for (const candidate of candidates) {
|
|
183
|
+
try { if (candidate && fs.existsSync(candidate)) return candidate } catch { /* ignore */ }
|
|
184
|
+
}
|
|
185
|
+
return null
|
|
186
|
+
}
|
|
187
|
+
const NPM_CLI = resolveNpmCli()
|
|
158
188
|
|
|
159
189
|
/** 异步 spawn + 收集 stdout/stderr,resolve 与 spawnSync 同形的结果
|
|
160
190
|
* ({ status, signal, stdout, stderr, error? },stdout/stderr 恒为 utf8 字符串)。
|