dsh-plugin 2.3.1 → 2.3.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.
@@ -12,6 +12,7 @@ import { isDshNpmPackageForRepo } from '../services/install/npm-resolve.js';
12
12
  import { probeUrl, systemProxy } from '../services/probe.js';
13
13
  import { loadSettings } from '../services/settings.js';
14
14
  import { registryCandidates, registryHost, userNpmRegistry } from '../services/install/registry-fallback.js';
15
+ import { lookupReleaseAge } from '../services/npm-release-age.js';
15
16
  import { profileDirectory } from '../services/profile/profile.js';
16
17
  import { readInstalled } from './catalog.js';
17
18
  import { COMMAND_TIMEOUT_MS, readJsonBody, requireTrustedPost, sendJson } from './shared.js';
@@ -178,6 +179,16 @@ export function registerInstallRoutes(webServer, profile, loader) {
178
179
  }
179
180
  ordered = [chosen, ...registries.filter((r) => r !== chosen)];
180
181
  }
182
+ // 新安装钉住「已过供应链门禁」的版本:pnpm 对发布未满 24h 的版本会静默回退到很旧的版本,
183
+ // 用户装完才发现功能缺失且没有任何提示。更新已有目标时客户端已按门禁筛选,继续走 @latest。
184
+ let installSpec = pinVersion !== '' ? `${target}@${pinVersion}` : undefined;
185
+ if (installSpec === undefined && already === null) {
186
+ // 解析源与安装首选源一致,钉住的版本一定存在于真正会用的那个源;解析失败则不钉,不阻断安装。
187
+ // 超时压到 5s:网络刚探通,慢也只在极端情况,不能为查版本把安装请求拖住 8s
188
+ const release = await lookupReleaseAge(target, ordered[0] ?? '', effectiveProxy, 5000);
189
+ if (release !== null && release.installable !== null)
190
+ installSpec = `${target}@${release.installable.version}`;
191
+ }
181
192
  // 入队前复检:网络探测的 await 期间并发请求可能已通过上方检查,而此处到 startPluginMutation
182
193
  // 之间无 await,JS 单线程保证同一目标至多一个任务,杜绝双击/并发双任务。
183
194
  if (hasQueuedTarget(target)) {
@@ -201,7 +212,7 @@ export function registerInstallRoutes(webServer, profile, loader) {
201
212
  env: mutationEnv(settings),
202
213
  // 候选源(首选在前):任务内遇到传输层失败时按顺序换源重试
203
214
  registries: ordered,
204
- installSpec: pinVersion !== '' ? `${target}@${pinVersion}` : undefined,
215
+ installSpec,
205
216
  // 自定义安装入口渠道:日志/报错据此溯源
206
217
  installChannel,
207
218
  });
@@ -8,6 +8,8 @@
8
8
  */
9
9
  import { systemProxy } from '../services/probe.js';
10
10
  import { lookupReleaseAge, parseReleaseAgeRequest } from '../services/npm-release-age.js';
11
+ import { userNpmRegistry } from '../services/install/registry-fallback.js';
12
+ import { profileDirectory } from '../services/profile/profile.js';
11
13
  import { loadSettings } from '../services/settings.js';
12
14
  import { readJsonBody, requireTrustedPost, sendJson } from './shared.js';
