dsh-mobile-plugin 0.1.61 → 0.1.63

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/lib/index.js CHANGED
@@ -60,6 +60,10 @@ export function apply(ctx) {
60
60
  const fn = ctx.logger?.[level]
61
61
  if (typeof fn === 'function') fn.call(ctx.logger, message, ...rest)
62
62
  }
63
+ /** 取一个宿主服务,拿不到就当没有(更新的两道判据都要它,缺了只降级、不抛)。 */
64
+ const hostService = key => {
65
+ try { return typeof ctx.get === 'function' ? ctx.get(key) ?? null : null } catch { return null }
66
+ }
63
67
 
64
68
  /** 查一次有没有新版。只记结果,装不装由开关或人来决定。 */
65
69
  async function check({ force = false } = {}) {
@@ -85,7 +89,14 @@ export function apply(ctx) {
85
89
  * 不照做 —— 外壳自己换代码,这正是这个文件存在的全部理由。
86
90
  */
87
91
  async function applyUpdate({ force = false } = {}) {
88
- const outcome = await updater.installIfNeeded(base(), { force })
92
+ const outcome = await updater.installIfNeeded(base(), {
93
+ force,
94
+ // 宿主发布的包管理器优先(PATH 上那个的版本可能和 profile 的 store 对不上,实测
95
+ // 10.x 装 11.x 的 profile 直接 `ERR_PNPM_UNEXPECTED_STORE`);agents 是「有对话在跑
96
+ // 就别换文件」那道闸的判据。自动更新永远不带 force。
97
+ packageManager: () => hostService('profileContext')?.packageManager ?? null,
98
+ agents: () => hostService('agents'),
99
+ })
89
100
  let swapped = false
90
101
  let status = runtime.status()
91
102
  if (outcome.installed) {