dsh-plugin 1.0.0 → 1.1.0

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.
@@ -723,18 +723,29 @@
723
723
  padding-right: 2px;
724
724
  }
725
725
 
726
- /* 每条通知 = 一张独立卡片:左侧圆形状态徽标 + 右侧内容列,
727
- 徽标垂直居中于整条(失败条目下方还有修复/提 Issue 动作,比成功条目高) */
726
+ /* 每条通知 = 一张独立卡片:纵向布局 —— 上(徽标+内容)行、下(时间戳)行;
727
+ 徽标与文字在 .noticeRowMain 里水平垂直居中,时间戳独立一行不参与居中 */
728
728
  .noticeRow {
729
729
  display: flex;
730
- align-items: center;
731
- gap: 10px;
730
+ flex-direction: column;
731
+ align-items: stretch;
732
+ gap: 6px;
732
733
  padding: 10px 12px;
733
734
  border: 1px solid var(--hub-border-2);
734
735
  border-radius: 8px;
735
736
  background: var(--hub-bg-2);
736
737
  }
737
738
 
739
+ /* 徽标 + 内容列一行:徽标与文字垂直居中(失败条目下方还有修复/提 Issue 动作,
740
+ 徽标仍与该行文字对齐,而非被下方动作拉偏) */
741
+ .noticeRowMain {
742
+ display: flex;
743
+ align-items: center;
744
+ gap: 10px;
745
+ width: 100%;
746
+ min-width: 0;
747
+ }
748
+
738
749
  /* 圆形状态徽标:成功 = 绿底白勾;失败 = 红底白叉(用户要求的「红色圆形 + 白色图形」语义) */
739
750
  .noticeBadgeOk,
740
751
  .noticeBadgeFail {
@@ -867,7 +878,14 @@
867
878
  text-decoration: underline;
868
879
  }
869
880
 
