dsh-plugin 1.4.6 → 1.4.8
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/README.en.md +1 -1
- package/README.md +1 -1
- package/client/client.js +326 -308
- package/client/client.js.map +1 -1
- package/lib/http/routes.js +41 -11
- package/lib/services/install/npm-resolve.js +14 -8
- package/lib/services/install/package-entry.js +39 -0
- package/lib/services/install/preflight.js +2 -7
- package/lib/services/install/task-queue.js +15 -7
- package/lib/services/probe.js +92 -63
- package/lib/types/services/install/npm-resolve.d.ts +3 -1
- package/lib/types/services/install/package-entry.d.ts +21 -0
- package/lib/types/services/probe.d.ts +25 -2
- package/package.json +2 -2
- package/src/client/components/views/DiagnosticsView.tsx +11 -4
- package/src/client/components/views/SettingsView.tsx +14 -5
- package/src/client/locales.ts +10 -0
- package/src/server/http/routes.ts +37 -11
- package/src/server/services/install/npm-resolve.ts +14 -9
- package/src/server/services/install/package-entry.ts +41 -0
- package/src/server/services/install/preflight.ts +2 -7
- package/src/server/services/install/task-queue.ts +15 -7
- package/src/server/services/probe.ts +113 -63
|
@@ -94,6 +94,8 @@ export function SettingsView({ t, settings, update, reset, env, onCopy, openSect
|
|
|
94
94
|
// —— HTTP 代理连通性:输入停笔后防抖实时探测(服务端 /proxy-check 用该代理打 github.com)。
|
|
95
95
|
// 结果只作提示、绝不阻断保存 —— 用户可能是先填地址后开代理,保存后再去开代理完全合法。
|
|
96
96
|
const [proxyProbe, setProxyProbe] = useState<'idle' | 'checking' | 'ok' | 'fail'>('idle')
|
|
97
|
+
// 失败细分原因(如 'tlsRevocation'):证书吊销受阻时提示「不是代理地址不通」,避免误导排查方向
|
|
98
|
+
const [proxyProbeReason, setProxyProbeReason] = useState<string | null>(null)
|
|
97
99
|
const proxyProbeTimer = useRef<number | null>(null)
|
|
98
100
|
const proxyProbeSeq = useRef(0)
|
|
99
101
|
// 卸载时清掉未触发的防抖计时器,避免卸载后 setState
|
|
@@ -103,25 +105,31 @@ export function SettingsView({ t, settings, update, reset, env, onCopy, openSect
|
|
|
103
105
|
}, [])
|
|
104
106
|
// 设置被外部重置(恢复默认/清空代理)时同步清掉探测状态,避免残留过期的「不通」提示
|
|
105
107
|
useEffect(() => {
|
|
106
|
-
if (settings.proxy === '') setProxyProbe('idle')
|
|
108
|
+
if (settings.proxy === '') { setProxyProbe('idle'); setProxyProbeReason(null) }
|
|
107
109
|
}, [settings.proxy])
|
|
108
110
|
|
|
109
111
|
const probeProxyNow = (value: string) => {
|
|
110
112
|
const v = value.trim()
|
|
111
|
-
if (v === '') { setProxyProbe('idle'); return }
|
|
113
|
+
if (v === '') { setProxyProbe('idle'); setProxyProbeReason(null); return }
|
|
112
114
|
const seq = ++proxyProbeSeq.current
|
|
113
115
|
setProxyProbe('checking')
|
|
116
|
+
setProxyProbeReason(null)
|
|
114
117
|
void fetch('/dsh-plugin-hub/proxy-check', {
|
|
115
118
|
method: 'POST',
|
|
116
119
|
headers: { 'content-type': 'application/json' },
|
|
117
120
|
body: JSON.stringify({ proxy: v }),
|
|
118
121
|
cache: 'no-store',
|
|
119
122
|
}).then((res) => res.json())
|
|
120
|
-
.then((data: { ok?: boolean }) => {
|
|
123
|
+
.then((data: { ok?: boolean; reason?: string | null }) => {
|
|
121
124
|
if (seq !== proxyProbeSeq.current) return
|
|
122
125
|
setProxyProbe(data.ok ? 'ok' : 'fail')
|
|
126
|
+
setProxyProbeReason(typeof data.reason === 'string' ? data.reason : null)
|
|
127
|
+
})
|
|
128
|
+
.catch(() => {
|
|
129
|
+
if (seq !== proxyProbeSeq.current) return
|
|
130
|
+
setProxyProbe('fail')
|
|
131
|
+
setProxyProbeReason(null)
|
|
123
132
|
})
|
|
124
|
-
.catch(() => { if (seq === proxyProbeSeq.current) setProxyProbe('fail') })
|
|
125
133
|
}
|
|
126
134
|
|
|
127
135
|
const onProxyChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
@@ -191,7 +199,8 @@ export function SettingsView({ t, settings, update, reset, env, onCopy, openSect
|
|
|
191
199
|
: proxyProbe === 'ok'
|
|
192
200
|
? h('div', { className: `${styles.proxyHint} ${styles.proxyHintOk}` }, t('proxyCheckOk'))
|
|
193
201
|
: proxyProbe === 'fail'
|
|
194
|
-
? h('div', { className: `${styles.proxyHint} ${styles.proxyHintFail}` },
|
|
202
|
+
? h('div', { className: `${styles.proxyHint} ${styles.proxyHintFail}` },
|
|
203
|
+
proxyProbeReason === 'tlsRevocation' ? t('proxyCheckRevocation') : t('proxyCheckFail'))
|
|
195
204
|
: null,
|
|
196
205
|
),
|
|
197
206
|
}),
|
package/src/client/locales.ts
CHANGED
|
@@ -116,6 +116,8 @@ export const zh = {
|
|
|
116
116
|
proxyCheckChecking: '正在测试该代理地址…',
|
|
117
117
|
proxyCheckOk: '测试可达,安装与目录请求将统一走该代理',
|
|
118
118
|
proxyCheckFail: '此地址测试不通,仍可保存;请确认代理已开启、地址与端口无误',
|
|
119
|
+
// 失败细分原因:Windows Schannel 必须取到证书吊销信息,取不到即中断握手 —— 不是代理地址不通
|
|
120
|
+
proxyCheckRevocation: '证书吊销检查受阻(Windows Schannel 取不到 CRL/OCSP),握手被中断;属本机 TLS 环境问题,非代理地址不通',
|
|
119
121
|
settingsMirror: 'npm 镜像源',
|
|
120
122
|
settingsMirrorDesc: '默认跟随本机 npm 配置;官方源慢可换国内镜像',
|
|
121
123
|
mirrorNone: '未配置(跟随本机 npm 配置)',
|
|
@@ -203,6 +205,9 @@ export const zh = {
|
|
|
203
205
|
diagSummaryRunning: '正在检测通道…',
|
|
204
206
|
diagSummaryOk: '全部通道正常',
|
|
205
207
|
diagSummaryFail: '存在不可达通道,点击对应行可重测',
|
|
208
|
+
// 失败细分原因:Windows Schannel 必须取到证书吊销信息才能握手,取不到即中断(易被误当成网络不通)
|
|
209
|
+
diagFailRevocation: '证书校验受阻',
|
|
210
|
+
diagFailRevocationHint: '系统 curl 取不到证书吊销信息(Windows Schannel 必需 CRL/OCSP),TLS 握手被中断 —— 这不是网络不通,npm/git 可能照常可用。升级 curl 到 7.70+ 可自动按「尽力而为」处理,或换一个能访问吊销服务的网络。',
|
|
206
211
|
settingsEnvSnapshot: '系统版本',
|
|
207
212
|
settingsEnvSnapshotDesc: '复制宿主版本与系统信息,提交 Issue 时粘贴到正文便于复现',
|
|
208
213
|
settingsEnvCopy: '复制',
|
|
@@ -483,6 +488,8 @@ export const en = {
|
|
|
483
488
|
proxyCheckChecking: 'Testing this proxy address…',
|
|
484
489
|
proxyCheckOk: 'Reachable — installs and catalog requests will route through it',
|
|
485
490
|
proxyCheckFail: 'Unreachable, but you can still save it; make sure the proxy is running and the address and port are correct',
|
|
491
|
+
// Failure reason: Windows Schannel aborts the handshake when revocation info (CRL/OCSP) is unreachable — not a bad proxy address
|
|
492
|
+
proxyCheckRevocation: 'Certificate revocation check blocked (Windows Schannel could not fetch CRL/OCSP), so the handshake was aborted — a local TLS issue, not a bad proxy address',
|
|
486
493
|
settingsMirror: 'npm mirror',
|
|
487
494
|
settingsMirrorDesc: 'Unset by default — follows local npm config; pick a domestic mirror if slow',
|
|
488
495
|
mirrorNone: 'Unset (follow local npm config)',
|
|
@@ -570,6 +577,9 @@ export const en = {
|
|
|
570
577
|
diagSummaryRunning: 'Checking channels…',
|
|
571
578
|
diagSummaryOk: 'All channels reachable',
|
|
572
579
|
diagSummaryFail: 'Unreachable channel(s) — click a row to re-check',
|
|
580
|
+
// Failure reason: Windows Schannel aborts the handshake when revocation info (CRL/OCSP) is unreachable (easily mistaken for a network outage)
|
|
581
|
+
diagFailRevocation: 'Cert check blocked',
|
|
582
|
+
diagFailRevocationHint: 'The system curl cannot fetch certificate revocation info (CRL/OCSP, required by Windows Schannel), so the TLS handshake is aborted — this is not a network outage, and npm/git may still work. curl 7.70+ downgrades the check to best-effort, or switch to a network that can reach the revocation service.',
|
|
573
583
|
settingsEnvSnapshot: 'System version',
|
|
574
584
|
settingsEnvSnapshotDesc: 'Copy host version and system info for pasting into issue reports',
|
|
575
585
|
settingsEnvCopy: 'Copy',
|
|
@@ -107,12 +107,13 @@ function catalogCacheFile(profile: string, key: string): string {
|
|
|
107
107
|
return join(profileDirectory(profile), 'cache', `catalog-${key}.json`)
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
/** 读缓存:文件存在、JSON
|
|
111
|
-
|
|
110
|
+
/** 读缓存:文件存在、JSON 合法、未超过 maxAgeMs → 返回原始响应字符串;否则 null(视为 miss)。
|
|
111
|
+
* maxAgeMs 传 Infinity 即「任意年龄的缓存」,供实时拉取失败时兜底使用。 */
|
|
112
|
+
function readCatalogCache(file: string, maxAgeMs: number): string | null {
|
|
112
113
|
try {
|
|
113
114
|
const entry = JSON.parse(readFileSync(file, 'utf8')) as CatalogCacheEntry
|
|
114
115
|
if (entry && typeof entry.at === 'number' && typeof entry.body === 'string'
|
|
115
|
-
&& Date.now() - entry.at <
|
|
116
|
+
&& Date.now() - entry.at < maxAgeMs) {
|
|
116
117
|
return entry.body
|
|
117
118
|
}
|
|
118
119
|
} catch {
|
|
@@ -494,13 +495,18 @@ export function mountPluginHubRoutes(webServer: WebServerService, profile: strin
|
|
|
494
495
|
const child = spawn(bin, args)
|
|
495
496
|
let out = ''
|
|
496
497
|
child.stdout.on('data', (d) => { out += String(d) })
|
|
497
|
-
|
|
498
|
-
|
|
498
|
+
// spawn 失败(如 Linux 无 zenity)会先触发 error 再触发 close(code=-2):
|
|
499
|
+
// 只允许第一个事件应答,否则第二次 sendJson 对已结束的响应再 writeHead,
|
|
500
|
+
// 抛 ERR_HTTP_HEADERS_SENT 成为宿主进程内的未捕获异常。
|
|
501
|
+
let done = false
|
|
502
|
+
const finish = (reply: () => void) => { if (!done) { done = true; reply() } }
|
|
503
|
+
child.on('error', () => finish(() => sendJson(response, 500, { error: 'directory picker unavailable' })))
|
|
504
|
+
child.on('close', (code) => finish(() => {
|
|
499
505
|
// macOS osascript 输出带引号(如 "/Users/x"),统一剥掉首尾空白与引号
|
|
500
506
|
const picked = out.trim().replace(/^"|"$/g, '')
|
|
501
507
|
if (code === 0 && picked !== '') sendJson(response, 200, { path: picked })
|
|
502
508
|
else sendJson(response, 200, { cancelled: true })
|
|
503
|
-
})
|
|
509
|
+
}))
|
|
504
510
|
} catch {
|
|
505
511
|
sendJson(response, 500, { error: 'directory picker unavailable' })
|
|
506
512
|
}
|
|
@@ -567,8 +573,16 @@ export function mountPluginHubRoutes(webServer: WebServerService, profile: strin
|
|
|
567
573
|
? await gitLsRemote(c.url, c.proxy ?? effectiveProxy, 6000)
|
|
568
574
|
: await probe(c.url, c.proxy)
|
|
569
575
|
results.push({ key: c.key, ok: r.ok })
|
|
570
|
-
// git 行的 status 是退出码,客户端 git 行只显示 OK / 不可达,不显示成 HTTP
|
|
571
|
-
|
|
576
|
+
// git 行的 status 是退出码,客户端 git 行只显示 OK / 不可达,不显示成 HTTP 码。
|
|
577
|
+
// reason 透出失败细分原因(如 Windows 证书吊销受阻),客户端据此给对症提示而非笼统「不可达」。
|
|
578
|
+
send({
|
|
579
|
+
type: r.ok ? 'ok' : 'fail',
|
|
580
|
+
key: c.key,
|
|
581
|
+
display: c.display,
|
|
582
|
+
ms: r.ms,
|
|
583
|
+
status: c.git ? null : r.status,
|
|
584
|
+
reason: r.ok ? null : (r.reason ?? null),
|
|
585
|
+
})
|
|
572
586
|
}
|
|
573
587
|
send({ type: 'end', at: Date.now() })
|
|
574
588
|
response.end()
|
|
@@ -609,9 +623,10 @@ export function mountPluginHubRoutes(webServer: WebServerService, profile: strin
|
|
|
609
623
|
sendJson(response, 200, { ok: false, ms: null, status: null, target, reason: 'empty' })
|
|
610
624
|
return
|
|
611
625
|
}
|
|
612
|
-
// 探测走该代理本身(不是 effectiveProxy
|
|
626
|
+
// 探测走该代理本身(不是 effectiveProxy):验证的就是用户填的这个地址。
|
|
627
|
+
// reason 带上失败细分原因(如证书吊销受阻),设置页才能提示「不是代理地址的问题」。
|
|
613
628
|
const r = await probeUrl(target, proxy, 6000)
|
|
614
|
-
sendJson(response, 200, { ok: r.ok, ms: r.ms, status: r.status, target })
|
|
629
|
+
sendJson(response, 200, { ok: r.ok, ms: r.ms, status: r.status, target, reason: r.reason ?? null })
|
|
615
630
|
},
|
|
616
631
|
}),
|
|
617
632
|
webServer.register({
|
|
@@ -635,7 +650,7 @@ export function mountPluginHubRoutes(webServer: WebServerService, profile: strin
|
|
|
635
650
|
: `https://api.dsh-plugin.org/plugins.${lang}.json`
|
|
636
651
|
// 1 小时本地缓存:命中直接返回(跨重启生效,插件市场秒开),未命中才走 curl 拉远程
|
|
637
652
|
const cacheFile = catalogCacheFile(profile, isStats ? 'stats' : `plugins-${lang}`)
|
|
638
|
-
const cached = readCatalogCache(cacheFile)
|
|
653
|
+
const cached = readCatalogCache(cacheFile, CATALOG_CACHE_TTL_MS)
|
|
639
654
|
if (cached !== null) {
|
|
640
655
|
try {
|
|
641
656
|
sendJson(response, 200, JSON.parse(cached))
|
|
@@ -646,6 +661,17 @@ export function mountPluginHubRoutes(webServer: WebServerService, profile: strin
|
|
|
646
661
|
}
|
|
647
662
|
const r = await fetchViaCurl(target, proxy, 20000)
|
|
648
663
|
if (!r.ok || r.body === '') {
|
|
664
|
+
// 实时拉取失败:退回任意年龄的本地缓存(上次成功数据),
|
|
665
|
+
// 避免证书吊销受阻 / 网络抖动时整个插件市场打不开 —— 数据可能过期,但好过空白。
|
|
666
|
+
const stale = readCatalogCache(cacheFile, Number.POSITIVE_INFINITY)
|
|
667
|
+
if (stale !== null) {
|
|
668
|
+
try {
|
|
669
|
+
sendJson(response, 200, JSON.parse(stale))
|
|
670
|
+
return
|
|
671
|
+
} catch {
|
|
672
|
+
// 兜底缓存也损坏:落到下面的 502
|
|
673
|
+
}
|
|
674
|
+
}
|
|
649
675
|
sendJson(response, 502, { error: 'catalog fetch failed' })
|
|
650
676
|
return
|
|
651
677
|
}
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import { get } from 'node:https'
|
|
15
15
|
|
|
16
|
-
/** 反查缓存:repo 小写 → npm 包名(null 表示已确认无对应 npm
|
|
16
|
+
/** 反查缓存:repo 小写 → npm 包名(null 表示已确认无对应 npm 包;网络异常不缓存)。 */
|
|
17
17
|
const cache = new Map<string, string | null>()
|
|
18
18
|
|
|
19
19
|
/** 单次 registry 查询超时(ms):慢网络下失败返回 null,不阻塞安装流程。 */
|
|
@@ -22,7 +22,9 @@ const REQUEST_TIMEOUT_MS = 8000
|
|
|
22
22
|
/**
|
|
23
23
|
* 反查 repo(`owner/repo`)对应的官方 npm 包名;未命中、网络异常或超时返回 null。
|
|
24
24
|
* 返回 null 不代表仓库一定没有 npm 包,只代表本次未能确认 —— 调用方应保留
|
|
25
|
-
*
|
|
25
|
+
* 原有错误路径,反查只是额外的一次尝试。只有「已确认」的结果(包名,或 200
|
|
26
|
+
* 响应下确认无匹配)会进缓存;网络异常/超时/解析失败不缓存,同一会话内下次
|
|
27
|
+
* 安装仍会重试反查,避免一次瞬时故障把整个会话锁死在 git 通道。
|
|
26
28
|
* registry 参数:npm 镜像源地址,空串 = 官方源;与安装通道吃同一 registry,
|
|
27
29
|
* 保证「配置了镜像」时反查和安装走同一个源(镜像节点同步完整时结果一致)。
|
|
28
30
|
* 慢网络下失败不阻塞安装。
|
|
@@ -31,12 +33,15 @@ export function resolveNpmPackage(repo: string, registry = ''): Promise<string |
|
|
|
31
33
|
const key = repo.toLowerCase()
|
|
32
34
|
if (cache.has(key)) return Promise.resolve(cache.get(key) ?? null)
|
|
33
35
|
const name = searchRepo(repo, registry)
|
|
34
|
-
name.then((found) =>
|
|
35
|
-
|
|
36
|
+
void name.then((found) => {
|
|
37
|
+
if (found !== undefined) cache.set(key, found)
|
|
38
|
+
})
|
|
39
|
+
return name.then((found) => found ?? null)
|
|
36
40
|
}
|
|
37
41
|
|
|
38
|
-
/** 用 npm search 接口按 repository 地址反查,并做铁证校验(包元数据必须指向该仓库)。
|
|
39
|
-
|
|
42
|
+
/** 用 npm search 接口按 repository 地址反查,并做铁证校验(包元数据必须指向该仓库)。
|
|
43
|
+
* 返回:包名 = 命中;null = 200 响应下确认无匹配;undefined = 本次未能确认(网络/超时/解析失败)。 */
|
|
44
|
+
function searchRepo(repo: string, registry: string): Promise<string | null | undefined> {
|
|
40
45
|
const [owner, name] = repo.split('/')
|
|
41
46
|
if (owner === undefined || name === undefined || name === '') return Promise.resolve(null)
|
|
42
47
|
const base = registry === '' ? 'https://registry.npmjs.org' : registry.replace(/\/+$/, '')
|
|
@@ -45,7 +50,7 @@ function searchRepo(repo: string, registry: string): Promise<string | null> {
|
|
|
45
50
|
const req = get(url, { timeout: REQUEST_TIMEOUT_MS }, (res) => {
|
|
46
51
|
if (res.statusCode !== 200) {
|
|
47
52
|
res.resume()
|
|
48
|
-
resolve(
|
|
53
|
+
resolve(undefined)
|
|
49
54
|
return
|
|
50
55
|
}
|
|
51
56
|
let body = ''
|
|
@@ -65,11 +70,11 @@ function searchRepo(repo: string, registry: string): Promise<string | null> {
|
|
|
65
70
|
}
|
|
66
71
|
resolve(null)
|
|
67
72
|
} catch {
|
|
68
|
-
resolve(
|
|
73
|
+
resolve(undefined)
|
|
69
74
|
}
|
|
70
75
|
})
|
|
71
76
|
})
|
|
72
77
|
req.on('timeout', () => req.destroy())
|
|
73
|
-
req.on('error', () => resolve(
|
|
78
|
+
req.on('error', () => resolve(undefined))
|
|
74
79
|
})
|
|
75
80
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DSH-Plugin Hub — the community plugin marketplace for DeepSeek Harness.
|
|
3
|
+
* Website: https://dsh-plugin.org
|
|
4
|
+
* GitHub: https://github.com/dshplugin/dsh-plugin-hub
|
|
5
|
+
*
|
|
6
|
+
* 包入口解析:从 package.json 的 exports["."] / main 推出用于校验的入口文件。
|
|
7
|
+
* git 通道(tar 预检)与 npm 通道(装后 statSync 校验)共用,保证两条通道
|
|
8
|
+
* 对同一个包判定一致。
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** exports 条件对象里按优先级尝试的键;Node 语义下 default 最宽,import/require 次之。 */
|
|
12
|
+
const EXPORT_CONDITION_KEYS = ['default', 'import', 'require'] as const
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 解析包的入口文件(相对包根,不带 `./` 前缀)。
|
|
16
|
+
*
|
|
17
|
+
* Node 的 exports 规范要求字符串 target 以 `./` 开头(如 `"./lib/index.js"`),
|
|
18
|
+
* 而 tar 成员名与磁盘路径都不带该前缀,因此统一剥掉;条件对象
|
|
19
|
+
* (`{ "import": ..., "require": ... }`)按 default → import → require 取第一
|
|
20
|
+
* 个字符串值。无 exports 时回退 main,再回退 index.js。
|
|
21
|
+
*/
|
|
22
|
+
export function resolvePackageEntry(meta: { main?: unknown; exports?: unknown }): string {
|
|
23
|
+
const dot = (meta.exports as Record<string, unknown> | undefined)?.['.']
|
|
24
|
+
const fromExports = typeof dot === 'string'
|
|
25
|
+
? dot
|
|
26
|
+
: dot !== null && typeof dot === 'object'
|
|
27
|
+
? firstStringOf(dot as Record<string, unknown>)
|
|
28
|
+
: undefined
|
|
29
|
+
const candidate = typeof fromExports === 'string' ? fromExports
|
|
30
|
+
: typeof meta.main === 'string' ? meta.main
|
|
31
|
+
: 'index.js'
|
|
32
|
+
return candidate.replace(/^\.\//u, '')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function firstStringOf(conditions: Record<string, unknown>): string | undefined {
|
|
36
|
+
for (const key of EXPORT_CONDITION_KEYS) {
|
|
37
|
+
const value = conditions[key]
|
|
38
|
+
if (typeof value === 'string' && value !== '') return value
|
|
39
|
+
}
|
|
40
|
+
return undefined
|
|
41
|
+
}
|
|
@@ -18,6 +18,7 @@ import { join } from 'node:path'
|
|
|
18
18
|
import { pipeline } from 'node:stream/promises'
|
|
19
19
|
import { promisify } from 'node:util'
|
|
20
20
|
import { githubRepoOf } from '../profile/profile.ts'
|
|
21
|
+
import { resolvePackageEntry } from './package-entry.ts'
|
|
21
22
|
|
|
22
23
|
const execFileAsync = promisify(execFile)
|
|
23
24
|
|
|
@@ -56,13 +57,7 @@ export async function preflightTarget(target: string): Promise<PreflightResult>
|
|
|
56
57
|
await download(`https://codeload.github.com/${owner}/${repo}/tar.gz/${commit}`, tar)
|
|
57
58
|
const meta = await readTarJson(tar, 'package/package.json')
|
|
58
59
|
if (meta === null) return { ok: true, missing: null, name: null }
|
|
59
|
-
const
|
|
60
|
-
const resolved = typeof dot === 'string'
|
|
61
|
-
? dot
|
|
62
|
-
: dot !== null && typeof dot === 'object'
|
|
63
|
-
? (dot as Record<string, unknown>).default
|
|
64
|
-
: undefined
|
|
65
|
-
const entry = typeof resolved === 'string' ? resolved : typeof meta.main === 'string' ? meta.main : 'index.js'
|
|
60
|
+
const entry = resolvePackageEntry(meta)
|
|
66
61
|
const inTar = await hasTarEntry(tar, `package/${entry}`)
|
|
67
62
|
return { ok: inTar, missing: inTar ? null : entry, name: typeof meta.name === 'string' ? meta.name : null }
|
|
68
63
|
} catch {
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* 输出流式收集到任务上;卸载成功时尝试从运行中 loader 即时停用(见 loader.ts)。
|
|
9
9
|
*/
|
|
10
10
|
import { spawn, spawnSync } from 'node:child_process'
|
|
11
|
+
import { resolvePackageEntry } from './package-entry.ts'
|
|
11
12
|
import { readFileSync, statSync } from 'node:fs'
|
|
12
13
|
import { dirname, join, resolve } from 'node:path'
|
|
13
14
|
import type { InstallResult, InstallTask, Invocation, QueueItem } from './install-types.ts'
|
|
@@ -258,7 +259,19 @@ function pumpQueue(): void {
|
|
|
258
259
|
if (!item) return
|
|
259
260
|
const { task, options } = item
|
|
260
261
|
task.status = 'running'
|
|
261
|
-
void runPluginMutation({ ...options, task })
|
|
262
|
+
void runPluginMutation({ ...options, task })
|
|
263
|
+
.catch((error) => {
|
|
264
|
+
// runPluginMutation 的恢复路径(如 allowBuilds 写回 pnpm-workspace.yaml)
|
|
265
|
+
// 可能抛出;落到 failed 终态并留痕,否则该 Promise 链成为未处理 rejection
|
|
266
|
+
//(Node >= 15 默认直接终止进程),而队列自身却在 finally 里继续 pump。
|
|
267
|
+
if (task.status !== 'cancelled') {
|
|
268
|
+
task.status = 'failed'
|
|
269
|
+
task.exitCode = null
|
|
270
|
+
task.progress = 0
|
|
271
|
+
pushLine(task, `[internal] ${error instanceof Error ? error.message : String(error)}`)
|
|
272
|
+
}
|
|
273
|
+
})
|
|
274
|
+
.finally(() => {
|
|
262
275
|
runningChildren.delete(task.id)
|
|
263
276
|
// 系统日志:任务终态(成功/失败/取消),按动作归类安装/卸载/更新日志
|
|
264
277
|
const show = task.displayTarget ?? task.target
|
|
@@ -547,12 +560,7 @@ export function verifyInstalledEntry(profile: string, target: string): { name: s
|
|
|
547
560
|
main?: unknown
|
|
548
561
|
exports?: unknown
|
|
549
562
|
}
|
|
550
|
-
|
|
551
|
-
const resolved = typeof dot === 'string' ? dot
|
|
552
|
-
: dot !== null && typeof dot === 'object'
|
|
553
|
-
? (dot as Record<string, unknown>).default
|
|
554
|
-
: undefined
|
|
555
|
-
entry = typeof resolved === 'string' ? resolved : typeof meta.main === 'string' ? meta.main : 'index.js'
|
|
563
|
+
entry = resolvePackageEntry(meta)
|
|
556
564
|
} catch {
|
|
557
565
|
return { name, missing: null }
|
|
558
566
|
}
|
|
@@ -21,10 +21,53 @@ export interface ProbeResult {
|
|
|
21
21
|
ms: number | null
|
|
22
22
|
/** HTTP 状态码;失败为 null */
|
|
23
23
|
status: number | null
|
|
24
|
+
/** 失败细分原因:仅当能确认为环境侧 TLS 问题时才有值,普通不可达为 null */
|
|
25
|
+
reason?: ProbeFailReason | null
|
|
24
26
|
}
|
|
25
27
|
|
|
28
|
+
/**
|
|
29
|
+
* 不可达的细分原因。把「证书吊销检查被挡」这类本机环境问题与「网络不通」分开,
|
|
30
|
+
* 诊断列表才能给出对症提示,而不是笼统显示不可达。
|
|
31
|
+
*/
|
|
32
|
+
export type ProbeFailReason = 'tlsRevocation'
|
|
33
|
+
|
|
26
34
|
const probeFail = (): ProbeResult => ({ ok: false, ms: null, status: null })
|
|
27
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Windows 的 curl 走 Schannel 做 TLS:握手阶段强制获取证书吊销信息(CRL/OCSP),
|
|
38
|
+
* 代理受限或吊销服务不可达时整个握手直接失败(CRYPT_E_NO_REVOCATION_CHECK),
|
|
39
|
+
* 表现为 `curl: (35) schannel: next InitializeSecurityContext failed` —— 而 Node/npm/
|
|
40
|
+
* 浏览器各有自己的 TLS 实现,照常可用,用户只会看到「插件市场打不开」。
|
|
41
|
+
* --ssl-revoke-best-effort(curl ≥ 7.70)把吊销检查降级为尽力而为,握手不再被它拦死;
|
|
42
|
+
* 其它平台后端(SecureTransport / OpenSSL)没有这个强制行为,不加参数。
|
|
43
|
+
* 运行时读 process.platform(而非模块级常量),便于测试覆盖两条分支。
|
|
44
|
+
*/
|
|
45
|
+
export function curlTlsArgs(): string[] {
|
|
46
|
+
return process.platform === 'win32' ? ['--ssl-revoke-best-effort'] : []
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 本机 curl 太老、不认识 --ssl-revoke-best-effort(curl < 7.70):退出码 2 + stderr 指向该参数。 */
|
|
50
|
+
export function curlRevokeFlagUnsupported(code: number | null, stderr: string): boolean {
|
|
51
|
+
return code === 2 && /ssl-revoke-best-effort/i.test(stderr) && /unknown|unrecognized/i.test(stderr)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** stderr 是否指向 Schannel 取不到证书吊销信息(据此归因为环境 TLS 问题,而非网络不通)。 */
|
|
55
|
+
export function tlsRevocationBlocked(stderr: string): boolean {
|
|
56
|
+
return /CRYPT_E_NO_REVOCATION_CHECK|CRYPT_E_REVOCATION_OFFLINE|0x80092012/i.test(stderr)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** 探测/安装同一套代理口径:curl 与 git 子进程都读 HTTP(S)_PROXY 环境变量。 */
|
|
60
|
+
function proxyEnv(proxy: string): NodeJS.ProcessEnv {
|
|
61
|
+
if (proxy === '') return { ...process.env }
|
|
62
|
+
return {
|
|
63
|
+
...process.env,
|
|
64
|
+
HTTP_PROXY: proxy,
|
|
65
|
+
HTTPS_PROXY: proxy,
|
|
66
|
+
http_proxy: proxy,
|
|
67
|
+
https_proxy: proxy,
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
28
71
|
/** macOS 系统代理:scutil --proxy 输出里的 HTTP(S) 代理;未开启返回 null。 */
|
|
29
72
|
function macSystemProxy(): string | null {
|
|
30
73
|
try {
|
|
@@ -74,46 +117,72 @@ export function systemProxy(): string | null {
|
|
|
74
117
|
return null
|
|
75
118
|
}
|
|
76
119
|
|
|
77
|
-
/**
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
120
|
+
/** curl 一次调用的原始结果:退出码(进程没起来 / 超时被杀为 null)+ 两路输出。 */
|
|
121
|
+
interface CurlRun {
|
|
122
|
+
code: number | null
|
|
123
|
+
stdout: string
|
|
124
|
+
stderr: string
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** 跑一次 curl 子进程,收集 stdout 与 stderr(stderr 是识别 Schannel 类 TLS 失败的唯一线索)。 */
|
|
128
|
+
function runCurl(args: string[], env: NodeJS.ProcessEnv, timeoutMs: number): Promise<CurlRun> {
|
|
83
129
|
return new Promise((resolve) => {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (proxy !== '') {
|
|
87
|
-
env.HTTP_PROXY = proxy
|
|
88
|
-
env.HTTPS_PROXY = proxy
|
|
89
|
-
env.http_proxy = proxy
|
|
90
|
-
env.https_proxy = proxy
|
|
91
|
-
}
|
|
92
|
-
const discard = process.platform === 'win32' ? 'NUL' : '/dev/null'
|
|
93
|
-
const child = spawn('curl', [
|
|
94
|
-
'-s', '-o', discard, '-w', '%{http_code}',
|
|
95
|
-
'--max-time', String(Math.max(1, Math.round(timeoutMs / 1000))),
|
|
96
|
-
url,
|
|
97
|
-
], { env })
|
|
98
|
-
let code = ''
|
|
99
|
-
child.stdout.on('data', (c: Buffer) => { code += c.toString() })
|
|
130
|
+
let stdout = ''
|
|
131
|
+
let stderr = ''
|
|
100
132
|
let done = false
|
|
101
|
-
const finish = (
|
|
133
|
+
const finish = (code: number | null) => {
|
|
102
134
|
if (done) return
|
|
103
135
|
done = true
|
|
104
136
|
clearTimeout(timer)
|
|
105
|
-
resolve(
|
|
137
|
+
resolve({ code, stdout, stderr })
|
|
106
138
|
}
|
|
107
|
-
child
|
|
108
|
-
child.on('
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
139
|
+
const child = spawn('curl', args, { env })
|
|
140
|
+
child.stdout.on('data', (c: Buffer) => { stdout += c.toString() })
|
|
141
|
+
child.stderr.on('data', (c: Buffer) => { stderr += c.toString() })
|
|
142
|
+
child.on('error', () => finish(null))
|
|
143
|
+
child.on('close', (code) => finish(code))
|
|
112
144
|
// 超时兜底:curl --max-time 到点自行退出,此处再设一个进程级超时防止悬挂
|
|
113
|
-
const timer = setTimeout(() => { child.kill(); finish(
|
|
145
|
+
const timer = setTimeout(() => { child.kill(); finish(null) }, timeoutMs + 1000)
|
|
114
146
|
})
|
|
115
147
|
}
|
|
116
148
|
|
|
149
|
+
/** 带 TLS 兜底的 curl 调用:先按平台参数跑(Windows 带吊销检查降级),
|
|
150
|
+
* 若本机 curl 不认这个参数(curl < 7.70)则去掉参数重跑一次,保证老版本不因此直接失败。 */
|
|
151
|
+
async function curlWithTlsFallback(args: string[], env: NodeJS.ProcessEnv, timeoutMs: number): Promise<CurlRun> {
|
|
152
|
+
const tlsArgs = curlTlsArgs()
|
|
153
|
+
const first = await runCurl([...tlsArgs, ...args], env, timeoutMs)
|
|
154
|
+
if (tlsArgs.length === 0 || !curlRevokeFlagUnsupported(first.code, first.stderr)) return first
|
|
155
|
+
return runCurl(args, env, timeoutMs)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* curl 子进程探测:spawn curl -s -w '%{http_code}' 并注入代理 env。
|
|
160
|
+
* curl 读 HTTP_PROXY/HTTPS_PROXY 是原生行为,与 pnpm/git 安装通道同一套代理口径;
|
|
161
|
+
* 失败(curl 不存在 / 连接失败 / 超时)都归为不可达,全程不抛错。
|
|
162
|
+
* 证书吊销检查受阻(Windows Schannel)另记 reason,供诊断给出对症提示。
|
|
163
|
+
*/
|
|
164
|
+
async function curlProbe(url: string, proxy: string, timeoutMs: number): Promise<ProbeResult> {
|
|
165
|
+
const started = Date.now()
|
|
166
|
+
const discard = process.platform === 'win32' ? 'NUL' : '/dev/null'
|
|
167
|
+
// -sS(而非仅 -s):silent 会把连接/TLS 错误一并吞掉,而识别证书吊销受阻正需要 stderr;
|
|
168
|
+
// 子进程 stderr 由我们收集、不会回显给用户,所以补 -S 不产生噪音。
|
|
169
|
+
const r = await curlWithTlsFallback([
|
|
170
|
+
'-sS', '-o', discard, '-w', '%{http_code}',
|
|
171
|
+
'--max-time', String(Math.max(1, Math.round(timeoutMs / 1000))),
|
|
172
|
+
url,
|
|
173
|
+
], proxyEnv(proxy), timeoutMs)
|
|
174
|
+
// 子进程没起来 / 超时被杀:没有任何可诊断信息,按不可达处理
|
|
175
|
+
if (r.code === null) return probeFail()
|
|
176
|
+
const status = /^\d+$/.test(r.stdout.trim()) ? Number(r.stdout.trim()) : null
|
|
177
|
+
const ok = status !== null && status >= 100 && status < 400
|
|
178
|
+
return {
|
|
179
|
+
ok,
|
|
180
|
+
ms: Date.now() - started,
|
|
181
|
+
status,
|
|
182
|
+
reason: !ok && tlsRevocationBlocked(r.stderr) ? 'tlsRevocation' : null,
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
117
186
|
/**
|
|
118
187
|
* 探测一个 HTTPS 目标:proxy 非空注入给 curl 子进程走代理,否则直连。
|
|
119
188
|
* 供系统诊断 /diagnostics 使用;目标 URL 非法返回不可达。
|
|
@@ -137,13 +206,7 @@ export function probeUrl(url: string, proxy: string, timeoutMs: number): Promise
|
|
|
137
206
|
export function gitLsRemote(url: string, proxy: string, timeoutMs: number): Promise<ProbeResult> {
|
|
138
207
|
return new Promise((resolve) => {
|
|
139
208
|
const started = Date.now()
|
|
140
|
-
const env: NodeJS.ProcessEnv = { ...
|
|
141
|
-
if (proxy !== '') {
|
|
142
|
-
env.HTTP_PROXY = proxy
|
|
143
|
-
env.HTTPS_PROXY = proxy
|
|
144
|
-
env.http_proxy = proxy
|
|
145
|
-
env.https_proxy = proxy
|
|
146
|
-
}
|
|
209
|
+
const env: NodeJS.ProcessEnv = { ...proxyEnv(proxy), GIT_TERMINAL_PROMPT: '0' }
|
|
147
210
|
const child = spawn('git', ['ls-remote', '--exit-code', url, 'HEAD'], { env })
|
|
148
211
|
let out = ''
|
|
149
212
|
child.stdout.on('data', (c: Buffer) => { out += c.toString() })
|
|
@@ -168,33 +231,20 @@ export function gitLsRemote(url: string, proxy: string, timeoutMs: number): Prom
|
|
|
168
231
|
}
|
|
169
232
|
|
|
170
233
|
/**
|
|
171
|
-
* curl 子进程抓取响应体(与 probeUrl 同一套代理 env
|
|
234
|
+
* curl 子进程抓取响应体(与 probeUrl 同一套代理 env 注入与 TLS 参数兜底)。
|
|
172
235
|
* 供服务端 /catalog 代理路由使用:目录/统计数据经此拉到服务端再转给浏览器,
|
|
173
236
|
* 使「目录数据请求走设置里的代理」与 npm / git 安装通道口径一致。
|
|
174
|
-
* 失败(curl 不存在 / 连接失败 / 超时 / 非零退出)时 ok=false
|
|
237
|
+
* 失败(curl 不存在 / 连接失败 / 超时 / 非零退出)时 ok=false,全程不抛错;
|
|
238
|
+
* reason 区分「证书吊销受阻」这类环境 TLS 问题,供调用方决定兜底策略。
|
|
175
239
|
*/
|
|
176
|
-
export function fetchViaCurl(
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
let body = ''
|
|
187
|
-
child.stdout.on('data', (c: Buffer) => { body += c.toString() })
|
|
188
|
-
let done = false
|
|
189
|
-
const finish = (ok: boolean) => {
|
|
190
|
-
if (done) return
|
|
191
|
-
done = true
|
|
192
|
-
clearTimeout(timer)
|
|
193
|
-
resolve({ ok, body })
|
|
194
|
-
}
|
|
195
|
-
child.on('error', () => finish(false))
|
|
196
|
-
child.on('close', (code) => finish(code === 0))
|
|
197
|
-
// 超时兜底:curl --max-time 到点自行退出,此处再设一个进程级超时防止悬挂
|
|
198
|
-
const timer = setTimeout(() => { child.kill(); finish(false) }, timeoutMs + 1000)
|
|
199
|
-
})
|
|
240
|
+
export function fetchViaCurl(
|
|
241
|
+
url: string, proxy: string, timeoutMs: number,
|
|
242
|
+
): Promise<{ ok: boolean; body: string; reason: ProbeFailReason | null }> {
|
|
243
|
+
// 同样用 -sS:正文之外还要 stderr 里的 TLS 失败线索(被 stderr 收集,不外泄给用户)
|
|
244
|
+
const args = ['-sS', '--max-time', String(Math.max(1, Math.round(timeoutMs / 1000))), url]
|
|
245
|
+
return curlWithTlsFallback(args, proxyEnv(proxy), timeoutMs).then((r) => ({
|
|
246
|
+
ok: r.code === 0,
|
|
247
|
+
body: r.stdout,
|
|
248
|
+
reason: r.code !== 0 && tlsRevocationBlocked(r.stderr) ? 'tlsRevocation' : null,
|
|
249
|
+
}))
|
|
200
250
|
}
|