farming-code 2.2.29 → 2.2.32
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 +25 -66
- package/README.zh_cn.md +15 -66
- package/THIRD_PARTY_NOTICES.md +7 -0
- package/backend/acp/{client-services.js → client-services.cjs} +132 -134
- package/backend/acp/packaged-claude-acp.cjs +37 -0
- package/backend/acp/packaged-codex-acp.cjs +37 -0
- package/backend/acp/patch-decisions.cjs +182 -0
- package/backend/acp/permission-security.cjs +131 -0
- package/backend/{acp-checkpoint-store.js → acp-checkpoint-store.cjs} +90 -59
- package/backend/{acp-runtime.js → acp-runtime.cjs} +1219 -1125
- package/backend/acp-session-state.cjs +622 -0
- package/backend/acp-transcript.cjs +525 -0
- package/backend/agent-env.cjs +257 -0
- package/backend/agent-extension-discovery.cjs +452 -0
- package/backend/agent-extension-inventory.cjs +116 -0
- package/backend/agent-json-stream.cjs +283 -0
- package/backend/agent-lifecycle-journal.cjs +185 -0
- package/backend/{agent-manager.js → agent-manager.cjs} +3116 -4275
- package/backend/agent-order-transaction.cjs +85 -0
- package/backend/agent-order.cjs +159 -0
- package/backend/agent-provider-session.cjs +98 -0
- package/backend/agent-runtime-binding.cjs +179 -0
- package/backend/agent-session-history.cjs +1022 -0
- package/backend/agent-session-inventory.cjs +291 -0
- package/backend/async-cache.cjs +104 -0
- package/backend/atomic-json-store.cjs +67 -0
- package/backend/auth.cjs +261 -0
- package/backend/authoritative-inventory-cache.cjs +383 -0
- package/backend/business-health.cjs +68 -0
- package/backend/chat-runtime.cjs +50 -0
- package/backend/claude-settings.cjs +132 -0
- package/backend/cli-agents.cjs +435 -0
- package/backend/codex-context-window.cjs +196 -0
- package/backend/codex-models.cjs +228 -0
- package/backend/codex-session-archive.cjs +82 -0
- package/backend/codex-session-history.cjs +590 -0
- package/backend/{codex-terminal-profile.js → codex-terminal-profile.cjs} +149 -155
- package/backend/codex-transcript-sanitizer.cjs +130 -0
- package/backend/codex-transcript.cjs +2107 -0
- package/backend/command-runner-child.cjs +105 -0
- package/backend/config-manager.cjs +1263 -0
- package/backend/control-api.cjs +439 -0
- package/backend/data/LICENSE.cua +21 -0
- package/backend/executable-discovery.cjs +204 -0
- package/backend/farming-agent-bootstrap.cjs +81 -0
- package/backend/farming-agent-bootstrap.zh_cn.md +6 -2
- package/backend/{farming-app-cli.js → farming-app-cli.cjs} +441 -493
- package/backend/farming-cli.cjs +414 -0
- package/backend/farming-net-pass.cjs +319 -0
- package/backend/farming-net-registry.cjs +123 -0
- package/backend/farming-net-server.cjs +309 -0
- package/backend/farming-session-store.cjs +651 -0
- package/backend/git-worktree-info.cjs +181 -0
- package/backend/haiku-token.cjs +828 -0
- package/backend/index-html.cjs +96 -0
- package/backend/input-parts.cjs +68 -0
- package/backend/input-routing.cjs +40 -0
- package/backend/{local-session-engine.js → local-session-engine.cjs} +276 -282
- package/backend/main-agent-skills.cjs +309 -0
- package/backend/main-page-session.cjs +132 -0
- package/backend/native-pty-controller-generation.cjs +139 -0
- package/backend/{native-pty-host-client.js → native-pty-host-client.cjs} +338 -346
- package/backend/native-pty-host-identity.cjs +125 -0
- package/backend/native-pty-host-path.cjs +68 -0
- package/backend/{native-pty-host.js → native-pty-host.cjs} +480 -569
- package/backend/native-session-engine.cjs +296 -0
- package/backend/network.cjs +57 -0
- package/backend/npm-update-helper.cjs +399 -0
- package/backend/packaged-node-pty.cjs +120 -0
- package/backend/preview-session-manager.cjs +89 -0
- package/backend/provider-adapters.cjs +492 -0
- package/backend/provider-home-configuration.cjs +211 -0
- package/backend/provider-session-id.cjs +79 -0
- package/backend/provider-session-service.cjs +333 -0
- package/backend/qr-share-tickets.cjs +119 -0
- package/backend/resource-broadcast-protocol.cjs +50 -0
- package/backend/review-diff-router.cjs +202 -0
- package/backend/review-diff-service.cjs +1267 -0
- package/backend/review-session-router.cjs +93 -0
- package/backend/review-session-service.cjs +470 -0
- package/backend/review-session-store.cjs +161 -0
- package/backend/review-state-router.cjs +132 -0
- package/backend/review-state-store.cjs +299 -0
- package/backend/run-history-store.cjs +97 -0
- package/backend/runtime-dependency-manager.cjs +893 -0
- package/backend/runtime-executable-invocation.cjs +37 -0
- package/backend/runtime-observation.cjs +96 -0
- package/backend/server-process-identity.cjs +70 -0
- package/backend/server.cjs +3356 -0
- package/backend/session-engine-bridge.cjs +144 -0
- package/backend/session-engine-router.cjs +105 -0
- package/backend/session-engine.cjs +64 -0
- package/backend/session-stream-protocol.cjs +181 -0
- package/backend/shell-busy-integration.cjs +442 -0
- package/backend/slash-command-discovery.cjs +423 -0
- package/backend/storage-layout.cjs +263 -0
- package/backend/system-monitor.cjs +96 -0
- package/backend/terminal-attach-checkpoint.cjs +73 -0
- package/backend/terminal-exit-quiescence.cjs +57 -0
- package/backend/{terminal-reducer-flow-control.js → terminal-reducer-flow-control.cjs} +45 -22
- package/backend/terminal-runtime-cleanup.cjs +99 -0
- package/backend/{terminal-screen-state.js → terminal-screen-state.cjs} +100 -108
- package/backend/{terminal-screen-worker-pool.js → terminal-screen-worker-pool.cjs} +89 -79
- package/backend/{terminal-screen-worker-thread.js → terminal-screen-worker-thread.cjs} +64 -65
- package/backend/terminal-screen-worker.cjs +352 -0
- package/backend/terminal-state-serialization.cjs +147 -0
- package/backend/{terminal-status.js → terminal-status.cjs} +137 -187
- package/backend/theme-manager.cjs +185 -0
- package/backend/update-service.cjs +675 -0
- package/backend/usage-forecast.cjs +95 -0
- package/backend/{usage-history-client.js → usage-history-client.cjs} +144 -94
- package/backend/usage-history-smoke.cjs +85 -0
- package/backend/usage-history-worker.cjs +60 -0
- package/backend/{usage-monitor.js → usage-monitor.cjs} +363 -390
- package/backend/workspace-directory.cjs +239 -0
- package/backend/workspace-discovery.cjs +271 -0
- package/backend/{workspace-file-router.js → workspace-file-router.cjs} +213 -282
- package/backend/{workspace-file-service.js → workspace-file-service.cjs} +1139 -1318
- package/backend/workspace-root-registry.cjs +192 -0
- package/bin/farming +1 -1
- package/config/farming.deploy.env.example +1 -1
- package/config/farming.install.env.example +1 -1
- package/dist/acp/codex-acp-1.1.4.mjs +405 -8
- package/dist/assets/App-BCkdpWB6.css +1 -0
- package/dist/assets/App-CRjKpaGp.js +697 -0
- package/dist/assets/CodeSelect-Ci8sKZPU.js +1 -0
- package/dist/assets/CodeSelect-T2eNzrOc.css +1 -0
- package/dist/assets/{FileEditorMarkdownPreview-Cs9cLv8a.js → FileEditorMarkdownPreview-V06QHlAg.js} +55 -55
- package/dist/assets/FileEditorPane-BX-Wjg9U.js +2 -0
- package/dist/assets/IconGlyphs-YhV7tqd4.js +1 -0
- package/dist/assets/ProjectFilesSection-BDT2_r0o.js +12 -0
- package/dist/assets/ReviewPage-BqAs5sG1.js +3 -0
- package/dist/assets/code-dark-B7eM_9G9.css +1 -0
- package/dist/assets/{cssMode-Bdg5RpcJ.js → cssMode-ADdAlxTO.js} +1 -1
- package/dist/assets/{editor.api2-D74ufkbr.js → editor.api2-BFLAr0YF.js} +162 -162
- package/dist/assets/file-icons-BpeqWkIB.js +1 -0
- package/dist/assets/{freemarker2-DfMDJfnE.js → freemarker2-C90q5jrp.js} +1 -1
- package/dist/assets/{handlebars-BEdPtzMT.js → handlebars-BwUQcEDq.js} +1 -1
- package/dist/assets/{html-B1fPb1QD.js → html-1s3uPKfh.js} +1 -1
- package/dist/assets/{htmlMode-CY2ZjHxH.js → htmlMode-xtKD99de.js} +1 -1
- package/dist/assets/{index-CQNaZc3l.js → index-C8MchCem.js} +3 -3
- package/dist/assets/{javascript-BV2OsWA0.js → javascript-Ph7ijyny.js} +1 -1
- package/dist/assets/{jsonMode-zd07aeuX.js → jsonMode-D-jGAnFH.js} +1 -1
- package/dist/assets/linkComputer-CbGyI_qx.js +1 -0
- package/dist/assets/{liquid-BParI24X.js → liquid-0IamE_cI.js} +1 -1
- package/dist/assets/{lspLanguageFeatures-BzredkoV.js → lspLanguageFeatures-BxnQunWF.js} +1 -1
- package/dist/assets/main-CLKXa6hf.css +1 -0
- package/dist/assets/{mdx-vGzUJN98.js → mdx-DdNmfivn.js} +1 -1
- package/dist/assets/{monaco.contribution-BmaeBQEc.js → monaco.contribution-B43jsUs1.js} +2 -2
- package/dist/assets/{python-CUwdLgsI.js → python-IAt4X5TS.js} +1 -1
- package/dist/assets/{razor-BScebUxU.js → razor-DRkFYW0S.js} +1 -1
- package/dist/assets/review-C8-oPKXk.css +1 -0
- package/dist/assets/{tsMode-DzUAibXK.js → tsMode-_d_4U2gf.js} +1 -1
- package/dist/assets/{typescript-D9EOeM7N.js → typescript-C7zcMq9l.js} +1 -1
- package/dist/assets/{workers-DAiomYZM.js → workers-D0nOyJzf.js} +1 -1
- package/dist/assets/workspace-editor-model-DND_Y-Bj.js +1 -0
- package/dist/assets/workspace-editor-monaco-BPWhgcIB.js +4 -0
- package/dist/assets/workspace-editor-monaco-N641qPjX.js +1 -0
- package/dist/assets/workspace-view-state-k1bTlJ_Z.js +13 -0
- package/dist/assets/{xml-wWl1dhkQ.js → xml-BR-HvxT8.js} +1 -1
- package/dist/assets/{yaml-Dc2WDaOZ.js → yaml-YtFQwh4q.js} +1 -1
- package/dist/index.html +2 -1
- package/extensions/browser/backend/agent-browser-runtime.cjs +1040 -0
- package/extensions/browser/backend/agent-capability.cjs +85 -0
- package/extensions/browser/backend/browser-mcp-server.cjs +655 -0
- package/extensions/browser/backend/browser-resource-manager.cjs +1486 -0
- package/extensions/browser/backend/browser-resource-store.cjs +228 -0
- package/extensions/browser/backend/browser-router.cjs +203 -0
- package/extensions/browser/backend/executable-discovery.cjs +248 -0
- package/extensions/browser/backend/farming-browser-client.cjs +116 -0
- package/extensions/browser/backend/index.cjs +32 -0
- package/extensions/browser/backend/managed-chromium-installer.cjs +833 -0
- package/extensions/browser/bin/farming-browser +16 -7
- package/extensions/computer/backend/agent-capability.cjs +72 -0
- package/extensions/computer/backend/computer-constants.cjs +59 -0
- package/extensions/computer/backend/computer-mcp-server.cjs +182 -0
- package/extensions/computer/backend/computer-resource-manager.cjs +1219 -0
- package/extensions/computer/backend/computer-resource-store.cjs +190 -0
- package/extensions/computer/backend/computer-router.cjs +257 -0
- package/extensions/computer/backend/cua-tools.json +3067 -0
- package/extensions/computer/backend/farming-computer-client.cjs +84 -0
- package/extensions/computer/backend/index.cjs +35 -0
- package/extensions/computer/backend/isolated-browser-provider.cjs +157 -0
- package/extensions/computer/bin/farming-computer +131 -0
- package/frontend/farming-net/app.js +255 -262
- package/frontend/ghostty-loader.js +24 -20
- package/frontend/reading-anchor.js +210 -193
- package/frontend/runtime-paths.js +24 -26
- package/frontend/session-bridge.js +90 -111
- package/frontend/session-modal-bridge.js +184 -302
- package/frontend/skin-bridge.js +20 -23
- package/frontend/skins/crt/app.js +7686 -7901
- package/frontend/skins/crt/effects.js +7 -6
- package/frontend/skins/crt/index.html +6 -6
- package/frontend/skins/crt/styles/markdown.css +4 -4
- package/frontend/terminal-bridge.js +174 -181
- package/frontend/terminal-replay.js +320 -345
- package/frontend/theme-loader.js +55 -71
- package/index.html +1 -0
- package/package.json +64 -37
- package/shared/backend-connection-status.js +38 -69
- package/shared/browser-protocol.js +235 -110
- package/shared/websocket-liveness.js +40 -0
- package/backend/acp/packaged-claude-acp.js +0 -13
- package/backend/acp/packaged-codex-acp.js +0 -13
- package/backend/acp/patch-decisions.js +0 -153
- package/backend/acp/permission-security.js +0 -108
- package/backend/acp-session-state.js +0 -644
- package/backend/acp-transcript.js +0 -512
- package/backend/agent-env.js +0 -250
- package/backend/agent-json-stream.js +0 -268
- package/backend/agent-lifecycle-journal.js +0 -133
- package/backend/agent-memory-report.js +0 -583
- package/backend/agent-order.js +0 -166
- package/backend/agent-provider-session.js +0 -76
- package/backend/agent-runtime-binding.js +0 -174
- package/backend/agent-session-history.js +0 -953
- package/backend/async-cache.js +0 -94
- package/backend/atomic-json-store.js +0 -37
- package/backend/auth.js +0 -251
- package/backend/bundle-update-helper.js +0 -113
- package/backend/chat-runtime.js +0 -28
- package/backend/claude-settings.js +0 -121
- package/backend/cli-agents.js +0 -486
- package/backend/codex-context-window.js +0 -189
- package/backend/codex-models.js +0 -226
- package/backend/codex-rollout-follower.js +0 -326
- package/backend/codex-session-archive.js +0 -65
- package/backend/codex-session-history.js +0 -647
- package/backend/codex-transcript-sanitizer.js +0 -115
- package/backend/codex-transcript.js +0 -2564
- package/backend/command-runner-child.js +0 -67
- package/backend/config-manager.js +0 -1133
- package/backend/control-api.js +0 -455
- package/backend/executable-discovery.js +0 -216
- package/backend/farming-agent-bootstrap.js +0 -49
- package/backend/farming-cli.js +0 -457
- package/backend/farming-net-pass.js +0 -285
- package/backend/farming-net-registry.js +0 -112
- package/backend/farming-net-server.js +0 -298
- package/backend/farming-session-store.js +0 -677
- package/backend/git-worktree-info.js +0 -181
- package/backend/haiku-token.js +0 -772
- package/backend/index-html.js +0 -62
- package/backend/input-parts.js +0 -54
- package/backend/input-routing.js +0 -24
- package/backend/json-cli-runtime.js +0 -275
- package/backend/main-agent-skills.js +0 -305
- package/backend/main-page-session.js +0 -122
- package/backend/native-pty-controller-generation.js +0 -106
- package/backend/native-pty-host-identity.js +0 -86
- package/backend/native-pty-host-path.js +0 -42
- package/backend/native-session-engine.js +0 -268
- package/backend/network.js +0 -23
- package/backend/npm-update-helper.js +0 -374
- package/backend/packaged-node-pty.js +0 -99
- package/backend/preview-session-manager.js +0 -68
- package/backend/provider-adapters.js +0 -399
- package/backend/provider-session-id.js +0 -47
- package/backend/provider-session-service.js +0 -345
- package/backend/qr-share-tickets.js +0 -100
- package/backend/review-diff-router.js +0 -180
- package/backend/review-diff-service.js +0 -1270
- package/backend/review-session-router.js +0 -74
- package/backend/review-session-service.js +0 -446
- package/backend/review-session-store.js +0 -151
- package/backend/review-state-router.js +0 -116
- package/backend/review-state-store.js +0 -286
- package/backend/run-history-store.js +0 -67
- package/backend/runtime-dependency-manager.js +0 -759
- package/backend/runtime-executable-invocation.js +0 -20
- package/backend/runtime-observation.js +0 -81
- package/backend/server-process-identity.js +0 -47
- package/backend/server.js +0 -3267
- package/backend/session-engine-bridge.js +0 -129
- package/backend/session-engine-router.js +0 -66
- package/backend/session-engine.js +0 -39
- package/backend/session-stream-protocol.js +0 -185
- package/backend/shell-busy-integration.js +0 -472
- package/backend/slash-command-discovery.js +0 -433
- package/backend/storage-layout.js +0 -190
- package/backend/system-monitor.js +0 -77
- package/backend/terminal-attach-checkpoint.js +0 -74
- package/backend/terminal-exit-quiescence.js +0 -39
- package/backend/terminal-runtime-cleanup.js +0 -80
- package/backend/terminal-screen-worker.js +0 -337
- package/backend/terminal-state-serialization.js +0 -127
- package/backend/theme-manager.js +0 -163
- package/backend/update-service.js +0 -1545
- package/backend/usage-forecast.js +0 -86
- package/backend/usage-history-scanner.ts +0 -2718
- package/backend/usage-history-smoke.js +0 -64
- package/backend/usage-history-worker.js +0 -34
- package/backend/workspace-directory.js +0 -232
- package/backend/workspace-discovery.js +0 -311
- package/backend/workspace-root-registry.js +0 -166
- package/dist/assets/App-BKNUILuL.css +0 -1
- package/dist/assets/App-Ex2oVVXO.js +0 -693
- package/dist/assets/FileEditorPane-CNtuGjQ3.js +0 -2
- package/dist/assets/IconGlyphs-BClgag6E.js +0 -1
- package/dist/assets/ProjectFilesSection-Cf2BEcAN.js +0 -12
- package/dist/assets/ReviewPage-BRuxFaH5.js +0 -3
- package/dist/assets/code-dark-BEZTQwYZ.css +0 -1
- package/dist/assets/file-icons-BOlcJ0ZF.js +0 -1
- package/dist/assets/main-DK9Sy7-c.css +0 -1
- package/dist/assets/review-BcnwQtJv.css +0 -1
- package/dist/assets/workspace-editor-model-CSGCl21x.js +0 -1
- package/dist/assets/workspace-editor-monaco-CJNwbpCy.js +0 -4
- package/dist/assets/workspace-editor-monaco-CO9w8YV0.js +0 -1
- package/dist/assets/workspace-view-state-BjKPYp0E.js +0 -7
- package/extensions/browser/backend/agent-browser-runtime.js +0 -1041
- package/extensions/browser/backend/agent-capability.js +0 -55
- package/extensions/browser/backend/browser-mcp-server.js +0 -621
- package/extensions/browser/backend/browser-resource-manager.js +0 -1309
- package/extensions/browser/backend/browser-resource-store.js +0 -190
- package/extensions/browser/backend/browser-router.js +0 -133
- package/extensions/browser/backend/executable-discovery.js +0 -224
- package/extensions/browser/backend/farming-browser-client.js +0 -83
- package/extensions/browser/backend/index.js +0 -7
- package/extensions/browser/frontend/BrowserSidebarPortals.tsx +0 -360
- package/extensions/browser/frontend/BrowserViewer.tsx +0 -500
- package/extensions/browser/frontend/browser-resource-state.ts +0 -60
- package/extensions/browser/frontend/browser.css +0 -567
- package/extensions/browser/frontend/types.ts +0 -31
- package/extensions/browser/frontend/useBrowserResources.ts +0 -158
- package/frontend/vendor/ghostty-web/index.d.ts +0 -1842
- package/shared/backend-connection-status.d.ts +0 -37
- package/shared/browser-protocol.d.ts +0 -5
- /package/dist/assets/{api-w2x5QfxB.js → api-ByCV9MEr.js} +0 -0
- /package/dist/assets/{core-vPkV8P_m.js → core-Czwdx12k.js} +0 -0
- /package/dist/assets/{fsharp-DNZNZyEE.js → fsharp-BjPpkoJe.js} +0 -0
- /package/dist/assets/{go-_kPJjNc_.js → go-BkIDmSUP.js} +0 -0
- /package/dist/assets/{graphql-4HCNVt5g.js → graphql-CCJTpqi1.js} +0 -0
- /package/dist/assets/{hcl-C87ymY0o.js → hcl-s4z8lUFg.js} +0 -0
- /package/dist/assets/{ini-BYrrGNTc.js → ini-CyUW1I7Z.js} +0 -0
- /package/dist/assets/{java-B211rJbk.js → java-CFCcGRiM.js} +0 -0
- /package/dist/assets/{julia-DVPsRtBm.js → julia-DQyH_EYb.js} +0 -0
- /package/dist/assets/{kotlin-BYyNerjp.js → kotlin-B8hA5O51.js} +0 -0
- /package/dist/assets/{less-EC9UblGE.js → less-DaVdaas0.js} +0 -0
- /package/dist/assets/{lexon-B1yuUdqW.js → lexon-DLBhPd3y.js} +0 -0
- /package/dist/assets/{lua-Bo6GFzxT.js → lua-gB1c_cif.js} +0 -0
- /package/dist/assets/{m3-C-Y9cBVI.js → m3-C2T3z3gB.js} +0 -0
- /package/dist/assets/{markdown-BHu-wLbe.js → markdown-CKq-Euj1.js} +0 -0
- /package/dist/assets/{mips-Dkds26rX.js → mips-Bcs5qIDX.js} +0 -0
- /package/dist/assets/{msdax-PU4g-8_g.js → msdax-CBP48FHF.js} +0 -0
- /package/dist/assets/{mysql-fPpuGpS7.js → mysql-c7tiPcFj.js} +0 -0
- /package/dist/assets/{objective-c-Wy1e5JUf.js → objective-c-D4BZkeEV.js} +0 -0
- /package/dist/assets/{pascal-BIXwvrqU.js → pascal-CJDZg0MN.js} +0 -0
- /package/dist/assets/{pascaligo-DwR0AtL_.js → pascaligo-Bygi8Ynl.js} +0 -0
- /package/dist/assets/{perl-CGHAl8my.js → perl-aS8bkf7E.js} +0 -0
- /package/dist/assets/{pgsql-B91M73E2.js → pgsql-CzNAYFYl.js} +0 -0
- /package/dist/assets/{php-C70ttrCx.js → php-DOtoEFTT.js} +0 -0
- /package/dist/assets/{pla-BNrXaRh0.js → pla-DugRnao1.js} +0 -0
- /package/dist/assets/{postiats-Dv2IAZR9.js → postiats-DsXwusKh.js} +0 -0
- /package/dist/assets/{powerquery-CkY5Wq7J.js → powerquery-DL3o72oD.js} +0 -0
- /package/dist/assets/{powershell-uGIYLU3C.js → powershell-C1qHekys.js} +0 -0
- /package/dist/assets/{protobuf-CavfmJu-.js → protobuf-DHgsc-cH.js} +0 -0
- /package/dist/assets/{pug-Drqnyitx.js → pug-FZXlE_Iu.js} +0 -0
- /package/dist/assets/{qrcode-7uGsTEmi.js → qrcode-DJDTdjL7.js} +0 -0
- /package/dist/assets/{qsharp-C7yF-Dti.js → qsharp-bLyhI3DT.js} +0 -0
- /package/dist/assets/{r-HXLGP0_-.js → r-DjFGXbAa.js} +0 -0
- /package/dist/assets/{redis-C4y6mf2p.js → redis-DSoZ_V6u.js} +0 -0
- /package/dist/assets/{redshift-DdQrFPrv.js → redshift-CzkdCsrg.js} +0 -0
- /package/dist/assets/{restructuredtext-CBrf2PNj.js → restructuredtext-B_XPrGCQ.js} +0 -0
- /package/dist/assets/{ruby-CVtMoX2B.js → ruby-Cry2RneJ.js} +0 -0
- /package/dist/assets/{rust-Ckq4sbMP.js → rust-CWzdbFq1.js} +0 -0
- /package/dist/assets/{sb-er66OpE3.js → sb-DmofU59h.js} +0 -0
- /package/dist/assets/{scala-BdWZz-hH.js → scala-BUC2l-vN.js} +0 -0
- /package/dist/assets/{scheme-kTV_s2kP.js → scheme-CNIB_72f.js} +0 -0
- /package/dist/assets/{scss-Bymy2VJQ.js → scss-DcL4-NbX.js} +0 -0
- /package/dist/assets/{shell-bwEP1LQ1.js → shell-CgAGvSSA.js} +0 -0
- /package/dist/assets/{solidity-DCddeBgL.js → solidity-DSkt6O_P.js} +0 -0
- /package/dist/assets/{sophia-BMN3AQig.js → sophia--5ytcjDN.js} +0 -0
- /package/dist/assets/{sparql-CSXOLjzi.js → sparql-C1Srr7cD.js} +0 -0
- /package/dist/assets/{sql-COg8ewmK.js → sql-2k_O5fj7.js} +0 -0
- /package/dist/assets/{st-CIaZtBS_.js → st-DCCCPqfz.js} +0 -0
- /package/dist/assets/{swift-DXiOhUHu.js → swift-Dd8mAfOt.js} +0 -0
- /package/dist/assets/{systemverilog-BTDE6Dr2.js → systemverilog-B0-aZYXu.js} +0 -0
- /package/dist/assets/{tcl-B0zy9NvV.js → tcl-CZAZwPVX.js} +0 -0
- /package/dist/assets/{twig-D594l4Z1.js → twig-D-Ag0tdS.js} +0 -0
- /package/dist/assets/{typespec-XKVjaPqo.js → typespec-B7kTFp0Z.js} +0 -0
- /package/dist/assets/{useWorkspaceMenuKeyboard-Bpy_s69Z.js → useWorkspaceMenuKeyboard-uYZpDxhU.js} +0 -0
- /package/dist/assets/{vb-B2wYoKRV.js → vb-20w1JPum.js} +0 -0
- /package/dist/assets/{wgsl-D0Yf2LbK.js → wgsl-CLJfqFt0.js} +0 -0
- /package/dist/assets/{workspace-working-copy-C3FSR3N6.js → workspace-working-copy-Cfz07cOd.js} +0 -0
|
@@ -1,1545 +0,0 @@
|
|
|
1
|
-
const childProcess = require('child_process');
|
|
2
|
-
const crypto = require('crypto');
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const http = require('http');
|
|
5
|
-
const https = require('https');
|
|
6
|
-
const os = require('os');
|
|
7
|
-
const path = require('path');
|
|
8
|
-
const { Transform } = require('stream');
|
|
9
|
-
const { pipeline } = require('stream/promises');
|
|
10
|
-
const { readServerProcessIdentity } = require('./server-process-identity');
|
|
11
|
-
const storageLayout = require('./storage-layout');
|
|
12
|
-
|
|
13
|
-
const CACHE_TTL_MS = 5 * 60 * 1000;
|
|
14
|
-
const UPDATE_SOURCE_UNCONFIGURED_REASON = 'Update source is empty. Save an Update URL in Settings or restore the default source.';
|
|
15
|
-
const NPM_PACKAGE_NAME = 'farming-code';
|
|
16
|
-
const DEFAULT_NPM_REGISTRY = 'https://registry.npmjs.org';
|
|
17
|
-
|
|
18
|
-
function readJsonFile(filePath) {
|
|
19
|
-
try {
|
|
20
|
-
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
21
|
-
} catch {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function normalizeVersion(value) {
|
|
27
|
-
const raw = String(value || '').trim();
|
|
28
|
-
if (!raw) return '';
|
|
29
|
-
const withoutPrefix = raw
|
|
30
|
-
.replace(/^refs\/tags\//i, '')
|
|
31
|
-
.replace(/^farming[-_]/i, '')
|
|
32
|
-
.replace(/^v/i, '');
|
|
33
|
-
const match = withoutPrefix.match(/\d+(?:\.\d+)*/);
|
|
34
|
-
return match ? match[0] : withoutPrefix;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function versionParts(value) {
|
|
38
|
-
const normalized = normalizeVersion(value);
|
|
39
|
-
if (!normalized) return [];
|
|
40
|
-
return normalized.split('.').map(part => Number(part)).filter(part => Number.isFinite(part));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function compareVersions(left, right) {
|
|
44
|
-
const leftParts = versionParts(left);
|
|
45
|
-
const rightParts = versionParts(right);
|
|
46
|
-
const length = Math.max(leftParts.length, rightParts.length);
|
|
47
|
-
for (let index = 0; index < length; index += 1) {
|
|
48
|
-
const leftValue = leftParts[index] || 0;
|
|
49
|
-
const rightValue = rightParts[index] || 0;
|
|
50
|
-
if (leftValue > rightValue) return 1;
|
|
51
|
-
if (leftValue < rightValue) return -1;
|
|
52
|
-
}
|
|
53
|
-
return 0;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function detectInstallMethod(rootDir, options = {}) {
|
|
57
|
-
if (options.packagedRuntime) return 'standalone-cli';
|
|
58
|
-
const release = readJsonFile(path.join(rootDir, 'RELEASE.json')) || {};
|
|
59
|
-
if (release.updateMethod === 'npm') return 'npm';
|
|
60
|
-
if (release.type) return String(release.type);
|
|
61
|
-
if (fs.existsSync(path.join(rootDir, '.farming.pid')) || fs.existsSync(path.join(rootDir, '.farming-launcher.sh'))) {
|
|
62
|
-
return 'app-bundle';
|
|
63
|
-
}
|
|
64
|
-
const pkg = readJsonFile(path.join(rootDir, 'package.json')) || {};
|
|
65
|
-
if (pkg.name === NPM_PACKAGE_NAME && !fs.existsSync(path.join(rootDir, '.git'))) return 'npm';
|
|
66
|
-
return 'source';
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function installMethodAllowsBundleUpdate(method) {
|
|
70
|
-
return method === 'app-bundle' || method === 'source-deploy';
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function installMethodBlockedReason(method) {
|
|
74
|
-
if (method === 'source') return 'Source checkouts update through Git, not the in-app updater';
|
|
75
|
-
if (method === 'standalone-cli') return 'Standalone CLI updates must reinstall the matching release asset';
|
|
76
|
-
return `In-app updates are not supported for ${method || 'this installation'}`;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function hasComparableVersion(value) {
|
|
80
|
-
return versionParts(value).length > 0;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function releaseVersionFromAsset(asset) {
|
|
84
|
-
return normalizeVersion(asset && (
|
|
85
|
-
asset.releaseVersion ||
|
|
86
|
-
asset.version ||
|
|
87
|
-
asset.file ||
|
|
88
|
-
asset.name ||
|
|
89
|
-
basenameFromUrl(asset.browser_download_url || asset.downloadUrl || asset.url)
|
|
90
|
-
));
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function releaseVersionFromRelease(release) {
|
|
94
|
-
const taggedVersion = normalizeVersion(release && (release.tag_name || release.name));
|
|
95
|
-
if (hasComparableVersion(taggedVersion)) return taggedVersion;
|
|
96
|
-
const assetVersion = releaseVersionFromAsset(selectReleaseAsset(release));
|
|
97
|
-
return hasComparableVersion(assetVersion) ? assetVersion : taggedVersion;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function releaseVersionFromManifest(manifest) {
|
|
101
|
-
if (!manifest) return '';
|
|
102
|
-
if (manifest.version) return normalizeVersion(manifest.version);
|
|
103
|
-
if (manifest.releaseVersion) return normalizeVersion(manifest.releaseVersion);
|
|
104
|
-
if (manifest.tag) return normalizeVersion(manifest.tag);
|
|
105
|
-
const assets = manifestAssets(manifest);
|
|
106
|
-
const appBundle = assets.find(asset => asset && asset.type === 'app-bundle') || assets[0];
|
|
107
|
-
return releaseVersionFromAsset(appBundle);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function releaseTagFromManifest(manifest) {
|
|
111
|
-
const tag = String(manifest && manifest.tag || '').trim();
|
|
112
|
-
if (tag) return tag;
|
|
113
|
-
const version = releaseVersionFromManifest(manifest);
|
|
114
|
-
return version ? `v${version}` : '';
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function isAbsoluteHttpUrl(value) {
|
|
118
|
-
return /^https?:\/\//i.test(String(value || ''));
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function resolveUpdateUrl(value, baseUrl = '') {
|
|
122
|
-
const raw = String(value || '').trim();
|
|
123
|
-
if (!raw) return '';
|
|
124
|
-
if (isAbsoluteHttpUrl(raw)) return raw;
|
|
125
|
-
if (!baseUrl) return '';
|
|
126
|
-
try {
|
|
127
|
-
return new URL(raw, baseUrl).toString();
|
|
128
|
-
} catch {
|
|
129
|
-
return '';
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function basenameFromUrl(value) {
|
|
134
|
-
const raw = String(value || '').trim();
|
|
135
|
-
if (!raw) return '';
|
|
136
|
-
try {
|
|
137
|
-
const parsed = isAbsoluteHttpUrl(raw) ? new URL(raw) : new URL(raw, 'http://farming.local/');
|
|
138
|
-
const pathname = parsed.pathname || '';
|
|
139
|
-
return pathname.split('/').filter(Boolean).pop() || '';
|
|
140
|
-
} catch {
|
|
141
|
-
return raw.split('/').filter(Boolean).pop() || '';
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function manifestAssets(manifest) {
|
|
146
|
-
if (Array.isArray(manifest && manifest.assets)) return manifest.assets;
|
|
147
|
-
const tarUrl = manifest && (manifest.tarUrl || manifest.downloadUrl || manifest.url);
|
|
148
|
-
const file = manifest && (manifest.file || manifest.name || basenameFromUrl(tarUrl));
|
|
149
|
-
if (!tarUrl && !file) return [];
|
|
150
|
-
return [{
|
|
151
|
-
type: 'app-bundle',
|
|
152
|
-
file,
|
|
153
|
-
url: tarUrl,
|
|
154
|
-
size: manifest.size || manifest.bytes || 0,
|
|
155
|
-
sha256: manifest.sha256 || '',
|
|
156
|
-
releaseVersion: manifest.releaseVersion || manifest.version || '',
|
|
157
|
-
}];
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function normalizeSha256(value) {
|
|
161
|
-
const normalized = String(value || '').trim().toLowerCase();
|
|
162
|
-
return /^[a-f0-9]{64}$/.test(normalized) ? normalized : '';
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function normalizePlatform(value) {
|
|
166
|
-
const raw = String(value || '').trim().toLowerCase();
|
|
167
|
-
if (raw === 'darwin' || raw === 'macos' || raw === 'macosx' || raw === 'osx') return 'darwin';
|
|
168
|
-
if (raw === 'linux') return 'linux';
|
|
169
|
-
return raw;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
function normalizeArch(value) {
|
|
173
|
-
const raw = String(value || '').trim().toLowerCase();
|
|
174
|
-
if (raw === 'x64' || raw === 'amd64' || raw === 'x86_64') return 'x64';
|
|
175
|
-
if (raw === 'arm64' || raw === 'aarch64') return 'arm64';
|
|
176
|
-
return raw;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function assetMatchesRuntime(asset, runtime) {
|
|
180
|
-
if (!runtime) return true;
|
|
181
|
-
return normalizePlatform(asset && asset.platform) === runtime.platform
|
|
182
|
-
&& normalizeArch(asset && asset.arch) === runtime.arch;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function assetCompatibilityPreference(asset, preferredProfile = '') {
|
|
186
|
-
const profile = String(asset && asset.compatibilityProfile || '').trim();
|
|
187
|
-
const preferred = String(preferredProfile || '').trim();
|
|
188
|
-
if (preferred) return profile === preferred ? 0 : 1;
|
|
189
|
-
return profile ? 1 : 0;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
function runtimeFromBundleName(value) {
|
|
193
|
-
const match = /-(darwin|linux)-(x64|arm64)\.tar\.gz$/i.exec(String(value || ''));
|
|
194
|
-
return match ? { platform: normalizePlatform(match[1]), arch: normalizeArch(match[2]) } : null;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
function releaseFromAssetListing(release) {
|
|
198
|
-
const rawAssets = Array.isArray(release && release.assets) ? release.assets : [];
|
|
199
|
-
const checksumAsset = rawAssets.find(asset => /(?:checksums?|sha256)\.(?:txt|sha256)$/i.test(String(asset && asset.name || '')));
|
|
200
|
-
return {
|
|
201
|
-
...release,
|
|
202
|
-
__directAssets: true,
|
|
203
|
-
assets: rawAssets.map(asset => {
|
|
204
|
-
const runtime = runtimeFromBundleName(asset && asset.name);
|
|
205
|
-
const isBundle = /^farming[-_].*\.tar\.gz$/i.test(String(asset && asset.name || ''));
|
|
206
|
-
return {
|
|
207
|
-
...asset,
|
|
208
|
-
...(isBundle ? { type: 'app-bundle' } : {}),
|
|
209
|
-
...(runtime || {}),
|
|
210
|
-
...(checksumAsset?.browser_download_url ? { checksum_url: checksumAsset.browser_download_url } : {}),
|
|
211
|
-
};
|
|
212
|
-
}),
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
function releaseFromManifest(manifest, options = {}) {
|
|
217
|
-
const tag = releaseTagFromManifest(manifest);
|
|
218
|
-
const assetBaseUrl = options.assetBaseUrl || options.manifestUrl || '';
|
|
219
|
-
const assets = manifestAssets(manifest);
|
|
220
|
-
return {
|
|
221
|
-
__manifest: manifest,
|
|
222
|
-
tag_name: tag,
|
|
223
|
-
name: manifest && manifest.name ? String(manifest.name) : tag,
|
|
224
|
-
published_at: manifest && (manifest.publishedAt || manifest.builtAt) ? String(manifest.publishedAt || manifest.builtAt) : '',
|
|
225
|
-
assets: assets
|
|
226
|
-
.map(asset => {
|
|
227
|
-
const file = String(asset && (
|
|
228
|
-
asset.file ||
|
|
229
|
-
asset.name ||
|
|
230
|
-
basenameFromUrl(asset.browser_download_url || asset.downloadUrl || asset.url)
|
|
231
|
-
) || '');
|
|
232
|
-
if (!file) return null;
|
|
233
|
-
return {
|
|
234
|
-
...asset,
|
|
235
|
-
name: file,
|
|
236
|
-
size: asset.size || asset.bytes || 0,
|
|
237
|
-
browser_download_url: asset.browser_download_url
|
|
238
|
-
|| resolveUpdateUrl(asset.downloadUrl || asset.url || file, assetBaseUrl),
|
|
239
|
-
};
|
|
240
|
-
})
|
|
241
|
-
.filter(asset => asset && asset.browser_download_url),
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
function selectReleaseAsset(release, patternText = '') {
|
|
246
|
-
const assets = Array.isArray(release && release.assets) ? release.assets : [];
|
|
247
|
-
if (patternText) {
|
|
248
|
-
const pattern = new RegExp(patternText);
|
|
249
|
-
const matched = assets.find(asset => pattern.test(String(asset.name || '')) && asset.browser_download_url);
|
|
250
|
-
if (matched) return matched;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
return assets.find(asset => (
|
|
254
|
-
/^farming[-_].*\.tar\.gz$/i.test(String(asset.name || '')) &&
|
|
255
|
-
!/(sha256|checksum|checksums)/i.test(String(asset.name || '')) &&
|
|
256
|
-
asset.browser_download_url
|
|
257
|
-
)) || null;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
function releaseAssetVersion(asset, fallbackVersion = '') {
|
|
261
|
-
return normalizeVersion(
|
|
262
|
-
asset && (asset.releaseVersion || asset.version || asset.name || asset.file || asset.browser_download_url) ||
|
|
263
|
-
fallbackVersion
|
|
264
|
-
);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
function selectableReleaseAssets(release, patternText = '', runtime = null, preferredCompatibilityProfile = '') {
|
|
268
|
-
const assets = Array.isArray(release && release.assets) ? release.assets : [];
|
|
269
|
-
const pattern = patternText ? new RegExp(patternText) : null;
|
|
270
|
-
return assets
|
|
271
|
-
.filter(asset => (
|
|
272
|
-
/^farming[-_].*\.tar\.gz$/i.test(String(asset.name || '')) &&
|
|
273
|
-
!/(sha256|checksum|checksums)/i.test(String(asset.name || '')) &&
|
|
274
|
-
asset.browser_download_url &&
|
|
275
|
-
assetMatchesRuntime(asset, runtime) &&
|
|
276
|
-
(!preferredCompatibilityProfile || String(asset.compatibilityProfile || '').trim() === preferredCompatibilityProfile) &&
|
|
277
|
-
(!pattern || pattern.test(String(asset.name || '')))
|
|
278
|
-
))
|
|
279
|
-
.sort((left, right) => (
|
|
280
|
-
compareVersions(releaseAssetVersion(right), releaseAssetVersion(left)) ||
|
|
281
|
-
assetCompatibilityPreference(left, preferredCompatibilityProfile) - assetCompatibilityPreference(right, preferredCompatibilityProfile) ||
|
|
282
|
-
String(right.name || '').localeCompare(String(left.name || ''))
|
|
283
|
-
));
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
function selectReleaseAssetByName(release, assetName, patternText = '', runtime = null, preferredCompatibilityProfile = '') {
|
|
287
|
-
const wanted = String(assetName || '').trim();
|
|
288
|
-
if (!wanted) return selectableReleaseAssets(release, patternText, runtime, preferredCompatibilityProfile)[0] || null;
|
|
289
|
-
return selectableReleaseAssets(release, patternText, runtime, preferredCompatibilityProfile)
|
|
290
|
-
.find(asset => String(asset.name || '') === wanted) || null;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
function selectManifestAsset(release) {
|
|
294
|
-
const assets = Array.isArray(release && release.assets) ? release.assets : [];
|
|
295
|
-
return assets.find(asset => (
|
|
296
|
-
String(asset.name || '').toLowerCase() === 'manifest.json' &&
|
|
297
|
-
asset.browser_download_url
|
|
298
|
-
)) || null;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
function manifestAssetSafety(asset, manifest, options = {}) {
|
|
302
|
-
const runtime = options.runtime || null;
|
|
303
|
-
if (!asset) {
|
|
304
|
-
return {
|
|
305
|
-
safe: false,
|
|
306
|
-
reason: 'Update manifest has no app bundle asset',
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
const assets = manifestAssets(manifest);
|
|
310
|
-
if (assets.length === 0 && !asset.checksum_url && !asset.checksumUrl && !asset.sha256) {
|
|
311
|
-
return {
|
|
312
|
-
safe: false,
|
|
313
|
-
reason: 'Update manifest is missing a SHA-256 checksum',
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
const assetName = String(asset.name || '');
|
|
318
|
-
const entry = assets.find(item => String(item.file || item.name || basenameFromUrl(item.url || item.tarUrl || item.downloadUrl) || '') === assetName) || (assets.length === 0 ? asset : null);
|
|
319
|
-
if (!entry) {
|
|
320
|
-
return {
|
|
321
|
-
safe: false,
|
|
322
|
-
reason: 'Update manifest does not describe the app bundle',
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
if (entry.type && entry.type !== 'app-bundle') {
|
|
326
|
-
return {
|
|
327
|
-
safe: false,
|
|
328
|
-
reason: 'Update manifest does not mark the app bundle correctly',
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
if (!assetMatchesRuntime(entry, runtime)) {
|
|
332
|
-
return {
|
|
333
|
-
safe: false,
|
|
334
|
-
reason: `Update app bundle is not compatible with ${runtime.platform}-${runtime.arch}`,
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
const checksumUrl = entry.checksum_url || entry.checksumUrl || asset.checksum_url || asset.checksumUrl || '';
|
|
338
|
-
if (!normalizeSha256(entry.sha256 || asset.sha256) && !checksumUrl) {
|
|
339
|
-
return {
|
|
340
|
-
safe: false,
|
|
341
|
-
reason: 'Update manifest app bundle is missing a SHA-256 checksum',
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
-
return { safe: true, reason: '' };
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
function requestWithRedirects(url, options = {}, redirectCount = 0, authOrigin = null) {
|
|
348
|
-
if (redirectCount > 5) {
|
|
349
|
-
return Promise.reject(new Error(`too many redirects for ${url}`));
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
return new Promise((resolve, reject) => {
|
|
353
|
-
const parsed = new URL(url);
|
|
354
|
-
const allowedAuthOrigin = authOrigin === false ? '' : (authOrigin || parsed.origin);
|
|
355
|
-
const sameAuthOrigin = Boolean(allowedAuthOrigin) && parsed.origin === allowedAuthOrigin;
|
|
356
|
-
const client = parsed.protocol === 'http:' ? http : https;
|
|
357
|
-
const headers = {
|
|
358
|
-
'User-Agent': 'Farming-Update-Check',
|
|
359
|
-
Accept: options.accept || 'application/json',
|
|
360
|
-
...(options.headers || {}),
|
|
361
|
-
};
|
|
362
|
-
if (!sameAuthOrigin) {
|
|
363
|
-
delete headers.Authorization;
|
|
364
|
-
delete headers.authorization;
|
|
365
|
-
} else if (options.authToken) {
|
|
366
|
-
headers.Authorization = `Bearer ${options.authToken}`;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
const request = client.get(parsed, { headers }, (response) => {
|
|
370
|
-
const status = response.statusCode || 0;
|
|
371
|
-
const location = response.headers.location;
|
|
372
|
-
if (status >= 300 && status < 400 && location) {
|
|
373
|
-
response.resume();
|
|
374
|
-
const nextUrl = new URL(location, parsed).toString();
|
|
375
|
-
const nextParsed = new URL(nextUrl);
|
|
376
|
-
const nextOptions = { ...options };
|
|
377
|
-
if (nextParsed.origin !== allowedAuthOrigin) {
|
|
378
|
-
// Update-source tokens are scoped to the configured origin. Never
|
|
379
|
-
// forward them to a redirect target on another origin.
|
|
380
|
-
delete nextOptions.authToken;
|
|
381
|
-
if (nextOptions.headers) {
|
|
382
|
-
nextOptions.headers = { ...nextOptions.headers };
|
|
383
|
-
delete nextOptions.headers.Authorization;
|
|
384
|
-
delete nextOptions.headers.authorization;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
requestWithRedirects(
|
|
388
|
-
nextUrl,
|
|
389
|
-
nextOptions,
|
|
390
|
-
redirectCount + 1,
|
|
391
|
-
nextParsed.origin === allowedAuthOrigin ? allowedAuthOrigin : false,
|
|
392
|
-
).then(resolve, reject);
|
|
393
|
-
return;
|
|
394
|
-
}
|
|
395
|
-
if (status < 200 || status >= 300) {
|
|
396
|
-
response.resume();
|
|
397
|
-
reject(new Error(`request failed with HTTP ${status}`));
|
|
398
|
-
return;
|
|
399
|
-
}
|
|
400
|
-
resolve(response);
|
|
401
|
-
});
|
|
402
|
-
request.on('error', reject);
|
|
403
|
-
request.setTimeout(options.timeoutMs || 30_000, () => {
|
|
404
|
-
request.destroy(new Error(`request timed out for ${url}`));
|
|
405
|
-
});
|
|
406
|
-
});
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
async function requestJson(url, options = {}) {
|
|
410
|
-
const response = await requestWithRedirects(url, options);
|
|
411
|
-
const chunks = [];
|
|
412
|
-
for await (const chunk of response) {
|
|
413
|
-
chunks.push(chunk);
|
|
414
|
-
}
|
|
415
|
-
return JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
async function requestText(url, options = {}) {
|
|
419
|
-
const response = await requestWithRedirects(url, options);
|
|
420
|
-
const chunks = [];
|
|
421
|
-
for await (const chunk of response) {
|
|
422
|
-
chunks.push(chunk);
|
|
423
|
-
}
|
|
424
|
-
return Buffer.concat(chunks).toString('utf8');
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
function decodeHtmlAttribute(value) {
|
|
428
|
-
return String(value || '')
|
|
429
|
-
.replace(/&/g, '&')
|
|
430
|
-
.replace(/"/g, '"')
|
|
431
|
-
.replace(/'/g, "'")
|
|
432
|
-
.replace(/</g, '<')
|
|
433
|
-
.replace(/>/g, '>');
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
function isDirectoryUpdateSource(value) {
|
|
437
|
-
const raw = String(value || '').trim();
|
|
438
|
-
if (!raw) return false;
|
|
439
|
-
try {
|
|
440
|
-
return new URL(raw).pathname.endsWith('/');
|
|
441
|
-
} catch {
|
|
442
|
-
return raw.endsWith('/');
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
function isGitHubReleasePage(value) {
|
|
447
|
-
try {
|
|
448
|
-
const url = new URL(value);
|
|
449
|
-
return url.hostname === 'github.com' && /\/releases\/(?:latest|tag\/[^/]+)\/?$/i.test(url.pathname);
|
|
450
|
-
} catch {
|
|
451
|
-
return false;
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
function githubReleaseTagFromPage(body) {
|
|
456
|
-
for (const match of String(body || '').matchAll(/\/releases\/tag\/([^"'/?#<]+)/gi)) {
|
|
457
|
-
const tag = decodeHtmlAttribute(match[1]);
|
|
458
|
-
if (/^v\d/.test(tag)) return tag;
|
|
459
|
-
}
|
|
460
|
-
return '';
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
function githubExpandedAssetsUrl(pageUrl, tag) {
|
|
464
|
-
try {
|
|
465
|
-
const url = new URL(pageUrl);
|
|
466
|
-
const parts = url.pathname.split('/').filter(Boolean);
|
|
467
|
-
if (parts.length < 2 || !tag) return '';
|
|
468
|
-
return `${url.origin}/${parts[0]}/${parts[1]}/releases/expanded_assets/${encodeURIComponent(tag)}`;
|
|
469
|
-
} catch {
|
|
470
|
-
return '';
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
function releaseFromGitHubReleasePage(body, options = {}) {
|
|
475
|
-
const pageUrl = options.pageUrl || '';
|
|
476
|
-
const entries = [];
|
|
477
|
-
for (const match of String(body || '').matchAll(/\bhref\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/gi)) {
|
|
478
|
-
const value = decodeHtmlAttribute(match[1] || match[2] || match[3]).trim();
|
|
479
|
-
if (value) entries.push(value);
|
|
480
|
-
}
|
|
481
|
-
const checksumUrl = entries
|
|
482
|
-
.map(entry => ({ entry, file: basenameFromUrl(entry) }))
|
|
483
|
-
.find(({ file }) => /(?:checksums?|sha256)\.(?:txt|sha256)$/i.test(file))?.entry || '';
|
|
484
|
-
const assets = entries
|
|
485
|
-
.map(entry => {
|
|
486
|
-
const file = basenameFromUrl(entry);
|
|
487
|
-
const runtime = runtimeFromBundleName(file);
|
|
488
|
-
if (!runtime || !/^farming[-_].*\.tar\.gz$/i.test(file)) return null;
|
|
489
|
-
const browser_download_url = resolveUpdateUrl(entry, pageUrl);
|
|
490
|
-
if (!browser_download_url) return null;
|
|
491
|
-
return {
|
|
492
|
-
type: 'app-bundle',
|
|
493
|
-
name: file,
|
|
494
|
-
file,
|
|
495
|
-
releaseVersion: normalizeVersion(file),
|
|
496
|
-
browser_download_url,
|
|
497
|
-
checksum_url: resolveUpdateUrl(checksumUrl, pageUrl),
|
|
498
|
-
...runtime,
|
|
499
|
-
};
|
|
500
|
-
})
|
|
501
|
-
.filter(Boolean);
|
|
502
|
-
const latestVersion = assets[0]?.releaseVersion || '';
|
|
503
|
-
return {
|
|
504
|
-
__directAssets: true,
|
|
505
|
-
tag_name: latestVersion ? `v${latestVersion}` : '',
|
|
506
|
-
name: latestVersion ? `v${latestVersion}` : '',
|
|
507
|
-
published_at: '',
|
|
508
|
-
assets,
|
|
509
|
-
};
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
function releaseFromDirectoryListing(body, options = {}) {
|
|
513
|
-
const directoryUrl = options.directoryUrl || '';
|
|
514
|
-
const assetBaseUrl = options.assetBaseUrl || directoryUrl;
|
|
515
|
-
const entries = [];
|
|
516
|
-
const seen = new Set();
|
|
517
|
-
const addCandidate = (value) => {
|
|
518
|
-
const raw = decodeHtmlAttribute(value).trim();
|
|
519
|
-
if (!raw || seen.has(raw)) return;
|
|
520
|
-
seen.add(raw);
|
|
521
|
-
entries.push(raw);
|
|
522
|
-
};
|
|
523
|
-
|
|
524
|
-
for (const match of String(body || '').matchAll(/\bhref\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/gi)) {
|
|
525
|
-
addCandidate(match[1] || match[2] || match[3]);
|
|
526
|
-
}
|
|
527
|
-
for (const match of String(body || '').matchAll(/\bfarming[-_][^\s"'<>]+?\.tar\.gz(?![\w.])/gi)) {
|
|
528
|
-
addCandidate(match[0]);
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
const checksumUrls = new Map();
|
|
532
|
-
entries.forEach(entry => {
|
|
533
|
-
const file = basenameFromUrl(entry);
|
|
534
|
-
const match = /^(farming[-_].*\.tar\.gz)\.sha256$/i.exec(file);
|
|
535
|
-
if (!match) return;
|
|
536
|
-
const url = resolveUpdateUrl(entry, assetBaseUrl) || resolveUpdateUrl(file, assetBaseUrl);
|
|
537
|
-
if (url) checksumUrls.set(match[1], url);
|
|
538
|
-
});
|
|
539
|
-
|
|
540
|
-
const assets = entries
|
|
541
|
-
.map(entry => {
|
|
542
|
-
const file = basenameFromUrl(entry);
|
|
543
|
-
if (!/^farming[-_].*\.tar\.gz$/i.test(file)) return null;
|
|
544
|
-
if (/(sha256|checksum|checksums)/i.test(file)) return null;
|
|
545
|
-
const url = resolveUpdateUrl(entry, assetBaseUrl) || resolveUpdateUrl(file, assetBaseUrl);
|
|
546
|
-
if (!url) return null;
|
|
547
|
-
return {
|
|
548
|
-
type: 'app-bundle',
|
|
549
|
-
file,
|
|
550
|
-
name: file,
|
|
551
|
-
releaseVersion: normalizeVersion(file),
|
|
552
|
-
browser_download_url: url,
|
|
553
|
-
checksum_url: checksumUrls.get(file) || '',
|
|
554
|
-
size: 0,
|
|
555
|
-
};
|
|
556
|
-
})
|
|
557
|
-
.filter(Boolean)
|
|
558
|
-
.sort((left, right) => (
|
|
559
|
-
compareVersions(right.releaseVersion, left.releaseVersion) ||
|
|
560
|
-
String(right.name).localeCompare(String(left.name))
|
|
561
|
-
));
|
|
562
|
-
const latestVersion = assets[0] ? assets[0].releaseVersion : '';
|
|
563
|
-
return {
|
|
564
|
-
__manifest: {
|
|
565
|
-
releaseVersion: latestVersion,
|
|
566
|
-
assets: assets.map(asset => ({
|
|
567
|
-
type: asset.type,
|
|
568
|
-
file: asset.file,
|
|
569
|
-
url: asset.browser_download_url,
|
|
570
|
-
checksum_url: asset.checksum_url,
|
|
571
|
-
releaseVersion: asset.releaseVersion,
|
|
572
|
-
})),
|
|
573
|
-
},
|
|
574
|
-
tag_name: latestVersion ? `v${latestVersion}` : '',
|
|
575
|
-
name: latestVersion ? `v${latestVersion}` : '',
|
|
576
|
-
published_at: '',
|
|
577
|
-
assets,
|
|
578
|
-
};
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
async function downloadFile(url, outputPath, options = {}) {
|
|
582
|
-
const response = await requestWithRedirects(url, {
|
|
583
|
-
...options,
|
|
584
|
-
accept: 'application/octet-stream',
|
|
585
|
-
});
|
|
586
|
-
const responseLength = Number(response.headers['content-length']);
|
|
587
|
-
const expectedLength = Number(options.totalBytes);
|
|
588
|
-
const totalBytes = Number.isFinite(responseLength) && responseLength > 0
|
|
589
|
-
? responseLength
|
|
590
|
-
: (Number.isFinite(expectedLength) && expectedLength > 0 ? expectedLength : 0);
|
|
591
|
-
let receivedBytes = 0;
|
|
592
|
-
const trackProgress = new Transform({
|
|
593
|
-
transform(chunk, _encoding, callback) {
|
|
594
|
-
receivedBytes += chunk.length;
|
|
595
|
-
try {
|
|
596
|
-
if (typeof options.onProgress === 'function') {
|
|
597
|
-
options.onProgress({ receivedBytes, totalBytes });
|
|
598
|
-
}
|
|
599
|
-
callback(null, chunk);
|
|
600
|
-
} catch (error) {
|
|
601
|
-
callback(error);
|
|
602
|
-
}
|
|
603
|
-
},
|
|
604
|
-
});
|
|
605
|
-
await pipeline(response, trackProgress, fs.createWriteStream(outputPath));
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
function sha256File(filePath) {
|
|
609
|
-
const hash = crypto.createHash('sha256');
|
|
610
|
-
hash.update(fs.readFileSync(filePath));
|
|
611
|
-
return hash.digest('hex');
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
function sha256FromChecksumText(text, assetName) {
|
|
615
|
-
const escapedName = String(assetName || '').replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
616
|
-
const match = new RegExp(`^\\s*([a-f0-9]{64})\\s+(?:\\*?${escapedName})\\s*$`, 'im').exec(String(text || ''));
|
|
617
|
-
return normalizeSha256(match && match[1]);
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
function validateArchiveEntries(entries) {
|
|
621
|
-
const roots = new Set();
|
|
622
|
-
for (const rawEntry of Array.isArray(entries) ? entries : []) {
|
|
623
|
-
const entry = String(rawEntry || '').replace(/\\/g, '/');
|
|
624
|
-
if (!entry || entry.startsWith('/') || entry.includes('\0')) {
|
|
625
|
-
throw new Error(`downloaded release contains an unsafe archive path: ${rawEntry}`);
|
|
626
|
-
}
|
|
627
|
-
const parts = entry.split('/').filter(Boolean);
|
|
628
|
-
if (parts.some(part => part === '..')) {
|
|
629
|
-
throw new Error(`downloaded release contains path traversal: ${rawEntry}`);
|
|
630
|
-
}
|
|
631
|
-
if (parts[0]) roots.add(parts[0]);
|
|
632
|
-
}
|
|
633
|
-
if (roots.size !== 1) {
|
|
634
|
-
throw new Error(`downloaded release must contain exactly one top-level directory, found ${roots.size}`);
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
function listTarArchiveEntries(archivePath) {
|
|
639
|
-
return new Promise((resolve, reject) => {
|
|
640
|
-
childProcess.execFile('tar', ['-tzf', archivePath], { maxBuffer: 20 * 1024 * 1024 }, (error, stdout) => {
|
|
641
|
-
if (error) {
|
|
642
|
-
reject(new Error(`failed to inspect downloaded release archive: ${error.message || error}`));
|
|
643
|
-
return;
|
|
644
|
-
}
|
|
645
|
-
resolve(String(stdout || '').split(/\r?\n/).map(line => line.trim()).filter(Boolean));
|
|
646
|
-
});
|
|
647
|
-
});
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
function validateExtractedSymlinks(releaseDir) {
|
|
651
|
-
const releaseRoot = path.resolve(releaseDir);
|
|
652
|
-
const visit = directory => {
|
|
653
|
-
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
|
|
654
|
-
const entryPath = path.join(directory, entry.name);
|
|
655
|
-
if (entry.isSymbolicLink()) {
|
|
656
|
-
const target = fs.readlinkSync(entryPath);
|
|
657
|
-
const resolvedTarget = path.resolve(path.dirname(entryPath), target);
|
|
658
|
-
if (path.isAbsolute(target) || (resolvedTarget !== releaseRoot && !resolvedTarget.startsWith(`${releaseRoot}${path.sep}`))) {
|
|
659
|
-
throw new Error(`downloaded release contains a symlink outside the bundle: ${entryPath}`);
|
|
660
|
-
}
|
|
661
|
-
continue;
|
|
662
|
-
}
|
|
663
|
-
if (entry.isDirectory()) visit(entryPath);
|
|
664
|
-
}
|
|
665
|
-
};
|
|
666
|
-
visit(releaseRoot);
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
function findReleaseDirectory(rootDir) {
|
|
670
|
-
const entries = fs.readdirSync(rootDir, { withFileTypes: true });
|
|
671
|
-
const directory = entries.find(entry => entry.isDirectory());
|
|
672
|
-
if (!directory) {
|
|
673
|
-
throw new Error('downloaded release archive did not contain a directory');
|
|
674
|
-
}
|
|
675
|
-
return path.join(rootDir, directory.name);
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
function releaseInstallDir(rootDir, env = process.env) {
|
|
679
|
-
if (env.FARMING_INSTALL_DIR) return env.FARMING_INSTALL_DIR;
|
|
680
|
-
if (fs.existsSync(path.join(rootDir, '.farming.pid')) || fs.existsSync(path.join(rootDir, 'RELEASE.json'))) {
|
|
681
|
-
return rootDir;
|
|
682
|
-
}
|
|
683
|
-
return path.join(os.homedir(), 'farming');
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
function nodeScriptInvocation(nodePath, scriptPath, env = process.env) {
|
|
687
|
-
if (env.FARMING_NODE_LD && env.FARMING_NODE_LIBRARY_PATH) {
|
|
688
|
-
return {
|
|
689
|
-
command: env.FARMING_NODE_LD,
|
|
690
|
-
args: ['--library-path', env.FARMING_NODE_LIBRARY_PATH, nodePath, scriptPath],
|
|
691
|
-
};
|
|
692
|
-
}
|
|
693
|
-
return { command: nodePath, args: [scriptPath] };
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
function npmPackageMetadataUrl(registryUrl, packageName) {
|
|
697
|
-
const registry = String(registryUrl || DEFAULT_NPM_REGISTRY).replace(/\/+$/, '');
|
|
698
|
-
return `${registry}/${encodeURIComponent(packageName).replace(/^%40/, '@')}`;
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
function normalizePathForCompare(filePath) {
|
|
702
|
-
try {
|
|
703
|
-
return fs.realpathSync(filePath);
|
|
704
|
-
} catch {
|
|
705
|
-
return path.resolve(filePath);
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
function pathIsInside(parentPath, childPath) {
|
|
710
|
-
const relative = path.relative(path.resolve(parentPath), path.resolve(childPath));
|
|
711
|
-
return relative !== '' && !relative.startsWith('..') && !path.isAbsolute(relative);
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
function npmPackageRoot(npmRoot, packageName) {
|
|
715
|
-
return path.join(npmRoot, ...String(packageName || '').split('/').filter(Boolean));
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
function npmPrefixForPackageRoot(packageRoot, packageName) {
|
|
719
|
-
const segments = String(packageName || '').split('/').filter(Boolean);
|
|
720
|
-
if (!path.isAbsolute(packageRoot) || segments.length === 0) return '';
|
|
721
|
-
let npmRoot = packageRoot;
|
|
722
|
-
for (let index = 0; index < segments.length; index += 1) npmRoot = path.dirname(npmRoot);
|
|
723
|
-
return path.dirname(path.dirname(npmRoot));
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
function readNpmGlobalRoot(npmCommand, npmPrefix, execFile = childProcess.execFile) {
|
|
727
|
-
const args = ['root', '--global'];
|
|
728
|
-
if (npmPrefix) args.push('--prefix', npmPrefix);
|
|
729
|
-
return new Promise((resolve, reject) => {
|
|
730
|
-
execFile(npmCommand, args, (error, stdout) => {
|
|
731
|
-
if (error) {
|
|
732
|
-
reject(error);
|
|
733
|
-
return;
|
|
734
|
-
}
|
|
735
|
-
const root = String(stdout || '').split(/\r?\n/).map(value => value.trim()).find(Boolean);
|
|
736
|
-
if (!root) {
|
|
737
|
-
reject(new Error('npm root --global returned no path'));
|
|
738
|
-
return;
|
|
739
|
-
}
|
|
740
|
-
resolve(root);
|
|
741
|
-
});
|
|
742
|
-
});
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
function npmVersionsFromMetadata(metadata, currentVersion) {
|
|
746
|
-
const versions = metadata && metadata.versions && typeof metadata.versions === 'object'
|
|
747
|
-
? Object.keys(metadata.versions)
|
|
748
|
-
: [];
|
|
749
|
-
return versions
|
|
750
|
-
.filter(version => hasComparableVersion(version) && !version.includes('-'))
|
|
751
|
-
.sort((left, right) => compareVersions(right, left))
|
|
752
|
-
.map(version => ({
|
|
753
|
-
version,
|
|
754
|
-
assetName: version,
|
|
755
|
-
assetSize: Number(metadata.versions[version]?.dist?.unpackedSize || 0),
|
|
756
|
-
blockedReason: '',
|
|
757
|
-
installable: true,
|
|
758
|
-
available: compareVersions(version, currentVersion) > 0,
|
|
759
|
-
}));
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
class FarmingUpdateService {
|
|
763
|
-
constructor(options = {}) {
|
|
764
|
-
this.rootDir = options.rootDir || path.join(__dirname, '..');
|
|
765
|
-
this.getUpdateUrl = typeof options.getUpdateUrl === 'function' ? options.getUpdateUrl : null;
|
|
766
|
-
this.manifestUrl = options.updateUrl || options.manifestUrl || '';
|
|
767
|
-
this.assetBaseUrl = options.assetBaseUrl || '';
|
|
768
|
-
this.assetPattern = options.assetPattern || '';
|
|
769
|
-
this.authToken = options.authToken || '';
|
|
770
|
-
this.installMethod = options.installMethod || detectInstallMethod(this.rootDir, {
|
|
771
|
-
packagedRuntime: options.packagedRuntime === true,
|
|
772
|
-
});
|
|
773
|
-
this.npmPackageName = options.npmPackageName || NPM_PACKAGE_NAME;
|
|
774
|
-
this.npmRegistryUrl = options.npmRegistryUrl || process.env.FARMING_NPM_REGISTRY || DEFAULT_NPM_REGISTRY;
|
|
775
|
-
this.npmPackageRoot = options.npmPackageRoot || process.env.FARMING_MANAGED_PACKAGE_ROOT || '';
|
|
776
|
-
this.npmPrefix = options.npmPrefix || process.env.FARMING_NPM_PREFIX || '';
|
|
777
|
-
this.runtime = options.platform || options.arch
|
|
778
|
-
? {
|
|
779
|
-
platform: normalizePlatform(options.platform || process.platform),
|
|
780
|
-
arch: normalizeArch(options.arch || process.arch),
|
|
781
|
-
}
|
|
782
|
-
: null;
|
|
783
|
-
this.configDir = options.configDir || path.join(os.homedir(), '.farming');
|
|
784
|
-
this.now = options.now || (() => Date.now());
|
|
785
|
-
this.fetchJson = options.fetchJson || requestJson;
|
|
786
|
-
this.fetchText = options.fetchText || requestText;
|
|
787
|
-
this.downloadFile = options.downloadFile || downloadFile;
|
|
788
|
-
this.listArchiveEntries = options.listArchiveEntries || listTarArchiveEntries;
|
|
789
|
-
this.execFile = options.execFile || childProcess.execFile;
|
|
790
|
-
this.getNpmGlobalRoot = options.getNpmGlobalRoot
|
|
791
|
-
|| ((npmCommand, npmPrefix) => readNpmGlobalRoot(npmCommand, npmPrefix, this.execFile));
|
|
792
|
-
this.spawn = options.spawn || childProcess.spawn;
|
|
793
|
-
this.prepareRuntimeDependencies = options.prepareRuntimeDependencies || (async (releaseDir) => {
|
|
794
|
-
if (process.env.NODE_ENV === 'test') return;
|
|
795
|
-
const managerPath = path.join(releaseDir, 'backend', 'runtime-dependency-manager.js');
|
|
796
|
-
const { prepareRuntimeDependencies } = require(managerPath);
|
|
797
|
-
await prepareRuntimeDependencies({
|
|
798
|
-
configDir: this.configDir,
|
|
799
|
-
env: { ...process.env, FARMING_CONFIG_DIR: this.configDir },
|
|
800
|
-
});
|
|
801
|
-
});
|
|
802
|
-
this.latestCache = null;
|
|
803
|
-
this.npmCache = null;
|
|
804
|
-
this.installState = { phase: 'idle' };
|
|
805
|
-
this.installStartPromise = null;
|
|
806
|
-
this.updateStateFile = options.updateStateFile || storageLayout.updateStateFile(this.configDir);
|
|
807
|
-
this.updateLogFile = options.updateLogFile || storageLayout.updateLogFile(this.configDir);
|
|
808
|
-
this.updateStagingDir = options.updateStagingDir || storageLayout.updateStagingDir(this.configDir);
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
updateUrl() {
|
|
812
|
-
const configured = this.getUpdateUrl ? this.getUpdateUrl() : this.manifestUrl;
|
|
813
|
-
return String(configured || '').trim();
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
currentVersion() {
|
|
817
|
-
const release = readJsonFile(path.join(this.rootDir, 'RELEASE.json')) || {};
|
|
818
|
-
const pkg = readJsonFile(path.join(this.rootDir, 'package.json')) || {};
|
|
819
|
-
const packageVersion = String(release.packageVersion || pkg.version || '');
|
|
820
|
-
const releaseVersion = String(release.releaseVersion || normalizeVersion(packageVersion) || '');
|
|
821
|
-
return {
|
|
822
|
-
releaseVersion,
|
|
823
|
-
packageVersion,
|
|
824
|
-
gitSha: release.gitSha || '',
|
|
825
|
-
compatibilityProfile: String(release.compatibilityProfile || ''),
|
|
826
|
-
bundledGlibcRuntime: release.bundledGlibcRuntime === true,
|
|
827
|
-
type: this.installMethod,
|
|
828
|
-
installDir: this.installMethod === 'npm' ? this.rootDir : releaseInstallDir(this.rootDir),
|
|
829
|
-
};
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
currentInstallState() {
|
|
833
|
-
const persisted = readJsonFile(this.updateStateFile);
|
|
834
|
-
if (persisted && persisted.method === this.installMethod) return persisted;
|
|
835
|
-
const current = this.currentVersion();
|
|
836
|
-
const currentVersion = normalizeVersion(current.releaseVersion || current.packageVersion);
|
|
837
|
-
if (
|
|
838
|
-
persisted
|
|
839
|
-
&& persisted.targetMethod === this.installMethod
|
|
840
|
-
&& normalizeVersion(persisted.version) === currentVersion
|
|
841
|
-
) {
|
|
842
|
-
return persisted;
|
|
843
|
-
}
|
|
844
|
-
return this.installState;
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
persistInstallState(state) {
|
|
848
|
-
this.installState = state;
|
|
849
|
-
fs.mkdirSync(this.configDir, { recursive: true });
|
|
850
|
-
const temporaryPath = `${this.updateStateFile}.${process.pid}.tmp`;
|
|
851
|
-
fs.writeFileSync(temporaryPath, `${JSON.stringify(state, null, 2)}\n`, { mode: 0o600 });
|
|
852
|
-
fs.renameSync(temporaryPath, this.updateStateFile);
|
|
853
|
-
return state;
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
async npmMetadata(options = {}) {
|
|
857
|
-
const source = npmPackageMetadataUrl(this.npmRegistryUrl, this.npmPackageName);
|
|
858
|
-
if (!options.force && this.npmCache && this.npmCache.source === source && this.now() - this.npmCache.checkedAt < CACHE_TTL_MS) {
|
|
859
|
-
return this.npmCache.metadata;
|
|
860
|
-
}
|
|
861
|
-
const metadata = await this.fetchJson(source, { accept: 'application/json' });
|
|
862
|
-
this.npmCache = { checkedAt: this.now(), source, metadata };
|
|
863
|
-
return metadata;
|
|
864
|
-
}
|
|
865
|
-
|
|
866
|
-
async npmStatus(options = {}) {
|
|
867
|
-
const current = this.currentVersion();
|
|
868
|
-
const currentVersion = normalizeVersion(current.releaseVersion || current.packageVersion);
|
|
869
|
-
const metadata = await this.npmMetadata(options);
|
|
870
|
-
const target = await this.npmUpdateTarget();
|
|
871
|
-
const versions = npmVersionsFromMetadata(metadata, currentVersion);
|
|
872
|
-
const latestVersion = normalizeVersion(metadata && metadata['dist-tags'] && metadata['dist-tags'].latest)
|
|
873
|
-
|| versions[0]?.version
|
|
874
|
-
|| '';
|
|
875
|
-
const requestedVersion = normalizeVersion(options.assetName);
|
|
876
|
-
const selected = versions.find(version => version.version === requestedVersion)
|
|
877
|
-
|| versions.find(version => version.version === latestVersion)
|
|
878
|
-
|| versions[0]
|
|
879
|
-
|| null;
|
|
880
|
-
const blockedReason = target.proven ? '' : target.error;
|
|
881
|
-
const available = Boolean(selected && selected.available && target.proven);
|
|
882
|
-
return {
|
|
883
|
-
method: 'npm',
|
|
884
|
-
current,
|
|
885
|
-
latest: {
|
|
886
|
-
version: latestVersion,
|
|
887
|
-
tag: latestVersion ? `v${latestVersion}` : '',
|
|
888
|
-
name: latestVersion ? `${this.npmPackageName}@${latestVersion}` : '',
|
|
889
|
-
publishedAt: '',
|
|
890
|
-
assetName: latestVersion,
|
|
891
|
-
assetSize: 0,
|
|
892
|
-
blockedReason,
|
|
893
|
-
source: npmPackageMetadataUrl(this.npmRegistryUrl, this.npmPackageName),
|
|
894
|
-
},
|
|
895
|
-
selected: {
|
|
896
|
-
version: selected?.version || '',
|
|
897
|
-
assetName: selected?.assetName || '',
|
|
898
|
-
assetSize: selected?.assetSize || 0,
|
|
899
|
-
blockedReason: selected?.blockedReason || blockedReason,
|
|
900
|
-
},
|
|
901
|
-
versions,
|
|
902
|
-
runtime: this.runtime,
|
|
903
|
-
target,
|
|
904
|
-
available,
|
|
905
|
-
installable: Boolean(selected && target.proven),
|
|
906
|
-
checkedAt: new Date(this.now()).toISOString(),
|
|
907
|
-
state: this.currentInstallState(),
|
|
908
|
-
};
|
|
909
|
-
}
|
|
910
|
-
|
|
911
|
-
async npmUpdateTarget() {
|
|
912
|
-
const runningPackageRoot = String(this.npmPackageRoot || '').trim();
|
|
913
|
-
if (!path.isAbsolute(runningPackageRoot)) {
|
|
914
|
-
return {
|
|
915
|
-
proven: false,
|
|
916
|
-
error: 'npm update target could not be proven: the running package has no managed package-root provenance',
|
|
917
|
-
};
|
|
918
|
-
}
|
|
919
|
-
const npmCommand = process.env.FARMING_NPM_COMMAND || 'npm';
|
|
920
|
-
const npmPrefix = this.npmPrefix || npmPrefixForPackageRoot(runningPackageRoot, this.npmPackageName);
|
|
921
|
-
if (!npmPrefix) {
|
|
922
|
-
return {
|
|
923
|
-
proven: false,
|
|
924
|
-
error: 'npm update target could not be proven: the running package has no npm prefix',
|
|
925
|
-
};
|
|
926
|
-
}
|
|
927
|
-
try {
|
|
928
|
-
const root = await this.getNpmGlobalRoot(npmCommand, npmPrefix);
|
|
929
|
-
const targetPackageRoot = npmPackageRoot(root, this.npmPackageName);
|
|
930
|
-
if (normalizePathForCompare(runningPackageRoot) !== normalizePathForCompare(targetPackageRoot)) {
|
|
931
|
-
return {
|
|
932
|
-
proven: false,
|
|
933
|
-
error: `npm update would target a different installation: running ${runningPackageRoot}; npm ${targetPackageRoot}`,
|
|
934
|
-
};
|
|
935
|
-
}
|
|
936
|
-
return {
|
|
937
|
-
proven: true,
|
|
938
|
-
npmPrefix,
|
|
939
|
-
packageRoot: targetPackageRoot,
|
|
940
|
-
};
|
|
941
|
-
} catch (error) {
|
|
942
|
-
return {
|
|
943
|
-
proven: false,
|
|
944
|
-
error: `npm update target could not be inspected: ${error.message || String(error)}`,
|
|
945
|
-
};
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
unsupportedStatus() {
|
|
950
|
-
const current = this.currentVersion();
|
|
951
|
-
const reason = installMethodBlockedReason(this.installMethod);
|
|
952
|
-
return {
|
|
953
|
-
method: this.installMethod,
|
|
954
|
-
current,
|
|
955
|
-
latest: {
|
|
956
|
-
version: '',
|
|
957
|
-
tag: '',
|
|
958
|
-
name: '',
|
|
959
|
-
publishedAt: '',
|
|
960
|
-
assetName: '',
|
|
961
|
-
assetSize: 0,
|
|
962
|
-
blockedReason: reason,
|
|
963
|
-
source: '',
|
|
964
|
-
},
|
|
965
|
-
selected: { version: '', assetName: '', assetSize: 0, blockedReason: reason },
|
|
966
|
-
versions: [],
|
|
967
|
-
runtime: this.runtime,
|
|
968
|
-
available: false,
|
|
969
|
-
installable: false,
|
|
970
|
-
checkedAt: new Date(this.now()).toISOString(),
|
|
971
|
-
state: this.currentInstallState(),
|
|
972
|
-
};
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
async latestRelease(options = {}) {
|
|
976
|
-
const updateUrl = this.updateUrl();
|
|
977
|
-
if (!updateUrl) return null;
|
|
978
|
-
if (!options.force && this.latestCache && this.latestCache.source === updateUrl && this.now() - this.latestCache.checkedAt < CACHE_TTL_MS) {
|
|
979
|
-
return this.latestCache.release;
|
|
980
|
-
}
|
|
981
|
-
let release;
|
|
982
|
-
if (isGitHubReleasePage(updateUrl)) {
|
|
983
|
-
const pageBody = await this.fetchText(updateUrl, {
|
|
984
|
-
accept: 'text/html,application/xhtml+xml',
|
|
985
|
-
authToken: this.authToken,
|
|
986
|
-
});
|
|
987
|
-
const tag = githubReleaseTagFromPage(pageBody);
|
|
988
|
-
const expandedAssetsUrl = githubExpandedAssetsUrl(updateUrl, tag);
|
|
989
|
-
if (!expandedAssetsUrl) throw new Error('GitHub Release page did not expose a release tag');
|
|
990
|
-
release = releaseFromGitHubReleasePage(await this.fetchText(expandedAssetsUrl, {
|
|
991
|
-
accept: 'text/html,application/xhtml+xml',
|
|
992
|
-
authToken: this.authToken,
|
|
993
|
-
}), { pageUrl: expandedAssetsUrl });
|
|
994
|
-
} else if (isDirectoryUpdateSource(updateUrl)) {
|
|
995
|
-
release = releaseFromDirectoryListing(await this.fetchText(updateUrl, {
|
|
996
|
-
accept: 'text/html, text/plain',
|
|
997
|
-
authToken: this.authToken,
|
|
998
|
-
}), {
|
|
999
|
-
directoryUrl: updateUrl,
|
|
1000
|
-
assetBaseUrl: this.assetBaseUrl,
|
|
1001
|
-
});
|
|
1002
|
-
} else {
|
|
1003
|
-
const payload = await this.fetchJson(updateUrl, {
|
|
1004
|
-
accept: 'application/json',
|
|
1005
|
-
authToken: this.authToken,
|
|
1006
|
-
});
|
|
1007
|
-
release = Array.isArray(payload && payload.assets) && payload.assets.some(asset => asset && asset.browser_download_url)
|
|
1008
|
-
? releaseFromAssetListing(payload)
|
|
1009
|
-
: releaseFromManifest(payload, {
|
|
1010
|
-
manifestUrl: updateUrl,
|
|
1011
|
-
assetBaseUrl: this.assetBaseUrl,
|
|
1012
|
-
});
|
|
1013
|
-
}
|
|
1014
|
-
this.latestCache = {
|
|
1015
|
-
checkedAt: this.now(),
|
|
1016
|
-
source: updateUrl,
|
|
1017
|
-
release,
|
|
1018
|
-
};
|
|
1019
|
-
return release;
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1022
|
-
async latestManifest(release) {
|
|
1023
|
-
if (release && release.__directAssets) return null;
|
|
1024
|
-
if (release && release.__manifest) return release.__manifest;
|
|
1025
|
-
const asset = selectManifestAsset(release);
|
|
1026
|
-
if (!asset) return null;
|
|
1027
|
-
try {
|
|
1028
|
-
return await this.fetchJson(asset.browser_download_url, {
|
|
1029
|
-
authToken: this.authToken,
|
|
1030
|
-
});
|
|
1031
|
-
} catch {
|
|
1032
|
-
return null;
|
|
1033
|
-
}
|
|
1034
|
-
}
|
|
1035
|
-
|
|
1036
|
-
versionOptionsFromRelease(release, manifest = null) {
|
|
1037
|
-
const current = this.currentVersion();
|
|
1038
|
-
const updateUrl = this.updateUrl();
|
|
1039
|
-
const comparableCurrentVersion = normalizeVersion(current.releaseVersion || current.packageVersion);
|
|
1040
|
-
const latestVersion = releaseVersionFromRelease(release);
|
|
1041
|
-
const configured = Boolean(updateUrl);
|
|
1042
|
-
return selectableReleaseAssets(release, this.assetPattern, this.runtime, current.compatibilityProfile).map(asset => {
|
|
1043
|
-
const version = releaseAssetVersion(asset, latestVersion);
|
|
1044
|
-
const safety = configured
|
|
1045
|
-
? manifestAssetSafety(asset, manifest, { runtime: this.runtime })
|
|
1046
|
-
: { safe: false, reason: UPDATE_SOURCE_UNCONFIGURED_REASON };
|
|
1047
|
-
const newer = Boolean(version && compareVersions(version, comparableCurrentVersion) > 0);
|
|
1048
|
-
return {
|
|
1049
|
-
version,
|
|
1050
|
-
assetName: asset.name || '',
|
|
1051
|
-
assetSize: asset.size || 0,
|
|
1052
|
-
blockedReason: safety.reason,
|
|
1053
|
-
installable: Boolean(safety.safe),
|
|
1054
|
-
available: Boolean(newer && safety.safe),
|
|
1055
|
-
};
|
|
1056
|
-
});
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
|
-
statusFromRelease(release, manifest = null, options = {}) {
|
|
1060
|
-
const current = this.currentVersion();
|
|
1061
|
-
const updateUrl = this.updateUrl();
|
|
1062
|
-
const latestVersion = releaseVersionFromRelease(release);
|
|
1063
|
-
const comparableCurrentVersion = normalizeVersion(current.releaseVersion || current.packageVersion);
|
|
1064
|
-
const latestAsset = selectableReleaseAssets(release, this.assetPattern, this.runtime, current.compatibilityProfile)[0] || null;
|
|
1065
|
-
const asset = selectReleaseAssetByName(release, options.assetName, this.assetPattern, this.runtime, current.compatibilityProfile);
|
|
1066
|
-
const configured = Boolean(updateUrl);
|
|
1067
|
-
const safety = configured
|
|
1068
|
-
? manifestAssetSafety(asset, manifest, { runtime: this.runtime })
|
|
1069
|
-
: { safe: false, reason: UPDATE_SOURCE_UNCONFIGURED_REASON };
|
|
1070
|
-
const selectedVersion = releaseAssetVersion(asset, latestVersion);
|
|
1071
|
-
const newer = Boolean(asset && selectedVersion && compareVersions(selectedVersion, comparableCurrentVersion) > 0);
|
|
1072
|
-
const available = Boolean(newer && safety.safe);
|
|
1073
|
-
const versions = this.versionOptionsFromRelease(release, manifest);
|
|
1074
|
-
const noCompatibleBundleReason = this.runtime
|
|
1075
|
-
? `Update source has no compatible app bundle for ${this.runtime.platform}-${this.runtime.arch}`
|
|
1076
|
-
: 'Update source has no app bundle asset';
|
|
1077
|
-
|
|
1078
|
-
return {
|
|
1079
|
-
method: this.installMethod,
|
|
1080
|
-
current,
|
|
1081
|
-
latest: {
|
|
1082
|
-
version: latestVersion,
|
|
1083
|
-
tag: release && release.tag_name ? release.tag_name : '',
|
|
1084
|
-
name: release && release.name ? release.name : '',
|
|
1085
|
-
publishedAt: release && release.published_at ? release.published_at : '',
|
|
1086
|
-
assetName: latestAsset ? latestAsset.name : '',
|
|
1087
|
-
assetSize: latestAsset ? latestAsset.size || 0 : 0,
|
|
1088
|
-
blockedReason: versions[0] ? versions[0].blockedReason : (this.runtime ? noCompatibleBundleReason : (safety.reason || noCompatibleBundleReason)),
|
|
1089
|
-
source: updateUrl || '',
|
|
1090
|
-
},
|
|
1091
|
-
selected: {
|
|
1092
|
-
version: selectedVersion,
|
|
1093
|
-
assetName: asset ? asset.name : '',
|
|
1094
|
-
assetSize: asset ? asset.size || 0 : 0,
|
|
1095
|
-
blockedReason: safety.reason,
|
|
1096
|
-
},
|
|
1097
|
-
versions,
|
|
1098
|
-
runtime: this.runtime,
|
|
1099
|
-
available,
|
|
1100
|
-
installable: Boolean(asset && safety.safe),
|
|
1101
|
-
checkedAt: new Date(this.now()).toISOString(),
|
|
1102
|
-
state: this.currentInstallState(),
|
|
1103
|
-
};
|
|
1104
|
-
}
|
|
1105
|
-
|
|
1106
|
-
async check(options = {}) {
|
|
1107
|
-
if (this.installMethod === 'npm') return this.npmStatus(options);
|
|
1108
|
-
if (!installMethodAllowsBundleUpdate(this.installMethod)) return this.unsupportedStatus();
|
|
1109
|
-
if (!this.updateUrl()) return this.statusFromRelease(null, null, options);
|
|
1110
|
-
const release = await this.latestRelease(options);
|
|
1111
|
-
const manifest = await this.latestManifest(release);
|
|
1112
|
-
return this.statusFromRelease(release, manifest, options);
|
|
1113
|
-
}
|
|
1114
|
-
|
|
1115
|
-
installEnvironment() {
|
|
1116
|
-
const current = this.currentVersion();
|
|
1117
|
-
return {
|
|
1118
|
-
...process.env,
|
|
1119
|
-
FARMING_INSTALL_DIR: current.installDir,
|
|
1120
|
-
FARMING_PORT: process.env.FARMING_PORT || process.env.PORT || '6694',
|
|
1121
|
-
FARMING_BASE_PATH: process.env.FARMING_BASE_PATH || '/farming',
|
|
1122
|
-
FARMING_CONFIG_DIR: process.env.FARMING_CONFIG_DIR || this.configDir,
|
|
1123
|
-
...(process.env.FARMING_SERVER_HOME ? { FARMING_SERVER_HOME: process.env.FARMING_SERVER_HOME } : {}),
|
|
1124
|
-
...(process.env.FARMING_DISABLE_AUTH ? { FARMING_DISABLE_AUTH: process.env.FARMING_DISABLE_AUTH } : {}),
|
|
1125
|
-
};
|
|
1126
|
-
}
|
|
1127
|
-
|
|
1128
|
-
async startInstall(options = {}) {
|
|
1129
|
-
if (this.installStartPromise) return this.installStartPromise;
|
|
1130
|
-
const startPromise = this.startInstallUnreserved(options);
|
|
1131
|
-
this.installStartPromise = startPromise;
|
|
1132
|
-
try {
|
|
1133
|
-
return await startPromise;
|
|
1134
|
-
} finally {
|
|
1135
|
-
if (this.installStartPromise === startPromise) this.installStartPromise = null;
|
|
1136
|
-
}
|
|
1137
|
-
}
|
|
1138
|
-
|
|
1139
|
-
async startInstallUnreserved(options = {}) {
|
|
1140
|
-
const currentState = this.currentInstallState();
|
|
1141
|
-
if (['downloading', 'extracting', 'installing', 'restarting', 'rolling-back'].includes(currentState.phase)) {
|
|
1142
|
-
return currentState;
|
|
1143
|
-
}
|
|
1144
|
-
if (currentState.phase === 'ready-to-restart') return currentState;
|
|
1145
|
-
|
|
1146
|
-
if (this.installMethod === 'npm') return this.startNpmInstall(options);
|
|
1147
|
-
if (!installMethodAllowsBundleUpdate(this.installMethod)) {
|
|
1148
|
-
throw new Error(installMethodBlockedReason(this.installMethod));
|
|
1149
|
-
}
|
|
1150
|
-
|
|
1151
|
-
const release = await this.latestRelease({ force: true });
|
|
1152
|
-
const manifest = await this.latestManifest(release);
|
|
1153
|
-
const status = this.statusFromRelease(release, manifest, options);
|
|
1154
|
-
if (!status.available) {
|
|
1155
|
-
const error = status.installable
|
|
1156
|
-
? 'Farming is already up to date'
|
|
1157
|
-
: (status.latest.blockedReason || 'Update source has no app bundle asset');
|
|
1158
|
-
this.installState = {
|
|
1159
|
-
phase: 'failed',
|
|
1160
|
-
error,
|
|
1161
|
-
checkedAt: status.checkedAt,
|
|
1162
|
-
};
|
|
1163
|
-
return this.installState;
|
|
1164
|
-
}
|
|
1165
|
-
|
|
1166
|
-
const asset = selectReleaseAssetByName(
|
|
1167
|
-
release,
|
|
1168
|
-
options.assetName,
|
|
1169
|
-
this.assetPattern,
|
|
1170
|
-
this.runtime,
|
|
1171
|
-
this.currentVersion().compatibilityProfile,
|
|
1172
|
-
);
|
|
1173
|
-
this.persistInstallState({
|
|
1174
|
-
phase: 'downloading',
|
|
1175
|
-
method: this.installMethod,
|
|
1176
|
-
version: status.selected.version,
|
|
1177
|
-
previousVersion: status.current.releaseVersion || status.current.packageVersion,
|
|
1178
|
-
assetName: status.selected.assetName,
|
|
1179
|
-
receivedBytes: 0,
|
|
1180
|
-
totalBytes: Number(status.selected.assetSize) || 0,
|
|
1181
|
-
startedAt: new Date(this.now()).toISOString(),
|
|
1182
|
-
logPath: path.join(this.configDir, 'farming-update.log'),
|
|
1183
|
-
});
|
|
1184
|
-
void this.runInstall(asset).catch(error => {
|
|
1185
|
-
this.persistInstallState({
|
|
1186
|
-
...this.installState,
|
|
1187
|
-
phase: 'failed',
|
|
1188
|
-
error: error.message || String(error),
|
|
1189
|
-
completedAt: new Date(this.now()).toISOString(),
|
|
1190
|
-
});
|
|
1191
|
-
});
|
|
1192
|
-
return this.installState;
|
|
1193
|
-
}
|
|
1194
|
-
|
|
1195
|
-
async startNpmInstall(options = {}) {
|
|
1196
|
-
const status = await this.npmStatus({ force: true, assetName: options.assetName });
|
|
1197
|
-
if (!status.available) {
|
|
1198
|
-
return this.persistInstallState({
|
|
1199
|
-
method: 'npm',
|
|
1200
|
-
phase: status.installable ? 'succeeded' : 'failed',
|
|
1201
|
-
version: status.selected.version,
|
|
1202
|
-
error: status.installable ? '' : (status.selected.blockedReason || 'No installable npm update is available'),
|
|
1203
|
-
completedAt: new Date(this.now()).toISOString(),
|
|
1204
|
-
});
|
|
1205
|
-
}
|
|
1206
|
-
|
|
1207
|
-
const startedAt = new Date(this.now()).toISOString();
|
|
1208
|
-
fs.mkdirSync(this.updateStagingDir, { recursive: true });
|
|
1209
|
-
const stagingPrefix = fs.mkdtempSync(path.join(this.updateStagingDir, `npm-${status.selected.version}.`));
|
|
1210
|
-
const stagingPackageRoot = npmPackageRoot(
|
|
1211
|
-
path.join(stagingPrefix, 'lib', 'node_modules'),
|
|
1212
|
-
this.npmPackageName,
|
|
1213
|
-
);
|
|
1214
|
-
const state = this.persistInstallState({
|
|
1215
|
-
method: 'npm',
|
|
1216
|
-
phase: 'installing',
|
|
1217
|
-
version: status.selected.version,
|
|
1218
|
-
previousVersion: status.current.releaseVersion || status.current.packageVersion,
|
|
1219
|
-
packageName: this.npmPackageName,
|
|
1220
|
-
stagingPrefix,
|
|
1221
|
-
stagingPackageRoot,
|
|
1222
|
-
startedAt,
|
|
1223
|
-
logPath: this.updateLogFile,
|
|
1224
|
-
});
|
|
1225
|
-
const helperPath = path.join(__dirname, 'npm-update-helper.js');
|
|
1226
|
-
const nodePath = process.env.FARMING_NODE_BIN || process.execPath;
|
|
1227
|
-
const payload = {
|
|
1228
|
-
action: 'prepare',
|
|
1229
|
-
packageName: this.npmPackageName,
|
|
1230
|
-
targetVersion: status.selected.version,
|
|
1231
|
-
previousVersion: status.current.releaseVersion || status.current.packageVersion,
|
|
1232
|
-
startedAt,
|
|
1233
|
-
stateFile: this.updateStateFile,
|
|
1234
|
-
logPath: this.updateLogFile,
|
|
1235
|
-
cliPath: path.join(this.rootDir, 'bin', 'farming'),
|
|
1236
|
-
packageRoot: status.target.packageRoot,
|
|
1237
|
-
nodePath,
|
|
1238
|
-
npmCommand: process.env.FARMING_NPM_COMMAND || 'npm',
|
|
1239
|
-
npmPrefix: status.target.npmPrefix,
|
|
1240
|
-
stagingPrefix,
|
|
1241
|
-
stagingPackageRoot,
|
|
1242
|
-
npmFallbackRegistryUrl: this.npmRegistryUrl,
|
|
1243
|
-
serverPid: process.pid,
|
|
1244
|
-
configDir: this.configDir,
|
|
1245
|
-
port: process.env.FARMING_PORT || process.env.PORT || '6694',
|
|
1246
|
-
basePath: process.env.FARMING_BASE_PATH || '/farming',
|
|
1247
|
-
serverHome: process.env.FARMING_SERVER_HOME || '',
|
|
1248
|
-
disableAuth: /^(1|true|yes|on)$/i.test(String(process.env.FARMING_DISABLE_AUTH || '')),
|
|
1249
|
-
};
|
|
1250
|
-
const helperInvocation = nodeScriptInvocation(nodePath, helperPath);
|
|
1251
|
-
const spawnOptions = {
|
|
1252
|
-
cwd: this.configDir,
|
|
1253
|
-
detached: true,
|
|
1254
|
-
stdio: 'ignore',
|
|
1255
|
-
env: {
|
|
1256
|
-
...process.env,
|
|
1257
|
-
FARMING_NPM_UPDATE_PAYLOAD: JSON.stringify(payload),
|
|
1258
|
-
},
|
|
1259
|
-
};
|
|
1260
|
-
let child;
|
|
1261
|
-
try {
|
|
1262
|
-
child = this.spawn(helperInvocation.command, helperInvocation.args, spawnOptions);
|
|
1263
|
-
} catch (error) {
|
|
1264
|
-
fs.rmSync(stagingPrefix, { recursive: true, force: true });
|
|
1265
|
-
this.persistInstallState({
|
|
1266
|
-
...state,
|
|
1267
|
-
phase: 'failed',
|
|
1268
|
-
error: error.message || String(error),
|
|
1269
|
-
completedAt: new Date(this.now()).toISOString(),
|
|
1270
|
-
});
|
|
1271
|
-
throw error;
|
|
1272
|
-
}
|
|
1273
|
-
if (child && typeof child.once === 'function') {
|
|
1274
|
-
child.once('error', (error) => {
|
|
1275
|
-
fs.rmSync(stagingPrefix, { recursive: true, force: true });
|
|
1276
|
-
this.persistInstallState({
|
|
1277
|
-
...state,
|
|
1278
|
-
phase: 'failed',
|
|
1279
|
-
error: error.message || String(error),
|
|
1280
|
-
completedAt: new Date(this.now()).toISOString(),
|
|
1281
|
-
});
|
|
1282
|
-
});
|
|
1283
|
-
}
|
|
1284
|
-
if (child && typeof child.unref === 'function') child.unref();
|
|
1285
|
-
return state;
|
|
1286
|
-
}
|
|
1287
|
-
|
|
1288
|
-
async applyPreparedUpdate() {
|
|
1289
|
-
if (this.installStartPromise) return this.installStartPromise;
|
|
1290
|
-
const applyPromise = this.applyPreparedUpdateUnreserved();
|
|
1291
|
-
this.installStartPromise = applyPromise;
|
|
1292
|
-
try {
|
|
1293
|
-
return await applyPromise;
|
|
1294
|
-
} finally {
|
|
1295
|
-
if (this.installStartPromise === applyPromise) this.installStartPromise = null;
|
|
1296
|
-
}
|
|
1297
|
-
}
|
|
1298
|
-
|
|
1299
|
-
async applyPreparedUpdateUnreserved() {
|
|
1300
|
-
const prepared = this.currentInstallState();
|
|
1301
|
-
if (prepared.phase !== 'ready-to-restart') {
|
|
1302
|
-
throw new Error('No prepared Farming update is ready to restart');
|
|
1303
|
-
}
|
|
1304
|
-
const current = this.currentVersion();
|
|
1305
|
-
const currentVersion = normalizeVersion(current.releaseVersion || current.packageVersion);
|
|
1306
|
-
if (normalizeVersion(prepared.previousVersion) !== currentVersion) {
|
|
1307
|
-
const error = 'Prepared update no longer matches the running Farming version';
|
|
1308
|
-
this.persistInstallState({ ...prepared, phase: 'failed', error, completedAt: new Date(this.now()).toISOString() });
|
|
1309
|
-
throw new Error(error);
|
|
1310
|
-
}
|
|
1311
|
-
|
|
1312
|
-
const nodePath = process.env.FARMING_NODE_BIN || process.execPath;
|
|
1313
|
-
const serverProcessIdentity = await readServerProcessIdentity(process.pid);
|
|
1314
|
-
if (!serverProcessIdentity) {
|
|
1315
|
-
throw new Error('Running Farming server process identity could not be verified');
|
|
1316
|
-
}
|
|
1317
|
-
let helperPath;
|
|
1318
|
-
let payload;
|
|
1319
|
-
let env;
|
|
1320
|
-
if (this.installMethod === 'npm') {
|
|
1321
|
-
const target = await this.npmUpdateTarget();
|
|
1322
|
-
if (!target.proven) throw new Error(target.error);
|
|
1323
|
-
if (!path.isAbsolute(String(prepared.stagingPrefix || '')) || !path.isAbsolute(String(prepared.stagingPackageRoot || ''))) {
|
|
1324
|
-
throw new Error('Prepared npm update is missing its staging identity');
|
|
1325
|
-
}
|
|
1326
|
-
const stagingPrefix = normalizePathForCompare(prepared.stagingPrefix);
|
|
1327
|
-
if (!pathIsInside(normalizePathForCompare(this.updateStagingDir), stagingPrefix)) {
|
|
1328
|
-
throw new Error('Prepared npm update is outside the Farming staging directory');
|
|
1329
|
-
}
|
|
1330
|
-
if (path.resolve(prepared.stagingPackageRoot) !== path.resolve(npmPackageRoot(
|
|
1331
|
-
path.join(prepared.stagingPrefix, 'lib', 'node_modules'),
|
|
1332
|
-
this.npmPackageName,
|
|
1333
|
-
))) {
|
|
1334
|
-
throw new Error('Prepared npm update has an invalid package root');
|
|
1335
|
-
}
|
|
1336
|
-
const stagingPackageRoot = normalizePathForCompare(prepared.stagingPackageRoot);
|
|
1337
|
-
const stagedMetadata = readJsonFile(path.join(stagingPackageRoot, 'package.json')) || {};
|
|
1338
|
-
if (normalizeVersion(stagedMetadata.version) !== normalizeVersion(prepared.version)) {
|
|
1339
|
-
throw new Error('Prepared npm update is no longer available; prepare it again');
|
|
1340
|
-
}
|
|
1341
|
-
helperPath = path.join(__dirname, 'npm-update-helper.js');
|
|
1342
|
-
payload = {
|
|
1343
|
-
action: 'apply',
|
|
1344
|
-
packageName: this.npmPackageName,
|
|
1345
|
-
targetVersion: prepared.version,
|
|
1346
|
-
previousVersion: prepared.previousVersion,
|
|
1347
|
-
startedAt: prepared.startedAt,
|
|
1348
|
-
preparedAt: prepared.preparedAt,
|
|
1349
|
-
stateFile: this.updateStateFile,
|
|
1350
|
-
logPath: prepared.logPath || this.updateLogFile,
|
|
1351
|
-
cliPath: path.join(this.rootDir, 'bin', 'farming'),
|
|
1352
|
-
packageRoot: target.packageRoot,
|
|
1353
|
-
nodePath,
|
|
1354
|
-
npmCommand: process.env.FARMING_NPM_COMMAND || 'npm',
|
|
1355
|
-
npmPrefix: target.npmPrefix,
|
|
1356
|
-
npmFallbackRegistryUrl: this.npmRegistryUrl,
|
|
1357
|
-
stagingPrefix,
|
|
1358
|
-
stagingPackageRoot,
|
|
1359
|
-
serverPid: process.pid,
|
|
1360
|
-
serverProcessIdentity,
|
|
1361
|
-
configDir: this.configDir,
|
|
1362
|
-
port: process.env.FARMING_PORT || process.env.PORT || '6694',
|
|
1363
|
-
basePath: process.env.FARMING_BASE_PATH || '/farming',
|
|
1364
|
-
serverHome: process.env.FARMING_SERVER_HOME || '',
|
|
1365
|
-
disableAuth: /^(1|true|yes|on)$/i.test(String(process.env.FARMING_DISABLE_AUTH || '')),
|
|
1366
|
-
};
|
|
1367
|
-
env = { ...process.env, FARMING_NPM_UPDATE_PAYLOAD: JSON.stringify(payload) };
|
|
1368
|
-
} else {
|
|
1369
|
-
if (!installMethodAllowsBundleUpdate(this.installMethod)) {
|
|
1370
|
-
throw new Error(installMethodBlockedReason(this.installMethod));
|
|
1371
|
-
}
|
|
1372
|
-
if (!path.isAbsolute(String(prepared.releaseDir || '')) || !path.isAbsolute(String(prepared.installer || '')) || !fs.existsSync(prepared.installer)) {
|
|
1373
|
-
throw new Error('Prepared bundle update is no longer available; prepare it again');
|
|
1374
|
-
}
|
|
1375
|
-
const releaseDir = normalizePathForCompare(prepared.releaseDir);
|
|
1376
|
-
const installer = normalizePathForCompare(prepared.installer);
|
|
1377
|
-
if (!pathIsInside(normalizePathForCompare(os.tmpdir()), releaseDir)
|
|
1378
|
-
|| !path.basename(path.dirname(releaseDir)).startsWith('farming-update.')
|
|
1379
|
-
|| installer !== normalizePathForCompare(path.join(releaseDir, 'scripts', 'install-release.sh'))) {
|
|
1380
|
-
throw new Error('Prepared bundle update has an invalid staging identity');
|
|
1381
|
-
}
|
|
1382
|
-
const releaseMetadata = readJsonFile(path.join(releaseDir, 'RELEASE.json')) || {};
|
|
1383
|
-
const preparedVersion = normalizeVersion(releaseMetadata.releaseVersion || releaseMetadata.packageVersion);
|
|
1384
|
-
if (preparedVersion && preparedVersion !== normalizeVersion(prepared.version)) {
|
|
1385
|
-
throw new Error('Prepared bundle version does not match the selected update');
|
|
1386
|
-
}
|
|
1387
|
-
if (!assetMatchesRuntime(releaseMetadata, this.runtime)) {
|
|
1388
|
-
throw new Error(`Prepared bundle is not compatible with ${this.runtime.platform}-${this.runtime.arch}`);
|
|
1389
|
-
}
|
|
1390
|
-
helperPath = path.join(__dirname, 'bundle-update-helper.js');
|
|
1391
|
-
payload = {
|
|
1392
|
-
method: this.installMethod,
|
|
1393
|
-
targetMethod: prepared.targetMethod,
|
|
1394
|
-
version: prepared.version,
|
|
1395
|
-
previousVersion: prepared.previousVersion,
|
|
1396
|
-
startedAt: prepared.startedAt,
|
|
1397
|
-
preparedAt: prepared.preparedAt,
|
|
1398
|
-
stateFile: this.updateStateFile,
|
|
1399
|
-
logPath: prepared.logPath || this.updateLogFile,
|
|
1400
|
-
releaseDir,
|
|
1401
|
-
installer,
|
|
1402
|
-
};
|
|
1403
|
-
env = { ...this.installEnvironment(), FARMING_BUNDLE_UPDATE_PAYLOAD: JSON.stringify(payload) };
|
|
1404
|
-
}
|
|
1405
|
-
|
|
1406
|
-
const state = this.persistInstallState({ ...prepared, phase: 'restarting', error: '' });
|
|
1407
|
-
const helperInvocation = nodeScriptInvocation(nodePath, helperPath);
|
|
1408
|
-
const spawnOptions = {
|
|
1409
|
-
cwd: this.configDir,
|
|
1410
|
-
detached: true,
|
|
1411
|
-
stdio: 'ignore',
|
|
1412
|
-
env,
|
|
1413
|
-
};
|
|
1414
|
-
const restorePreparedState = (error) => this.persistInstallState({
|
|
1415
|
-
...prepared,
|
|
1416
|
-
phase: 'ready-to-restart',
|
|
1417
|
-
error: error.message || String(error),
|
|
1418
|
-
});
|
|
1419
|
-
let child;
|
|
1420
|
-
try {
|
|
1421
|
-
child = this.spawn(helperInvocation.command, helperInvocation.args, spawnOptions);
|
|
1422
|
-
} catch (error) {
|
|
1423
|
-
restorePreparedState(error);
|
|
1424
|
-
throw error;
|
|
1425
|
-
}
|
|
1426
|
-
if (child && typeof child.once === 'function') child.once('error', restorePreparedState);
|
|
1427
|
-
if (child && typeof child.unref === 'function') child.unref();
|
|
1428
|
-
return state;
|
|
1429
|
-
}
|
|
1430
|
-
|
|
1431
|
-
async runInstall(asset) {
|
|
1432
|
-
if (!asset || !asset.browser_download_url) {
|
|
1433
|
-
throw new Error('release asset is missing a download URL');
|
|
1434
|
-
}
|
|
1435
|
-
|
|
1436
|
-
fs.mkdirSync(this.configDir, { recursive: true });
|
|
1437
|
-
const tempRoot = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'farming-update.'));
|
|
1438
|
-
const archivePath = path.join(tempRoot, asset.name || 'farming-update.tar.gz');
|
|
1439
|
-
let lastProgressPercent = -1;
|
|
1440
|
-
let lastProgressBytes = 0;
|
|
1441
|
-
await this.downloadFile(asset.browser_download_url, archivePath, {
|
|
1442
|
-
authToken: this.authToken,
|
|
1443
|
-
totalBytes: Number(asset.size) || Number(this.installState.totalBytes) || 0,
|
|
1444
|
-
onProgress: ({ receivedBytes, totalBytes }) => {
|
|
1445
|
-
const safeReceivedBytes = Math.max(0, Number(receivedBytes) || 0);
|
|
1446
|
-
const safeTotalBytes = Math.max(0, Number(totalBytes) || 0);
|
|
1447
|
-
if (safeTotalBytes > 0) {
|
|
1448
|
-
const percent = Math.min(100, Math.floor((safeReceivedBytes / safeTotalBytes) * 100));
|
|
1449
|
-
if (percent === lastProgressPercent && safeReceivedBytes < safeTotalBytes) return;
|
|
1450
|
-
lastProgressPercent = percent;
|
|
1451
|
-
} else if (safeReceivedBytes - lastProgressBytes < 1024 * 1024) {
|
|
1452
|
-
return;
|
|
1453
|
-
}
|
|
1454
|
-
lastProgressBytes = safeReceivedBytes;
|
|
1455
|
-
this.persistInstallState({
|
|
1456
|
-
...this.installState,
|
|
1457
|
-
receivedBytes: safeReceivedBytes,
|
|
1458
|
-
totalBytes: safeTotalBytes,
|
|
1459
|
-
});
|
|
1460
|
-
},
|
|
1461
|
-
});
|
|
1462
|
-
let expectedSha256 = normalizeSha256(asset.sha256);
|
|
1463
|
-
const checksumUrl = asset.checksum_url || asset.checksumUrl || '';
|
|
1464
|
-
if (!expectedSha256 && checksumUrl) {
|
|
1465
|
-
const checksumText = await this.fetchText(checksumUrl, {
|
|
1466
|
-
accept: 'text/plain',
|
|
1467
|
-
authToken: this.authToken,
|
|
1468
|
-
});
|
|
1469
|
-
expectedSha256 = sha256FromChecksumText(checksumText, asset.name);
|
|
1470
|
-
}
|
|
1471
|
-
if (!expectedSha256) {
|
|
1472
|
-
throw new Error(`release asset is missing a valid SHA-256 checksum: ${asset.name || 'asset'}`);
|
|
1473
|
-
}
|
|
1474
|
-
const actualSha256 = sha256File(archivePath);
|
|
1475
|
-
if (actualSha256 !== expectedSha256) {
|
|
1476
|
-
throw new Error(`downloaded release checksum mismatch for ${asset.name || 'asset'}`);
|
|
1477
|
-
}
|
|
1478
|
-
|
|
1479
|
-
validateArchiveEntries(await this.listArchiveEntries(archivePath));
|
|
1480
|
-
|
|
1481
|
-
this.persistInstallState({ ...this.installState, phase: 'extracting' });
|
|
1482
|
-
await new Promise((resolve, reject) => {
|
|
1483
|
-
this.execFile('tar', ['-xzf', archivePath, '-C', tempRoot], (error) => {
|
|
1484
|
-
if (error) reject(error);
|
|
1485
|
-
else resolve();
|
|
1486
|
-
});
|
|
1487
|
-
});
|
|
1488
|
-
|
|
1489
|
-
const releaseDir = findReleaseDirectory(tempRoot);
|
|
1490
|
-
validateExtractedSymlinks(releaseDir);
|
|
1491
|
-
const releaseMetadata = readJsonFile(path.join(releaseDir, 'RELEASE.json')) || {};
|
|
1492
|
-
if (!assetMatchesRuntime(releaseMetadata, this.runtime)) {
|
|
1493
|
-
throw new Error(`downloaded release is not compatible with ${this.runtime.platform}-${this.runtime.arch}`);
|
|
1494
|
-
}
|
|
1495
|
-
const installer = path.join(releaseDir, 'scripts', 'install-release.sh');
|
|
1496
|
-
if (!fs.existsSync(installer)) {
|
|
1497
|
-
throw new Error('downloaded release is missing scripts/install-release.sh');
|
|
1498
|
-
}
|
|
1499
|
-
const logPath = this.installState.logPath || path.join(this.configDir, 'farming-update.log');
|
|
1500
|
-
const targetMethod = String(releaseMetadata.updateMethod || releaseMetadata.type || this.installMethod);
|
|
1501
|
-
this.persistInstallState({
|
|
1502
|
-
...this.installState,
|
|
1503
|
-
phase: 'preparing-runtimes',
|
|
1504
|
-
targetMethod,
|
|
1505
|
-
releaseDir,
|
|
1506
|
-
installer,
|
|
1507
|
-
logPath,
|
|
1508
|
-
});
|
|
1509
|
-
await this.prepareRuntimeDependencies(releaseDir);
|
|
1510
|
-
const runtimePreparedAt = new Date(this.now()).toISOString();
|
|
1511
|
-
this.persistInstallState({
|
|
1512
|
-
...this.installState,
|
|
1513
|
-
phase: 'ready-to-restart',
|
|
1514
|
-
targetMethod,
|
|
1515
|
-
releaseDir,
|
|
1516
|
-
installer,
|
|
1517
|
-
logPath,
|
|
1518
|
-
preparedAt: runtimePreparedAt,
|
|
1519
|
-
runtimePreparedAt,
|
|
1520
|
-
});
|
|
1521
|
-
}
|
|
1522
|
-
}
|
|
1523
|
-
|
|
1524
|
-
module.exports = {
|
|
1525
|
-
FarmingUpdateService,
|
|
1526
|
-
compareVersions,
|
|
1527
|
-
detectInstallMethod,
|
|
1528
|
-
installMethodAllowsBundleUpdate,
|
|
1529
|
-
normalizeVersion,
|
|
1530
|
-
npmPackageMetadataUrl,
|
|
1531
|
-
npmPrefixForPackageRoot,
|
|
1532
|
-
npmPackageRoot,
|
|
1533
|
-
npmVersionsFromMetadata,
|
|
1534
|
-
readNpmGlobalRoot,
|
|
1535
|
-
releaseInstallDir,
|
|
1536
|
-
manifestAssetSafety,
|
|
1537
|
-
normalizeSha256,
|
|
1538
|
-
validateArchiveEntries,
|
|
1539
|
-
releaseFromManifest,
|
|
1540
|
-
releaseFromDirectoryListing,
|
|
1541
|
-
releaseFromGitHubReleasePage,
|
|
1542
|
-
releaseVersionFromManifest,
|
|
1543
|
-
selectManifestAsset,
|
|
1544
|
-
selectReleaseAsset,
|
|
1545
|
-
};
|