@michengai/dsh-im-connect 0.1.76 → 1.0.0
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/CHANGELOG.md +21 -0
- package/CHANGELOG.zh-CN.md +21 -0
- package/README.md +6 -4
- package/README.zh-CN.md +6 -4
- package/client.js +692 -107
- package/lib/channels/weixin.d.ts.map +1 -1
- package/lib/channels/weixin.js +2 -0
- package/lib/channels/weixin.js.map +1 -1
- package/lib/client.js +724 -340
- package/lib/engine/assistant-text.d.ts +11 -0
- package/lib/engine/assistant-text.d.ts.map +1 -0
- package/lib/engine/assistant-text.js +12 -0
- package/lib/engine/assistant-text.js.map +1 -0
- package/lib/engine/choices.d.ts +2 -0
- package/lib/engine/choices.d.ts.map +1 -1
- package/lib/engine/choices.js +4 -2
- package/lib/engine/choices.js.map +1 -1
- package/lib/engine/deferred-delivery.d.ts +1 -1
- package/lib/engine/deferred-delivery.d.ts.map +1 -1
- package/lib/engine/deferred-delivery.js +3 -2
- package/lib/engine/deferred-delivery.js.map +1 -1
- package/lib/engine/delivery-history.d.ts +1 -1
- package/lib/engine/delivery-history.d.ts.map +1 -1
- package/lib/engine/delivery-history.js +2 -2
- package/lib/engine/delivery-history.js.map +1 -1
- package/lib/engine/file-delivery.js +1 -1
- package/lib/engine/file-delivery.js.map +1 -1
- package/lib/engine/gateway.d.ts.map +1 -1
- package/lib/engine/gateway.js +10 -8
- package/lib/engine/gateway.js.map +1 -1
- package/lib/engine/question.d.ts +1 -0
- package/lib/engine/question.d.ts.map +1 -1
- package/lib/engine/question.js +5 -1
- package/lib/engine/question.js.map +1 -1
- package/lib/engine/types.d.ts +2 -0
- package/lib/engine/types.d.ts.map +1 -1
- package/lib/plugin-updater.d.ts +3 -0
- package/lib/plugin-updater.d.ts.map +1 -1
- package/lib/plugin-updater.js +188 -3
- package/lib/plugin-updater.js.map +1 -1
- package/package.json +16 -16
- package/src/channels/weixin.ts +2 -0
- package/src/engine/assistant-text.ts +12 -0
- package/src/engine/choices.ts +11 -3
- package/src/engine/deferred-delivery.ts +3 -2
- package/src/engine/delivery-history.ts +2 -2
- package/src/engine/file-delivery.ts +1 -1
- package/src/engine/gateway.ts +10 -8
- package/src/engine/question.ts +5 -2
- package/src/engine/types.ts +2 -0
- package/src/plugin-update-ui.js +32 -13
- package/src/plugin-updater.ts +162 -3
package/src/plugin-update-ui.js
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
const UPDATE_HEADER = "x-michengai-plugin-update";
|
|
2
2
|
const STYLE_ID = "michengai-plugin-update-ui";
|
|
3
|
+
const updatePrimitives = (typeof require === "function" ? (function () { try { return require("@deepseek-ai/dsh-client-ui-primitives"); } catch { return {}; } })() : {});
|
|
4
|
+
const UpdatePrimitiveButton = typeof updatePrimitives.Button === "function" ? updatePrimitives.Button : function FallbackButton(props) {
|
|
5
|
+
const iconNode = props && props.icon ? React.createElement("span", { key: "icon", className: "ima-btn-icon", style: { display: "inline-flex", alignItems: "center" } }, props.icon) : null;
|
|
6
|
+
const content = iconNode ? [iconNode, props && props.children] : (props && props.children);
|
|
7
|
+
const classes = ["ima-btn", "ima-link-btn", props && props.className].filter(Boolean).join(" ");
|
|
8
|
+
return React.createElement("button", Object.assign({}, props, { type: "button", className: classes, icon: undefined }), content);
|
|
9
|
+
};
|
|
10
|
+
function Progress() {
|
|
11
|
+
return React.createElement("div", { className: "mpi-progress", role: "progressbar", "aria-busy": "true" },
|
|
12
|
+
React.createElement("div", { className: "mpi-progress-bar" })
|
|
13
|
+
);
|
|
14
|
+
}
|
|
3
15
|
const CSS = `
|
|
4
16
|
.mpi-version{margin-left:8px;color:var(--dsw-alias-label-tertiary,#a0a0a0);font-family:inherit;font-size:12px;font-weight:500;line-height:18px;letter-spacing:0;white-space:nowrap;vertical-align:baseline}.mpi-check-host{display:inline-flex;align-items:center}.mpi-icon{display:inline-flex;flex:0 0 auto;width:16px;height:16px;align-items:center;justify-content:center;pointer-events:none}.mpi-icon svg{display:block;width:16px;height:16px}
|
|
5
|
-
.mpi-intro{margin:0 0 16px;color:var(--dsw-alias-label-secondary,#b9b9b9);font-size:13px;line-height:20px}.mpi-meta{display:grid;grid-template-columns:max-content minmax(0,1fr);gap:8px 18px;margin:0 0 16px;font-size:12px;line-height:18px}.mpi-meta dt{color:var(--dsw-alias-label-secondary,#b9b9b9)}.mpi-meta dd{margin:0}.mpi-mono{font-family:ui-monospace,SFMono-Regular,Consolas,monospace}.mpi-latest{display:flex;align-items:baseline;flex-wrap:wrap;gap:4px 10px}.mpi-status{font-size:13px;font-weight:600;line-height:18px}.mpi-status[data-kind=error]{color:var(--dsw-alias-state-error-primary,#ef7272)}.mpi-status[data-kind=success]{color:var(--dsw-alias-state-success-primary,#51b976)}.mpi-status[data-kind=update]{color:#e8b15a !important}.mpi-manual{border-top:
|
|
17
|
+
.mpi-intro{margin:0 0 16px;color:var(--dsw-alias-label-secondary,#b9b9b9);font-size:13px;line-height:20px}.mpi-meta{display:grid;grid-template-columns:max-content minmax(0,1fr);gap:8px 18px;margin:0 0 16px;font-size:12px;line-height:18px}.mpi-meta dt{color:var(--dsw-alias-label-secondary,#b9b9b9)}.mpi-meta dd{margin:0}.mpi-mono{font-family:ui-monospace,SFMono-Regular,Consolas,monospace}.mpi-latest{display:flex;align-items:baseline;flex-wrap:wrap;gap:4px 10px}.mpi-status{font-size:13px;font-weight:600;line-height:18px}.mpi-status[data-kind=error]{color:var(--dsw-alias-state-error-primary,#ef7272)}.mpi-status[data-kind=success]{color:var(--dsw-alias-state-success-primary,#51b976)}.mpi-status[data-kind=update]{color:#e8b15a !important}.mpi-manual{border-top:0.5px solid var(--dsw-alias-border-l2,#494949);padding-top:16px}.mpi-manual h3{margin:0 0 6px;font-size:14px;line-height:20px}.mpi-manual p{margin:0 0 10px;color:var(--dsw-alias-label-secondary,#b9b9b9);font-size:12px;line-height:18px}.mpi-command{display:flex;align-items:flex-start;gap:8px;border:0.5px solid var(--dsw-alias-border-l2,#494949);border-radius:var(--dsw-radius-lg,16px);padding:10px;background:var(--dsw-alias-bg-layer-1,var(--dsw-alias-interactive-bg-hover,transparent))}.mpi-command code{min-width:0;flex:1;overflow:visible;font-family:ui-monospace,SFMono-Regular,Consolas,monospace;font-size:12px;line-height:18px;white-space:pre-wrap;overflow-wrap:anywhere}
|
|
18
|
+
.mpi-progress{height:4px;border-radius:2px;background:var(--dsw-alias-border-l1,#3a3a3a);overflow:hidden;margin:12px 0;position:relative}
|
|
19
|
+
.mpi-progress-bar{height:100%;width:40%;background:var(--dsw-alias-button-primary-fill,#4176e6);border-radius:2px;animation:mpi-progress 1.4s ease-in-out infinite}
|
|
20
|
+
@keyframes mpi-progress{0%{transform:translateX(-100%)}100%{transform:translateX(300%)}}
|
|
21
|
+
@media (prefers-reduced-motion:reduce){.mpi-progress-bar{animation:none;width:100%;opacity:.6}}
|
|
22
|
+
@media(max-width:560px){.mpi-meta{grid-template-columns:1fr;gap:2px}.mpi-meta dd{margin-bottom:6px}}
|
|
6
23
|
`;
|
|
7
24
|
const ZH = {
|
|
8
25
|
check: "检查更新",
|
|
@@ -178,7 +195,10 @@ function UpdateDialog(props) {
|
|
|
178
195
|
}, []);
|
|
179
196
|
React.useEffect(() => { void props.flow.check(); }, [props.flow]);
|
|
180
197
|
React.useEffect(() => {
|
|
181
|
-
const onKey = (event) => {
|
|
198
|
+
const onKey = (event) => {
|
|
199
|
+
if (typeof modalLayers !== "undefined" && modalLayers.length && modalLayers[modalLayers.length - 1].owner !== "update") return;
|
|
200
|
+
handlePluginUpdateEscape(event, props.onClose);
|
|
201
|
+
};
|
|
182
202
|
document.addEventListener("keydown", onKey, true);
|
|
183
203
|
return () => document.removeEventListener("keydown", onKey, true);
|
|
184
204
|
}, [props.onClose]);
|
|
@@ -187,13 +207,12 @@ function UpdateDialog(props) {
|
|
|
187
207
|
const name = lang.toLowerCase().startsWith("en") ? props.enName : props.zhName;
|
|
188
208
|
const command = manualPluginUpdateCommand(view.profileRaw, props.packageName, view.latestRaw);
|
|
189
209
|
const copyLabel = copyState === "copied" ? view.copy.copied : copyState === "failed" ? view.copy.copyFailed : view.copy.copy;
|
|
190
|
-
return React.createElement(
|
|
191
|
-
open: true, className: "mpi-dialog",
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
React.createElement(
|
|
195
|
-
|
|
196
|
-
],
|
|
210
|
+
return React.createElement(HostThemeProvider, null, React.createElement(Modal, {
|
|
211
|
+
open: true, className: "mpi-dialog", layerOwner: "update", title: `${name} ${view.copy.update}`, onCancel: props.onClose,
|
|
212
|
+
footer: React.createElement("div", { className: "ima-modal-actions" },
|
|
213
|
+
React.createElement(UpdatePrimitiveButton, { key: "check", variant: "outline", size: "sm", disabled: view.busy, onClick: () => { void props.flow.check(); } }, view.copy.recheck),
|
|
214
|
+
React.createElement(UpdatePrimitiveButton, { key: "update", variant: "primary", size: "sm", disabled: view.disabled, onClick: () => { void props.flow.update(); } }, view.updateLabel),
|
|
215
|
+
),
|
|
197
216
|
}, React.createElement("div", { ref: bodyRef },
|
|
198
217
|
React.createElement("p", { className: "mpi-intro" }, view.copy.intro),
|
|
199
218
|
React.createElement("dl", { className: "mpi-meta" },
|
|
@@ -206,7 +225,7 @@ function UpdateDialog(props) {
|
|
|
206
225
|
React.createElement("p", null, view.copy.manualHint),
|
|
207
226
|
React.createElement("div", { className: "mpi-command" },
|
|
208
227
|
React.createElement("code", null, command),
|
|
209
|
-
React.createElement(
|
|
228
|
+
React.createElement(UpdatePrimitiveButton, { variant: "outline", size: "sm", disabled: view.busy, onClick: () => {
|
|
210
229
|
const write = navigator.clipboard?.writeText(command);
|
|
211
230
|
if (write === undefined) { setCopyState("failed"); return; }
|
|
212
231
|
void write.then(() => { setCopyState("copied"); window.setTimeout(() => setCopyState("idle"), 1400); }).catch(() => setCopyState("failed"));
|
|
@@ -234,9 +253,9 @@ function observePluginUpdate(options) {
|
|
|
234
253
|
if (buttonRoot === undefined) return;
|
|
235
254
|
if (iconNode === undefined) iconNode = options.createIcon("refresh");
|
|
236
255
|
const icon = iconNode;
|
|
237
|
-
buttonRoot.render(React.createElement(
|
|
238
|
-
|
|
239
|
-
}, React.createElement("span", { "data-mpi-label": "" }, pluginUpdateCopy(document.documentElement.lang).check)))
|
|
256
|
+
buttonRoot.render(React.createElement(UpdatePrimitiveButton, {
|
|
257
|
+
variant: "outline", size: "sm", onClick: openDialog, icon: React.createElement(HostIcon, { node: icon }),
|
|
258
|
+
}, React.createElement("span", { "data-mpi-label": "" }, pluginUpdateCopy(document.documentElement.lang).check)));
|
|
240
259
|
};
|
|
241
260
|
const closeDialog = () => { dialogRoot?.unmount(); dialogRoot = undefined; dialogHost?.remove(); dialogHost = undefined; };
|
|
242
261
|
function openDialog() {
|
package/src/plugin-updater.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Context } from '@deepseek-ai/cordis'
|
|
2
2
|
import { spawn } from 'node:child_process'
|
|
3
3
|
import { existsSync, readFileSync } from 'node:fs'
|
|
4
|
-
import { readFile } from 'node:fs/promises'
|
|
4
|
+
import { readFile, rename, unlink, writeFile } from 'node:fs/promises'
|
|
5
5
|
import { homedir } from 'node:os'
|
|
6
6
|
import { basename, delimiter, dirname, isAbsolute, resolve } from 'node:path'
|
|
7
7
|
import { fileURLToPath } from 'node:url'
|
|
@@ -267,6 +267,155 @@ async function status(options: PluginUpdaterOptions, target: Runtime): Promise<V
|
|
|
267
267
|
}
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
+
function releaseAgeSpec(packageSpec: string) {
|
|
271
|
+
const at = packageSpec.lastIndexOf('@')
|
|
272
|
+
if (at <= 0) return undefined
|
|
273
|
+
const name = packageSpec.slice(0, at)
|
|
274
|
+
const version = packageSpec.slice(at + 1)
|
|
275
|
+
if (!isPackageName(name) || !isReleaseVersion(version)) return undefined
|
|
276
|
+
return { name, version }
|
|
277
|
+
}
|
|
278
|
+
function isPackageName(name: string) {
|
|
279
|
+
return /^@[^/\s]+\/[^/\s]+$/.test(name) || /^[^@/\s]+$/.test(name)
|
|
280
|
+
}
|
|
281
|
+
function isReleaseVersion(version: string) {
|
|
282
|
+
return /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(version)
|
|
283
|
+
}
|
|
284
|
+
function unreadableReleaseAgeExclude() {
|
|
285
|
+
return new Error('发布年龄白名单无法安全合并,已停止更新,避免这个 profile 之后无法安装插件。')
|
|
286
|
+
}
|
|
287
|
+
function excludeEntry(indent: string, name: string, versions: readonly string[], comment = '') {
|
|
288
|
+
const entry = `${indent}- '${name}@${versions.join(' || ')}'`
|
|
289
|
+
return comment === '' ? entry : `${entry} ${comment}`
|
|
290
|
+
}
|
|
291
|
+
function parseExcludeLine(line: string) {
|
|
292
|
+
const dash = line.indexOf('-')
|
|
293
|
+
if (!/^\s+-/.test(line) || dash < 0) return undefined
|
|
294
|
+
const indent = line.slice(0, dash)
|
|
295
|
+
const raw = line.slice(dash + 1).trim()
|
|
296
|
+
let body = raw
|
|
297
|
+
let comment = ''
|
|
298
|
+
if (raw.startsWith("'") || raw.startsWith('"')) {
|
|
299
|
+
const quote = raw[0] ?? "'"
|
|
300
|
+
const end = raw.lastIndexOf(quote)
|
|
301
|
+
if (end <= 0) return undefined
|
|
302
|
+
const rest = raw.slice(end + 1).trim()
|
|
303
|
+
if (rest !== '' && !rest.startsWith('#')) return undefined
|
|
304
|
+
if (rest.startsWith('#')) comment = rest
|
|
305
|
+
body = raw.slice(1, end)
|
|
306
|
+
} else if (raw.includes('#')) return undefined
|
|
307
|
+
if (body.includes('#')) return undefined
|
|
308
|
+
const versionAt = body.lastIndexOf('@')
|
|
309
|
+
if (versionAt > 0) {
|
|
310
|
+
const name = body.slice(0, versionAt)
|
|
311
|
+
const versions = body.slice(versionAt + 1).split(' || ')
|
|
312
|
+
if (isPackageName(name) && versions.every(isReleaseVersion)) return { indent, name, versions, comment }
|
|
313
|
+
return undefined
|
|
314
|
+
}
|
|
315
|
+
if (isPackageName(body) || /^@[^/\s]+\/\*$/.test(body)) return { indent, name: body, versions: undefined, comment }
|
|
316
|
+
return undefined
|
|
317
|
+
}
|
|
318
|
+
/** 把刚安装的精确版本并进 profile 白名单。pnpm 每个包名只认第一条,所以必须并进已有 union,不能另起一行,也不能收成裸包名。 */
|
|
319
|
+
export function mergeMinimumReleaseAgeExclude(yaml: string, packageSpec: string) {
|
|
320
|
+
const spec = releaseAgeSpec(packageSpec)
|
|
321
|
+
if (spec === undefined) throw new Error('更新版本无法写入发布年龄白名单,已停止更新。')
|
|
322
|
+
const eol = yaml.includes('\r\n') ? '\r\n' : '\n'
|
|
323
|
+
const text = yaml.replaceAll('\r\n', '\n')
|
|
324
|
+
const next = mergeReleaseAgeText(text, spec.name, spec.version)
|
|
325
|
+
return eol === '\r\n' ? next.replaceAll('\n', '\r\n') : next
|
|
326
|
+
}
|
|
327
|
+
function mergeReleaseAgeText(yaml: string, name: string, version: string) {
|
|
328
|
+
if (/minimumReleaseAgeExclude:[^\n\r]/.test(yaml)) throw unreadableReleaseAgeExclude()
|
|
329
|
+
const marker = /(?:^|\n)minimumReleaseAgeExclude:[ \t]*(?:\n|$)/.exec(yaml)
|
|
330
|
+
if (marker === null) {
|
|
331
|
+
const base = yaml.endsWith('\n') || yaml.length === 0 ? yaml : `${yaml}\n`
|
|
332
|
+
const gap = base.length === 0 || base.endsWith('\n\n') ? '' : '\n'
|
|
333
|
+
return `${base}${gap}minimumReleaseAgeExclude:\n - '${name}@${version}'\n`
|
|
334
|
+
}
|
|
335
|
+
const keyAt = (marker.index ?? 0) + (marker[0].startsWith('\n') ? 1 : 0)
|
|
336
|
+
let cursor = keyAt + 'minimumReleaseAgeExclude:'.length
|
|
337
|
+
while (cursor < yaml.length && (yaml[cursor] === ' ' || yaml[cursor] === '\t')) cursor += 1
|
|
338
|
+
if (yaml[cursor] !== '\n') throw unreadableReleaseAgeExclude()
|
|
339
|
+
const bodyStart = cursor + 1
|
|
340
|
+
const lines: string[] = []
|
|
341
|
+
let bodyEnd = bodyStart
|
|
342
|
+
while (bodyEnd <= yaml.length) {
|
|
343
|
+
const nextNl = yaml.indexOf('\n', bodyEnd)
|
|
344
|
+
const lineEnd = nextNl === -1 ? yaml.length : nextNl
|
|
345
|
+
const line = yaml.slice(bodyEnd, lineEnd)
|
|
346
|
+
const ended = line.trim() !== '' && !/^[ \t]*#/.test(line) && !/^[ \t]/.test(line)
|
|
347
|
+
if (ended) break
|
|
348
|
+
if (line.trim() !== '' && !/^[ \t]*#/.test(line) && !/^[ \t]+-/.test(line)) throw unreadableReleaseAgeExclude()
|
|
349
|
+
lines.push(line)
|
|
350
|
+
if (nextNl === -1) {
|
|
351
|
+
bodyEnd = yaml.length
|
|
352
|
+
break
|
|
353
|
+
}
|
|
354
|
+
bodyEnd = nextNl + 1
|
|
355
|
+
if (bodyEnd === yaml.length) break
|
|
356
|
+
}
|
|
357
|
+
let ours: { index: number; versions: string[] | undefined; indent: string; comment: string } | undefined
|
|
358
|
+
const rewritten = lines.map((line, index) => {
|
|
359
|
+
if (line.trim() === '' || /^[ \t]*#/.test(line)) return line
|
|
360
|
+
const parsed = parseExcludeLine(line)
|
|
361
|
+
if (parsed === undefined) throw unreadableReleaseAgeExclude()
|
|
362
|
+
if (parsed.name !== name) return line
|
|
363
|
+
if (ours === undefined) {
|
|
364
|
+
ours = { index, indent: parsed.indent, versions: parsed.versions, comment: parsed.comment }
|
|
365
|
+
return line
|
|
366
|
+
}
|
|
367
|
+
if (ours.versions !== undefined && parsed.versions !== undefined) ours.versions = [...ours.versions, ...parsed.versions.filter((item) => !ours?.versions?.includes(item))]
|
|
368
|
+
return ''
|
|
369
|
+
})
|
|
370
|
+
if (ours?.versions === undefined && ours !== undefined) return yaml
|
|
371
|
+
const indent = ours?.indent ?? lines.find((line) => /^[ \t]+-/.test(line))?.match(/^([ \t]+)/)?.[1] ?? ' '
|
|
372
|
+
const versions = ours?.versions === undefined ? [version] : ours.versions.includes(version) ? ours.versions : [...ours.versions, version]
|
|
373
|
+
const entry = excludeEntry(indent, name, versions, ours?.comment ?? '')
|
|
374
|
+
if (ours === undefined) rewritten.push(entry)
|
|
375
|
+
else rewritten[ours.index] = entry
|
|
376
|
+
const body = rewritten.filter((line) => line !== '').join('\n')
|
|
377
|
+
const prefix = yaml.slice(0, bodyStart)
|
|
378
|
+
const suffix = yaml.slice(bodyEnd)
|
|
379
|
+
const joined = `${prefix}${body}${body.length === 0 || body.endsWith('\n') ? '' : '\n'}${suffix}`
|
|
380
|
+
return joined.endsWith('\n') ? joined : `${joined}\n`
|
|
381
|
+
}
|
|
382
|
+
async function guardReleaseAgeExclude(profileDir: string, packageSpec: string) {
|
|
383
|
+
const file = resolve(profileDir, 'pnpm-workspace.yaml')
|
|
384
|
+
const current = existsSync(file) ? await readFile(file, 'utf8') : 'packages:\n - .\n'
|
|
385
|
+
mergeMinimumReleaseAgeExclude(current, packageSpec)
|
|
386
|
+
}
|
|
387
|
+
async function replaceTextFile(file: string, next: string) {
|
|
388
|
+
const tmp = `${file}.${process.pid}.tmp`
|
|
389
|
+
const backup = `${file}.${process.pid}.bak`
|
|
390
|
+
await writeFile(tmp, next, 'utf8')
|
|
391
|
+
try {
|
|
392
|
+
await rename(tmp, file)
|
|
393
|
+
return
|
|
394
|
+
} catch (error) {
|
|
395
|
+
const code = error && typeof error === 'object' && 'code' in error ? String(error.code) : ''
|
|
396
|
+
if (code !== 'EEXIST' && code !== 'EPERM' && code !== 'EACCES') {
|
|
397
|
+
await unlink(tmp).catch(() => {})
|
|
398
|
+
throw error
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
await unlink(backup).catch(() => {})
|
|
402
|
+
await rename(file, backup)
|
|
403
|
+
try {
|
|
404
|
+
await rename(tmp, file)
|
|
405
|
+
} catch (error) {
|
|
406
|
+
await rename(backup, file).catch(() => {})
|
|
407
|
+
await unlink(tmp).catch(() => {})
|
|
408
|
+
throw error
|
|
409
|
+
}
|
|
410
|
+
await unlink(backup).catch(() => {})
|
|
411
|
+
}
|
|
412
|
+
export async function recordReleaseAgeExclude(profileDir: string, packageSpec: string) {
|
|
413
|
+
const file = resolve(profileDir, 'pnpm-workspace.yaml')
|
|
414
|
+
const current = existsSync(file) ? await readFile(file, 'utf8') : 'packages:\n - .\n'
|
|
415
|
+
const next = mergeMinimumReleaseAgeExclude(current, packageSpec)
|
|
416
|
+
if (next !== current) await replaceTextFile(file, next)
|
|
417
|
+
}
|
|
418
|
+
|
|
270
419
|
async function runCliInstall(target: Runtime, packageSpec: string): Promise<void> {
|
|
271
420
|
if (target.cliEntry === undefined) throw new Error('当前环境不支持自动更新,请使用手工更新命令。')
|
|
272
421
|
await new Promise<void>((resolvePromise, reject) => {
|
|
@@ -288,12 +437,15 @@ async function runCliInstall(target: Runtime, packageSpec: string): Promise<void
|
|
|
288
437
|
|
|
289
438
|
async function install(target: Runtime, packageSpec: string): Promise<void> {
|
|
290
439
|
if (target.desktopPnpm !== undefined) {
|
|
440
|
+
await guardReleaseAgeExclude(target.profileDir, packageSpec)
|
|
291
441
|
const handle = target.desktopPnpm.runPlugin(['add', '--config.minimumReleaseAge=0', packageSpec, '--registry=https://registry.npmjs.org/'], target.profileDir)
|
|
292
442
|
const result = await handle.done
|
|
293
443
|
if (result.exitCode !== 0) throw new Error(`更新进程退出码 ${String(result.exitCode)}。`)
|
|
444
|
+
await recordReleaseAgeExclude(target.profileDir, packageSpec)
|
|
294
445
|
return
|
|
295
446
|
}
|
|
296
447
|
if (target.packageManager !== undefined) {
|
|
448
|
+
await guardReleaseAgeExclude(target.profileDir, packageSpec)
|
|
297
449
|
const manager = target.packageManager
|
|
298
450
|
await new Promise<void>((resolvePromise, reject) => {
|
|
299
451
|
const child = spawn(manager.command, [...manager.args, 'add', '--config.minimumReleaseAge=0', packageSpec, '--registry=https://registry.npmjs.org/'], {
|
|
@@ -306,14 +458,21 @@ async function install(target: Runtime, packageSpec: string): Promise<void> {
|
|
|
306
458
|
child.once('error', error => { clearTimeout(timer); reject(error) })
|
|
307
459
|
child.once('exit', code => { clearTimeout(timer); if (code === 0) resolvePromise(); else reject(new Error(detail.trim() || `更新进程退出码 ${String(code)}`)) })
|
|
308
460
|
})
|
|
461
|
+
await recordReleaseAgeExclude(target.profileDir, packageSpec)
|
|
309
462
|
return
|
|
310
463
|
}
|
|
311
464
|
if (target.pluginManager !== undefined) {
|
|
465
|
+
await guardReleaseAgeExclude(target.profileDir, packageSpec)
|
|
312
466
|
const result = await target.pluginManager.installBundle(packageSpec)
|
|
313
|
-
if (result.application === 'applied' || result.application === 'restart-required' || result.application === 'overridden')
|
|
467
|
+
if (result.application === 'applied' || result.application === 'restart-required' || result.application === 'overridden') {
|
|
468
|
+
await recordReleaseAgeExclude(target.profileDir, packageSpec)
|
|
469
|
+
return
|
|
470
|
+
}
|
|
314
471
|
throw new Error(result.error?.message || result.packageResult?.output || '更新失败,请查看服务端日志。')
|
|
315
472
|
}
|
|
316
|
-
|
|
473
|
+
await guardReleaseAgeExclude(target.profileDir, packageSpec)
|
|
474
|
+
await runCliInstall(target, packageSpec)
|
|
475
|
+
await recordReleaseAgeExclude(target.profileDir, packageSpec)
|
|
317
476
|
}
|
|
318
477
|
|
|
319
478
|
function json(response: HostResponse, statusCode: number, value: unknown): void {
|