@whyshu/argent 0.1.10 → 0.1.11
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/bin/argent.mjs +11 -3
- package/lib/index.mjs +32 -5
- package/package.json +1 -1
package/bin/argent.mjs
CHANGED
|
@@ -223,7 +223,7 @@ async function updateCommand(sub) {
|
|
|
223
223
|
}
|
|
224
224
|
const current = launcherVersion()
|
|
225
225
|
let remote
|
|
226
|
-
try { remote = await checkForUpdate({ target: opts.target, registry: opts.registry }) }
|
|
226
|
+
try { remote = await checkForUpdate({ target: opts.target, registry: opts.registry, dshHome: opts.dshHome, profile: opts.profile }) }
|
|
227
227
|
catch (e) { console.error(`❌ 检查更新失败:${e.message}`); process.exit(2) }
|
|
228
228
|
if (!remote.ok) {
|
|
229
229
|
if (JSON_OUT) console.log(JSON.stringify(remote, null, 2)); else console.error(`❌ ${remote.message}`)
|
|
@@ -237,13 +237,14 @@ async function updateCommand(sub) {
|
|
|
237
237
|
console.log(`当前启动器: ${current || '(未知)'}`)
|
|
238
238
|
console.log(`npm latest: ${remote.latest}`)
|
|
239
239
|
console.log(remote.updateAvailable ? '→ 有可用更新' : '→ 已是最新')
|
|
240
|
+
if (remote.pluginUpdates?.length) console.log('插件可更新:' + remote.pluginUpdates.map((x) => `${x.name} ${x.current}→${x.latest}`).join(';'))
|
|
240
241
|
console.log(`runtime: ${remote.runtime || '(未物化)'} @ ${remote.runtimeTarget}`)
|
|
241
242
|
console.log(`来源: ${remote.registry}`)
|
|
242
243
|
}
|
|
243
244
|
return
|
|
244
245
|
}
|
|
245
|
-
if (
|
|
246
|
-
console.log(`已是最新(${current}),无需更新。`)
|
|
246
|
+
if (!remote.updateAvailable && !has('--force')) {
|
|
247
|
+
console.log(`已是最新(${current}${remote.pluginUpdates?.length ? ',插件也无更新' : ''}),无需更新。`)
|
|
247
248
|
return
|
|
248
249
|
}
|
|
249
250
|
const npx = process.platform === 'win32' ? 'npx.cmd' : 'npx'
|
|
@@ -259,6 +260,13 @@ async function updateCommand(sub) {
|
|
|
259
260
|
console.error('⛔ 更新会改 runtime / profile 插件,必须显式加 --yes。先看计划:argent update run --dry-run')
|
|
260
261
|
process.exit(2)
|
|
261
262
|
}
|
|
263
|
+
// 宿主版本不匹配时绝不能先改 profile(新插件可能要求新 dsh;改完再 health 失败会留下半升级)。
|
|
264
|
+
const dshProbe = probeDshVersion()
|
|
265
|
+
if (!dshProbe.ok || !versionMatches(dshProbe.version)) {
|
|
266
|
+
console.error(`⛔ 宿主 dsh 版本不匹配:当前 ${dshProbe.ok ? dshProbe.version : '(未找到)'},启动器要求 ${DSH_EXACT_VERSION}。`)
|
|
267
|
+
console.error(' 请先按客户机 dsh 升级流程升级宿主,再重跑 update run;本次未改任何文件。')
|
|
268
|
+
process.exit(2)
|
|
269
|
+
}
|
|
262
270
|
const stamp = new Date().toISOString().replace(/[:.]/g, '-')
|
|
263
271
|
const profileDir = join(opts.dshHome, 'profiles', opts.profile)
|
|
264
272
|
const backupDir = join(opts.dshHome, 'argent', 'backup', `update-${stamp}`)
|
package/lib/index.mjs
CHANGED
|
@@ -403,18 +403,45 @@ export function readRuntimeVersion(target = join(homedir(), '.argent-dsh')) {
|
|
|
403
403
|
} catch { return '' }
|
|
404
404
|
}
|
|
405
405
|
|
|
406
|
+
/** 读 profile 当前插件版本(用于判断“runtime 已是最新、但插件还是旧版”)。 */
|
|
407
|
+
export function readProfilePluginVersions({ dshHome = dshHomeOf(), profile = PROFILE_NAME } = {}) {
|
|
408
|
+
try {
|
|
409
|
+
const pkg = JSON.parse(readFileSync(join(profileDir(dshHome, profile), 'package.json'), 'utf8'))
|
|
410
|
+
const deps = pkg && typeof pkg.dependencies === 'object' ? pkg.dependencies : {}
|
|
411
|
+
const out = {}
|
|
412
|
+
for (const [name, ver] of Object.entries(deps)) {
|
|
413
|
+
if (!name.startsWith('@whyshu/argent-')) continue
|
|
414
|
+
const v = String(ver || '')
|
|
415
|
+
out[name] = v.startsWith('file:') ? '' : v
|
|
416
|
+
}
|
|
417
|
+
return out
|
|
418
|
+
} catch { return {} }
|
|
419
|
+
}
|
|
420
|
+
|
|
406
421
|
/** 检查更新(只读;不下载、不安装)。 */
|
|
407
422
|
export async function checkForUpdate({
|
|
408
|
-
launcherLib,
|
|
423
|
+
launcherLib, dshHome = dshHomeOf(), profile = PROFILE_NAME,
|
|
424
|
+
target = join(homedir(), '.argent-dsh'), registry = process.env.ARGENT_NPM_REGISTRY || DEFAULT_NPM_REGISTRY,
|
|
409
425
|
fetchImpl = globalThis.fetch,
|
|
410
426
|
} = {}) {
|
|
411
427
|
const current = launcherVersion(launcherLib)
|
|
412
428
|
const remote = await latestLauncherVersion({ registry, fetchImpl })
|
|
413
429
|
const runtime = readRuntimeVersion(target)
|
|
414
|
-
|
|
415
|
-
|
|
430
|
+
const installedPlugins = readProfilePluginVersions({ dshHome, profile })
|
|
431
|
+
if (!remote.ok) return { ok: false, code: remote.code, message: remote.message, current, runtime, installedPlugins, registry }
|
|
432
|
+
const pluginUpdates = []
|
|
433
|
+
for (const [name, want] of Object.entries(PUBLISHED_BUNDLE_VERSIONS)) {
|
|
434
|
+
const have = installedPlugins[name]
|
|
435
|
+
// 本地 file: 装配(开发机)不算可更新客户机;只比较明确版本号。
|
|
436
|
+
if (!have || !want) continue
|
|
437
|
+
if (compareVersions(want, have) > 0) pluginUpdates.push({ name, current: have, latest: want })
|
|
438
|
+
}
|
|
439
|
+
const launcherUpdate = current ? compareVersions(remote.version, current) > 0 : true
|
|
416
440
|
return {
|
|
417
|
-
ok: true, current, latest: remote.version,
|
|
418
|
-
|
|
441
|
+
ok: true, current, latest: remote.version,
|
|
442
|
+
updateAvailable: Boolean(launcherUpdate || pluginUpdates.length),
|
|
443
|
+
launcherUpdate, pluginUpdates, installedPlugins,
|
|
444
|
+
registry: remote.registry, integrity: remote.integrity, tarball: remote.tarball,
|
|
445
|
+
runtime, runtimeTarget: target,
|
|
419
446
|
}
|
|
420
447
|
}
|