13
15
  export function registerNpmReleaseAgeRoutes(webServer, profile) {
@@ -30,7 +32,11 @@ export function registerNpmReleaseAgeRoutes(webServer, profile) {
30
32
  ? settings.proxy
31
33
  : (systemProxy() ?? process.env.HTTPS_PROXY ?? process.env.https_proxy ?? '');
32
34
  // 并发查询:单包各自带超时且失败即 null,整体不因任一包失败而失败
33
- const results = await Promise.all(packages.map(async (name) => [name, await lookupReleaseAge(name, settings.npmRegistry, proxy)]));
35
+ // 查询源与安装首选源同口径(设置 → 本机 npm 配置):安装钉住的版本必须来自真正要用的那个源
36
+ const registry = settings.npmRegistry !== ''
37
+ ? settings.npmRegistry
38
+ : userNpmRegistry(profileDirectory(profile));
39
+ const results = await Promise.all(packages.map(async (name) => [name, await lookupReleaseAge(name, registry, proxy)]));
34
40
  sendJson(response, 200, { packages: Object.fromEntries(results) });
35
41
  }
36
42
  catch (error) {
@@ -11,6 +11,8 @@
11
11
  import { get as httpsGet } from 'node:https';
12
12
  import { validPackageName } from './profile/profile.js';
13
13
  import { fetchViaCurl } from './probe.js';
14
+ /** pnpm profile 默认 minimumReleaseAge=1440 分钟;+30 分钟缓冲与客户端 release-age 判定同口径。 */
15
+ export const MIN_RELEASE_AGE_MS = 24 * 60 * 60 * 1000 + 30 * 60 * 1000;
14
16
  /** 请求体包名数量上限:只为已安装插件按需查询,几十个足矣,封顶防滥用。 */
15
17
  export const MAX_RELEASE_AGE_PACKAGES = 50;
16
18
  /** 单包查询超时(ms):慢网络下失败即返回 null,不拖住整个响应。 */
@@ -38,6 +40,39 @@ export function latestReleaseOf(packument) {
38
40
  return null;
39
41
  return { version, publishedAt };
40
42
  }
43
+ /**
44
+ * 已过供应链门禁的最高稳定版本:安装时钉住它,pnpm 就不会把最新版静默回退成很旧的版本。
45
+ * 只看纯 x.y.z(预发布版不参与,避免把用户带到不兼容预览版);时间表缺失或无满足项返回 null。
46
+ */
47
+ export function installableReleaseOf(packument, now = Date.now()) {
48
+ if (packument === null || typeof packument !== 'object')
49
+ return null;
50
+ const time = packument.time;
51
+ if (time === null || typeof time !== 'object')
52
+ return null;
53
+ let best = null;
54
+ for (const [version, published] of Object.entries(time)) {
55
+ if (!/^\d+\.\d+\.\d+$/.test(version) || typeof published !== 'string')
56
+ continue;
57
+ const at = Date.parse(published);
58
+ if (Number.isNaN(at) || now - at < MIN_RELEASE_AGE_MS)
59
+ continue;
60
+ if (best === null || compareVersion(version, best.version) > 0)
61
+ best = { version, publishedAt: published };
62
+ }
63
+ return best;
64
+ }
65
+ /** 纯数字段版本比较(installableReleaseOf 只在 x.y.z 里用)。 */
66
+ function compareVersion(a, b) {
67
+ const pa = a.split('.');
68
+ const pb = b.split('.');
69
+ for (let i = 0; i < 3; i++) {
70
+ const d = Number.parseInt(pa[i] ?? '0', 10) - Number.parseInt(pb[i] ?? '0', 10);
71
+ if (d !== 0)
72
+ return d;
73
+ }
74
+ return 0;
75
+ }
41
76
  /** 请求体 → 去重后的合法包名列表;非数组 / 超量 / 含非法包名一律 null(拒绝非法输入)。 */
42
77
  export function parseReleaseAgeRequest(body) {
43
78
  if (body === null || typeof body !== 'object')
@@ -99,7 +134,7 @@ async function fetchPackument(url, proxy, timeoutMs) {
99
134
  }
100
135
  return getJson(url, timeoutMs);
101
136
  }
102
- /** 查询一个包的最新版本与发布时间(成功结果按源缓存 10 分钟);registry 为空回退官方源,失败返回 null。 */
137
+ /** 查询一个包的最新版本、发布时间与可钉住的安装版本(成功结果按源缓存 10 分钟);registry 为空回退官方源,失败返回 null。 */
103
138
  export async function lookupReleaseAge(packageName, registry, proxy, timeoutMs = RELEASE_AGE_TIMEOUT_MS) {
104
139
  const base = registry.replace(/\/+$/, '') || DEFAULT_NPM_REGISTRY;
105
140
  const key = `${base}\n${packageName}`;
@@ -116,8 +151,10 @@ export async function lookupReleaseAge(packageName, registry, proxy, timeoutMs =
116
151
  catch {
117
152
  return null;
118
153
  }
119
- const release = latestReleaseOf(parsed);
120
- if (release !== null)
121
- releaseCache.set(key, { at: Date.now(), release });
154
+ const latest = latestReleaseOf(parsed);
155
+ if (latest === null)
156
+ return null;
157
+ const release = { ...latest, installable: installableReleaseOf(parsed) };
158
+ releaseCache.set(key, { at: Date.now(), release });
122
159
  return release;
123
160
  }
@@ -2,6 +2,13 @@ export interface NpmRelease {
2
2
  version: string;
3
3
  publishedAt: string;
4
4
  }
5
+ /** 最新版 + 可钉住的安装版本:安装时钉住后者,pnpm 才不会把「发布未满门禁」的最新版回退成很旧的版本。 */
6
+ export interface NpmReleaseWithInstallable extends NpmRelease {
7
+ /** 已过供应链门禁的最高稳定版;时间表缺失或没有满足项时为 null(调用方退回不钉版本)。 */
8
+ installable: NpmRelease | null;
9
+ }
10
+ /** pnpm profile 默认 minimumReleaseAge=1440 分钟;+30 分钟缓冲与客户端 release-age 判定同口径。 */
11
+ export declare const MIN_RELEASE_AGE_MS: number;
5
12
  /** 请求体包名数量上限:只为已安装插件按需查询,几十个足矣,封顶防滥用。 */
6
13
  export declare const MAX_RELEASE_AGE_PACKAGES = 50;
7
14
  /** 单包查询超时(ms):慢网络下失败即返回 null,不拖住整个响应。 */
@@ -9,7 +16,12 @@ export declare const RELEASE_AGE_TIMEOUT_MS = 8000;
9
16
  export declare const DEFAULT_NPM_REGISTRY = "https://registry.npmjs.org";
10
17
  /** 从完整 packument 取 dist-tags.latest 对应版本及其发布时间;缺任一字段返回 null。 */
11
18
  export declare function latestReleaseOf(packument: unknown): NpmRelease | null;
19
+ /**
20
+ * 已过供应链门禁的最高稳定版本:安装时钉住它,pnpm 就不会把最新版静默回退成很旧的版本。
21
+ * 只看纯 x.y.z(预发布版不参与,避免把用户带到不兼容预览版);时间表缺失或无满足项返回 null。
22
+ */
23
+ export declare function installableReleaseOf(packument: unknown, now?: number): NpmRelease | null;
12
24
  /** 请求体 → 去重后的合法包名列表;非数组 / 超量 / 含非法包名一律 null(拒绝非法输入)。 */
13
25
  export declare function parseReleaseAgeRequest(body: unknown): string[] | null;
14
- /** 查询一个包的最新版本与发布时间(成功结果按源缓存 10 分钟);registry 为空回退官方源,失败返回 null。 */
15
- export declare function lookupReleaseAge(packageName: string, registry: string, proxy: string, timeoutMs?: number): Promise<NpmRelease | null>;
26
+ /** 查询一个包的最新版本、发布时间与可钉住的安装版本(成功结果按源缓存 10 分钟);registry 为空回退官方源,失败返回 null。 */
27
+ export declare function lookupReleaseAge(packageName: string, registry: string, proxy: string, timeoutMs?: number): Promise<NpmReleaseWithInstallable | null>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin",
3
- "version": "2.3.1",
3
+ "version": "2.3.2",
4
4
  "description": "A community plugin marketplace for DeepSeek Harness, built to the official plugin spec — browse, search and install 10000+ human-curated community plugins without leaving the app. · DeepSeek Harness 社区插件市场(遵循官方开发规范):10000+ 人工精选社区插件,每日更新。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -11,10 +11,10 @@ import type { MouseEvent } from 'react'
11
11
  import styles from '../styles/Header.module.css'
12
12
  import modalStyles from '../styles/Modal.module.css'
13
13
  import type { EnvInfo, HubPlugin, InstallChannel, SectionProps, ToastState } from '../types.ts'
14
- import { installCommandOf, repoFromInstallTarget } from '../logic/install-command.ts'
14
+ import { installCommandOf, installTargetOf, repoFromInstallTarget } from '../logic/install-command.ts'
15
15
  import { PLUGIN_VERSION } from '../logic/constants.ts'
16
16
  import { ensurePluginCss } from '../logic/ensure-plugin-css.ts'
17
- import { getEnv, revealInstallFolder } from '../data/host.ts'
17
+ import { fetchNpmReleaseAge, getEnv, revealInstallFolder } from '../data/host.ts'
18
18
  import { useCatalog } from '../hooks/useCatalog.ts'
19
19
  import { useLanguage } from '../hooks/useLanguage.ts'
20
20
  import { useSettings } from '../hooks/useSettings.ts'
@@ -76,9 +76,11 @@ export function PluginHubSection({ t: _hostT, locale }: SectionProps) {
76
76
  const [confirmPlugin, setConfirmPlugin] = useState<HubPlugin | null>(null)
77
77
  /** 弹窗动作是否为「更新」:已安装插件点「更新」→ 走同一条 add 命令原位覆盖重装,文案区分安装/更新 */
78
78
  const [confirmIsUpdate, setConfirmIsUpdate] = useState(false)
79
- /** Hub 自我更新指定的精确版本:连续发版时提示的是「已过供应链门禁」的旧一版,
80
- * 安装必须钉在该版本上,否则又会被 @latest 带回门禁内的最新版。 */
79
+ /** 安装要钉住的精确版本:Hub 连续发版时提示的旧一版、以及新安装的「已过供应链门禁」版本,
80
+ * 都必须钉住,否则 @latest 会被 pnpm 门禁带回门禁内的版本或静默回退到很旧的版本。 */
81
81
  const [confirmPinVersion, setConfirmPinVersion] = useState<string | null>(null)
82
+ /** 门禁版本查询的在途序号:只采用最后一次弹窗的查询结果,避免切换插件后旧结果覆盖 */
83
+ const installPinSeq = useRef(0)
82
84
  /** 命令行安装确认弹窗:记录待安装的裸目标(npm 包名)——
83
85
  * 与应用商店同一套确认/进度/结果弹窗,提供时 plugin 传 null 走 customTarget 模式 */
84
86
  const [confirmCustomTarget, setConfirmCustomTarget] = useState<string | null>(null)
@@ -321,9 +323,9 @@ export function PluginHubSection({ t: _hostT, locale }: SectionProps) {
321
323
  }
322
324
 
323
325
  /** 弹窗动作一:复制安装命令到剪贴板,引导去终端粘贴执行(npm 安装显示包名命令)。 */
324
- const copyCommand = async (p: HubPlugin) => {
326
+ const copyCommand = async (p: HubPlugin, version?: string) => {
325
327
  const repo = p.source?.repo ?? ''
326
- const ok = await doCopy(installCommandOf(p))
328
+ const ok = await doCopy(installCommandOf(p, false, version))
327
329
  if (ok) {
328
330
  setCopied(repo)
329
331
  setToast({ id: Date.now(), kind: 'copied' })
@@ -332,6 +334,21 @@ export function PluginHubSection({ t: _hostT, locale }: SectionProps) {
332
334
  setConfirmPlugin(null)
333
335
  }
334
336
 
337
+ /** 新安装先查「已过 pnpm 供应链门禁」的版本:命令条与执行都钉住它,
338
+ * 否则 pnpm 会把发布未满 24h 的最新版静默回退成很旧的版本。查不到则不钉,由服务端兜底解析。 */
339
+ const resolveInstallPin = (p: HubPlugin) => {
340
+ // 目录下发了官方安装命令的条目(CLI-only / 人工干预)只展示该命令,追加版本会改坏它
341
+ if (p.install?.command !== undefined && p.install.command !== '') return
342
+ const pkg = installTargetOf(p)
343
+ if (!pkg) return
344
+ const seq = ++installPinSeq.current
345
+ void fetchNpmReleaseAge([pkg]).then((res) => {
346
+ if (installPinSeq.current !== seq) return
347
+ const version = res?.[pkg]?.installable?.version
348
+ if (version !== undefined && version !== '') setConfirmPinVersion(version)
349
+ })
350
+ }
351
+
335
352
  /** 卸载弹窗动作:复制卸载命令,万一直接卸载失败可去终端手动执行。
336
353
  * 自定义安装(无目录数据)按已安装项包名直卸,同样给复制通道。 */
337
354
  const copyUninstallCommand = async () => {
@@ -451,12 +468,17 @@ export function PluginHubSection({ t: _hostT, locale }: SectionProps) {
451
468
  ? t('pluginsTotal', { n: count })
452
469
  : t('filterResults', { n: count }),
453
470
  onInstall: (p, opts) => {
471
+ const update = opts?.update ?? false
454
472
  setInstallDone(false)
455
- setConfirmIsUpdate(opts?.update ?? false)
473
+ setConfirmIsUpdate(update)
456
474
  setConfirmPinVersion(null)
475
+ // 本次弹窗重新开始:作废上一次仍在途的门禁版本查询
476
+ ++installPinSeq.current
457
477
  // 与卸载一致:重置弹窗关联任务,避免新弹窗误匹配到进行中的任务而禁用安装按钮
458
478
  queue.clearModalTask()
459
479
  setConfirmPlugin(p)
480
+ // 更新走 @latest 语义(客户端已按门禁筛选),只有新安装需要钉住门禁内可用的版本
481
+ if (!update) resolveInstallPin(p)
460
482
  },
461
483
  onUninstall: (p) => {
462
484
  setUninstallDone(false)
@@ -489,6 +511,8 @@ export function PluginHubSection({ t: _hostT, locale }: SectionProps) {
489
511
  setInstallDone(false)
490
512
  setConfirmIsUpdate(true)
491
513
  setConfirmPinVersion(null)
514
+ // 更新不钉版本:作废可能仍在途的新安装门禁查询
515
+ ++installPinSeq.current
492
516
  queue.clearModalTask()
493
517
  setConfirmPlugin(item.plugin)
494
518
  },
@@ -567,6 +591,8 @@ export function PluginHubSection({ t: _hostT, locale }: SectionProps) {
567
591
  setConfirmIsUpdate(true)
568
592
  // 钉住本次提示的版本:最新版可能仍在门禁内,@latest 会被 pnpm 拒绝
569
593
  setConfirmPinVersion(catalog.hubUpdateTarget?.version ?? null)
594
+ // 作废可能仍在途的新安装门禁查询,避免它覆盖本次钉住的版本
595
+ ++installPinSeq.current
570
596
  queue.clearModalTask()
571
597
  setConfirmPlugin(hubEntry)
572
598
  }
@@ -668,6 +694,7 @@ export function PluginHubSection({ t: _hostT, locale }: SectionProps) {
668
694
  langPath,
669
695
  restarting,
670
696
  update: confirmIsUpdate,
697
+ pinVersion: confirmPinVersion ?? undefined,
671
698
  // 仅命令行插件(webInstallable=false / 人工干预 manualInstall):弹窗只展示命令供复制,不提供一键安装
672
699
  cliOnly: confirmPlugin.install?.webInstallable === false || confirmPlugin.install?.manualInstall === true,
673
700
  submitting: queue.submitting,
@@ -681,8 +708,12 @@ export function PluginHubSection({ t: _hostT, locale }: SectionProps) {
681
708
  setInstallBundleDeselected(false)
682
709
  if (reload) window.location.reload()
683
710
  },
684
- onCopy: () => copyCommand(confirmPlugin),
685
- onInstall: () => queue.installNow(confirmPlugin, confirmIsUpdate ? { update: true, pinVersion: confirmPinVersion ?? undefined } : undefined),
711
+ onCopy: () => copyCommand(confirmPlugin, confirmPinVersion ?? undefined),
712
+ onInstall: () => queue.installNow(confirmPlugin, {
713
+ update: confirmIsUpdate,
714
+ // 新安装钉住门禁版本:查询尚未回来时为空,服务端会自行解析
715
+ pinVersion: confirmPinVersion ?? undefined,
716
+ }),
686
717
  // 重启:结果视图「立即重启」也会中断进行中的任务 → 先弹重启确认弹窗
687
718
  onRestart: () => setShowRestartConfirm(true),
688
719
  }),
@@ -90,6 +90,8 @@ export interface InstallModalProps {
90
90
  restarting: boolean
91
91
  /** 已安装插件的覆盖更新(走同一条 add 命令原位重装,文案区分安装/更新) */
92
92
  update: boolean
93
+ /** 已过供应链门禁的安装版本:命令条带上它,手抄执行与一键安装结果一致(未查到时不传) */
94
+ pinVersion?: string
93
95
  /** 仅命令行插件(webInstallable=false):不提供一键安装,只展示命令供复制到 dsh 终端 */
94
96
  cliOnly: boolean
95
97
  /** 安装请求在途(fetch 等待响应):此时任务尚未入队,需禁用确认按钮防止二次点击 */
@@ -112,7 +114,7 @@ export interface InstallModalProps {
112
114
  * 目录插件与命令行安装(customTarget 模式)共用同一套确认/进度/结果流程。
113
115
  */
114
116
  export function InstallModal(props: InstallModalProps) {
115
- const { plugin, customTarget, globalNpm, done, task, t, langPath, restarting, submitting, update, cliOnly, needsRestart, needsReload, bundleDeselected, onClose, onCopy, onInstall, onRestart } = props
117
+ const { plugin, customTarget, globalNpm, done, task, t, langPath, restarting, submitting, update, pinVersion, cliOnly, needsRestart, needsReload, bundleDeselected, onClose, onCopy, onInstall, onRestart } = props
116
118
  const busy = submitting || (task !== null && (task.status === 'pending' || task.status === 'running'))
117
119
  // 进行中标题带上插件名(中文「XX 插件安装中」;英文状态词在前更自然),并用状态色区分;
118
120
  // 命令行安装无插件元数据 → 直接用输入的目标展示;全局 npm 安装 → 包列表空格拼接
@@ -191,7 +193,7 @@ export function InstallModal(props: InstallModalProps) {
191
193
  h('span', { className: styles.modalCmdText },
192
194
  globalNpm !== undefined && globalNpm.length > 0
193
195
  ? `npm install -g ${globalNpm.join(' ')}`
194
- : customTarget ? `pnpm add ${customTarget}` : installCommandOf(plugin!)),
196
+ : customTarget ? `pnpm add ${customTarget}` : installCommandOf(plugin!, false, pinVersion)),
195
197
  h('span', { className: styles.modalCmdCopy }, h(CopyIcon), t('copyCmdLabel')),
196
198
  ),
197
199
  // 全局 npm 安装说明:装的是系统级 CLI 工具,不进插件列表、无需重启宿主
@@ -48,6 +48,8 @@ export async function fetchInstalled(): Promise<HostInstalled | null> {
48
48
  export interface NpmReleaseInfo {
49
49
  version: string
50
50
  publishedAt: string
51
+ /** 已过 pnpm 供应链门禁的最高稳定版:安装/展示命令钉住它;无可钉版本时为 null。 */
52
+ installable?: NpmReleaseInfo | null
51
53
  }
52
54
 
53
55
  /** 批量查询已安装插件 npm 包的最新版本发布时间(供应链门禁用);失败返回 null(调用方按原逻辑照常提示)。 */
@@ -562,7 +562,7 @@ export function useTaskQueue(opts: TaskQueueOptions) {
562
562
  desc: p.description,
563
563
  version: p.version,
564
564
  updatedAt: p.dates?.repoUpdatedAt,
565
- command: installCommandOf(p, true),
565
+ command: installCommandOf(p, true, opts?.pinVersion),
566
566
  source: 'catalog',
567
567
  update: opts?.update,
568
568
  pinVersion: opts?.pinVersion,
@@ -404,7 +404,7 @@ export const zh = {
404
404
  failKind_pluginMissingDep: '插件依赖未发布',
405
405
  failReason_pluginMissingDep: '插件声明依赖的包在官方 npm 源上不存在(已删除或从未发布)。',
406
406
  failKind_registryVersionStale: '该版本在所用源上不存在',
407
- failReason_registryVersionStale: '实际安装用的源还没同步到这个版本,或版本号写错。',
407
+ failReason_registryVersionStale: '实际安装用的源还没同步到这个版本。可稍后重试,或到「设置 → npm 镜像源」换成官方源;也可先安装上一个可用版本。',
408
408
  failKind_registryAuth: 'npm 源拒绝了访问',
409
409
  failReason_registryAuth: 'registry 返回 401/403:这个源需要登录凭据,或当前网络不被允许。',
410
410
  failKind_profileExclusive: 'profile 由桌面应用独占管理',
@@ -510,10 +510,10 @@ export const zh = {
510
510
  close: '关闭',
511
511
  // 暂缓提示:远端确有新版本,但发布未满 24 小时(pnpm 供应链安全门槛),与「已是最新」严格区分
512
512
  hubPendingDesc: '最新版已发布,但发布尚未满 24 小时:此时更新会被 pnpm 静默回退到旧版本,因此暂不提示。稍后这里会自动出现更新入口。',
513
- // 头部「关注我们」弹窗:平台介绍 + 用户反馈群二维码(内容由 Worker /about Markdown 推送,非写死)
513
+ // 头部「关注我们」弹窗:平台介绍(内容由 Worker /about Markdown 推送,非写死)
514
514
  followUs: '关注我们',
515
515
  aboutTitle: '关注我们',
516
- aboutDesc: '了解 DSH Plugin Hub 是做什么的,加入用户反馈群随时交流。',
516
+ aboutDesc: '了解 DSH Plugin Hub 是做什么的,访问主站浏览插件,或到 GitHub 提交 Issue。',
517
517
  aboutEmpty: '内容暂未发布,敬请期待。',
518
518
  aboutUpdated: '更新于',
519
519
  empty: '该分类暂无插件',
@@ -915,7 +915,7 @@ export const en = {
915
915
  failKind_pluginMissingDep: 'plugin dependency is not published',
916
916
  failReason_pluginMissingDep: 'A package the plugin depends on does not exist on the official npm registry.',
917
917
  failKind_registryVersionStale: 'this version is not available on the registry in use',
918
- failReason_registryVersionStale: 'The registry that actually performs the install has not synced this version yet, or the version is mistyped.',
918
+ failReason_registryVersionStale: 'The registry that actually performs the install has not synced this version yet. Retry later, switch to the official registry under Settings → npm mirror, or install a previous version for now.',
919
919
  failKind_registryAuth: 'the npm registry rejected access',
920
920
  failReason_registryAuth: 'The registry returned 401/403: it needs credentials, or the current network is not allowed.',
921
921
  failKind_profileExclusive: 'the profile is managed only by the desktop app',
@@ -1019,10 +1019,10 @@ export const en = {
1019
1019
  close: 'Close',
1020
1020
  // 暂缓提示:确有新版本,但仍在 pnpm 24h 供应链门禁窗口内
1021
1021
  hubPendingDesc: 'The latest version has been released, but it is still within the 24-hour window where pnpm silently falls back to the older version, so the update is not offered yet. The update entry will appear here shortly.',
1022
- // 头部「关注我们」弹窗:平台介绍 + 用户反馈群二维码(内容由 Worker /about 以 Markdown 推送)
1022
+ // 头部「关注我们」弹窗:平台介绍(内容由 Worker /about 以 Markdown 推送)
1023
1023
  followUs: 'Follow us',
1024
1024
  aboutTitle: 'Follow us',
1025
- aboutDesc: 'Learn what DSH Plugin Hub does and join our user feedback group.',
1025
+ aboutDesc: 'Learn what DSH Plugin Hub does — browse plugins on the website, or open an Issue on GitHub.',
1026
1026
  aboutEmpty: 'Content not published yet — stay tuned.',
1027
1027
  aboutUpdated: 'Updated',
1028
1028
  empty: 'No plugins in this category yet',
@@ -29,12 +29,15 @@ export function installTargetOf(p: HubPlugin): string {
29
29
 
30
30
  /** 展示用安装命令(复制/弹窗):目录下发的权威命令优先(CLI-only 插件如 dsh-tui
31
31
  * 需专属 profile(--profile dsh-tui),无法从 npm 包名推断,必须用官方命令);
32
- * 常规插件无目录命令时用 npm 包名回退生成。 */
33
- export function installCommandOf(p: HubPlugin, withProfile = false): string {
32
+ * 常规插件无目录命令时用 npm 包名回退生成。
33
+ * version 为已过供应链门禁的版本:带上它,手抄命令与原位安装的执行结果一致,
34
+ * 不会因 pnpm 门禁静默回退到很旧的版本。 */
35
+ export function installCommandOf(p: HubPlugin, withProfile = false, version?: string): string {
34
36
  const cmd = p.install?.command
35
37
  if (cmd) return cmd
36
38
  const prefix = `dsh plugin${withProfile ? ' --profile web' : ''} add `
37
- return `${prefix}${installTargetOf(p)}`
39
+ const target = installTargetOf(p)
40
+ return `${prefix}${version === undefined || version === '' ? target : `${target}@${version}`}`
38
41
  }
39
42
 
40
43
  /** 把任务/安装目标归一化为 owner/repo 展示身份。 */
@@ -12,6 +12,7 @@ import { isDshNpmPackageForRepo } from '../services/install/npm-resolve.ts'
12
12
  import { probeUrl, systemProxy } from '../services/probe.ts'
13
13
  import { loadSettings, type HubSettings } from '../services/settings.ts'
14
14
  import { registryCandidates, registryHost, userNpmRegistry } from '../services/install/registry-fallback.ts'
15
+ import { lookupReleaseAge } from '../services/npm-release-age.ts'
15
16
  import { profileDirectory } from '../services/profile/profile.ts'
16
17
  import { readInstalled } from './catalog.ts'
17
18
  import { COMMAND_TIMEOUT_MS, readJsonBody, requireTrustedPost, sendJson, type WebRoute, type WebServerService } from './shared.ts'
@@ -181,6 +182,15 @@ export function registerInstallRoutes(webServer: WebServerService, profile: stri
181
182
  }
182
183
  ordered = [chosen, ...registries.filter((r) => r !== chosen)]
183
184
  }
185
+ // 新安装钉住「已过供应链门禁」的版本:pnpm 对发布未满 24h 的版本会静默回退到很旧的版本,
186
+ // 用户装完才发现功能缺失且没有任何提示。更新已有目标时客户端已按门禁筛选,继续走 @latest。
187
+ let installSpec = pinVersion !== '' ? `${target}@${pinVersion}` : undefined
188
+ if (installSpec === undefined && already === null) {
189
+ // 解析源与安装首选源一致,钉住的版本一定存在于真正会用的那个源;解析失败则不钉,不阻断安装。
190
+ // 超时压到 5s:网络刚探通,慢也只在极端情况,不能为查版本把安装请求拖住 8s
191
+ const release = await lookupReleaseAge(target, ordered[0] ?? '', effectiveProxy, 5000)
192
+ if (release !== null && release.installable !== null) installSpec = `${target}@${release.installable.version}`
193
+ }
184
194
  // 入队前复检:网络探测的 await 期间并发请求可能已通过上方检查,而此处到 startPluginMutation
185
195
  // 之间无 await,JS 单线程保证同一目标至多一个任务,杜绝双击/并发双任务。
186
196
  if (hasQueuedTarget(target)) {
@@ -204,7 +214,7 @@ export function registerInstallRoutes(webServer: WebServerService, profile: stri
204
214
  env: mutationEnv(settings),
205
215
  // 候选源(首选在前):任务内遇到传输层失败时按顺序换源重试
206
216
  registries: ordered,
207
- installSpec: pinVersion !== '' ? `${target}@${pinVersion}` : undefined,
217
+ installSpec,
208
218
  // 自定义安装入口渠道:日志/报错据此溯源
209
219
  installChannel,
210
220
  })
@@ -8,6 +8,8 @@
8
8
  */
9
9
  import { systemProxy } from '../services/probe.ts'
10
10
  import { lookupReleaseAge, parseReleaseAgeRequest } from '../services/npm-release-age.ts'
11
+ import { userNpmRegistry } from '../services/install/registry-fallback.ts'
12
+ import { profileDirectory } from '../services/profile/profile.ts'
11
13
  import { loadSettings } from '../services/settings.ts'
12
14
  import { readJsonBody, requireTrustedPost, sendJson, type WebRoute, type WebServerService } from './shared.ts'
13
15
 
@@ -30,8 +32,12 @@ export function registerNpmReleaseAgeRoutes(webServer: WebServerService, profile
30
32
  ? settings.proxy
31
33
  : (systemProxy() ?? process.env.HTTPS_PROXY ?? process.env.https_proxy ?? '')
32
34
  // 并发查询:单包各自带超时且失败即 null,整体不因任一包失败而失败
35
+ // 查询源与安装首选源同口径(设置 → 本机 npm 配置):安装钉住的版本必须来自真正要用的那个源
36
+ const registry = settings.npmRegistry !== ''
37
+ ? settings.npmRegistry
38
+ : userNpmRegistry(profileDirectory(profile))
33
39
  const results = await Promise.all(packages.map(async (name) =>
34
- [name, await lookupReleaseAge(name, settings.npmRegistry, proxy)] as const))
40
+ [name, await lookupReleaseAge(name, registry, proxy)] as const))
35
41
  sendJson(response, 200, { packages: Object.fromEntries(results) })
36
42
  } catch (error) {
37
43
  sendJson(response, 500, { error: error instanceof Error ? error.message : String(error) })
@@ -17,6 +17,15 @@ export interface NpmRelease {
17
17
  publishedAt: string
18
18
  }
19
19
 
20
+ /** 最新版 + 可钉住的安装版本:安装时钉住后者,pnpm 才不会把「发布未满门禁」的最新版回退成很旧的版本。 */
21
+ export interface NpmReleaseWithInstallable extends NpmRelease {
22
+ /** 已过供应链门禁的最高稳定版;时间表缺失或没有满足项时为 null(调用方退回不钉版本)。 */
23
+ installable: NpmRelease | null
24
+ }
25
+
26
+ /** pnpm profile 默认 minimumReleaseAge=1440 分钟;+30 分钟缓冲与客户端 release-age 判定同口径。 */
27
+ export const MIN_RELEASE_AGE_MS = 24 * 60 * 60 * 1000 + 30 * 60 * 1000
28
+
20
29
  /** 请求体包名数量上限:只为已安装插件按需查询,几十个足矣,封顶防滥用。 */
21
30
  export const MAX_RELEASE_AGE_PACKAGES = 50
22
31
  /** 单包查询超时(ms):慢网络下失败即返回 null,不拖住整个响应。 */
@@ -29,7 +38,7 @@ export const DEFAULT_NPM_REGISTRY = 'https://registry.npmjs.org'
29
38
  * 必须带过期时间 —— 插件中心可能连续开着几小时,作者发了新版本后不能一直沿用旧结果;
30
39
  * 也必须把源算进键 —— 同一个包在官方源与镜像上的 latest / 发布时间不同,混用会算错门禁。 */
31
40
  const CACHE_TTL_MS = 10 * 60 * 1000
32
- const releaseCache = new Map<string, { at: number; release: NpmRelease }>()
41
+ const releaseCache = new Map<string, { at: number; release: NpmReleaseWithInstallable }>()
33
42
 
34
43
  /** 从完整 packument 取 dist-tags.latest 对应版本及其发布时间;缺任一字段返回 null。 */
35
44
  export function latestReleaseOf(packument: unknown): NpmRelease | null {
@@ -44,6 +53,35 @@ export function latestReleaseOf(packument: unknown): NpmRelease | null {
44
53
  return { version, publishedAt }
45
54
  }
46
55
 
56
+ /**
57
+ * 已过供应链门禁的最高稳定版本:安装时钉住它,pnpm 就不会把最新版静默回退成很旧的版本。
58
+ * 只看纯 x.y.z(预发布版不参与,避免把用户带到不兼容预览版);时间表缺失或无满足项返回 null。
59
+ */
60
+ export function installableReleaseOf(packument: unknown, now = Date.now()): NpmRelease | null {
61
+ if (packument === null || typeof packument !== 'object') return null
62
+ const time = (packument as { time?: unknown }).time
63
+ if (time === null || typeof time !== 'object') return null
64
+ let best: NpmRelease | null = null
65
+ for (const [version, published] of Object.entries(time as Record<string, unknown>)) {
66
+ if (!/^\d+\.\d+\.\d+$/.test(version) || typeof published !== 'string') continue
67
+ const at = Date.parse(published)
68
+ if (Number.isNaN(at) || now - at < MIN_RELEASE_AGE_MS) continue
69
+ if (best === null || compareVersion(version, best.version) > 0) best = { version, publishedAt: published }
70
+ }
71
+ return best
72
+ }
73
+
74
+ /** 纯数字段版本比较(installableReleaseOf 只在 x.y.z 里用)。 */
75
+ function compareVersion(a: string, b: string): number {
76
+ const pa = a.split('.')
77
+ const pb = b.split('.')
78
+ for (let i = 0; i < 3; i++) {
79
+ const d = Number.parseInt(pa[i] ?? '0', 10) - Number.parseInt(pb[i] ?? '0', 10)
80
+ if (d !== 0) return d
81
+ }
82
+ return 0
83
+ }
84
+
47
85
  /** 请求体 → 去重后的合法包名列表;非数组 / 超量 / 含非法包名一律 null(拒绝非法输入)。 */
48
86
  export function parseReleaseAgeRequest(body: unknown): string[] | null {
49
87
  if (body === null || typeof body !== 'object') return null
@@ -90,13 +128,13 @@ async function fetchPackument(url: string, proxy: string, timeoutMs: number): Pr
90
128
  return getJson(url, timeoutMs)
91
129
  }
92
130
 
93
- /** 查询一个包的最新版本与发布时间(成功结果按源缓存 10 分钟);registry 为空回退官方源,失败返回 null。 */
131
+ /** 查询一个包的最新版本、发布时间与可钉住的安装版本(成功结果按源缓存 10 分钟);registry 为空回退官方源,失败返回 null。 */
94
132
  export async function lookupReleaseAge(
95
133
  packageName: string,
96
134
  registry: string,
97
135
  proxy: string,
98
136
  timeoutMs = RELEASE_AGE_TIMEOUT_MS,
99
- ): Promise<NpmRelease | null> {
137
+ ): Promise<NpmReleaseWithInstallable | null> {
100
138
  const base = registry.replace(/\/+$/, '') || DEFAULT_NPM_REGISTRY
101
139
  const key = `${base}\n${packageName}`
102
140
  const cached = releaseCache.get(key)
@@ -105,7 +143,9 @@ export async function lookupReleaseAge(
105
143
  if (body === null) return null
106
144
  let parsed: unknown
107
145
  try { parsed = JSON.parse(body) } catch { return null }
108
- const release = latestReleaseOf(parsed)
109
- if (release !== null) releaseCache.set(key, { at: Date.now(), release })
146
+ const latest = latestReleaseOf(parsed)
147
+ if (latest === null) return null
148
+ const release: NpmReleaseWithInstallable = { ...latest, installable: installableReleaseOf(parsed) }
149
+ releaseCache.set(key, { at: Date.now(), release })
110
150
  return release
111
151
  }