dsh-aupdate 0.7.5 → 0.8.1

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.
Files changed (4) hide show
  1. package/README.md +41 -0
  2. package/client.js +368 -78
  3. package/index.js +61 -5
  4. package/package.json +1 -1
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')
@@ -1371,6 +1458,16 @@ window.__ModuleLoader__.load({
1371
1458
  h('span', null, T.registry + ': ' + (state?.registry === '' || !state?.registry ? T.regPnpm : state.registry)),
1372
1459
  ),
1373
1460
  ),
1461
+ // 显示位置:四个挂载点各自可以关掉。设置本身存在后端,客户端只是把它镜像
1462
+ // 到 localStorage,供 apply() 在注册槽位时同步判断(见 readDisplay 的注释)。
1463
+ h('div', { className: S.card },
1464
+ h('h3', { className: S.h }, T.displayGroup),
1465
+ h('p', { className: S.note }, T.displayHint),
1466
+ h(SwitchRow, { label: T.showSettings, value: draft.showSettingsSection !== false, onChange: (v) => patch('showSettingsSection', v) }),
1467
+ h(SwitchRow, { label: T.showRow, value: draft.showPluginsRow !== false, onChange: (v) => patch('showPluginsRow', v) }),
1468
+ h(SwitchRow, { label: T.showBundle, value: draft.showPluginsBundle !== false, onChange: (v) => patch('showPluginsBundle', v) }),
1469
+ h(SwitchRow, { label: T.showTab, value: draft.showVersionsTab !== false, onChange: (v) => patch('showVersionsTab', v) }),
1470
+ ),
1374
1471
  h('div', { className: S.card },
1375
1472
  h('h3', { className: S.h }, T.keepTitle),
1376
1473
  h('p', { className: S.note }, T.keepHint),
@@ -1827,34 +1924,113 @@ window.__ModuleLoader__.load({
1827
1924
  * 版本列表按包按需拉(一次一个包),不进首屏:整页一次拉一堆包的 packument
1828
1925
  * 在镜像上会慢到没法用。
1829
1926
  */
1927
+ /**
1928
+ * 「版本管理」标签页。
1929
+ *
1930
+ * 复刻 dsh-plugin-upgrader 那个「版本」页的主干:一眼看清哪些能升、哪些有问题,
1931
+ * 一键升级 / 勾选升级,展开看全部已发布版本并切过去,装源开关与测源,复制诊断;
1932
+ * 再把 aupdate 自己的设置嵌进来,免得在两处之间来回跳。
1933
+ *
1934
+ * 和设置页的分工没变:设置页管「什么时候自动升」,这一页管「现在就要某一版」。
1935
+ */
1830
1936
  function VersionsTab() {
1831
1937
  useLang()
1832
1938
  const [state, setState] = useState(null)
1833
1939
  const [query, setQuery] = useState('')
1940
+ const [picked, setPicked] = useState({})
1834
1941
  const [openName, setOpenName] = useState('')
1835
1942
  const [lists, setLists] = useState({})
1836
1943
  const [loadError, setLoadError] = useState('')
1837
1944
  const [busy, setBusy] = useState('')
1838
1945
  const [hint, setHint] = useState('')
1946
+ const [showSettings, setShowSettings] = useState(false)
1947
+ const [showSources, setShowSources] = useState(false)
1948
+ const [sourceUrl, setSourceUrl] = useState('')
1949
+ const [testing, setTesting] = useState('')
1950
+ const [tested, setTested] = useState(null)
1839
1951
 
1840
1952
  const reload = useCallback(async () => {
1841
1953
  try {
1842
- setState(await getState(LANG))
1954
+ const next = await getState(LANG)
1955
+ setState(next)
1956
+ writeDisplay(next?.settings)
1843
1957
  } catch {}
1844
1958
  }, [])
1845
1959
 
1846
1960
  useEffect(() => { void reload() }, [reload])
1847
1961
 
1848
- // 切版本可能要好几分钟(pnpm 要校验锁文件),期间才轮询;闲着时一个请求都不发。
1962
+ // 空闲时 15 秒拉一次 /state(不碰 registry),够让统计跟上后台轮次;
1963
+ // 切版本/跑一轮期间改回 3 秒,进度才跟得上。
1849
1964
  useEffect(() => {
1850
- if (busy === '') return undefined
1851
- const timer = setInterval(async () => {
1852
- try {
1853
- setState(await getState(LANG))
1854
- } catch {}
1855
- }, 3000)
1965
+ const every = busy === '' ? 15000 : 3000
1966
+ const timer = setInterval(() => { void reload() }, every)
1856
1967
  return () => clearInterval(timer)
1857
- }, [busy])
1968
+ }, [busy, reload])
1969
+
1970
+ const post = useCallback(async (path, body) => {
1971
+ try {
1972
+ const response = await fetch(endpoint(path) + langQuery(), {
1973
+ method: 'POST',
1974
+ headers: { 'content-type': 'application/json', accept: 'application/json' },
1975
+ body: JSON.stringify(body),
1976
+ })
1977
+ const payload = await response.json().catch(() => null)
1978
+ return { ok: response.ok, payload }
1979
+ } catch {
1980
+ return { ok: false, payload: null }
1981
+ }
1982
+ }, [])
1983
+
1984
+ const packages = useMemo(() => (Array.isArray(state?.packages) ? state.packages : []), [state])
1985
+ const rows = useMemo(() => {
1986
+ const needle = query.trim().toLowerCase()
1987
+ return needle === '' ? packages : packages.filter((item) => String(item.name).toLowerCase().includes(needle))
1988
+ }, [packages, query])
1989
+
1990
+ // 最近一轮里「查到的可更新版本」和「镜像落后」:都用名字索引,行上直接查。
1991
+ const updatable = useMemo(() => {
1992
+ const mark = new Map()
1993
+ for (const item of (Array.isArray(state?.lastRun?.updates) ? state.lastRun.updates : [])) {
1994
+ const row = describeUpdate(item)
1995
+ if (row !== null) mark.set(row.name, row.versions)
1996
+ }
1997
+ return mark
1998
+ }, [state])
1999
+ const lagged = useMemo(() => {
2000
+ const mark = new Map()
2001
+ for (const item of (Array.isArray(state?.lastRun?.lagged) ? state.lastRun.lagged : [])) {
2002
+ if (item !== null && typeof item === 'object' && typeof item.name === 'string') {
2003
+ mark.set(item.name, (item.mirror || '?') + ' → ' + (item.upstream || '?'))
2004
+ }
2005
+ }
2006
+ return mark
2007
+ }, [state])
2008
+
2009
+ const attention = useMemo(() => packages.filter((item) => item.ok === false || item.version === ''), [packages])
2010
+ const pickedNames = useMemo(() => packages.filter((item) => picked[item.name] === true).map((item) => item.name), [packages, picked])
2011
+
2012
+ const copyDiagnostics = useCallback(async () => {
2013
+ const lines = [
2014
+ T.versionsTitle + ' — dsh-aupdate ' + (state?.version ?? '?'),
2015
+ 'DSH ' + (state?.dshVersion ?? 'unknown'),
2016
+ T.registry + ': ' + (state?.registry === '' || !state?.registry ? T.regPnpm : state.registry),
2017
+ '',
2018
+ ]
2019
+ for (const item of packages) {
2020
+ const flags = []
2021
+ if (item.ok === false) flags.push('needs DSH ' + (item.need || '?'))
2022
+ if (item.version === '') flags.push('not installed')
2023
+ if (updatable.get(item.name) !== undefined) flags.push('updatable -> ' + updatable.get(item.name))
2024
+ if (lagged.get(item.name) !== undefined) flags.push('mirror lag -> ' + lagged.get(item.name))
2025
+ lines.push('- ' + item.name + ' ' + (item.version || '?') + (flags.length > 0 ? ' ' + flags.join('; ') : ''))
2026
+ }
2027
+ try {
2028
+ await navigator.clipboard.writeText(lines.join(String.fromCharCode(10)))
2029
+ setHint(T.versionsCopied)
2030
+ } catch {
2031
+ setHint(T.versionsCopyFail)
2032
+ }
2033
+ }, [state, packages, updatable, lagged])
1858
2034
 
1859
2035
  const openVersions = useCallback(async (name) => {
1860
2036
  if (openName === name) {
@@ -1881,37 +2057,45 @@ window.__ModuleLoader__.load({
1881
2057
  if (busy !== '') return
1882
2058
  setBusy(name + '@' + version)
1883
2059
  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 }),
2060
+ const { ok, payload } = await post('switch', { name, version })
2061
+ if (ok) {
2062
+ setHint(payload?.unchanged === true ? T.versionsNoop : T.versionsDone.replace('{v}', version))
2063
+ setLists((prev) => {
2064
+ const next = { ...prev }
2065
+ delete next[name]
2066
+ return next
1889
2067
  })
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('')
2068
+ } else {
2069
+ setHint(T.versionsFail + ' · ' + (payload?.reason || payload?.detail || ''))
1907
2070
  }
1908
- }, [busy, reload])
2071
+ setBusy('')
2072
+ await reload()
2073
+ }, [busy, post, reload])
1909
2074
 
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])
2075
+ const runCycle = useCallback(async (mode, names, fresh) => {
2076
+ if (busy !== '') return
2077
+ setBusy('cycle')
2078
+ setHint('')
2079
+ const { ok, payload } = await post('run', { mode, names: names ?? [], fresh: fresh === true })
2080
+ if (!ok) setHint(T.versionsFail)
2081
+ else if (payload?.started === false) setHint(payload?.reason || T.running)
2082
+ else setHint(T.runDone)
2083
+ setBusy('')
2084
+ await reload()
2085
+ }, [busy, post, reload])
2086
+
2087
+ const chooseSource = useCallback(async (mode) => {
2088
+ await post('state', { registryMode: mode })
2089
+ await reload()
2090
+ }, [post, reload])
2091
+
2092
+ const testSource = useCallback(async (url) => {
2093
+ setTesting(url)
2094
+ setTested(null)
2095
+ const { ok, payload } = await post('registry/test', { url })
2096
+ setTested({ url, ok: ok && payload?.ok === true, ms: payload?.ms ?? 0 })
2097
+ setTesting('')
2098
+ }, [post])
1915
2099
 
