dsh-aupdate 0.8.0 → 0.8.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/README.md CHANGED
@@ -216,6 +216,24 @@ stargazers)与「分享」(复制项目地址到剪贴板,任何环境都
216
216
  已经卸下之后才拒绝的,不能让它走到那一步)。版本列表按包按需拉,不进首屏:整页一次拉一排
217
217
  包的 packument,在镜像上会慢到没法用。
218
218
 
219
+ 这一页还把 aupdate 自己的设置嵌了进来(工具条上的「设置」),改完不用切回设置页。
220
+
221
+ 工具条从左到右:搜索、检查更新(绕过缓存)、一键升级、升级选中 N 个、注册表、复制诊断、设置。
222
+ 顶部三个数字分别是**需处理**(已装版本声明的 DSH 范围不满足,或者读不到已装版本——这些包很可能
223
+ 根本没被加载,升级救不了它们)、**可升级**、**已装**。
224
+
225
+ 「注册表」面板列出三档预设,每行能单独测(`/-/ping` 和根地址同时发,谁先答应用谁,整次 5 秒
226
+ 封顶),也能直接切过去;自定义源可以填完先测再切。
227
+
228
+ ## 显示位置
229
+
230
+ 设置页有一组开关,决定这个插件挂在哪些地方:**设置 → 插件更新**、**插件页里的那一行**、
231
+ **插件配置页**、**插件页「版本管理」标签**。关掉的那一处干脆不注册槽位,而不是挂上去再渲染成
232
+ 空条目。
233
+
234
+ 「挂不挂」是在插件加载时决定的,而那时读不到后端设置,所以选择会在 localStorage 里存一份镜像
235
+ 供加载时同步读取;改完开关后插件会**就地重载**一次,新的一组槽位立刻生效,不用重启 DSH。
236
+
219
237
  ## 安装源与兼容性预检
220
238
 
221
239
  设置页的「安装源」有三档预设加一个自定义:**跟随 pnpm**(默认,一个字节都不改)/ 官方源 /
@@ -498,6 +516,29 @@ marked and their button disabled (the host's gate only refuses after the bundle
498
516
  must not be allowed to get that far). Version lists are fetched per package on demand, never on
499
517
  first paint: fetching packuments for a whole page of packages is unusably slow on a mirror.
500
518
 
519
+ This page also embeds aupdate's own settings (the **Settings** button in the toolbar), so there is
520
+ no need to switch back to the settings page.
521
+
522
+ The toolbar is: search, Check now (bypasses the cache), Upgrade all, Upgrade the N selected,
523
+ Registries, Copy diagnostics, Settings. The three numbers on top are **Needs attention** (the
524
+ installed version declares a DSH range this host does not satisfy, or the installed version is
525
+ unreadable — those bundles are likely not loaded at all, and upgrading cannot fix them),
526
+ **Upgradable**, and **Installed**.
527
+
528
+ The **Registries** panel lists the three presets, each with its own Test button (`/-/ping` and the
529
+ root URL are fired together and whichever answers first wins, inside a 5 s budget) and a switch; a
530
+ custom URL can be tested before it is used.
531
+
532
+ ## Where it shows
533
+
534
+ A group of switches decides which surfaces this plugin occupies: **Settings → Plugin updates**,
535
+ **the row in the plugins page**, **the plugin config page**, and **the plugins page Versions tab**.
536
+ A disabled surface is not registered at all, rather than registered and rendered empty.
537
+
538
+ Whether a slot is registered is decided at plugin load time, when the backend settings are not
539
+ readable, so the choice is mirrored into localStorage for that synchronous read; changing a switch
540
+ reloads the plugin in place, so the new set of slots takes effect without restarting DSH.
541
+
501
542
  ## Registry and compatibility pre-check
502
543
 