870
- .failTime {
881
+ /* 每条通知底部的完整时间戳:YYYY-MM-DD HH:mm:ss,靠右下角展示 */
882
+ .noticeFoot {
883
+ display: flex;
884
+ justify-content: flex-end;
885
+ align-items: center;
886
+ }
887
+
888
+ .noticeTime {
871
889
  flex-shrink: 0;
872
890
  font-size: 11px;
873
891
  line-height: 16px;
@@ -875,6 +893,29 @@
875
893
  font-variant-numeric: tabular-nums;
876
894
  }
877
895
 
896
+ /* 每条通知右侧的单条删除按钮:小号透明 X,靠右对齐,hover 变红提示可删,可单独移除该条 */
897
+ .noticeRemove {
898
+ margin-left: auto;
899
+ flex-shrink: 0;
900
+ display: inline-flex;
901
+ align-items: center;
902
+ justify-content: center;
903
+ width: 22px;
904
+ height: 22px;
905
+ color: var(--hub-text-tertiary);
906
+ background: transparent;
907
+ border: none;
908
+ border-radius: 5px;
909
+ cursor: pointer;
910
+ user-select: none;
911
+ transition: color 120ms ease, background 120ms ease;
912
+ }
913
+
914
+ .noticeRemove:hover {
915
+ color: var(--hub-danger-text);
916
+ background: var(--hub-danger-tint);
917
+ }
918
+
878
919
  /* 记录内的复制按钮:纯灰文字、无边框,低调隐蔽,点击即可复制该条完整错误日志 */
879
920
  .failCopy {
880
921
  flex-shrink: 0;
@@ -53,9 +53,9 @@ body[data-ds-dark-theme] {
53
53
  --hub-btn-hover: var(--dsw-alias-button-primary-hover, #43454a);
54
54
 
55
55
  /* success */
56
- --hub-success: var(--dsw-alias-state-success-primary, #1a7f37);
57
- --hub-success-tint: rgba(34, 197, 94, 0.14);
58
- --hub-success-border: var(--dsw-alias-state-success-secondary, rgba(26, 127, 55, 0.3));
56
+ --hub-success: #16a34a;
57
+ --hub-success-tint: rgba(22, 163, 74, 0.12);
58
+ --hub-success-border: rgba(22, 163, 74, 0.3);
59
59
 
60
60
  /* warning (amber) */
61
61
  --hub-warn: var(--dsw-alias-state-warn-primary, #b8860b);
@@ -83,4 +83,9 @@ body[data-ds-dark-theme] {
83
83
  /* 暗色下的计数胶囊底色:白半透明,深色底上更可辨 */
84
84
  body[data-ds-dark-theme] {
85
85
  --hub-bg-btn: rgba(255, 255, 255, 0.12);
86
+
87
+ /* 暗色下的成功绿:提亮一档,对勾在深底上清晰且不刺眼 */
88
+ --hub-success: #22c55e;
89
+ --hub-success-tint: rgba(34, 197, 94, 0.16);
90
+ --hub-success-border: rgba(34, 197, 94, 0.35);
86
91
  }
@@ -46,7 +46,7 @@ export interface HubPlugin {
46
46
  topics?: string[]
47
47
  features?: string[]
48
48
  description?: string
49
- source?: { repo?: string }
49
+ source?: { repo?: string; npmPackage?: string }
50
50
  compatibility?: { status?: string }
51
51
  dates?: { repoUpdatedAt?: string; addedAt?: string }
52
52
  stats?: { stargazers_count?: number; forks_count?: number }
@@ -10,7 +10,8 @@ import { homedir, release } from 'node:os'
10
10
  import { dirname, join, resolve } from 'node:path'
11
11
  import { spawn } from 'node:child_process'
12
12
  import { activeTask, cancelTask, dumpLoaderEntries, getTask, githubTarget, hasQueuedTarget, listPendingRestarts, readProfileArg, startPluginMutation, validPackageName, type LoaderHandle } from '../services/install.ts'
13
- import { recordInstalledVersion, readInstalledVersions, removeInstalledVersion } from '../services/installed-versions.ts'
13
+ import { recordInstalledVersion, recordResolvedNpmPackage, readInstalledVersions, removeInstalledVersion } from '../services/installed-versions.ts'
14
+ import { resolveNpmPackage } from '../services/npm-resolve.ts'
14
15
  import { preflightTarget } from '../services/preflight.ts'
15
16
 
16
17
  export interface WebRoute {
@@ -172,17 +173,44 @@ export function mountPluginHubRoutes(webServer: WebServerService, profile: strin
172
173
  const rawRepo = typeof body === 'object' && body !== null && typeof (body as { repo?: unknown }).repo === 'string'
173
174
  ? (body as { repo: string }).repo.trim()
174
175
  : ''
176
+ // 前端决策的展示用仓库名(owner/repo):npm 安装时 body.repo 是包名,display 用于
177
+ // 待重启行 / 任务恢复时展示仓库名,保证用户无感知(安装通道变化不改变所见目标)
178
+ const displayRepo = typeof body === 'object' && body !== null && typeof (body as { display?: unknown }).display === 'string'
179
+ ? (body as { display: string }).display.trim()
180
+ : rawRepo
175
181
  // 目标语法两态:owner/repo → github 源(走装前预检);npm 包名(@scope/name 或 name)→ 信任 registry 直接安装
176
182
  const repoTarget = githubTarget(rawRepo)
177
- const target = repoTarget ?? (repoTarget === null && validPackageName(rawRepo) ? rawRepo : null)
183
+ let target: string | null = repoTarget ?? (repoTarget === null && validPackageName(rawRepo) ? rawRepo : null)
178
184
  if (target === null) {
179
185
  sendJson(response, 400, { error: 'unsupported install target' })
180
186
  return
181
187
  }
188
+ // npm 优先:git 目标先反查该仓库的官方 npm 包,命中则改走 npm 通道。
189
+ // git 分发常缺构建产物/子模块导致 prepare 必败,而 npm 包是作者发布的
190
+ // 完整产物,成功率高得多;未命中或查询失败保留 github 直装(不阻塞安装,
191
+ // 预检仍会兜底拦截 git 分发缺入口文件的情况)。通用机制,不针对具体插件。
192
+ // 反查本身计入「已尝试的安装方式」:组织 scope 与 GitHub 用户名不一致时仅凭
193
+ // 仓库名猜不到包名,失败提 Issue 时作者看到我们查过的命令就能直接指认正确包名。
194
+ const attempts: string[] = []
195
+ if (repoTarget !== null) {
196
+ const npmName = await resolveNpmPackage(rawRepo)
197
+ if (npmName !== null) {
198
+ target = npmName
199
+ attempts.push(`npm registry search: \`npm search repository:${rawRepo}\` → found \`${npmName}\``)
200
+ // 持久化 repo → npm 包名映射:目录数据未下发 npmPackage(组织 scope 与 GitHub
201
+ // 用户名不一致)时,客户端仍能通过 /installed 的 versions 把依赖 key 匹配回仓库,
202
+ // 列表立即显示「已安装」,避免安装成功后仍显示可安装
203
+ recordResolvedNpmPackage(profile, rawRepo, npmName)
204
+ } else {
205
+ attempts.push(`npm registry search: \`npm search repository:${rawRepo}\` → no matching package found (falling back to git install)`)
206
+ }
207
+ }
182
208
  // 重复安装防护:非更新请求命中已安装目标时直接拒绝,不重复跑 CLI
183
209
  // (否则 CLI 会因「已存在」失败,且用户看到的是莫名其妙的报错);
184
- // 更新请求(mode: 'update')放行,CLI 的 add 对已存在依赖是 pnpm 原位覆盖重装
185
- const already = installedByRepo(readInstalled(profile), target)
210
+ // 更新请求(mode: 'update')放行,CLI 的 add 对已存在依赖是 pnpm 原位覆盖重装。
211
+ // 命中判定双通道:npm 包名按 dependencies 键直接命中,github: 目标按 spec 值匹配。
212
+ const installed = readInstalled(profile)
213
+ const already = installedByRepo(installed, target) ?? (installed[target] !== undefined ? target : null)
186
214
  if (already !== null && mode !== 'update') {
187
215
  sendJson(response, 409, { error: `already installed: ${already}` })
188
216
  return
@@ -194,13 +222,16 @@ export function mountPluginHubRoutes(webServer: WebServerService, profile: strin
194
222
  }
195
223
  // 安装前预检:仅新安装走预检(github 源分发改入口文件缺失时直接拦截)。
196
224
  // 更新是已信任目标的覆盖重装,跳过预检避免重复下载 tarball。
197
- // 只支持官方默认安装方式(dsh plugin add github:owner/repo),不做任何 npm 兜底降级;
198
- // [packaging] 前缀供客户端归类为「插件未适配官方默认安装方式」并引导去仓库提 Issue
225
+ // npm 包信任 registry 直接放行;github 源拦截时标记 [packaging] 前缀,
226
+ // 供客户端归类为「插件分发不完整」并引导去仓库提 Issue
199
227
  if (already === null) {
200
228
  const preflight = await preflightTarget(target)
201
229
  if (!preflight.ok) {
230
+ // 预检拦截(git 分发缺入口文件):同步 400 返回,附上已尝试的安装方式,
231
+ // 客户端失败弹窗提 Issue 时一并贴给作者
202
232
  sendJson(response, 400, {
203
- error: `[packaging] ${target}: does not support the official default install method — the git distribution lacks build output (the entry file ${preflight.missing ?? '?'} declared in package.json is not in the repository). Report to the author.`,
233
+ error: `[packaging] ${target}: plugin distribution is incomplete — the entry file ${preflight.missing ?? '?'} declared in package.json is not present in the git distribution (build output not committed). Report to the author.`,
234
+ attempts,
204
235
  })
205
236
  return
206
237
  }
@@ -217,6 +248,10 @@ export function mountPluginHubRoutes(webServer: WebServerService, profile: strin
217
248
  action: 'add',
218
249
  profile,
219
250
  target,
251
+ // npm 安装时 target 是包名:displayTarget 固定展示仓库名,待重启行/前端恢复不受通道变化影响
252
+ displayTarget: githubTarget(displayRepo) ?? undefined,
253
+ // 已尝试的安装方式(npm 反查):实际执行命令由 spawn 时追加,失败 issue 一并展示
254
+ attempts,
220
255
  timeoutMs: COMMAND_TIMEOUT_MS,
221
256
  env: { ...process.env, CI: 'true' },
222
257
  })
@@ -13,6 +13,12 @@ export interface InstallTask {
13
13
  id: number
14
14
  /** 操作目标:`github:<owner>/<repo>`(安装)或 npm 包名(卸载),冲突/恢复时需要展示给用户 */
15
15
  target: string
16
+ /** 展示用目标(owner/repo):npm 安装时 target 是包名,前端恢复用此字段显示仓库名,保持用户无感知 */
17
+ displayTarget?: string
18
+ /** 尝试过的安装方式(npm registry 反查 + 实际执行的 CLI 命令,按先后顺序):
19
+ * 失败提 Issue 时如实贴给作者,作者据此反推正确的 npm 包名(组织 scope 与 GitHub 用户名不一致时
20
+ * 仅凭仓库名猜不到,作者看到我们查过/试过的命令就能直接指认)。 */
21
+ attempts: string[]
16
22
  action: 'add' | 'remove'
17
23
  /** 队列语义:pending 排队中 / running 执行中 / done / failed / cancelled(用户取消) */
18
24
  status: 'pending' | 'running' | 'done' | 'failed' | 'cancelled'
@@ -27,6 +27,9 @@ export interface InstalledVersionRecord {
27
27
  /** 安装时的仓库最近更新时间(ISO,GitHub pushed_at);无 release 仓库的更新依据 */
28
28
  updatedAt: string
29
29
  installedAt: string
30
+ /** npm 优先通道反查命中的官方 npm 包名(repo → 包名映射):目录数据可能未下发
31
+ * npmPackage(组织 scope 与 GitHub 用户名不一致),客户端据此把依赖 key 匹配回仓库 */
32
+ npmPackage?: string
30
33
  }
31
34
 
32
35
  export type InstalledVersionTable = Record<string, InstalledVersionRecord>
@@ -47,7 +50,23 @@ export function readInstalledVersions(profile: string): InstalledVersionTable {
47
50
  /** Record the catalog signals (version + repo updated time) present at install time for one repo. */
48
51
  export function recordInstalledVersion(profile: string, repo: string, version: string, updatedAt: string): void {
49
52
  const table = readInstalledVersions(profile)
50
- table[repo.toLowerCase()] = { version, updatedAt, installedAt: new Date().toISOString() }
53
+ const key = repo.toLowerCase()
54
+ // 合并写入:保留已记录的 npmPackage(npm 优先通道的 repo → 包名映射),
55
+ // 客户端同步版本信号时不能把它覆盖掉
56
+ table[key] = { ...table[key], version, updatedAt, installedAt: new Date().toISOString() }
57
+ writeVersions(profile, table)
58
+ }
59
+
60
+ /**
61
+ * Record the npm package name resolved for a repo (npm-first install channel).
62
+ * Called at `/install` time so the mapping exists even before the task finishes;
63
+ * harmless when the repo is not (yet) installed — the client only treats a repo
64
+ * as installed when its dependency key actually exists.
65
+ */
66
+ export function recordResolvedNpmPackage(profile: string, repo: string, npmPackage: string): void {
67
+ const table = readInstalledVersions(profile)
68
+ const key = repo.toLowerCase()
69
+ table[key] = { ...table[key], npmPackage }
51
70
  writeVersions(profile, table)
52
71
  }
53
72
 
@@ -0,0 +1,67 @@
1
+ /**
2
+ * npm 包反查:git 分发不完整(缺构建产物/子模块)导致安装失败时,用 npm
3
+ * registry 的搜索接口按 repository 地址反查该仓库对应的官方 npm 包。
4
+ *
5
+ * 这是通用机制,不针对任何具体插件:只要作者发布了 repository 指向该
6
+ * GitHub 仓库的 npm 包(scope 名与 GitHub 用户名是否一致无所谓),就能命中,
7
+ * 从而把「git 直装必败」的插件切换到 npm 通道安装。命中结果带内存缓存,
8
+ * 避免同一会话内重复查询 registry。
9
+ */
10
+ import { get } from 'node:https'
11
+
12
+ /** 反查缓存:repo 小写 → npm 包名(null 表示已确认无对应 npm 包)。 */
13
+ const cache = new Map<string, string | null>()
14
+
15
+ /** 单次 registry 查询超时(ms):慢网络下失败返回 null,不阻塞安装流程。 */
16
+ const REQUEST_TIMEOUT_MS = 8000
17
+
18
+ /**
19
+ * 反查 repo(`owner/repo`)对应的官方 npm 包名;未命中、网络异常或超时返回 null。
20
+ * 返回 null 不代表仓库一定没有 npm 包,只代表本次未能确认 —— 调用方应保留
21
+ * 原有错误路径,反查只是额外的一次尝试。
22
+ */
23
+ export function resolveNpmPackage(repo: string): Promise<string | null> {
24
+ const key = repo.toLowerCase()
25
+ if (cache.has(key)) return Promise.resolve(cache.get(key) ?? null)
26
+ const name = searchRepo(repo)
27
+ name.then((found) => cache.set(key, found)).catch(() => cache.set(key, null))
28
+ return name
29
+ }
30
+
31
+ /** 用 npm search 接口按 repository 地址反查,并做铁证校验(包元数据必须指向该仓库)。 */
32
+ function searchRepo(repo: string): Promise<string | null> {
33
+ const [owner, name] = repo.split('/')
34
+ if (owner === undefined || name === undefined || name === '') return Promise.resolve(null)
35
+ const url = `https://registry.npmjs.org/-/v1/search?text=${encodeURIComponent(`repository:${owner}/${name}`)}&size=10`
36
+ return new Promise((resolve) => {
37
+ const req = get(url, { timeout: REQUEST_TIMEOUT_MS }, (res) => {
38
+ if (res.statusCode !== 200) {
39
+ res.resume()
40
+ resolve(null)
41
+ return
42
+ }
43
+ let body = ''
44
+ res.on('data', (chunk: Buffer) => { body += chunk.toString() })
45
+ res.on('end', () => {
46
+ try {
47
+ const data = JSON.parse(body) as { objects?: Array<{ package?: { name?: unknown; links?: { repository?: unknown }; repository?: { url?: unknown } } }> }
48
+ const needle = `github.com/${owner}/${name}`.toLowerCase()
49
+ for (const obj of data.objects ?? []) {
50
+ const pkg = obj.package
51
+ if (typeof pkg?.name !== 'string' || pkg.name === '') continue
52
+ const repoUrl = String(pkg.repository?.url ?? pkg.links?.repository ?? '')
53
+ if (repoUrl.toLowerCase().includes(needle)) {
54
+ resolve(pkg.name)
55
+ return
56
+ }
57
+ }
58
+ resolve(null)
59
+ } catch {
60
+ resolve(null)
61
+ }
62
+ })
63
+ })
64
+ req.on('timeout', () => req.destroy())
65
+ req.on('error', () => resolve(null))
66
+ })
67
+ }
@@ -36,20 +36,25 @@ export interface ActiveTaskInfo {
36
36
  status: 'pending' | 'running'
37
37
  progress: number
38
38
  lines: string[]
39
+ /** 尝试过的安装方式(npm 反查 + 实际执行命令):失败时前端 issue 预填需要 */
40
+ attempts: string[]
39
41
  }
40
42
 
41
43
  /** All non-terminal tasks in queue order (running first, then pending). Lets the client resume a queue after a page reload. */
42
44
  export function activeTask(): ActiveTaskInfo[] {
43
45
  const found: ActiveTaskInfo[] = []
46
+ // 展示目标用 displayTarget(owner/repo):安装 target 可能被服务端切成 npm 包名
47
+ // (npm 反查命中),队列恢复/待重启展示对用户保持仓库名无感知
48
+ const show = (task: InstallTask): string => task.displayTarget ?? task.target
44
49
  for (const item of queue) {
45
50
  const task = item.task
46
51
  if (task.status === 'pending') {
47
- found.push({ id: task.id, target: task.target, action: task.action, status: 'pending', progress: task.progress, lines: task.lines.slice(0, MAX_TASK_LINES) })
52
+ found.push({ id: task.id, target: show(task), action: task.action, status: 'pending', progress: task.progress, lines: task.lines.slice(0, MAX_TASK_LINES), attempts: task.attempts })
48
53
  }
49
54
  }
50
55
  tasks.forEach((task) => {
51
56
  if (task.status === 'running') {
52
- found.unshift({ id: task.id, target: task.target, action: task.action, status: 'running', progress: task.progress, lines: task.lines.slice(0, MAX_TASK_LINES) })
57
+ found.unshift({ id: task.id, target: show(task), action: task.action, status: 'running', progress: task.progress, lines: task.lines.slice(0, MAX_TASK_LINES), attempts: task.attempts })
53
58
  }
54
59
  })
55
60
  return found
@@ -162,8 +167,10 @@ export function startPluginMutation(options: {
162
167
  displayTarget?: string
163
168
  /** 运行中 loader:卸载成功后主动移除条目、立即生效(缺失时卸载仍需重启清理) */
164
169
  uninstallLoader?: LoaderHandle
170
+ /** 入队前已尝试的安装方式(npm registry 反查等):失败提 Issue 时如实展示;实际执行的命令由 spawn 时追加 */
171
+ attempts?: string[]
165
172
  }): InstallTask {
166
- const task: InstallTask = { id: nextTaskId, target: options.target, action: options.action, status: 'pending', timedOut: false, exitCode: null, progress: 0, lines: [] }
173
+ const task: InstallTask = { id: nextTaskId, target: options.target, displayTarget: options.displayTarget, action: options.action, status: 'pending', timedOut: false, exitCode: null, progress: 0, lines: [], attempts: options.attempts ?? [] }
167
174
  nextTaskId = nextTaskId >= Number.MAX_SAFE_INTEGER ? 1 : nextTaskId + 1
168
175
  tasks.set(task.id, task)
169
176
  if (tasks.size > MAX_TASKS) {
@@ -216,6 +223,12 @@ function spawnMutation(options: {
216
223
  const { action, profile, target, timeoutMs = 5 * 60 * 1000, env, task, displayTarget, uninstallLoader } = options
217
224
  const invocation = cliInvocation()
218
225
  const args = [...invocation.prefixArgs, 'plugin', '--profile', profile, action, target]
226
+ // 记录实际执行的命令(npm 通道显示包名,git 通道显示 github: 源):失败提 Issue 时
227
+ // 「已尝试的安装方式」如实展示完整命令链,作者一眼看清我们跑过什么
228
+ const executed = `dsh plugin --profile ${profile} ${action} ${target}`
229
+ if (task && !task.attempts.includes(executed)) {
230
+ task.attempts.push(executed)
231
+ }
219
232
  return new Promise((resolvePromise) => {
220
233
  let stdout = ''
221
234
  let stderr = ''
@@ -393,12 +406,24 @@ export function verifyInstalledEntry(profile: string, target: string): { name: s
393
406
  }
394
407
  }
395
408
 
409
+ /** 从 pnpm `Ignored build scripts:` 提示行解析被拦截的构建脚本 key(name@version,逗号分隔)。 */
410
+ function ignoredBuildKeys(output: string): string[] {
411
+ const m = /Ignored build scripts:\s*(.+)/i.exec(output)
412
+ if (m === null) return []
413
+ return m[1]
414
+ .split(',')
415
+ .map((s) => s.trim())
416
+ .filter((s) => s !== '')
417
+ }
418
+
396
419
  /**
397
- * Run a plugin mutation with one recovery path: when `add` fails because a
398
- * git-hosted package's `prepare` script is blocked by pnpm's allowBuilds
399
- * gate (`ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED`), read the exact allowlist
400
- * key pnpm printed, write it into the profile's pnpm-workspace.yaml, and
401
- * retry once. Other failures fall through to the single-spawn result.
420
+ * Run a plugin mutation with one recovery path: when `add` fails because
421
+ * pnpm's allowBuilds gate blocks a build script — either the git-hosted
422
+ * package's own `prepare` (`ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED`, key from
423
+ * the printed key@url hint) or a dependency's native build
424
+ * (`ERR_PNPM_IGNORED_BUILDS`, key = the listed name@version) — write the
425
+ * exact keys into the profile's pnpm-workspace.yaml and retry once.
426
+ * Other failures fall through to the single-spawn result.
402
427
  */
403
428
  export async function runPluginMutation(options: {
404
429
  action: 'add' | 'remove'
@@ -415,6 +440,7 @@ export async function runPluginMutation(options: {
415
440
  const result = await spawnMutation(options)
416
441
  if (options.action === 'add' && result.exitCode !== 0 && !result.timedOut) {
417
442
  const output = `${result.stderr}\n${result.stdout}`
443
+ // git 源:pnpm 打印的 key@url 提示
418
444
  if (output.includes('ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED')) {
419
445
  const key = parseAllowBuildsKey(output)
420
446
  if (key !== null) {
@@ -429,6 +455,22 @@ export async function runPluginMutation(options: {
429
455
  return spawnMutation(options)
430
456
  }
431
457
  }
458
+ // 依赖原生模块/构建脚本被 pnpm v11 拦截(ERR_PNPM_IGNORED_BUILDS):git 与 npm 源都会出现。
459
+ // allowBuilds 的 key 是输出里列出的 name@version(如 node-pty@1.1.0),逐个放行后重试一次;
460
+ // 输出解析不到时回退用目标名(插件自身构建脚本被拦的 npm 场景)。
461
+ if (output.includes('ERR_PNPM_IGNORED_BUILDS')) {
462
+ const keys = ignoredBuildKeys(output)
463
+ if (keys.length === 0 && !options.target.startsWith('github:')) keys.push(options.target)
464
+ if (keys.length > 0) {
465
+ if (options.task) {
466
+ options.task.status = 'running'
467
+ options.task.exitCode = null
468
+ pushLine(options.task, `[allow build] ${keys.join(', ')}`)
469
+ }
470
+ for (const key of keys) addAllowBuildsKey(options.profile, key)
471
+ return spawnMutation(options)
472
+ }
473
+ }
432
474
  }
433
475
  // pnpm 安装本身成功,但目标包入口文件缺失(git 分发缺构建产物)→ 判为失败:
434
476
  // 撤销刚登记的待重启,避免用户重启时宿主加载残缺包直接崩溃