@covro/covro 0.9.1-dev.2 → 0.9.1-dev.3
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 +1 -1
- package/README.zh-CN.md +1 -1
- package/dist/cli/control.js +5 -1
- package/dist/cli/control.js.map +2 -2
- package/dist/cli/daemon.js +21 -1
- package/dist/cli/daemon.js.map +2 -2
- package/dist/server/http.js +5 -0
- package/dist/server/http.js.map +3 -3
- package/dist/server/service.js +2 -2
- package/dist/server/service.js.map +2 -2
- package/dist/shared/updates.js.map +2 -2
- package/dist/update-worker.cjs +142 -50
- package/dist/updates/manager.js +125 -21
- package/dist/updates/manager.js.map +2 -2
- package/dist/updates/plan.js +59 -0
- package/dist/updates/plan.js.map +7 -0
- package/dist/updates/worker.js +37 -3
- package/dist/updates/worker.js.map +2 -2
- package/dist/web/assets/{abnfDiagram-WEYOIA3C-Dwk1w868.js → abnfDiagram-WEYOIA3C-BjKPZWkQ.js} +1 -1
- package/dist/web/assets/{arc-DRIvOmRg.js → arc-B9kEeQux.js} +1 -1
- package/dist/web/assets/{architecture-WOLXFQ4H-tMNKNWuC.js → architecture-WOLXFQ4H-DtGpSjpu.js} +1 -1
- package/dist/web/assets/{architectureDiagram-ZHVYKT53-BNmMrcQl.js → architectureDiagram-ZHVYKT53-N421cjgM.js} +1 -1
- package/dist/web/assets/{blockDiagram-RJAE7QA3-DS1OuMPD.js → blockDiagram-RJAE7QA3-xTVjUZvn.js} +1 -1
- package/dist/web/assets/{c4Diagram-XDPPPE54-CmFKbnHD.js → c4Diagram-XDPPPE54-Bzde5CNZ.js} +1 -1
- package/dist/web/assets/channel-BSSgis91.js +1 -0
- package/dist/web/assets/{chunk-2E7WHVMD-VL8kvDQA.js → chunk-2E7WHVMD-DRQNeSoP.js} +1 -1
- package/dist/web/assets/{chunk-4EMNKR2T-JLlww7FR.js → chunk-4EMNKR2T-33yxkote.js} +1 -1
- package/dist/web/assets/{chunk-55XCU76K-Bq5c3Afg.js → chunk-55XCU76K-CW0h-mdD.js} +1 -1
- package/dist/web/assets/{chunk-7S6XSTFO-BPpxtCBn.js → chunk-7S6XSTFO-DCqqhVMc.js} +1 -1
- package/dist/web/assets/{chunk-AQDTSKZB-BBP0lwKL.js → chunk-AQDTSKZB-Dipvair2.js} +1 -1
- package/dist/web/assets/{chunk-DSNLSHJZ-C10XUS9Y.js → chunk-DSNLSHJZ-BURUGXUl.js} +1 -1
- package/dist/web/assets/{chunk-HAGFOTED-LHTmvqv5.js → chunk-HAGFOTED-BIZ-MS0x.js} +1 -1
- package/dist/web/assets/{chunk-HNE4Q36P-2vwd0X-j.js → chunk-HNE4Q36P-C2wQjOA0.js} +1 -1
- package/dist/web/assets/{chunk-NQOKRVIF-C42lIrgK.js → chunk-NQOKRVIF-B2Mev7Zt.js} +1 -1
- package/dist/web/assets/{chunk-UHW7PFBP-Br-2jjaP.js → chunk-UHW7PFBP-BscdqWA6.js} +1 -1
- package/dist/web/assets/{chunk-VQ5W62QI-Cv6PXEf1.js → chunk-VQ5W62QI-D31WLgI4.js} +1 -1
- package/dist/web/assets/{chunk-WQQL4CDK-BttmOOnq.js → chunk-WQQL4CDK-CxAAvC_l.js} +1 -1
- package/dist/web/assets/{chunk-XXDRQBXY-CFyVzTm_.js → chunk-XXDRQBXY--nM5P_MO.js} +1 -1
- package/dist/web/assets/{chunk-YZO67HFG-Bw7IdSRn.js → chunk-YZO67HFG-B8dxZw27.js} +1 -1
- package/dist/web/assets/{chunk-ZAUX2LTX-BjSmbRtC.js → chunk-ZAUX2LTX-ByoVBn5L.js} +1 -1
- package/dist/web/assets/{chunk-ZCHMQSOR-Bzfc5MnU.js → chunk-ZCHMQSOR-sSbSgLw6.js} +1 -1
- package/dist/web/assets/{classDiagram-v2-4MYWR3UA-qeYoJJAt.js → classDiagram-v2-4MYWR3UA-BCtsvTXU.js} +1 -1
- package/dist/web/assets/{cose-bilkent-JH36ORCC-BvjpquOv.js → cose-bilkent-JH36ORCC-9p-DmnKi.js} +1 -1
- package/dist/web/assets/{cynefin-EF2NZ3EQ-D5Y1WOQN.js → cynefin-EF2NZ3EQ-miWeDxJu.js} +1 -1
- package/dist/web/assets/{cynefinDiagram-WF24UDRP-AGSbtRK7.js → cynefinDiagram-WF24UDRP-QPLu03ZE.js} +1 -1
- package/dist/web/assets/{dagre-NK4GIZVX-BBX8q0Q_.js → dagre-NK4GIZVX-CAOLyQK2.js} +1 -1
- package/dist/web/assets/{diagram-CBK3MWTC-B0zTIj27.js → diagram-CBK3MWTC-DepddJst.js} +1 -1
- package/dist/web/assets/{diagram-I5XIIV2D-BuUByx-O.js → diagram-I5XIIV2D-DXFTNR3c.js} +1 -1
- package/dist/web/assets/{diagram-ODIL2UCW-CJSKJ4oh.js → diagram-ODIL2UCW-osFWXWSr.js} +1 -1
- package/dist/web/assets/{diagram-PFBEJUXE-BBW5NaOZ.js → diagram-PFBEJUXE-B_O77v3p.js} +1 -1
- package/dist/web/assets/{diagram-RJA3I4VV-CbbNlBPq.js → diagram-RJA3I4VV-DjruvCfX.js} +1 -1
- package/dist/web/assets/{diagram-TYUNFSNR-C-RuVij0.js → diagram-TYUNFSNR-BvaFbzkd.js} +1 -1
- package/dist/web/assets/{dist-D0GcBgg7.js → dist-CqcAwjz8.js} +1 -1
- package/dist/web/assets/{ebnfDiagram-V4P3TTPT-BSgnX-E5.js → ebnfDiagram-V4P3TTPT-BxBz1jiA.js} +1 -1
- package/dist/web/assets/{elk-QONTBCTQ-BEtCDu8T.js → elk-QONTBCTQ-CYacnrUC.js} +1 -1
- package/dist/web/assets/{erDiagram-KYQIGQAA-CVvcdpSn.js → erDiagram-KYQIGQAA-BvnoTswC.js} +1 -1
- package/dist/web/assets/{eventmodeling-K75KTNOO-Uip57str.js → eventmodeling-K75KTNOO-D71pbA8B.js} +1 -1
- package/dist/web/assets/flowDiagram-IUGLLWBU-Dt5BcUUc.js +1 -0
- package/dist/web/assets/{ganttDiagram-R7GPNTJY-BVHhQcuG.js → ganttDiagram-R7GPNTJY-C6rCQD2I.js} +1 -1
- package/dist/web/assets/{gitGraph-VSP46ZUC-DS34qfdX.js → gitGraph-VSP46ZUC-BGvanMn4.js} +1 -1
- package/dist/web/assets/{gitGraphDiagram-PDYL7XHY-BsQVk-Fx.js → gitGraphDiagram-PDYL7XHY-BHdauTG3.js} +1 -1
- package/dist/web/assets/{index-DXwPOJTh.js → index-B63XFWyv.js} +9 -9
- package/dist/web/assets/{info-OHQRW6UA-D5nXY-pr.js → info-OHQRW6UA-CcjtcXni.js} +1 -1
- package/dist/web/assets/{infoDiagram-MVDRKAX5-DgEUiqZq.js → infoDiagram-MVDRKAX5-MYJobcL9.js} +1 -1
- package/dist/web/assets/{ishikawaDiagram-HPEHV2GE-DjxmLyi4.js → ishikawaDiagram-HPEHV2GE-Psi_IHly.js} +1 -1
- package/dist/web/assets/{journeyDiagram-BOSHW7O7-MoAS0Dy-.js → journeyDiagram-BOSHW7O7-Cr4HAmh0.js} +1 -1
- package/dist/web/assets/{kanban-definition-FNSA4HC5-BPlTAqak.js → kanban-definition-FNSA4HC5-jxyhrW3G.js} +1 -1
- package/dist/web/assets/{line-CLuA_aKc.js → line-CNxlQX4M.js} +1 -1
- package/dist/web/assets/{linear-CCPgkPmA.js → linear--NJWiJ9W.js} +1 -1
- package/dist/web/assets/{mermaid-parser.core-CYclG3kS.js → mermaid-parser.core-sNBwe3zk.js} +3 -3
- package/dist/web/assets/{mermaid.core-CMwgbyRM.js → mermaid.core-Bprxe1pT.js} +4 -4
- package/dist/web/assets/{mindmap-definition-6OY57UG3-CqwSHqPb.js → mindmap-definition-6OY57UG3-C0LMAiFc.js} +1 -1
- package/dist/web/assets/{packet-JDAUHWVQ-DmPU4q5p.js → packet-JDAUHWVQ-vNf7Cv_O.js} +1 -1
- package/dist/web/assets/{pegDiagram-ECIUJNBX-CJqaAe9G.js → pegDiagram-ECIUJNBX-DYUvwQ4J.js} +1 -1
- package/dist/web/assets/{pie-XZMESJXO-FWabtlXG.js → pie-XZMESJXO-CBKeDUwO.js} +1 -1
- package/dist/web/assets/{pieDiagram-GNMPY74T-Cq0RzYPd.js → pieDiagram-GNMPY74T-DTIK7Z-L.js} +1 -1
- package/dist/web/assets/{quadrantDiagram-D57K4MC3-CNor7uu4.js → quadrantDiagram-D57K4MC3-A44MmCfc.js} +1 -1
- package/dist/web/assets/{radar-ABXABTNO-CFEkqeiv.js → radar-ABXABTNO-CJgPqPwV.js} +1 -1
- package/dist/web/assets/{railroad-I3PHUGI6-IlkyK56o.js → railroad-I3PHUGI6--iwkcGQQ.js} +1 -1
- package/dist/web/assets/{railroad-abnf-LNEFI6M7-qJuStEyY.js → railroad-abnf-LNEFI6M7-Dk7z4OWN.js} +1 -1
- package/dist/web/assets/{railroad-ebnf-DWYD2UWJ-k3xCC6xr.js → railroad-ebnf-DWYD2UWJ-D_wdSwm6.js} +1 -1
- package/dist/web/assets/{railroad-peg-JR7BVNR7-iVHAqYEL.js → railroad-peg-JR7BVNR7-CEoZVoK6.js} +1 -1
- package/dist/web/assets/{railroadDiagram-Y72NRBL7-BeG-UZLd.js → railroadDiagram-Y72NRBL7-CUtTGpaj.js} +1 -1
- package/dist/web/assets/{requirementDiagram-EQYSW5RA-DQ6Vuc82.js → requirementDiagram-EQYSW5RA-tH0aCAi1.js} +1 -1
- package/dist/web/assets/{sankeyDiagram-SY24JHO5-DJpwATH0.js → sankeyDiagram-SY24JHO5-D14JYHRm.js} +1 -1
- package/dist/web/assets/{sequenceDiagram-BLEHNHQU-DGlUQHBd.js → sequenceDiagram-BLEHNHQU-D5IY4yFL.js} +1 -1
- package/dist/web/assets/{src-3ryccu9p.js → src-B8K_a83e.js} +1 -1
- package/dist/web/assets/{stateDiagram-v2-A6IESKWZ-C3io1sXA.js → stateDiagram-v2-A6IESKWZ-Co_JCSST.js} +1 -1
- package/dist/web/assets/{swimlanes-B3ENRKFQ-CmcSh4VV.js → swimlanes-B3ENRKFQ-B6Sp1jzn.js} +1 -1
- package/dist/web/assets/swimlanesDiagram-AYQRV4AK-DruJRTbj.js +8 -0
- package/dist/web/assets/{timeline-definition-JXYKGLGB-BR_J0uAm.js → timeline-definition-JXYKGLGB-C39JQvkU.js} +1 -1
- package/dist/web/assets/{treeView-D4JQ5SDB-BZZp3AxX.js → treeView-D4JQ5SDB-COV5qRrd.js} +1 -1
- package/dist/web/assets/{treemap-SAJKECNS-sSzRNn8T.js → treemap-SAJKECNS-BQeVkrEA.js} +1 -1
- package/dist/web/assets/{usecaseDiagram-WPOLBNNX-Ca0b1RdR.js → usecaseDiagram-WPOLBNNX-BZTx892-.js} +1 -1
- package/dist/web/assets/{vennDiagram-Q3Y3IDCW-C469H7YJ.js → vennDiagram-Q3Y3IDCW-CYF0RQdz.js} +1 -1
- package/dist/web/assets/{wardley-7MLQ67FV-Du12nvBi.js → wardley-7MLQ67FV-jpzdSmzm.js} +1 -1
- package/dist/web/assets/{wardleyDiagram-IVAIDKWA-CPhm2ZEC.js → wardleyDiagram-IVAIDKWA-DrXDqijK.js} +1 -1
- package/dist/web/assets/{xychartDiagram-4URNHDU4-0FN7fE0z.js → xychartDiagram-4URNHDU4-B-jWn5HS.js} +1 -1
- package/dist/web/index.html +1 -1
- package/package.json +3 -3
- package/dist/web/assets/channel-CJaCLKUD.js +0 -1
- package/dist/web/assets/flowDiagram-IUGLLWBU-DHyDmVGv.js +0 -1
- package/dist/web/assets/swimlanesDiagram-AYQRV4AK-BOhFPrIq.js +0 -8
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/shared/updates.ts"],
|
|
4
|
-
"sourcesContent": ["import type {\n CodexCompatibility,\n CodexCompatibilityManifest,\n CodexUpdateConfirmation,\n} from './codex-compatibility.js';\nexport const releaseChannels = ['stable', 'beta', 'dev'] as const;\nexport type ReleaseChannel = (typeof releaseChannels)[number];\nexport interface UpdateSettings {\n channel: ReleaseChannel;\n automatic: boolean;\n}\nexport type UpdatePhase =\n 'installing'
|
|
5
|
-
"mappings": "AAKO,MAAM,kBAAkB,CAAC,UAAU,QAAQ,KAAK;
|
|
4
|
+
"sourcesContent": ["import type {\n CodexCompatibility,\n CodexCompatibilityManifest,\n CodexUpdateConfirmation,\n} from './codex-compatibility.js';\nexport const releaseChannels = ['stable', 'beta', 'dev'] as const;\nexport type ReleaseChannel = (typeof releaseChannels)[number];\nexport interface UpdateSettings {\n channel: ReleaseChannel;\n automatic: boolean;\n}\nexport type UpdatePhase =\n | 'installing'\n | 'waiting'\n | 'stopping'\n | 'verifying'\n | 'succeeded'\n | 'rolledBack'\n | 'failed'\n | 'cancelled';\nexport interface RuntimeIdentity {\n node: string;\n nodeVersion: string;\n root: string;\n entry: string;\n npm?: string;\n npmVersion?: string;\n globalRoot?: string;\n}\nexport interface UpdateRun {\n id: string;\n from: string;\n target: string;\n /** Subscribed channel after activation, independent of the candidate's source. */\n channel: ReleaseChannel;\n /** Optional for update records created by older versions. */\n sourceChannel?: ReleaseChannel;\n commit?: string;\n phase: UpdatePhase;\n message: string;\n startedAt: number;\n updatedAt: number;\n committed?: boolean;\n /** Only channel-following automatic plans can change before installation. */\n automatic?: { revision: string };\n transactionStartedAt?: number;\n candidate?: UpdateStatus['available'];\n runtime?: { from: RuntimeIdentity; target: RuntimeIdentity; actual?: RuntimeIdentity };\n codex?: { version: string; manifest: CodexCompatibilityManifest; confirmedUnverified: boolean };\n}\nexport interface UpdateStatus {\n version: string;\n commit?: string;\n source: 'npm';\n codex: CodexCompatibility;\n settings: UpdateSettings;\n available?: {\n version: string;\n requestedChannel: ReleaseChannel;\n /** Actual npm source of the selected version. */\n channel: ReleaseChannel;\n commit?: string;\n downgrade: boolean;\n codex: CodexCompatibility;\n };\n checkedAt?: number;\n checkError?: string;\n supported: boolean;\n unsupportedReason?: string;\n run?: UpdateRun;\n runtime?: {\n current: RuntimeIdentity;\n target?: RuntimeIdentity;\n migration: boolean;\n error?: string;\n };\n}\nexport const updateActive = (run?: UpdateRun) =>\n Boolean(run && ['installing', 'waiting', 'stopping', 'verifying'].includes(run.phase));\nexport interface UpdateController {\n status(): Promise<UpdateStatus>;\n check(channel?: ReleaseChannel): Promise<UpdateStatus>;\n configure(settings: UpdateSettings): Promise<UpdateStatus>;\n start(input: {\n clientOperationId: string;\n channel?: ReleaseChannel;\n allowDowngrade?: boolean;\n codexConfirmation?: CodexUpdateConfirmation;\n }): Promise<UpdateStatus>;\n cancel?(id: string): Promise<UpdateStatus>;\n close(): void;\n}\n"],
|
|
5
|
+
"mappings": "AAKO,MAAM,kBAAkB,CAAC,UAAU,QAAQ,KAAK;AAwEhD,MAAM,eAAe,CAAC,QAC3B,QAAQ,OAAO,CAAC,cAAc,WAAW,YAAY,WAAW,EAAE,SAAS,IAAI,KAAK,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/update-worker.cjs
CHANGED
|
@@ -38725,7 +38725,11 @@ function control(location, action, input2 = {}) {
|
|
|
38725
38725
|
try {
|
|
38726
38726
|
const result = JSON.parse(body);
|
|
38727
38727
|
if (incoming.statusCode !== 200)
|
|
38728
|
-
reject(
|
|
38728
|
+
reject(
|
|
38729
|
+
Object.assign(new Error(result.error ?? "Control request failed"), {
|
|
38730
|
+
code: result.code
|
|
38731
|
+
})
|
|
38732
|
+
);
|
|
38729
38733
|
else resolve4(result);
|
|
38730
38734
|
} catch (error62) {
|
|
38731
38735
|
reject(error62);
|
|
@@ -39168,9 +39172,102 @@ async function stop(location) {
|
|
|
39168
39172
|
var startBackground = (location, entry, runtime) => lifecycle(location, () => start(location, entry, runtime));
|
|
39169
39173
|
var stopBackground = (location) => lifecycle(location, () => stop(location));
|
|
39170
39174
|
|
|
39171
|
-
// src/updates/
|
|
39175
|
+
// src/updates/registry.ts
|
|
39172
39176
|
var import_promises13 = require("node:fs/promises");
|
|
39177
|
+
var import_node_fs4 = require("node:fs");
|
|
39173
39178
|
var import_node_path12 = require("node:path");
|
|
39179
|
+
var registry2 = "https://registry.npmjs.org";
|
|
39180
|
+
var releaseSchema = external_exports.object({
|
|
39181
|
+
name: external_exports.literal(npmPackageName),
|
|
39182
|
+
version: external_exports.string().refine(validVersion),
|
|
39183
|
+
gitHead: external_exports.string().optional(),
|
|
39184
|
+
covroCommit: external_exports.string().optional(),
|
|
39185
|
+
covroCodex: external_exports.unknown().optional()
|
|
39186
|
+
});
|
|
39187
|
+
async function inspectInstallation(root) {
|
|
39188
|
+
try {
|
|
39189
|
+
const globalRoot = (0, import_node_path12.dirname)((0, import_node_path12.dirname)((0, import_node_path12.resolve)(root)));
|
|
39190
|
+
if (!globalRoot.endsWith("/lib/node_modules"))
|
|
39191
|
+
return "\u5F53\u524D\u4E3A\u975E npm \u5168\u5C40\u5B89\u88C5\uFF1B\u8BF7\u4F7F\u7528\u539F\u90E8\u7F72\u65B9\u5F0F\u66F4\u65B0\u3002";
|
|
39192
|
+
if (await (0, import_promises13.realpath)((0, import_node_path12.join)((0, import_node_path12.dirname)((0, import_node_path12.dirname)(globalRoot)), "bin/covro")) !== (0, import_node_path12.join)((0, import_node_path12.resolve)(root), "bin/covro.mjs"))
|
|
39193
|
+
return "\u5F53\u524D Covro \u5165\u53E3\u4E0E npm \u5168\u5C40\u5B89\u88C5\u6765\u6E90\u4E0D\u5339\u914D\uFF1B\u8BF7\u4F7F\u7528\u539F\u90E8\u7F72\u65B9\u5F0F\u66F4\u65B0\u3002";
|
|
39194
|
+
return await inspectPackageDirectory(root, globalRoot);
|
|
39195
|
+
} catch {
|
|
39196
|
+
return "\u65E0\u6CD5\u786E\u8BA4\u53EF\u5199\u7684 npm \u5168\u5C40\u5B89\u88C5\uFF1B\u8BF7\u68C0\u67E5 npm\u3001\u5B89\u88C5\u76EE\u5F55\u6743\u9650\u53CA\u540E\u53F0 PATH\u3002";
|
|
39197
|
+
}
|
|
39198
|
+
}
|
|
39199
|
+
async function inspectPackageDirectory(root, globalRoot) {
|
|
39200
|
+
const expected = (0, import_node_path12.join)(await (0, import_promises13.realpath)(globalRoot), npmPackageName);
|
|
39201
|
+
if ((await (0, import_promises13.lstat)(expected)).isSymbolicLink() || await (0, import_promises13.realpath)(root) !== expected)
|
|
39202
|
+
return "\u5F53\u524D\u4E3A\u6E90\u7801\u3001\u94FE\u63A5\u6216\u975E npm \u5168\u5C40\u5B89\u88C5\uFF1B\u8BF7\u4F7F\u7528\u539F\u90E8\u7F72\u65B9\u5F0F\u66F4\u65B0\u3002";
|
|
39203
|
+
try {
|
|
39204
|
+
await (0, import_promises13.lstat)((0, import_node_path12.join)(expected, ".git"));
|
|
39205
|
+
return "\u5F53\u524D\u5B89\u88C5\u5305\u542B Git \u5DE5\u4F5C\u533A\uFF1B\u8BF7\u4F7F\u7528\u539F\u90E8\u7F72\u65B9\u5F0F\u66F4\u65B0\u3002";
|
|
39206
|
+
} catch (error62) {
|
|
39207
|
+
if (error62.code !== "ENOENT") throw error62;
|
|
39208
|
+
}
|
|
39209
|
+
await (0, import_promises13.access)(root, import_node_fs4.constants.W_OK);
|
|
39210
|
+
return void 0;
|
|
39211
|
+
}
|
|
39212
|
+
|
|
39213
|
+
// src/updates/plan.ts
|
|
39214
|
+
async function waitForAutomaticPlan(run, effects) {
|
|
39215
|
+
const refresh = async (fresh) => {
|
|
39216
|
+
const status = await effects.status(fresh);
|
|
39217
|
+
const candidate = status.available;
|
|
39218
|
+
if (candidate) {
|
|
39219
|
+
run = {
|
|
39220
|
+
...run,
|
|
39221
|
+
target: candidate.version,
|
|
39222
|
+
commit: candidate.commit,
|
|
39223
|
+
sourceChannel: candidate.channel,
|
|
39224
|
+
candidate,
|
|
39225
|
+
codex: candidate.codex.manifest && candidate.codex.version ? {
|
|
39226
|
+
version: candidate.codex.version,
|
|
39227
|
+
manifest: candidate.codex.manifest,
|
|
39228
|
+
confirmedUnverified: false
|
|
39229
|
+
} : void 0,
|
|
39230
|
+
runtime: status.runtime?.target && run.runtime ? {
|
|
39231
|
+
from: run.runtime.from,
|
|
39232
|
+
target: status.runtime.target
|
|
39233
|
+
} : void 0
|
|
39234
|
+
};
|
|
39235
|
+
}
|
|
39236
|
+
run = { ...run, updatedAt: Date.now() };
|
|
39237
|
+
await effects.save(run);
|
|
39238
|
+
if (status.checkError || status.runtime?.error)
|
|
39239
|
+
throw new Error(status.checkError ?? status.runtime?.error);
|
|
39240
|
+
if (!candidate || !status.runtime?.target || candidate.requestedChannel !== run.channel || !candidate.commit || candidate.codex.status !== "verified" || candidate.downgrade || compareVersions(candidate.version, run.from) <= 0)
|
|
39241
|
+
throw new Error(candidate?.codex.reason ?? "\u81EA\u52A8\u5347\u7EA7\u76EE\u6807\u6216\u517C\u5BB9\u6027\u65E0\u6CD5\u786E\u8BA4\uFF0C\u8BF7\u91CD\u65B0\u68C0\u67E5\u66F4\u65B0");
|
|
39242
|
+
return status;
|
|
39243
|
+
};
|
|
39244
|
+
for (; ; ) {
|
|
39245
|
+
await refresh(false);
|
|
39246
|
+
const idle = await effects.readiness();
|
|
39247
|
+
if (idle.ready) {
|
|
39248
|
+
const checked = await refresh(true);
|
|
39249
|
+
const frozen = await effects.freeze(checked.checkedAt);
|
|
39250
|
+
if (frozen.ready && frozen.run) return frozen.run;
|
|
39251
|
+
} else {
|
|
39252
|
+
run = { ...run, message: idle.reason ?? "\u7B49\u5F85\u6240\u6709\u4EFB\u52A1\u7ED3\u675F", updatedAt: Date.now() };
|
|
39253
|
+
await effects.save(run);
|
|
39254
|
+
}
|
|
39255
|
+
await effects.pause();
|
|
39256
|
+
}
|
|
39257
|
+
}
|
|
39258
|
+
async function confirmAutomaticFreeze(id, freeze, readRun) {
|
|
39259
|
+
try {
|
|
39260
|
+
return await freeze();
|
|
39261
|
+
} catch (error62) {
|
|
39262
|
+
const durable = await readRun();
|
|
39263
|
+
if (durable?.id === id && durable.transactionStartedAt) return { ready: true, run: durable };
|
|
39264
|
+
throw error62;
|
|
39265
|
+
}
|
|
39266
|
+
}
|
|
39267
|
+
|
|
39268
|
+
// src/updates/transaction.ts
|
|
39269
|
+
var import_promises14 = require("node:fs/promises");
|
|
39270
|
+
var import_node_path13 = require("node:path");
|
|
39174
39271
|
async function activateUpdate(paths, effects, reuseTarget = false) {
|
|
39175
39272
|
let stopped = false;
|
|
39176
39273
|
let moved = false;
|
|
@@ -39185,9 +39282,9 @@ async function activateUpdate(paths, effects, reuseTarget = false) {
|
|
|
39185
39282
|
await effects.backup();
|
|
39186
39283
|
backedUp = true;
|
|
39187
39284
|
if (!reuseTarget) {
|
|
39188
|
-
await (0,
|
|
39285
|
+
await (0, import_promises14.rename)(paths.root, paths.previous);
|
|
39189
39286
|
moved = true;
|
|
39190
|
-
await (0,
|
|
39287
|
+
await (0, import_promises14.rename)(paths.candidate, paths.root);
|
|
39191
39288
|
}
|
|
39192
39289
|
await effects.switchLaunch?.();
|
|
39193
39290
|
await effects.phase("verifying", "\u6B63\u5728\u542F\u52A8\u65B0\u7248\u3001\u8FC1\u79FB\u6570\u636E\u5E93\u5E76\u9A8C\u8BC1\uFF1B\u4E1A\u52A1\u5199\u5165\u4FDD\u6301\u6682\u505C");
|
|
@@ -39206,8 +39303,8 @@ async function activateUpdate(paths, effects, reuseTarget = false) {
|
|
|
39206
39303
|
try {
|
|
39207
39304
|
await effects.stop();
|
|
39208
39305
|
if (moved) {
|
|
39209
|
-
await (0,
|
|
39210
|
-
await (0,
|
|
39306
|
+
await (0, import_promises14.rm)(paths.root, { recursive: true, force: true });
|
|
39307
|
+
await (0, import_promises14.rename)(paths.previous, paths.root);
|
|
39211
39308
|
}
|
|
39212
39309
|
if (backedUp) await effects.restore();
|
|
39213
39310
|
await effects.restoreLaunch?.();
|
|
@@ -39227,60 +39324,22 @@ async function activateUpdate(paths, effects, reuseTarget = false) {
|
|
|
39227
39324
|
}
|
|
39228
39325
|
}
|
|
39229
39326
|
function transactionPaths(root, id, dataDir, config2, backup) {
|
|
39230
|
-
const prefix = (0,
|
|
39327
|
+
const prefix = (0, import_node_path13.join)((0, import_node_path13.dirname)(root), `.covro-stage-${id}`);
|
|
39231
39328
|
return {
|
|
39232
39329
|
root,
|
|
39233
39330
|
prefix,
|
|
39234
|
-
candidate: (0,
|
|
39331
|
+
candidate: (0, import_node_path13.join)(
|
|
39235
39332
|
prefix,
|
|
39236
39333
|
process.platform === "win32" ? "node_modules" : "lib/node_modules",
|
|
39237
39334
|
npmPackageName
|
|
39238
39335
|
),
|
|
39239
|
-
previous: (0,
|
|
39336
|
+
previous: (0, import_node_path13.join)((0, import_node_path13.dirname)(root), `.covro-previous-${id}`),
|
|
39240
39337
|
backup,
|
|
39241
39338
|
dataDir,
|
|
39242
39339
|
config: config2
|
|
39243
39340
|
};
|
|
39244
39341
|
}
|
|
39245
39342
|
|
|
39246
|
-
// src/updates/registry.ts
|
|
39247
|
-
var import_promises14 = require("node:fs/promises");
|
|
39248
|
-
var import_node_fs4 = require("node:fs");
|
|
39249
|
-
var import_node_path13 = require("node:path");
|
|
39250
|
-
var registry2 = "https://registry.npmjs.org";
|
|
39251
|
-
var releaseSchema = external_exports.object({
|
|
39252
|
-
name: external_exports.literal(npmPackageName),
|
|
39253
|
-
version: external_exports.string().refine(validVersion),
|
|
39254
|
-
gitHead: external_exports.string().optional(),
|
|
39255
|
-
covroCommit: external_exports.string().optional(),
|
|
39256
|
-
covroCodex: external_exports.unknown().optional()
|
|
39257
|
-
});
|
|
39258
|
-
async function inspectInstallation(root) {
|
|
39259
|
-
try {
|
|
39260
|
-
const globalRoot = (0, import_node_path13.dirname)((0, import_node_path13.dirname)((0, import_node_path13.resolve)(root)));
|
|
39261
|
-
if (!globalRoot.endsWith("/lib/node_modules"))
|
|
39262
|
-
return "\u5F53\u524D\u4E3A\u975E npm \u5168\u5C40\u5B89\u88C5\uFF1B\u8BF7\u4F7F\u7528\u539F\u90E8\u7F72\u65B9\u5F0F\u66F4\u65B0\u3002";
|
|
39263
|
-
if (await (0, import_promises14.realpath)((0, import_node_path13.join)((0, import_node_path13.dirname)((0, import_node_path13.dirname)(globalRoot)), "bin/covro")) !== (0, import_node_path13.join)((0, import_node_path13.resolve)(root), "bin/covro.mjs"))
|
|
39264
|
-
return "\u5F53\u524D Covro \u5165\u53E3\u4E0E npm \u5168\u5C40\u5B89\u88C5\u6765\u6E90\u4E0D\u5339\u914D\uFF1B\u8BF7\u4F7F\u7528\u539F\u90E8\u7F72\u65B9\u5F0F\u66F4\u65B0\u3002";
|
|
39265
|
-
return await inspectPackageDirectory(root, globalRoot);
|
|
39266
|
-
} catch {
|
|
39267
|
-
return "\u65E0\u6CD5\u786E\u8BA4\u53EF\u5199\u7684 npm \u5168\u5C40\u5B89\u88C5\uFF1B\u8BF7\u68C0\u67E5 npm\u3001\u5B89\u88C5\u76EE\u5F55\u6743\u9650\u53CA\u540E\u53F0 PATH\u3002";
|
|
39268
|
-
}
|
|
39269
|
-
}
|
|
39270
|
-
async function inspectPackageDirectory(root, globalRoot) {
|
|
39271
|
-
const expected = (0, import_node_path13.join)(await (0, import_promises14.realpath)(globalRoot), npmPackageName);
|
|
39272
|
-
if ((await (0, import_promises14.lstat)(expected)).isSymbolicLink() || await (0, import_promises14.realpath)(root) !== expected)
|
|
39273
|
-
return "\u5F53\u524D\u4E3A\u6E90\u7801\u3001\u94FE\u63A5\u6216\u975E npm \u5168\u5C40\u5B89\u88C5\uFF1B\u8BF7\u4F7F\u7528\u539F\u90E8\u7F72\u65B9\u5F0F\u66F4\u65B0\u3002";
|
|
39274
|
-
try {
|
|
39275
|
-
await (0, import_promises14.lstat)((0, import_node_path13.join)(expected, ".git"));
|
|
39276
|
-
return "\u5F53\u524D\u5B89\u88C5\u5305\u542B Git \u5DE5\u4F5C\u533A\uFF1B\u8BF7\u4F7F\u7528\u539F\u90E8\u7F72\u65B9\u5F0F\u66F4\u65B0\u3002";
|
|
39277
|
-
} catch (error62) {
|
|
39278
|
-
if (error62.code !== "ENOENT") throw error62;
|
|
39279
|
-
}
|
|
39280
|
-
await (0, import_promises14.access)(root, import_node_fs4.constants.W_OK);
|
|
39281
|
-
return void 0;
|
|
39282
|
-
}
|
|
39283
|
-
|
|
39284
39343
|
// src/updates/runtime.ts
|
|
39285
39344
|
var import_node_child_process4 = require("node:child_process");
|
|
39286
39345
|
var import_node_util4 = require("node:util");
|
|
@@ -39523,7 +39582,7 @@ async function workerCore(directory, logger) {
|
|
|
39523
39582
|
await saveJson((0, import_node_path15.join)(directory, "run.json"), record2);
|
|
39524
39583
|
logger.info("update.phase_changed", { updateId: record2.id, stage: phase });
|
|
39525
39584
|
};
|
|
39526
|
-
|
|
39585
|
+
let paths = transactionPaths(
|
|
39527
39586
|
context2.target?.root ?? context2.root,
|
|
39528
39587
|
record2.id,
|
|
39529
39588
|
context2.dataDir,
|
|
@@ -39533,6 +39592,32 @@ async function workerCore(directory, logger) {
|
|
|
39533
39592
|
let releaseMaintenance;
|
|
39534
39593
|
let releaseData;
|
|
39535
39594
|
try {
|
|
39595
|
+
if (record2.automatic && !record2.transactionStartedAt && process.argv[3] !== "--repair") {
|
|
39596
|
+
record2 = await waitForAutomaticPlan(record2, {
|
|
39597
|
+
status: (fresh) => control(context2.location, "automatic-update-plan", { id: record2.id, fresh }),
|
|
39598
|
+
readiness: () => control(context2.location, "update-readiness"),
|
|
39599
|
+
save: async (next) => {
|
|
39600
|
+
record2 = next;
|
|
39601
|
+
await saveJson((0, import_node_path15.join)(directory, "run.json"), record2);
|
|
39602
|
+
},
|
|
39603
|
+
freeze: (checkedAt) => confirmAutomaticFreeze(
|
|
39604
|
+
record2.id,
|
|
39605
|
+
() => control(context2.location, "freeze-automatic-update", { id: record2.id, checkedAt }),
|
|
39606
|
+
() => readJson((0, import_node_path15.join)(directory, "run.json"))
|
|
39607
|
+
),
|
|
39608
|
+
pause: () => (0, import_promises17.setTimeout)(2e3)
|
|
39609
|
+
});
|
|
39610
|
+
const frozen = await readJson((0, import_node_path15.join)(directory, "context.json"));
|
|
39611
|
+
if (!frozen) throw new Error("\u7F3A\u5C11\u56FA\u5B9A\u76EE\u6807\u8FD0\u884C\u73AF\u5883");
|
|
39612
|
+
Object.assign(context2, frozen);
|
|
39613
|
+
paths = transactionPaths(
|
|
39614
|
+
context2.target?.root ?? context2.root,
|
|
39615
|
+
record2.id,
|
|
39616
|
+
context2.dataDir,
|
|
39617
|
+
context2.location.config,
|
|
39618
|
+
(0, import_node_path15.join)(backupDirectory(context2.location.home, context2.dataDir), record2.id)
|
|
39619
|
+
);
|
|
39620
|
+
}
|
|
39536
39621
|
if (record2.runtime) await verifyRuntimeExecutable(record2.runtime.from);
|
|
39537
39622
|
const previousMetadata = await readJson(
|
|
39538
39623
|
(0, import_node_path15.join)(paths.previous, "package.json")
|
|
@@ -39757,6 +39842,10 @@ async function workerCore(directory, logger) {
|
|
|
39757
39842
|
);
|
|
39758
39843
|
if (result.ready) {
|
|
39759
39844
|
await checkCodex();
|
|
39845
|
+
await verifyMigrations(context2, candidateRoot);
|
|
39846
|
+
const pinned = await readJson((0, import_node_path15.join)(candidateRoot, "package.json"));
|
|
39847
|
+
if (JSON.stringify(pinned) !== JSON.stringify(candidate))
|
|
39848
|
+
throw new Error("\u56FA\u5B9A\u5019\u9009\u5305\u5728\u5B89\u88C5\u540E\u53D1\u751F\u53D8\u5316\uFF0C\u62D2\u7EDD\u5207\u6362");
|
|
39760
39849
|
return;
|
|
39761
39850
|
}
|
|
39762
39851
|
await update("waiting", result.reason ?? "\u7B49\u5F85\u6240\u6709\u4EFB\u52A1\u7ED3\u675F");
|
|
@@ -39808,9 +39897,12 @@ async function workerCore(directory, logger) {
|
|
|
39808
39897
|
if (latest?.committed) {
|
|
39809
39898
|
record2 = latest;
|
|
39810
39899
|
} else if (!["rolledBack", "failed"].includes(record2.phase))
|
|
39811
|
-
await update(
|
|
39900
|
+
await update(
|
|
39901
|
+
error62.code === "UPDATE_PLAN_CANCELLED" ? "cancelled" : "failed",
|
|
39902
|
+
message(error62)
|
|
39903
|
+
);
|
|
39812
39904
|
logger.error("update.failed", { updateId: record2.id, ...errorFields(error62) });
|
|
39813
|
-
process.exitCode = record2.committed || record2.phase
|
|
39905
|
+
process.exitCode = record2.committed || ["rolledBack", "cancelled"].includes(record2.phase) ? 0 : 1;
|
|
39814
39906
|
} finally {
|
|
39815
39907
|
await releaseData?.();
|
|
39816
39908
|
await releaseMaintenance?.();
|
package/dist/updates/manager.js
CHANGED
|
@@ -57,6 +57,14 @@ class UpdateManager {
|
|
|
57
57
|
channel: packageInfo.covroChannel ?? (packageInfo.version?.includes("-dev.") ? "dev" : packageInfo.version?.includes("-beta.") ? "beta" : "stable"),
|
|
58
58
|
automatic: false
|
|
59
59
|
};
|
|
60
|
+
revision = "initial";
|
|
61
|
+
mutations = Promise.resolve();
|
|
62
|
+
serialize(work) {
|
|
63
|
+
const result = this.mutations.then(work);
|
|
64
|
+
this.mutations = result.catch(() => {
|
|
65
|
+
});
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
60
68
|
available;
|
|
61
69
|
checkedAt;
|
|
62
70
|
checkError;
|
|
@@ -64,6 +72,7 @@ class UpdateManager {
|
|
|
64
72
|
runtimeError;
|
|
65
73
|
reason = "\u5F53\u524D\u670D\u52A1\u672A\u901A\u8FC7 covro \u542F\u52A8\uFF0C\u7F51\u9875\u4EC5\u652F\u6301\u7248\u672C\u68C0\u6D4B\uFF1B\u5347\u7EA7\u8BF7\u4F7F\u7528\u539F\u90E8\u7F72\u65B9\u5F0F\u3002";
|
|
66
74
|
timer;
|
|
75
|
+
checks = Promise.resolve();
|
|
67
76
|
checking;
|
|
68
77
|
network = new AbortController();
|
|
69
78
|
context;
|
|
@@ -72,6 +81,7 @@ class UpdateManager {
|
|
|
72
81
|
await this.loadDirectory();
|
|
73
82
|
const saved = await readJson(join(this.context.directory, "settings.json"));
|
|
74
83
|
if (saved !== void 0) this.settings = settingsSchema.parse(saved);
|
|
84
|
+
this.revision = await readJson(join(this.context.directory, "settings-revision.json")) ?? "initial";
|
|
75
85
|
this.reason = process.platform === "win32" ? "Windows \u6682\u4E0D\u652F\u6301\u53D7\u7BA1\u81EA\u52A8\u5347\u7EA7\uFF0C\u8BF7\u4F7F\u7528 npm \u66F4\u65B0\u5E76\u91CD\u542F\u3002" : await inspectInstallation(this.context.root) ?? "";
|
|
76
86
|
this.timer = setInterval(
|
|
77
87
|
() => void this.automatic().catch(
|
|
@@ -121,25 +131,34 @@ class UpdateManager {
|
|
|
121
131
|
}
|
|
122
132
|
};
|
|
123
133
|
}
|
|
124
|
-
|
|
134
|
+
check(channel = this.settings.channel) {
|
|
135
|
+
const result = this.checks.then(() => this.performCheck(channel));
|
|
136
|
+
this.checks = result.catch(() => {
|
|
137
|
+
});
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
140
|
+
async performCheck(channel) {
|
|
125
141
|
const started = performance.now();
|
|
126
142
|
this.logger.debug("update.check_started");
|
|
127
|
-
|
|
128
|
-
|
|
143
|
+
let target;
|
|
144
|
+
let runtimeError;
|
|
145
|
+
let available;
|
|
146
|
+
let checkError;
|
|
129
147
|
if (this.context && !this.reason) {
|
|
130
148
|
try {
|
|
131
|
-
|
|
149
|
+
target = await resolveRuntimeTarget();
|
|
132
150
|
} catch (error) {
|
|
133
|
-
|
|
151
|
+
runtimeError = error.message;
|
|
134
152
|
}
|
|
135
153
|
}
|
|
136
154
|
try {
|
|
137
|
-
const local =
|
|
155
|
+
const local = target && runtimeChanged(target) ? target : void 0;
|
|
138
156
|
let release;
|
|
139
157
|
try {
|
|
140
158
|
release = await lookupRelease(channel, this.network.signal);
|
|
141
159
|
} catch (error) {
|
|
142
160
|
if (!local) throw error;
|
|
161
|
+
checkError = error instanceof Error ? error.message : "\u65E0\u6CD5\u68C0\u67E5\u66F4\u65B0";
|
|
143
162
|
}
|
|
144
163
|
if (local && (!release || compareVersions(local.version, release.version) >= 0))
|
|
145
164
|
release = {
|
|
@@ -150,7 +169,7 @@ class UpdateManager {
|
|
|
150
169
|
covroCodex: local.covroCodex
|
|
151
170
|
};
|
|
152
171
|
if (!release) throw new Error("\u672A\u627E\u5230\u53EF\u7528\u7248\u672C");
|
|
153
|
-
|
|
172
|
+
available = {
|
|
154
173
|
version: release.version,
|
|
155
174
|
requestedChannel: channel,
|
|
156
175
|
channel: release.channel,
|
|
@@ -158,27 +177,105 @@ class UpdateManager {
|
|
|
158
177
|
downgrade: compareVersions(release.version, packageInfo.version) < 0,
|
|
159
178
|
codex: assessCodexCompatibility(release.covroCodex, this.codexVersion())
|
|
160
179
|
};
|
|
161
|
-
this.checkError = void 0;
|
|
162
180
|
} catch (error) {
|
|
163
|
-
|
|
164
|
-
|
|
181
|
+
available = void 0;
|
|
182
|
+
checkError = error instanceof Error ? error.message : "\u65E0\u6CD5\u68C0\u67E5\u66F4\u65B0";
|
|
165
183
|
this.logger.warn("update.check_failed", {
|
|
166
184
|
...errorFields(error),
|
|
167
185
|
durationMs: Math.round(performance.now() - started)
|
|
168
186
|
});
|
|
169
187
|
}
|
|
188
|
+
this.target = target;
|
|
189
|
+
this.runtimeError = runtimeError;
|
|
190
|
+
this.available = available;
|
|
191
|
+
this.checkError = checkError;
|
|
170
192
|
this.checkedAt = Date.now();
|
|
171
193
|
this.logger.debug("update.check_finished", {
|
|
172
|
-
outcome:
|
|
194
|
+
outcome: checkError ? "failed" : "succeeded",
|
|
173
195
|
durationMs: Math.round(performance.now() - started)
|
|
174
196
|
});
|
|
175
197
|
return this.status();
|
|
176
198
|
}
|
|
177
199
|
async configure(input) {
|
|
178
200
|
if (!this.context || this.reason) throw new AppError("UPDATE_UNSUPPORTED", this.reason, 409);
|
|
179
|
-
this.
|
|
180
|
-
|
|
181
|
-
|
|
201
|
+
return this.serialize(async () => {
|
|
202
|
+
const run = (await this.status()).run;
|
|
203
|
+
if (updateActive(run) && (!run?.automatic || run.transactionStartedAt))
|
|
204
|
+
throw new AppError("UPDATE_PLAN_FIXED", "\u5347\u7EA7\u4E8B\u52A1\u5DF2\u5F00\u59CB\uFF0C\u8BF7\u7B49\u5F85\u5B8C\u6210\u540E\u66F4\u6539\u8BBE\u7F6E", 409);
|
|
205
|
+
this.settings = settingsSchema.parse(input);
|
|
206
|
+
this.revision = crypto.randomUUID();
|
|
207
|
+
await saveJson(join(this.context.directory, "settings-revision.json"), this.revision);
|
|
208
|
+
await saveJson(join(this.context.directory, "settings.json"), this.settings);
|
|
209
|
+
return this.status();
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
async assertAutomaticPlan(run) {
|
|
213
|
+
if (!run.automatic || run.transactionStartedAt || run.phase !== "waiting")
|
|
214
|
+
throw new AppError("UPDATE_PLAN_FIXED", "\u5347\u7EA7\u5DF2\u5F00\u59CB\u6216\u4E0D\u662F\u81EA\u52A8\u5347\u7EA7\u8BA1\u5212", 409);
|
|
215
|
+
if (!this.settings.automatic || this.settings.channel !== run.channel || this.revision !== run.automatic.revision || await readJson(join(this.context.directory, `cancel-${run.id}.json`)))
|
|
216
|
+
throw new AppError("UPDATE_PLAN_CANCELLED", "\u81EA\u52A8\u5347\u7EA7\u8BA1\u5212\u5DF2\u53D6\u6D88\u6216\u8BBE\u7F6E\u5DF2\u53D8\u5316", 409);
|
|
217
|
+
}
|
|
218
|
+
async cancel(id) {
|
|
219
|
+
z.uuid().parse(id);
|
|
220
|
+
return this.serialize(async () => {
|
|
221
|
+
const run = (await this.status()).run;
|
|
222
|
+
if (!run || run.id !== id) throw new AppError("UPDATE_PLAN_CHANGED", "\u5347\u7EA7\u8BA1\u5212\u5DF2\u53D8\u5316", 409);
|
|
223
|
+
if (run.phase === "cancelled") return this.status();
|
|
224
|
+
if (!run.automatic || run.transactionStartedAt || run.phase !== "waiting")
|
|
225
|
+
throw new AppError("UPDATE_PLAN_FIXED", "\u5347\u7EA7\u5DF2\u5F00\u59CB\uFF0C\u4E0D\u80FD\u53D6\u6D88\u4E8B\u52A1", 409);
|
|
226
|
+
await saveJson(join(this.context.directory, `cancel-${id}.json`), { cancelled: true });
|
|
227
|
+
return this.status();
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
async automaticPlan(id, fresh = false) {
|
|
231
|
+
const run = (await this.status()).run;
|
|
232
|
+
if (!run || run.id !== id) throw new Error("\u5347\u7EA7\u8BA1\u5212\u5DF2\u53D8\u5316");
|
|
233
|
+
await this.assertAutomaticPlan(run);
|
|
234
|
+
const otherChannel = this.available && this.available.requestedChannel !== run.channel;
|
|
235
|
+
const result = fresh || otherChannel ? await this.check(run.channel) : await this.status();
|
|
236
|
+
await this.assertAutomaticPlan(run);
|
|
237
|
+
return result;
|
|
238
|
+
}
|
|
239
|
+
async freezeAutomatic(id, checkedAt, readiness) {
|
|
240
|
+
return this.serialize(async () => {
|
|
241
|
+
const status = await this.status();
|
|
242
|
+
const run = status.run;
|
|
243
|
+
if (!run || run.id !== id) throw new Error("\u5347\u7EA7\u8BA1\u5212\u5DF2\u53D8\u5316");
|
|
244
|
+
await this.assertAutomaticPlan(run);
|
|
245
|
+
const candidate = status.available;
|
|
246
|
+
const target = status.runtime?.target;
|
|
247
|
+
if (checkedAt !== status.checkedAt || !candidate || JSON.stringify(candidate) !== JSON.stringify(run.candidate) || JSON.stringify(target) !== JSON.stringify(run.runtime?.target))
|
|
248
|
+
return { ready: false };
|
|
249
|
+
if (status.checkError || status.runtime?.error || candidate.codex.status !== "verified" || candidate.downgrade || compareVersions(candidate.version, packageInfo.version) <= 0 || candidate.requestedChannel !== run.channel || !candidate.commit)
|
|
250
|
+
throw new Error("\u81EA\u52A8\u5347\u7EA7\u76EE\u6807\u6216\u517C\u5BB9\u6027\u65E0\u6CD5\u786E\u8BA4\uFF0C\u8BF7\u91CD\u65B0\u68C0\u67E5\u66F4\u65B0");
|
|
251
|
+
const context = await readJson(join(this.context.directory, "context.json"));
|
|
252
|
+
if (!context || !target) throw new Error("\u7F3A\u5C11\u5347\u7EA7\u8FD0\u884C\u73AF\u5883");
|
|
253
|
+
if (!readiness().ready) return { ready: false };
|
|
254
|
+
await saveJson(join(this.context.directory, "context.json"), {
|
|
255
|
+
...context,
|
|
256
|
+
target,
|
|
257
|
+
reuseTarget: runtimeChanged(target) && target.root !== context.root.replace(/\/$/, "") && target.version === candidate.version
|
|
258
|
+
});
|
|
259
|
+
const frozen = {
|
|
260
|
+
...run,
|
|
261
|
+
target: candidate.version,
|
|
262
|
+
commit: candidate.commit,
|
|
263
|
+
sourceChannel: candidate.channel,
|
|
264
|
+
candidate,
|
|
265
|
+
codex: {
|
|
266
|
+
version: candidate.codex.version,
|
|
267
|
+
manifest: candidate.codex.manifest,
|
|
268
|
+
confirmedUnverified: false
|
|
269
|
+
},
|
|
270
|
+
runtime: { from: run.runtime.from, target },
|
|
271
|
+
phase: "installing",
|
|
272
|
+
message: "\u6B63\u5728\u5B89\u88C5\u5019\u9009 npm \u5305",
|
|
273
|
+
transactionStartedAt: Date.now(),
|
|
274
|
+
updatedAt: Date.now()
|
|
275
|
+
};
|
|
276
|
+
await saveJson(join(this.context.directory, "run.json"), frozen);
|
|
277
|
+
return { ready: true, run: frozen };
|
|
278
|
+
});
|
|
182
279
|
}
|
|
183
280
|
async activationPending() {
|
|
184
281
|
const run = (await this.status()).run;
|
|
@@ -220,8 +317,9 @@ class UpdateManager {
|
|
|
220
317
|
runtime: run.runtime ? { ...run.runtime, actual: runningRuntime() } : void 0
|
|
221
318
|
});
|
|
222
319
|
}
|
|
223
|
-
async start(input) {
|
|
320
|
+
async start(input, automatic = false) {
|
|
224
321
|
const request = updateRequestSchema.parse(input);
|
|
322
|
+
const automaticRevision = this.revision;
|
|
225
323
|
if (!this.context || this.reason) throw new AppError("UPDATE_UNSUPPORTED", this.reason, 409);
|
|
226
324
|
await mkdir(this.context.directory, { recursive: true, mode: 448 });
|
|
227
325
|
let releaseLock;
|
|
@@ -252,11 +350,14 @@ class UpdateManager {
|
|
|
252
350
|
}
|
|
253
351
|
const channel = request.channel ?? this.settings.channel;
|
|
254
352
|
const checked = await this.check(channel);
|
|
255
|
-
const target =
|
|
256
|
-
if (this.
|
|
353
|
+
const target = checked.runtime?.target;
|
|
354
|
+
if (automatic && (!this.settings.automatic || channel !== this.settings.channel || automaticRevision !== this.revision))
|
|
355
|
+
return this.status();
|
|
356
|
+
if (automatic && checked.available?.codex.status !== "verified") return this.status();
|
|
357
|
+
if (checked.runtime?.error || !target)
|
|
257
358
|
throw new AppError(
|
|
258
359
|
"UPDATE_RUNTIME",
|
|
259
|
-
|
|
360
|
+
checked.runtime?.error ?? "\u65E0\u6CD5\u786E\u8BA4\u76EE\u6807 Node \u73AF\u5883\uFF0C\u8BF7\u91CD\u65B0\u68C0\u67E5\u3002",
|
|
260
361
|
409
|
|
261
362
|
);
|
|
262
363
|
if (!checked.available)
|
|
@@ -294,8 +395,11 @@ class UpdateManager {
|
|
|
294
395
|
sourceChannel: checked.available.channel,
|
|
295
396
|
commit: checked.available.commit,
|
|
296
397
|
codex: { version: codex.version, manifest: codex.manifest, confirmedUnverified },
|
|
297
|
-
|
|
298
|
-
|
|
398
|
+
automatic: automatic ? { revision: automaticRevision } : void 0,
|
|
399
|
+
candidate: checked.available,
|
|
400
|
+
transactionStartedAt: automatic ? void 0 : Date.now(),
|
|
401
|
+
phase: automatic ? "waiting" : "installing",
|
|
402
|
+
message: automatic ? "\u7B49\u5F85\u6240\u6709\u4EFB\u52A1\u7ED3\u675F\u540E\u91CD\u65B0\u68C0\u67E5\u66F4\u65B0" : "\u6B63\u5728\u5B89\u88C5\u5019\u9009 npm \u5305",
|
|
299
403
|
startedAt: Date.now(),
|
|
300
404
|
updatedAt: Date.now(),
|
|
301
405
|
runtime: { from: runningRuntime(), target }
|
|
@@ -404,7 +508,7 @@ class UpdateManager {
|
|
|
404
508
|
this.checking = (async () => {
|
|
405
509
|
const result = await this.check();
|
|
406
510
|
if (this.settings.automatic && result.available && result.available.codex.status === "verified" && !result.available.downgrade && compareVersions(result.available.version, packageInfo.version) > 0 && result.run?.target !== result.available.version && !updateActive(result.run))
|
|
407
|
-
return this.start({ clientOperationId: crypto.randomUUID() });
|
|
511
|
+
return this.start({ clientOperationId: crypto.randomUUID() }, true);
|
|
408
512
|
return result;
|
|
409
513
|
})();
|
|
410
514
|
try {
|