1916
2100
  const progress = state?.progress
1917
2101
  const runningText = (() => {
@@ -1925,12 +2109,44 @@ window.__ModuleLoader__.load({
1925
2109
  if (progress.phase === 'applying') return T.progressApply
1926
2110
  return T.running
1927
2111
  })()
2112
+ const sourceRows = [
2113
+ { mode: 'pnpm', label: T.regPnpm, url: '' },
2114
+ { mode: 'npmjs', label: T.regNpmjs, url: 'https://registry.npmjs.org' },
2115
+ { mode: 'mirror', label: T.regMirror, url: 'https://registry.npmmirror.com' },
2116
+ ]
2117
+ const activeMode = state?.settings?.registryMode ?? 'pnpm'
1928
2118
 
1929
2119
  return h('div', { className: S.wrap },
1930
2120
  h('div', { className: S.head },
1931
2121
  h('h3', { className: S.title }, T.versionsTitle),
1932
2122
  h('p', { className: S.sub }, T.versionsSubtitle),
1933
2123
  ),
2124
+ // 概览:需处理 / 可升级 / 已装。刻意只留三个能让人立刻行动的数字。
2125
+ h('div', { className: S.card },
2126
+ h('div', { className: S.cards },
2127
+ h('div', { className: S.stat },
2128
+ h('span', { className: S.statK }, T.versionsAttention),
2129
+ h('span', { className: S.statV }, String(attention.length)),
2130
+ h('span', { className: S.hint }, attention.length > 0 ? attention.slice(0, 2).map((item) => item.name).join('、') : T.versionsEmpty),
2131
+ ),
2132
+ h('div', { className: S.stat },
2133
+ h('span', { className: S.statK }, T.versionsUpgradable),
2134
+ h('span', { className: S.statV }, String(updatable.size)),
2135
+ h('span', { className: S.hint }, state?.lastRun?.at ? formatWhen(state.lastRun.at) : T.never),
2136
+ ),
2137
+ h('div', { className: S.stat },
2138
+ h('span', { className: S.statK }, T.versionsInstalledCount),
2139
+ h('span', { className: S.statV }, String(packages.length)),
2140
+ h('span', { className: S.hint }, T.versionsCount.replace('{n}', String(packages.length))),
2141
+ ),
2142
+ ),
2143
+ h('div', { className: S.meta },
2144
+ h('span', null, T.dshVersion + ': ' + (state?.dshVersion ?? '—')),
2145
+ h('span', null, T.registry + ': ' + (state?.registry === '' || !state?.registry ? T.regPnpm : state.registry)),
2146
+ ),
2147
+ progress ? h('span', { className: 'dsh-au-badge run' }, runningText) : null,
2148
+ ),
2149
+ // 工具条
1934
2150
  h('div', { className: S.card },
1935
2151
  h('div', { className: S.vhead },
1936
2152
  h('input', {
@@ -1941,34 +2157,98 @@ window.__ModuleLoader__.load({
1941
2157
  className: S.search,
1942
2158
  style: { flex: '1 1 200px' },
1943
2159
  }),
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)),
2160
+ h('div', { className: S.actions },
2161
+ h('button', { type: 'button', className: S.btn, disabled: busy !== '', onClick: () => void runCycle('check', [], true) }, T.versionsChecks),
2162
+ h('button', { type: 'button', className: S.btnPrimary, disabled: busy !== '', onClick: () => void runCycle('update', [], true) }, T.versionsUpgradeAll),
2163
+ 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))),
2164
+ h('button', { type: 'button', className: S.btn, onClick: () => setShowSources((v) => !v) }, T.versionsSources),
2165
+ h('button', { type: 'button', className: S.btn, onClick: () => void copyDiagnostics() }, T.versionsDiagnostics),
2166
+ h('button', { type: 'button', className: S.btn, onClick: () => setShowSettings((v) => !v) }, showSettings ? T.versionsHideSettings : T.versionsSettings),
2167
+ ),
1949
2168
  ),
1950
- progress ? h('span', { className: 'dsh-au-badge run' }, runningText) : null,
1951
2169
  hint ? h('span', { className: S.status }, hint) : null,
1952
2170
  loadError ? h('p', { className: S.err }, loadError) : null,
1953
- packages.length === 0
2171
+ ),
2172
+ // 注册表:预设三档 + 自定义,每行能单独测。
2173
+ showSources
2174
+ ? h('div', { className: S.card },
2175
+ h('h3', { className: S.h }, T.versionsSources),
2176
+ sourceRows.map((row) => h('div', { key: row.mode, className: S.vrow },
2177
+ h('span', { className: S.vnum, style: { minWidth: '110px' } }, row.label),
2178
+ h('span', { className: S.dim, style: { flex: '1 1 auto', minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, row.url === '' ? T.regPnpm : row.url),
2179
+ activeMode === row.mode ? h('span', { className: S.pivot }, T.versionsCurrentSource) : null,
2180
+ row.url === ''
2181
+ ? null
2182
+ : h('button', { type: 'button', className: S.btn, disabled: testing !== '', onClick: () => void testSource(row.url) }, testing === row.url ? T.versionsTesting : T.versionsTest),
2183
+ activeMode === row.mode
2184
+ ? null
2185
+ : h('button', { type: 'button', className: S.btn, onClick: () => void chooseSource(row.mode) }, T.versionsUse),
2186
+ )),
2187
+ h('div', { className: S.row, style: { marginTop: '4px' } },
2188
+ h('div', { className: S.labelBox },
2189
+ h('span', { className: S.label }, T.versionsCustomSource),
2190
+ h('span', { className: S.hint }, T.regUrlHint),
2191
+ ),
2192
+ h('input', {
2193
+ type: 'url',
2194
+ value: sourceUrl,
2195
+ placeholder: 'https://registry.example.com',
2196
+ onChange: (event) => setSourceUrl(event.target.value),
2197
+ className: S.url,
2198
+ }),
2199
+ ),
2200
+ h('div', { className: S.actions },
2201
+ h('button', { type: 'button', className: S.btn, disabled: sourceUrl.trim() === '' || testing !== '', onClick: () => void testSource(sourceUrl.trim()) }, T.versionsTest),
2202
+ h('button', {
2203
+ type: 'button',
2204
+ className: S.btn,
2205
+ disabled: sourceUrl.trim() === '',
2206
+ onClick: async () => {
2207
+ await post('state', { registryMode: 'custom', registryUrl: sourceUrl.trim() })
2208
+ await reload()
2209
+ },
2210
+ }, T.versionsUse),
2211
+ ),
2212
+ tested === null
2213
+ ? null
2214
+ : h('p', { className: tested.ok ? S.note : S.err }, tested.url + ' · ' + (tested.ok ? T.versionsTestOk.replace('{ms}', String(tested.ms)) : T.versionsTestFail)),
2215
+ )
2216
+ : null,
2217
+ // 设置内嵌:不用为了改一处设置离开这一页。
2218
+ showSettings
2219
+ ? h('div', { className: S.card }, h(AutoUpdateCard), null)
2220
+ : null,
2221
+ // 包列表:勾选 → 升级选中;展开 → 全部版本 → 切过去。
2222
+ h('div', { className: S.card },
2223
+ rows.length === 0
1954
2224
  ? h('span', { className: S.status }, T.versionsEmpty)
1955
2225
  : h('div', { className: S.scrollList },
1956
- packages.map((item) => {
2226
+ rows.map((item) => {
1957
2227
  const listed = lists[item.name]
1958
2228
  const expanded = openName === item.name
2229
+ const behind = lagged.get(item.name)
2230
+ const next = updatable.get(item.name)
1959
2231
  return h('div', { key: item.name, style: { display: 'flex', flexDirection: 'column', gap: '4px' } },
1960
2232
  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 : '')),
2233
+ h('div', { className: S.pkgRow, style: { flex: '1 1 auto', padding: '2px 0' } },
2234
+ h('input', {
2235
+ type: 'checkbox',
2236
+ className: S.check,
2237
+ checked: picked[item.name] === true,
2238
+ onChange: (event) => setPicked((prev) => ({ ...prev, [item.name]: event.target.checked })),
2239
+ }),
2240
+ h('div', { className: S.labelBox, style: { flex: '1 1 auto' } },
2241
+ h('span', { title: item.name }, item.name),
2242
+ h('span', { className: S.hint },
2243
+ T.versionsInstalled + ' ' + (item.version === '' ? '—' : item.version) +
2244
+ (next !== undefined ? ' · ' + T.versionsLatest + ' ' + next : '') +
2245
+ (behind !== undefined ? ' · ' + T.lagTitle + ' ' + behind : '')),
2246
+ ),
1966
2247
  ),
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),
2248
+ item.ok === false ? h('span', { className: S.bad, title: T.versionsNeed.replace('{r}', item.need || '?') }, T.versionsBlocked) : null,
2249
+ item.version === '' ? h('span', { className: S.pivot }, T.pkgsNotInstalled) : null,
2250
+ next !== undefined ? h('span', { className: S.pivot }, T.versionsUpgradable) : null,
2251
+ h('button', { type: 'button', className: S.btn, onClick: () => void openVersions(item.name) }, expanded ? T.versionsHide : T.versionsShow),
1972
2252
  ),
1973
2253
  expanded
1974
2254
  ? listed === undefined
@@ -1984,9 +2264,7 @@ window.__ModuleLoader__.load({
1984
2264
  isCurrent ? h('span', { className: S.pivot }, T.versionsCurrent) : null,
1985
2265
  row.version === listed.latest && !isCurrent ? h('span', { className: S.pivot }, T.versionsLatest) : null,
1986
2266
  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,
2267
+ blocked ? h('span', { className: S.bad, title: T.versionsNeed.replace('{r}', row.need || '?') }, T.versionsBlocked) : null,
1990
2268
  h('div', { className: S.vact },
1991
2269
  isCurrent
1992
2270
  ? null
@@ -2017,36 +2295,48 @@ window.__ModuleLoader__.load({
2017
2295
  installStyles()
2018
2296
  // 提醒跟着插件一起上、一起卸:ctx.effect 收的是清理函数。
2019
2297
  if (typeof ctx.effect === 'function') ctx.effect(startUpdateNotifier, 'dsh-aupdate: update notices')
2298
+ // 「显示位置」:关掉的那一处干脆不注册槽位,而不是挂上去再渲染成空——
2299
+ // 后者会在标签栏/设置导航里留下一个点进去什么都没有的空条目。
2300
+ const display = readDisplay()
2301
+
2020
2302
  // key 的格式是「包名#条目id」:本插件在 cordis.patch.yml 里的条目 id 就是包名本身,
2021
2303
  // 和 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))))
2304
+ if (display.showPluginsRow) {
2305
+ ctx.slots.inject('plugins.row.config', () => ctx.slots.register({
2306
+ name: 'plugins.row.config',
2307
+ key: NS + '#' + NS,
2308
+ }, (props) => (props && props.view === 'summary' ? h(AutoUpdateSummary) : h(AutoUpdateCard))))
2309
+ }
2026
2310
 
2027
2311
  // 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))))
2312
+ if (display.showPluginsBundle) {
2313
+ ctx.slots.inject('plugins.bundle.config', () => ctx.slots.register({
2314
+ name: 'plugins.bundle.config',
2315
+ key: NS,
2316
+ }, (props) => (props && props.view === 'summary' ? h(AutoUpdateSummary) : h(AutoUpdateCard))))
2317
+ }
2032
2318
 
2033
2319
  // 设置 → 插件更新:挂成独立的一页,写法照抄 dsh-our-free-model-balance-zxp
2034
2320
  // 的「渠道余额」。原来只有插件页里那张卡,想改策略得先去插件页翻它。
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)))
2321
+ if (display.showSettingsSection) {
2322
+ ctx.slots.inject('settings.section', () => ctx.slots.register({
2323
+ name: 'settings.section',
2324
+ id: NS,
2325
+ order: 36,
2326
+ label: () => T.pageLabel,
2327
+ }, () => h(AutoUpdateCard)))
2328
+ }
2041
2329
 
2042
2330
  // 插件页标签栏多一个「版本管理」:和设置页分工——设置页管「什么时候自动升」,
2043
2331
  // 这一页管「现在就要某一版」。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)))
2332
+ if (display.showVersionsTab) {
2333
+ ctx.slots.inject('plugins.tab', () => ctx.slots.register({
2334
+ name: 'plugins.tab',
2335
+ id: NS,
2336
+ order: 2,
2337
+ label: () => T.versionsTab,
2338
+ }, () => h(VersionsTab)))
2339
+ }
2050
2340
  },
2051
2341
  }
2052
2342
  },
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.7.5",
3
+ "version": "0.8.1",
4
4
  "type": "module",
5
5
  "description": "定时检查 DSH 插件更新,串行安装后就地生效,不重启;支持多种调度节奏、失败抑制、按包回滚,并在动手前留快照、忙时自动让开;不更新/只更新哪些插件改成勾选,发现更新在右下角提醒,日志最新在最上面,并在「设置 → 插件更新」里有独立一页。",
6
6
  "license": "MIT",