503
544
  Under Settings, **Registry** has three presets plus a custom value: **Follow pnpm** (the default,
package/client.js CHANGED
@@ -163,6 +163,31 @@ window.__ModuleLoader__.load({
163
163
  versionsNoop: '已经是这一版',
164
164
  versionsFail: '切换失败',
165
165
  versionsTotal: '共 {n} 个版本',
166
+ versionsChecks: '检查更新',
167
+ versionsUpgradeAll: '一键升级',
168
+ versionsUpgradePicked: '升级选中 {n}',
169
+ versionsSources: '注册表',
170
+ versionsSettings: '设置',
171
+ versionsHideSettings: '收起设置',
172
+ versionsTest: '测试',
173
+ versionsTesting: '测试中…',
174
+ versionsTestOk: '能连上({ms} ms)',
175
+ versionsTestFail: '连不上',
176
+ versionsUse: '切到这个源',
177
+ versionsCurrentSource: '当前',
178
+ versionsAttention: '需处理',
179
+ versionsUpgradable: '可升级',
180
+ versionsInstalledCount: '已装',
181
+ versionsCopied: '诊断信息已复制',
182
+ versionsCopyFail: '复制失败',
183
+ versionsDiagnostics: '复制诊断',
184
+ versionsCustomSource: '自定义源',
185
+ displayGroup: '显示位置',
186
+ displayHint: '关掉哪一处就不再挂那一处;改动会让插件就地重载一次生效,不用重启 DSH',
187
+ showSettings: '设置 → 插件更新',
188
+ showRow: '插件页里的这一行',
189
+ showBundle: '插件配置页',
190
+ showTab: '插件页「版本管理」标签',
166
191
  maxPerCycle: '一轮最多装几个',
167
192
  maxPerCycleHint: '0 表示不限。装包会一直占着 pnpm 锁,限一个数就把单次占用封顶,剩下的下一轮接着装',
168
193
  sessionIdle: '会话静默(分钟)',
@@ -345,6 +370,31 @@ window.__ModuleLoader__.load({
345
370
  versionsNoop: 'Already on this version',
346
371
  versionsFail: 'Switch failed',
347
372
  versionsTotal: '{n} versions',
373
+ versionsChecks: 'Check now',
374
+ versionsUpgradeAll: 'Upgrade all',
375
+ versionsUpgradePicked: 'Upgrade {n}',
376
+ versionsSources: 'Registries',
377
+ versionsSettings: 'Settings',
378
+ versionsHideSettings: 'Hide settings',
379
+ versionsTest: 'Test',
380
+ versionsTesting: 'Testing…',
381
+ versionsTestOk: 'Reachable ({ms} ms)',
382
+ versionsTestFail: 'Unreachable',
383
+ versionsUse: 'Use this',
384
+ versionsCurrentSource: 'current',
385
+ versionsAttention: 'Needs attention',
386
+ versionsUpgradable: 'Upgradable',
387
+ versionsInstalledCount: 'Installed',
388
+ versionsCopied: 'Diagnostics copied',
389
+ versionsCopyFail: 'Could not copy',
390
+ versionsDiagnostics: 'Copy diagnostics',
391
+ versionsCustomSource: 'Custom registry',
392
+ displayGroup: 'Where it shows',
393
+ displayHint: 'Turning one off stops registering that surface; the plugin reloads itself in place, no DSH restart',
394
+ showSettings: 'Settings → Plugin updates',
395
+ showRow: 'The row in the plugins page',
396
+ showBundle: 'Plugin config page',
397
+ showTab: 'Plugins page "Versions" tab',
348
398
  maxPerCycle: 'Installs per cycle',
349
399
  maxPerCycleHint: '0 means no limit. pnpm holds a lock for the whole install, so a cap bounds how long the profile stays busy; the rest wait for the next cycle',
350
400
  sessionIdle: 'Session quiet window (minutes)',
@@ -719,6 +769,41 @@ window.__ModuleLoader__.load({
719
769
  @media (prefers-reduced-motion:reduce){.dsh-au-toast{animation:none}}
720
770
  `
721
771
 
772
+ /* ── 显示位置 ─────────────────────────────────────────────────────────
773
+ *
774
+ * 四个挂载点各自可以被关掉。麻烦在于「挂不挂」是在 apply() 里决定的,
775
+ * 而 apply() 是同步的、拿不到后端的设置——设置要等 /state 回来。
776
+ *
777
+ * 所以把选择在 localStorage 里存一份镜像:设置页每次拿到 /state 就刷一次,
778
+ * apply() 同步读它。改完显示开关后后端会让插件就地重载一次,apply() 重新跑,
779
+ * 读到的就是新值——不需要重启 DSH。
780
+ *
781
+ * 读不到(第一次装、换浏览器)时全部按「显示」,和改造前一致。
782
+ */
783
+ const DISPLAY_KEY = 'dsh-aupdate:display'
784
+ const DISPLAY_FIELDS = ['showSettingsSection', 'showPluginsRow', 'showPluginsBundle', 'showVersionsTab']
785
+
786
+ function readDisplay() {
787
+ const value = { showSettingsSection: true, showPluginsRow: true, showPluginsBundle: true, showVersionsTab: true }
788
+ try {
789
+ const raw = window.localStorage.getItem(DISPLAY_KEY)
790
+ if (raw === null) return value
791
+ const parsed = JSON.parse(raw)
792
+ for (const key of DISPLAY_FIELDS) {
793
+ if (typeof parsed?.[key] === 'boolean') value[key] = parsed[key]
794
+ }
795
+ } catch {}
796
+ return value
797
+ }
798
+
799
+ function writeDisplay(settings) {
800
+ try {
801
+ const value = {}
802
+ for (const key of DISPLAY_FIELDS) value[key] = settings?.[key] !== false
803
+ window.localStorage.setItem(DISPLAY_KEY, JSON.stringify(value))
804
+ } catch {}
805
+ }
806
+
722
807
  /** 只注入一次:id 存在就跳过,重复挂载/热更新都不会叠出第二份样式表。 */
723
808
  function installStyles() {
724
809
  try {
@@ -1060,6 +1145,8 @@ window.__ModuleLoader__.load({
1060
1145
  applyLang(next?.settings?.lang)
1061
1146
  setState(next)
1062
1147
  setDraft(next.settings)
1148
+ // 把显示选择镜像到 localStorage:apply() 下次重载时同步读它。
1149
+ writeDisplay(next.settings)
1063
1150
  setPhase('ready')
1064
1151
  } catch {
1065
1152
  setPhase('error')
@@ -1142,6 +1229,11 @@ window.__ModuleLoader__.load({
1142
1229
  useEffect(() => () => {
1143
1230
  if (timerRef.current !== null) clearTimeout(timerRef.current)
1144
1231
  }, [])
1232
+ // 显示开关一改就刷镜像:就地重载是在 1.2 秒后发生的,那时 apply() 读的
1233
+ // 就是这份镜像——不跟着改,切换会看起来「没生效」,要再加载一次才对。
1234
+ useEffect(() => {
1235
+ if (draft !== null) writeDisplay(draft)
1236
+ }, [draft])
1145
1237
 
1146
1238
 
1147
1239
  /** 把后端进度翻成一行中文/英文;没进度就退回普通「正在检查」。 */
@@ -1371,6 +1463,16 @@ window.__ModuleLoader__.load({
1371
1463
  h('span', null, T.registry + ': ' + (state?.registry === '' || !state?.registry ? T.regPnpm : state.registry)),
1372
1464
  ),
1373
1465
  ),
1466
+ // 显示位置:四个挂载点各自可以关掉。设置本身存在后端,客户端只是把它镜像
1467
+ // 到 localStorage,供 apply() 在注册槽位时同步判断(见 readDisplay 的注释)。
1468
+ h('div', { className: S.card },
1469
+ h('h3', { className: S.h }, T.displayGroup),
1470
+ h('p', { className: S.note }, T.displayHint),
1471
+ h(SwitchRow, { label: T.showSettings, value: draft.showSettingsSection !== false, onChange: (v) => patch('showSettingsSection', v) }),
1472
+ h(SwitchRow, { label: T.showRow, value: draft.showPluginsRow !== false, onChange: (v) => patch('showPluginsRow', v) }),
1473
+ h(SwitchRow, { label: T.showBundle, value: draft.showPluginsBundle !== false, onChange: (v) => patch('showPluginsBundle', v) }),
1474
+ h(SwitchRow, { label: T.showTab, value: draft.showVersionsTab !== false, onChange: (v) => patch('showVersionsTab', v) }),
1475
+ ),
1374
1476
  h('div', { className: S.card },
1375
1477
  h('h3', { className: S.h }, T.keepTitle),
1376
1478
  h('p', { className: S.note }, T.keepHint),
@@ -1827,34 +1929,113 @@ window.__ModuleLoader__.load({
1827
1929
  * 版本列表按包按需拉(一次一个包),不进首屏:整页一次拉一堆包的 packument
1828
1930
  * 在镜像上会慢到没法用。
1829
1931
  */
1932
+ /**
1933
+ * 「版本管理」标签页。
1934
+ *
1935
+ * 复刻 dsh-plugin-upgrader 那个「版本」页的主干:一眼看清哪些能升、哪些有问题,
1936
+ * 一键升级 / 勾选升级,展开看全部已发布版本并切过去,装源开关与测源,复制诊断;
1937
+ * 再把 aupdate 自己的设置嵌进来,免得在两处之间来回跳。
1938
+ *
1939
+ * 和设置页的分工没变:设置页管「什么时候自动升」,这一页管「现在就要某一版」。
1940
+ */
1830
1941
  function VersionsTab() {
1831
1942
  useLang()
1832
1943
  const [state, setState] = useState(null)
1833
1944
  const [query, setQuery] = useState('')
1945
+ const [picked, setPicked] = useState({})
1834
1946
  const [openName, setOpenName] = useState('')
1835
1947
  const [lists, setLists] = useState({})
1836
1948
  const [loadError, setLoadError] = useState('')
1837
1949
  const [busy, setBusy] = useState('')
1838
1950
  const [hint, setHint] = useState('')
1951
+ const [showSettings, setShowSettings] = useState(false)
1952
+ const [showSources, setShowSources] = useState(false)
1953
+ const [sourceUrl, setSourceUrl] = useState('')
1954
+ const [testing, setTesting] = useState('')
1955
+ const [tested, setTested] = useState(null)
1839
1956
 
1840
1957
  const reload = useCallback(async () => {
1841
1958
  try {
1842
- setState(await getState(LANG))
1959
+ const next = await getState(LANG)
1960
+ setState(next)
1961
+ writeDisplay(next?.settings)
1843
1962
  } catch {}
1844
1963
  }, [])
1845
1964
 
1846
1965
  useEffect(() => { void reload() }, [reload])
1847
1966
 
1848
- // 切版本可能要好几分钟(pnpm 要校验锁文件),期间才轮询;闲着时一个请求都不发。
1967
+ // 空闲时 15 秒拉一次 /state(不碰 registry),够让统计跟上后台轮次;
1968
+ // 切版本/跑一轮期间改回 3 秒,进度才跟得上。
1849
1969
  useEffect(() => {
1850
- if (busy === '') return undefined
1851
- const timer = setInterval(async () => {
1852
- try {
1853
- setState(await getState(LANG))
1854
- } catch {}
1855
- }, 3000)
1970
+ const every = busy === '' ? 15000 : 3000
1971
+ const timer = setInterval(() => { void reload() }, every)
1856
1972
  return () => clearInterval(timer)
1857
- }, [busy])
1973
+ }, [busy, reload])
1974
+
1975
+ const post = useCallback(async (path, body) => {
1976
+ try {
1977
+ const response = await fetch(endpoint(path) + langQuery(), {
1978
+ method: 'POST',
1979
+ headers: { 'content-type': 'application/json', accept: 'application/json' },
1980
+ body: JSON.stringify(body),
1981
+ })
1982
+ const payload = await response.json().catch(() => null)
1983
+ return { ok: response.ok, payload }
1984
+ } catch {
1985
+ return { ok: false, payload: null }
1986
+ }
1987
+ }, [])
1988
+
1989
+ const packages = useMemo(() => (Array.isArray(state?.packages) ? state.packages : []), [state])
1990
+ const rows = useMemo(() => {
1991
+ const needle = query.trim().toLowerCase()
1992
+ return needle === '' ? packages : packages.filter((item) => String(item.name).toLowerCase().includes(needle))
1993
+ }, [packages, query])
1994
+
1995
+ // 最近一轮里「查到的可更新版本」和「镜像落后」:都用名字索引,行上直接查。
1996
+ const updatable = useMemo(() => {
1997
+ const mark = new Map()
1998
+ for (const item of (Array.isArray(state?.lastRun?.updates) ? state.lastRun.updates : [])) {
1999
+ const row = describeUpdate(item)
2000
+ if (row !== null) mark.set(row.name, row.versions)
2001
+ }
2002
+ return mark
2003
+ }, [state])
2004
+ const lagged = useMemo(() => {
2005
+ const mark = new Map()
2006
+ for (const item of (Array.isArray(state?.lastRun?.lagged) ? state.lastRun.lagged : [])) {
2007
+ if (item !== null && typeof item === 'object' && typeof item.name === 'string') {
2008
+ mark.set(item.name, (item.mirror || '?') + ' → ' + (item.upstream || '?'))
2009
+ }
2010
+ }
2011
+ return mark
2012
+ }, [state])
2013
+
2014
+ const attention = useMemo(() => packages.filter((item) => item.ok === false || item.version === ''), [packages])
2015
+ const pickedNames = useMemo(() => packages.filter((item) => picked[item.name] === true).map((item) => item.name), [packages, picked])
2016
+
2017
+ const copyDiagnostics = useCallback(async () => {
2018
+ const lines = [
2019
+ T.versionsTitle + ' — dsh-aupdate ' + (state?.version ?? '?'),
2020
+ 'DSH ' + (state?.dshVersion ?? 'unknown'),
2021
+ T.registry + ': ' + (state?.registry === '' || !state?.registry ? T.regPnpm : state.registry),
2022
+ '',
2023
+ ]
2024
+ for (const item of packages) {
2025
+ const flags = []
2026
+ if (item.ok === false) flags.push('needs DSH ' + (item.need || '?'))
2027
+ if (item.version === '') flags.push('not installed')
2028
+ if (updatable.get(item.name) !== undefined) flags.push('updatable -> ' + updatable.get(item.name))
2029
+ if (lagged.get(item.name) !== undefined) flags.push('mirror lag -> ' + lagged.get(item.name))
2030
+ lines.push('- ' + item.name + ' ' + (item.version || '?') + (flags.length > 0 ? ' ' + flags.join('; ') : ''))
2031
+ }
2032
+ try {
2033
+ await navigator.clipboard.writeText(lines.join(String.fromCharCode(10)))
2034
+ setHint(T.versionsCopied)
2035
+ } catch {
2036
+ setHint(T.versionsCopyFail)
2037
+ }
2038
+ }, [state, packages, updatable, lagged])
1858
2039
 
1859
2040
  const openVersions = useCallback(async (name) => {
1860
2041
  if (openName === name) {
@@ -1881,37 +2062,45 @@ window.__ModuleLoader__.load({
1881
2062
  if (busy !== '') return
1882
2063
  setBusy(name + '@' + version)
1883
2064
  setHint('')
1884
- try {
1885
- const response = await fetch(endpoint('switch') + langQuery(), {
1886
- method: 'POST',
1887
- headers: { 'content-type': 'application/json', accept: 'application/json' },
1888
- body: JSON.stringify({ name, version }),
2065
+ const { ok, payload } = await post('switch', { name, version })
2066
+ if (ok) {
2067
+ setHint(payload?.unchanged === true ? T.versionsNoop : T.versionsDone.replace('{v}', version))
2068
+ setLists((prev) => {
2069
+ const next = { ...prev }
2070
+ delete next[name]
2071
+ return next
1889
2072
  })
1890
- const payload = await response.json().catch(() => null)
1891
- if (response.ok) {
1892
- setHint(payload?.unchanged === true ? T.versionsNoop : T.versionsDone.replace('{v}', version))
1893
- // 版本变了,这个包的缓存列表要作废,否则「当前」标记还停在旧版本上。
1894
- setLists((prev) => {
1895
- const next = { ...prev }
1896
- delete next[name]
1897
- return next
1898
- })
1899
- await reload()
1900
- } else {
1901
- setHint(T.versionsFail + ' · ' + (payload?.reason || payload?.detail || ('HTTP ' + response.status)))
1902
- }
1903
- } catch {
1904
- setHint(T.versionsFail)
1905
- } finally {
1906
- setBusy('')
2073
+ } else {
2074
+ setHint(T.versionsFail + ' · ' + (payload?.reason || payload?.detail || ''))
1907
2075
  }
1908
- }, [busy, reload])
2076
+ setBusy('')
2077
+ await reload()
2078
+ }, [busy, post, reload])
1909
2079
 
1910
- const packages = useMemo(() => {
1911
- const all = Array.isArray(state?.packages) ? state.packages : []
1912
- const text = query.trim().toLowerCase()
1913
- return text === '' ? all : all.filter((item) => String(item.name).toLowerCase().includes(text))
1914
- }, [state, query])
2080
+ const runCycle = useCallback(async (mode, names, fresh) => {
2081
+ if (busy !== '') return
2082
+ setBusy('cycle')
2083
+ setHint('')
2084
+ const { ok, payload } = await post('run', { mode, names: names ?? [], fresh: fresh === true })
2085
+ if (!ok) setHint(T.versionsFail)
2086
+ else if (payload?.started === false) setHint(payload?.reason || T.running)
2087
+ else setHint(T.runDone)
2088
+ setBusy('')
2089
+ await reload()
2090
+ }, [busy, post, reload])
2091
+
2092
+ const chooseSource = useCallback(async (mode) => {
2093
+ await post('state', { registryMode: mode })
2094
+ await reload()
2095
+ }, [post, reload])
2096
+
2097
+ const testSource = useCallback(async (url) => {
2098
+ setTesting(url)
2099
+ setTested(null)
2100
+ const { ok, payload } = await post('registry/test', { url })
2101
+ setTested({ url, ok: ok && payload?.ok === true, ms: payload?.ms ?? 0 })
2102
+ setTesting('')
2103
+ }, [post])
1915
2104
 
1916
2105
  const progress = state?.progress
1917
2106
  const runningText = (() => {
@@ -1925,12 +2114,44 @@ window.__ModuleLoader__.load({
1925
2114
  if (progress.phase === 'applying') return T.progressApply
1926
2115
  return T.running
1927
2116
  })()
2117
+ const sourceRows = [
2118
+ { mode: 'pnpm', label: T.regPnpm, url: '' },
2119
+ { mode: 'npmjs', label: T.regNpmjs, url: 'https://registry.npmjs.org' },
2120
+ { mode: 'mirror', label: T.regMirror, url: 'https://registry.npmmirror.com' },
2121
+ ]
2122
+ const activeMode = state?.settings?.registryMode ?? 'pnpm'
1928
2123
 
1929
2124
  return h('div', { className: S.wrap },
1930
2125
  h('div', { className: S.head },
1931
2126
  h('h3', { className: S.title }, T.versionsTitle),
1932
2127
  h('p', { className: S.sub }, T.versionsSubtitle),
1933
2128
  ),
2129
+ // 概览:需处理 / 可升级 / 已装。刻意只留三个能让人立刻行动的数字。
2130
+ h('div', { className: S.card },
2131
+ h('div', { className: S.cards },
2132
+ h('div', { className: S.stat },
2133
+ h('span', { className: S.statK }, T.versionsAttention),
2134
+ h('span', { className: S.statV }, String(attention.length)),
2135
+ h('span', { className: S.hint }, attention.length > 0 ? attention.slice(0, 2).map((item) => item.name).join('、') : T.versionsEmpty),
2136
+ ),
2137
+ h('div', { className: S.stat },
2138
+ h('span', { className: S.statK }, T.versionsUpgradable),
2139
+ h('span', { className: S.statV }, String(updatable.size)),
2140
+ h('span', { className: S.hint }, state?.lastRun?.at ? formatWhen(state.lastRun.at) : T.never),
2141
+ ),
2142
+ h('div', { className: S.stat },
2143
+ h('span', { className: S.statK }, T.versionsInstalledCount),
2144
+ h('span', { className: S.statV }, String(packages.length)),
2145
+ h('span', { className: S.hint }, T.versionsCount.replace('{n}', String(packages.length))),
2146
+ ),
2147
+ ),
2148
+ h('div', { className: S.meta },
2149
+ h('span', null, T.dshVersion + ': ' + (state?.dshVersion ?? '—')),
2150
+ h('span', null, T.registry + ': ' + (state?.registry === '' || !state?.registry ? T.regPnpm : state.registry)),
2151
+ ),
2152
+ progress ? h('span', { className: 'dsh-au-badge run' }, runningText) : null,
2153
+ ),
2154
+ // 工具条
1934
2155
  h('div', { className: S.card },
1935
2156
  h('div', { className: S.vhead },
1936
2157
  h('input', {
@@ -1941,34 +2162,98 @@ window.__ModuleLoader__.load({
1941
2162
  className: S.search,
1942
2163
  style: { flex: '1 1 200px' },
1943
2164
  }),
1944
- h('span', { className: S.hint }, T.versionsCount.replace('{n}', String(packages.length))),
1945
- ),
1946
- h('div', { className: S.meta },
1947
- h('span', null, T.dshVersion + ': ' + (state?.dshVersion ?? '—')),
1948
- h('span', null, T.registry + ': ' + (state?.registry === '' || !state?.registry ? T.regPnpm : state.registry)),
2165
+ h('div', { className: S.actions },
2166
+ h('button', { type: 'button', className: S.btn, disabled: busy !== '', onClick: () => void runCycle('check', [], true) }, T.versionsChecks),
2167
+ h('button', { type: 'button', className: S.btnPrimary, disabled: busy !== '', onClick: () => void runCycle('update', [], true) }, T.versionsUpgradeAll),
2168
+ h('button', { type: 'button', className: S.btn, disabled: busy !== '' || pickedNames.length === 0, onClick: () => void runCycle('update', pickedNames, false) }, T.versionsUpgradePicked.replace('{n}', String(pickedNames.length))),
2169
+ h('button', { type: 'button', className: S.btn, onClick: () => setShowSources((v) => !v) }, T.versionsSources),
2170
+ h('button', { type: 'button', className: S.btn, onClick: () => void copyDiagnostics() }, T.versionsDiagnostics),
2171
+ h('button', { type: 'button', className: S.btn, onClick: () => setShowSettings((v) => !v) }, showSettings ? T.versionsHideSettings : T.versionsSettings),
2172
+ ),
1949
2173
  ),
1950
- progress ? h('span', { className: 'dsh-au-badge run' }, runningText) : null,
1951
2174
  hint ? h('span', { className: S.status }, hint) : null,
1952
2175
  loadError ? h('p', { className: S.err }, loadError) : null,
1953
- packages.length === 0
2176
+ ),
2177
+ // 注册表:预设三档 + 自定义,每行能单独测。
2178
+ showSources
2179
+ ? h('div', { className: S.card },
2180
+ h('h3', { className: S.h }, T.versionsSources),
2181
+ sourceRows.map((row) => h('div', { key: row.mode, className: S.vrow },
2182
+ h('span', { className: S.vnum, style: { minWidth: '110px' } }, row.label),
2183
+ h('span', { className: S.dim, style: { flex: '1 1 auto', minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, row.url === '' ? T.regPnpm : row.url),
2184
+ activeMode === row.mode ? h('span', { className: S.pivot }, T.versionsCurrentSource) : null,
2185
+ row.url === ''
2186
+ ? null
2187
+ : h('button', { type: 'button', className: S.btn, disabled: testing !== '', onClick: () => void testSource(row.url) }, testing === row.url ? T.versionsTesting : T.versionsTest),
2188
+ activeMode === row.mode
2189
+ ? null
2190
+ : h('button', { type: 'button', className: S.btn, onClick: () => void chooseSource(row.mode) }, T.versionsUse),
2191
+ )),
2192
+ h('div', { className: S.row, style: { marginTop: '4px' } },
2193
+ h('div', { className: S.labelBox },
2194
+ h('span', { className: S.label }, T.versionsCustomSource),
2195
+ h('span', { className: S.hint }, T.regUrlHint),
2196
+ ),
2197
+ h('input', {
2198
+ type: 'url',
2199
+ value: sourceUrl,
2200
+ placeholder: 'https://registry.example.com',
2201
+ onChange: (event) => setSourceUrl(event.target.value),
2202
+ className: S.url,
2203
+ }),
2204
+ ),
2205
+ h('div', { className: S.actions },
2206
+ h('button', { type: 'button', className: S.btn, disabled: sourceUrl.trim() === '' || testing !== '', onClick: () => void testSource(sourceUrl.trim()) }, T.versionsTest),
2207
+ h('button', {
2208
+ type: 'button',
2209
+ className: S.btn,
2210
+ disabled: sourceUrl.trim() === '',
2211
+ onClick: async () => {
2212
+ await post('state', { registryMode: 'custom', registryUrl: sourceUrl.trim() })
2213
+ await reload()
2214
+ },
2215
+ }, T.versionsUse),
2216
+ ),
2217
+ tested === null
2218
+ ? null
2219
+ : h('p', { className: tested.ok ? S.note : S.err }, tested.url + ' · ' + (tested.ok ? T.versionsTestOk.replace('{ms}', String(tested.ms)) : T.versionsTestFail)),
2220
+ )
2221
+ : null,
2222
+ // 设置内嵌:不用为了改一处设置离开这一页。
2223
+ showSettings
2224
+ ? h('div', { className: S.card }, h(AutoUpdateCard), null)
2225
+ : null,
2226
+ // 包列表:勾选 → 升级选中;展开 → 全部版本 → 切过去。
2227
+ h('div', { className: S.card },
2228
+ rows.length === 0
1954
2229
  ? h('span', { className: S.status }, T.versionsEmpty)
1955
2230
  : h('div', { className: S.scrollList },
1956
- packages.map((item) => {
2231
+ rows.map((item) => {
1957
2232
  const listed = lists[item.name]
1958
2233
  const expanded = openName === item.name
2234
+ const behind = lagged.get(item.name)
2235
+ const next = updatable.get(item.name)
1959
2236
  return h('div', { key: item.name, style: { display: 'flex', flexDirection: 'column', gap: '4px' } },
1960
2237
  h('div', { className: S.row },
1961
- h('div', { className: S.labelBox },
1962
- h('span', { title: item.name }, item.name),
1963
- h('span', { className: S.hint },
1964
- T.versionsInstalled + ' ' + (item.version === '' ? '—' : item.version) +
1965
- (listed && listed.tagVersion !== '' ? ' · ' + T.versionsLatest + ' ' + listed.tagVersion : '')),
2238
+ h('div', { className: S.pkgRow, style: { flex: '1 1 auto', padding: '2px 0' } },
2239
+ h('input', {
2240
+ type: 'checkbox',
2241
+ className: S.check,
2242
+ checked: picked[item.name] === true,
2243
+ onChange: (event) => setPicked((prev) => ({ ...prev, [item.name]: event.target.checked })),
2244
+ }),
2245
+ h('div', { className: S.labelBox, style: { flex: '1 1 auto' } },
2246
+ h('span', { title: item.name }, item.name),
2247
+ h('span', { className: S.hint },
2248
+ T.versionsInstalled + ' ' + (item.version === '' ? '—' : item.version) +
2249
+ (next !== undefined ? ' · ' + T.versionsLatest + ' ' + next : '') +
2250
+ (behind !== undefined ? ' · ' + T.lagTitle + ' ' + behind : '')),
2251
+ ),
1966
2252
  ),
1967
- h('button', {
1968
- type: 'button',
1969
- className: expanded ? S.btn : S.btn,
1970
- onClick: () => void openVersions(item.name),
1971
- }, expanded ? T.versionsHide : T.versionsShow),
2253
+ item.ok === false ? h('span', { className: S.bad, title: T.versionsNeed.replace('{r}', item.need || '?') }, T.versionsBlocked) : null,
2254
+ item.version === '' ? h('span', { className: S.pivot }, T.pkgsNotInstalled) : null,
2255
+ next !== undefined ? h('span', { className: S.pivot }, T.versionsUpgradable) : null,
2256
+ h('button', { type: 'button', className: S.btn, onClick: () => void openVersions(item.name) }, expanded ? T.versionsHide : T.versionsShow),
1972
2257
  ),
1973
2258
  expanded
1974
2259
  ? listed === undefined
@@ -1984,9 +2269,7 @@ window.__ModuleLoader__.load({
1984
2269
  isCurrent ? h('span', { className: S.pivot }, T.versionsCurrent) : null,
1985
2270
  row.version === listed.latest && !isCurrent ? h('span', { className: S.pivot }, T.versionsLatest) : null,
1986
2271
  row.deprecated === true ? h('span', { className: S.dim }, T.versionsDeprecated) : null,
1987
- blocked
1988
- ? h('span', { className: S.bad, title: T.versionsNeed.replace('{r}', row.need || '?') }, T.versionsBlocked)
1989
- : null,
2272
+ blocked ? h('span', { className: S.bad, title: T.versionsNeed.replace('{r}', row.need || '?') }, T.versionsBlocked) : null,
1990
2273
  h('div', { className: S.vact },
1991
2274
  isCurrent
1992
2275
  ? null
@@ -2017,36 +2300,48 @@ window.__ModuleLoader__.load({
2017
2300
  installStyles()
2018
2301
  // 提醒跟着插件一起上、一起卸:ctx.effect 收的是清理函数。
2019
2302
  if (typeof ctx.effect === 'function') ctx.effect(startUpdateNotifier, 'dsh-aupdate: update notices')
2303
+ // 「显示位置」:关掉的那一处干脆不注册槽位,而不是挂上去再渲染成空——
2304
+ // 后者会在标签栏/设置导航里留下一个点进去什么都没有的空条目。
2305
+ const display = readDisplay()
2306
+
2020
2307
  // key 的格式是「包名#条目id」:本插件在 cordis.patch.yml 里的条目 id 就是包名本身,
2021
2308
  // 和 dsh-ops 的 dsh-ops#dsh-ops 一样。写成 #auto-update 之类是挂不上的。
2022
- ctx.slots.inject('plugins.row.config', () => ctx.slots.register({
2023
- name: 'plugins.row.config',
2024
- key: NS + '#' + NS,
2025
- }, (props) => (props && props.view === 'summary' ? h(AutoUpdateSummary) : h(AutoUpdateCard))))
2309
+ if (display.showPluginsRow) {
2310
+ ctx.slots.inject('plugins.row.config', () => ctx.slots.register({
2311
+ name: 'plugins.row.config',
2312
+ key: NS + '#' + NS,
2313
+ }, (props) => (props && props.view === 'summary' ? h(AutoUpdateSummary) : h(AutoUpdateCard))))
2314
+ }
2026
2315
 
2027
2316
  // bundle 级配置页用包名做 key,和 free-search 的写法一致。
2028
- ctx.slots.inject('plugins.bundle.config', () => ctx.slots.register({
2029
- name: 'plugins.bundle.config',
2030
- key: NS,
2031
- }, (props) => (props && props.view === 'summary' ? h(AutoUpdateSummary) : h(AutoUpdateCard))))
2317
+ if (display.showPluginsBundle) {
2318
+ ctx.slots.inject('plugins.bundle.config', () => ctx.slots.register({
2319
+ name: 'plugins.bundle.config',
2320
+ key: NS,
2321
+ }, (props) => (props && props.view === 'summary' ? h(AutoUpdateSummary) : h(AutoUpdateCard))))
2322
+ }
2032
2323
 
2033
2324
  // 设置 → 插件更新:挂成独立的一页,写法照抄 dsh-our-free-model-balance-zxp
2034
2325
  // 的「渠道余额」。原来只有插件页里那张卡,想改策略得先去插件页翻它。
2035
- ctx.slots.inject('settings.section', () => ctx.slots.register({
2036
- name: 'settings.section',
2037
- id: NS,
2038
- order: 36,
2039
- label: () => T.pageLabel,
2040
- }, () => h(AutoUpdateCard)))
2326
+ if (display.showSettingsSection) {
2327
+ ctx.slots.inject('settings.section', () => ctx.slots.register({
2328
+ name: 'settings.section',
2329
+ id: NS,
2330
+ order: 36,
2331
+ label: () => T.pageLabel,
2332
+ }, () => h(AutoUpdateCard)))
2333
+ }
2041
2334
 
2042
2335
  // 插件页标签栏多一个「版本管理」:和设置页分工——设置页管「什么时候自动升」,
2043
2336
  // 这一页管「现在就要某一版」。order 2 排在「已安装/发现」(0) 和市场(1) 之后。
2044
- ctx.slots.inject('plugins.tab', () => ctx.slots.register({
2045
- name: 'plugins.tab',
2046
- id: NS,
2047
- order: 2,
2048
- label: () => T.versionsTab,
2049
- }, () => h(VersionsTab)))
2337
+ if (display.showVersionsTab) {
2338
+ ctx.slots.inject('plugins.tab', () => ctx.slots.register({
2339
+ name: 'plugins.tab',
2340
+ id: NS,
2341
+ order: 2,
2342
+ label: () => T.versionsTab,
2343
+ }, () => h(VersionsTab)))
2344
+ }
2050
2345
  },
2051
2346
  }
2052
2347
  },
@@ -4,11 +4,11 @@
4
4
  它和 dsh-aupdate 是同类:都在插件页补「一键升级」。区别是它手动触发、把精力放在**版本可见性和安装前后的边界**上,
5
5
  aupdate 自动跑、把精力放在**调度和让开**上。
6
6
 
7
- 这份清单是 0.8.0 的施工依据:只有能落在 aupdate 现有架构里的项才做,做了的写明代价,没做的写明为什么。
7
+ 这份清单是 0.7.5 的施工依据:只有能落在 aupdate 现有架构里的项才做,做了的写明代价,没做的写明为什么。
8
8
 
9
9
  ## 可借鉴项
10
10
 
11
- | 能力 | 它怎么做 | aupdate 0.8.0 | 代价 / 边界 |
11
+ | 能力 | 它怎么做 | aupdate 0.7.5 | 代价 / 边界 |
12
12
  | --- | --- | --- | --- |
13
13
  | **按版本比 DSH 兼容性** | 装之前先查该版本 manifest 的 `engines.dsh`(没有才看 `@deepseek-ai/dsh(-*)` 的 peer),和宿主版本比 | ✅ 已实现(`compatOf`),不满足的版本不进安装队列 | 每个**候选**版本多一次几 KB 的 manifest 请求;只在「已经决定要升」时发生,不是每包每轮 |
14
14
  | **DSH 版本从哪来** | 从 `process.argv` 的入口往上找 `@deepseek-ai/dsh-app-boot/package.json` | ✅ 已实现(`dshVersion`) | 读不到就返回 null 并**不拦**:宁可漏拦,也不按猜的版本误拦 |
@@ -28,7 +28,7 @@ aupdate 自动跑、把精力放在**调度和让开**上。
28
28
  - **in-place 替换(先摘 manifest 再装)**:它靠临时改 profile 的 `package.json` 做到「不卸载换版本」,配了 journal 和写入锁。aupdate 走 `dsh plugin add pkg@version`,这条命令本身就会换版本;再自己动 manifest 等于和 plugin-manager 抢同一份文件,风险大于收益。
29
29
  - **自动写 pnpm 配置**:见上表。
30
30
 
31
- ## 0.8.0 的验收点
31
+ ## 0.7.5 的验收点
32
32
 
33
33
  1. 没选安装源时:`/state.registry === ''`,dist-tags 仍走官方源,安装命令环境变量不变。
34
34
  2. 选镜像时:`lastRun.lagged` 能列出「镜像 x.y.z、官方 a.b.c」。
package/index.js CHANGED
@@ -541,6 +541,8 @@ const OVERRIDEABLE = [
541
541
  'allowMajor', 'allowPrerelease',
542
542
  // 安装源与兼容性预检(0.8.0 借自 dsh-plugin-upgrader)。
543
543
  'registryMode', 'registryUrl', 'compatCheck',
544
+ // 显示位置(设置页 / 插件行 / 插件配置页 / 版本管理标签)。
545
+ 'showSettingsSection', 'showPluginsRow', 'showPluginsBundle', 'showVersionsTab',
544
546
  // 调度:四种节奏 + 失败抑制时长。这些键不写进 Config schema,
545
547
  // 只活在覆盖层里——Config 的字段类型是宿主校验的,加错一个类型
546
548
  // 会在加载期直接抛错,而覆盖层是我们自己的文件,改坏了只影响这一项。
@@ -740,6 +742,12 @@ function settingsOf(config) {
740
742
  // 兼容性预检:装之前先看目标版本声明的 DSH 范围。默认开——宿主闸门是在
741
743
  // bundle 已经卸下之后才拒绝的,等它拒绝就已经晚了。
742
744
  compatCheck: booleanSetting(config, 'compatCheck', true),
745
+ // 显示位置:四个界面各自能被关掉。关掉由客户端在注册槽位时跳过,
746
+ // 所以改完要重新加载一次插件(POST /state 会自己安排一次就地重载)。
747
+ showSettingsSection: booleanSetting(config, 'showSettingsSection', true),
748
+ showPluginsRow: booleanSetting(config, 'showPluginsRow', true),
749
+ showPluginsBundle: booleanSetting(config, 'showPluginsBundle', true),
750
+ showVersionsTab: booleanSetting(config, 'showVersionsTab', true),
743
751
  intervalMinutes: numberSetting(config, 'intervalMinutes', 1440, 10, 10080),
744
752
  firstDelayMinutes: numberSetting(config, 'firstDelayMinutes', 5, 0, 1440),
745
753
  exclude: stringList(config?.exclude),
@@ -1517,10 +1525,18 @@ function packageChoices(profileDir, settings) {
1517
1525
  if (/^(link|file|workspace|portal):/iu.test(spec)) continue
1518
1526
  if (!NPM_NAME_RE.test(name)) continue
1519
1527
  const version = installedVersion(profileDir, name, spec)
1528
+ // 已装版本自己声明的 DSH 要求:读的是本地 node_modules 里的 manifest,
1529
+ // 不发任何网络请求。宿主闸门只认它,所以「装不上」的判断要按它来。
1530
+ // 这类包很可能根本没被加载,而升级按钮救不了它,只能换版本或升 DSH。
1531
+ const local = readJson(join(profileDir, 'node_modules', name, 'package.json'))
1532
+ const need = dshRequirementOf(local)
1533
+ const host = dshVersion()
1520
1534
  rows.push({
1521
1535
  name,
1522
1536
  version: typeof version === 'string' ? version : '',
1523
1537
  excluded: skip.has(name),
1538
+ need: need === null ? '' : need.range,
1539
+ ok: need === null || host === null ? null : satisfiesRange(need.range, host),
1524
1540
  })
1525
1541
  }
1526
1542
  // 不能直接用 localeCompare:它的结果跟着系统区域变,同一个 profile 在不同机器上
@@ -2096,10 +2112,10 @@ async function hotApply(ctx, requiredBefore) {
2096
2112
  return { status: 'failed', reason: oneLine(error?.message ?? error, 400) }
2097
2113
  }
2098
2114
  }
2099
- function beginningRun(mode, ctxRef) {
2115
+ function beginningRun(mode, ctxRef, options = {}) {
2100
2116
  if (running !== null) return null
2101
2117
  if (mode === 'update') setProgress({ phase: 'checking', index: 0, total: 0, name: '' })
2102
- const promise = runCycle(mode, ctxRef).finally(() => {
2118
+ const promise = runCycle(mode, ctxRef, options).finally(() => {
2103
2119
  running = null
2104
2120
  clearProgress()
2105
2121
  })
@@ -2107,8 +2123,16 @@ function beginningRun(mode, ctxRef) {
2107
2123
  return promise
2108
2124
  }
2109
2125
 
2110
- async function runCycle(mode, ctxRef) {
2126
+ async function runCycle(mode, ctxRef, options = {}) {
2111
2127
  const settings = settingsOf(ctxRef.config)
2128
+ const only = Array.isArray(options.names) ? options.names.filter((item) => typeof item === 'string' && item !== '') : []
2129
+ // 「检查更新」要能绕过缓存:dist-tags 缓存 10 分钟,用户刚在别处发了新版时
2130
+ // 等 10 分钟才看见没有道理。
2131
+ if (options.fresh === true) {
2132
+ tagCache.clear()
2133
+ versionsCache.clear()
2134
+ manifestCache.clear()
2135
+ }
2112
2136
  const report = {
2113
2137
  status: 'done',
2114
2138
  startedAt: new Date().toISOString(),
@@ -2124,7 +2148,9 @@ async function runCycle(mode, ctxRef) {
2124
2148
  try {
2125
2149
  const profileDir = profileDirOf(ctxRef.ctx)
2126
2150
  const profileName = basename(profileDir)
2127
- const deps = dependencyList(profileDir, settings.exclude)
2151
+ let deps = dependencyList(profileDir, settings.exclude)
2152
+ // 只跑选中的那些:版本管理页的「升级选中」用它,别为了几个包重查整轮。
2153
+ if (only.length > 0) deps = deps.filter((dep) => only.includes(dep.name))
2128
2154
  report.checked = deps.length
2129
2155
  if (deps.length === 0) {
2130
2156
  report.reason = { code: 'noDeps' }
@@ -2740,12 +2766,20 @@ function registerRoutes(scope, ctxRef) {
2740
2766
  sendJson(res, 400, { error: 'bad json' })
2741
2767
  return
2742
2768
  }
2769
+ const before = settingsOf(ctxRef.config)
2743
2770
  const result = writeOverrides(body)
2744
2771
  if (!result.ok) {
2745
2772
  sendJson(res, 500, { error: result.error })
2746
2773
  return
2747
2774
  }
2748
2775
  writeLog('settingsChanged', [Object.keys(body)])
2776
+ // 显示位置是「注册哪些槽位」决定的,改完必须重新加载一次插件才生效。
2777
+ // 这里不重启应用,只让本插件就地重载(和装完包之后做的是同一件事)。
2778
+ const displayChanged = ['showSettingsSection', 'showPluginsRow', 'showPluginsBundle', 'showVersionsTab']
2779
+ .some((key) => before[key] !== settingsOf(ctxRef.config)[key])
2780
+ if (displayChanged && settingsOf(ctxRef.config).hotReload) {
2781
+ setTimeout(() => { void hotApply(ctxRef.ctx, []).catch(() => {}) }, 1200).unref?.()
2782
+ }
2749
2783
  // 改完立刻按新设置重排,否则要等下一次触发才换节奏。
2750
2784
  try {
2751
2785
  if (typeof ctxRef.reschedule === 'function') ctxRef.reschedule()
@@ -2755,6 +2789,25 @@ function registerRoutes(scope, ctxRef) {
2755
2789
  sendJson(res, 200, settingsSnapshot(ctxRef.config, ctxRef, url.searchParams.get('lang')))
2756
2790
  return
2757
2791
  }
2792
+ if (suffix === '/registry/test') {
2793
+ const body = await readBody(req)
2794
+ const target = typeof body?.url === 'string' ? body.url.trim().replace(/\/+$/u, '') : ''
2795
+ if (!/^https?:\/\/[^\s]+$/iu.test(target)) {
2796
+ sendJson(res, 400, { ok: false, url: target, ms: 0, detail: 'not http(s)' })
2797
+ return
2798
+ }
2799
+ // 两支一起发、谁先答应用谁:/-/ping 在大陆镜像上有时要 15 秒,根地址只要 0.3 秒,
2800
+ // 串行探测会把能用的镜像报成连不上。整次 5 秒封顶。
2801
+ const probe = async (url) => {
2802
+ const response = await fetch(url, { headers: { accept: 'application/json' }, signal: AbortSignal.timeout(5000) })
2803
+ return response.ok
2804
+ }
2805
+ const started = Date.now()
2806
+ const [ping, root] = await Promise.allSettled([probe(target + '/-/ping'), probe(target + '/')])
2807
+ const ok = (ping.status === 'fulfilled' && ping.value === true) || (root.status === 'fulfilled' && root.value === true)
2808
+ sendJson(res, 200, { ok, url: target, ms: Date.now() - started })
2809
+ return
2810
+ }
2758
2811
  if (suffix === '/switch') {
2759
2812
  const body = await readBody(req)
2760
2813
  const target = typeof body?.name === 'string' ? body.name : ''
@@ -2804,7 +2857,10 @@ function registerRoutes(scope, ctxRef) {
2804
2857
  if (suffix === '/run') {
2805
2858
  const body = await readBody(req)
2806
2859
  const mode = body?.mode === 'check' ? 'check' : 'update'
2807
- const report = await beginningRun(mode, ctxRef)
2860
+ const report = await beginningRun(mode, ctxRef, {
2861
+ names: Array.isArray(body?.names) ? body.names : [],
2862
+ fresh: body?.fresh === true,
2863
+ })
2808
2864
  if (report === null) {
2809
2865
  sendJson(res, 200, { started: false, reason: renderReason({ code: 'alreadyRunning' }, url.searchParams.get('lang')) })
2810
2866
  return
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-aupdate",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
4
4
  "type": "module",
5
5
  "description": "定时检查 DSH 插件更新,串行安装后就地生效,不重启;支持多种调度节奏、失败抑制、按包回滚,并在动手前留快照、忙时自动让开;不更新/只更新哪些插件改成勾选,发现更新在右下角提醒,日志最新在最上面,并在「设置 → 插件更新」里有独立一页。",
6
6
  "license": "MIT",