@countinghouse/ch-local 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +361 -2
- package/bin/ch-local.js +472 -0
- package/clients/claude-code/.claude-plugin/plugin.json +6 -0
- package/clients/claude-code/.mcp.json +11 -0
- package/clients/claude-code/bin/launch.js +235 -0
- package/clients/claude-code/bin/win-acl.js +420 -0
- package/clients/claude-code/skills/ci-failure-triage/SKILL.md +21 -0
- package/clients/claude-code/skills/countinghouse-module/SKILL.md +177 -0
- package/clients/claude-code/skills/countinghouse-setup/SKILL.md +74 -0
- package/lib/allowlist.js +65 -0
- package/lib/aside.js +16 -0
- package/lib/atomic.js +45 -0
- package/lib/auto-apply.js +245 -0
- package/lib/auto-upgrade.js +98 -0
- package/lib/availability.js +307 -0
- package/lib/ceiling.js +280 -0
- package/lib/clean-text.js +20 -0
- package/lib/cli-change.js +38 -0
- package/lib/client-conditions-fixtures.js +143 -0
- package/lib/client-conditions.js +656 -0
- package/lib/clients.js +179 -0
- package/lib/command-line.js +202 -0
- package/lib/conditions-command.js +116 -0
- package/lib/control.js +134 -0
- package/lib/credential-store.js +414 -0
- package/lib/credentials-command.js +344 -0
- package/lib/daemon-requests.js +137 -0
- package/lib/daemon.js +888 -0
- package/lib/describe-module.js +137 -0
- package/lib/description-check.js +175 -0
- package/lib/failed-json.js +43 -0
- package/lib/gc.js +274 -0
- package/lib/github-token.js +57 -0
- package/lib/handoff-io.js +73 -0
- package/lib/held-back.js +116 -0
- package/lib/hidden-input.js +64 -0
- package/lib/history.js +49 -0
- package/lib/home.js +372 -0
- package/lib/in-place.js +1036 -0
- package/lib/install-plan.js +142 -0
- package/lib/install.js +846 -0
- package/lib/installed-description.js +153 -0
- package/lib/integrity.js +7 -0
- package/lib/lock.js +456 -0
- package/lib/lockfile-rules.js +98 -0
- package/lib/machine.js +20 -0
- package/lib/module-credentials.js +403 -0
- package/lib/module-record.js +298 -0
- package/lib/module-roles.js +44 -0
- package/lib/module-seams.js +26 -0
- package/lib/module-store.js +202 -0
- package/lib/module-values.js +334 -0
- package/lib/names.js +31 -0
- package/lib/next-steps.js +8 -0
- package/lib/node-check.js +56 -0
- package/lib/npm-fetch.js +123 -0
- package/lib/npm-release.js +99 -0
- package/lib/npm-upgrade.js +146 -0
- package/lib/npm.js +41 -0
- package/lib/outside-edits.js +162 -0
- package/lib/own-applied.js +175 -0
- package/lib/own-command.js +380 -0
- package/lib/own-file.js +120 -0
- package/lib/own-record.js +96 -0
- package/lib/own-tree.js +336 -0
- package/lib/pack-table.js +290 -0
- package/lib/packs-command.js +570 -0
- package/lib/packs.js +219 -0
- package/lib/pins.js +64 -0
- package/lib/pipe-probe.js +82 -0
- package/lib/plain-read.js +63 -0
- package/lib/private-file.js +90 -0
- package/lib/private-write.js +33 -0
- package/lib/provenance.js +234 -0
- package/lib/record.js +82 -0
- package/lib/registry.js +22 -0
- package/lib/release-pins.js +350 -0
- package/lib/release-pins.json +4225 -0
- package/lib/release-tags.js +12 -0
- package/lib/release.js +36 -0
- package/lib/restart-command.js +161 -0
- package/lib/rollback.js +227 -0
- package/lib/run-liveness.js +15 -0
- package/lib/runtime-log.js +287 -0
- package/lib/sandbox-support.js +17 -0
- package/lib/semver-order.js +40 -0
- package/lib/session-socket.js +69 -0
- package/lib/session-table.js +238 -0
- package/lib/session.js +281 -0
- package/lib/settings-command.js +82 -0
- package/lib/settings.js +564 -0
- package/lib/shim-binary.js +152 -0
- package/lib/shim-config.js +159 -0
- package/lib/shim-install.js +365 -0
- package/lib/sigstore/README.md +44 -0
- package/lib/sigstore/npm-keys.json +18 -0
- package/lib/sigstore/trusted-root.json +126 -0
- package/lib/snippets.js +76 -0
- package/lib/start.js +721 -0
- package/lib/store-files.js +48 -0
- package/lib/store-paths.js +33 -0
- package/lib/swap-preload.js +38 -0
- package/lib/tar.js +220 -0
- package/lib/uninstall.js +314 -0
- package/lib/unpack.js +41 -0
- package/lib/upgrade-stamp.js +63 -0
- package/lib/upgrade.js +281 -0
- package/lib/watch.js +40 -0
- package/lib/win-acl.js +420 -0
- package/node_modules/@sigstore/bundle/LICENSE +202 -0
- package/node_modules/@sigstore/bundle/README.md +19 -0
- package/node_modules/@sigstore/bundle/dist/build.d.ts +18 -0
- package/node_modules/@sigstore/bundle/dist/build.js +100 -0
- package/node_modules/@sigstore/bundle/dist/bundle.d.ts +74 -0
- package/node_modules/@sigstore/bundle/dist/bundle.js +24 -0
- package/node_modules/@sigstore/bundle/dist/error.d.ts +4 -0
- package/node_modules/@sigstore/bundle/dist/error.js +25 -0
- package/node_modules/@sigstore/bundle/dist/index.d.ts +8 -0
- package/node_modules/@sigstore/bundle/dist/index.js +43 -0
- package/node_modules/@sigstore/bundle/dist/serialized.d.ts +74 -0
- package/node_modules/@sigstore/bundle/dist/serialized.js +49 -0
- package/node_modules/@sigstore/bundle/dist/utility.d.ts +14 -0
- package/node_modules/@sigstore/bundle/dist/utility.js +2 -0
- package/node_modules/@sigstore/bundle/dist/validate.d.ts +7 -0
- package/node_modules/@sigstore/bundle/dist/validate.js +199 -0
- package/node_modules/@sigstore/bundle/package.json +35 -0
- package/node_modules/@sigstore/core/LICENSE +202 -0
- package/node_modules/@sigstore/core/README.md +10 -0
- package/node_modules/@sigstore/core/dist/asn1/error.d.ts +4 -0
- package/node_modules/@sigstore/core/dist/asn1/error.js +24 -0
- package/node_modules/@sigstore/core/dist/asn1/index.d.ts +1 -0
- package/node_modules/@sigstore/core/dist/asn1/index.js +20 -0
- package/node_modules/@sigstore/core/dist/asn1/length.d.ts +3 -0
- package/node_modules/@sigstore/core/dist/asn1/length.js +62 -0
- package/node_modules/@sigstore/core/dist/asn1/obj.d.ts +14 -0
- package/node_modules/@sigstore/core/dist/asn1/obj.js +155 -0
- package/node_modules/@sigstore/core/dist/asn1/parse.d.ts +6 -0
- package/node_modules/@sigstore/core/dist/asn1/parse.js +124 -0
- package/node_modules/@sigstore/core/dist/asn1/tag.d.ts +16 -0
- package/node_modules/@sigstore/core/dist/asn1/tag.js +89 -0
- package/node_modules/@sigstore/core/dist/crypto.d.ts +6 -0
- package/node_modules/@sigstore/core/dist/crypto.js +69 -0
- package/node_modules/@sigstore/core/dist/dsse.d.ts +1 -0
- package/node_modules/@sigstore/core/dist/dsse.js +29 -0
- package/node_modules/@sigstore/core/dist/encoding.d.ts +2 -0
- package/node_modules/@sigstore/core/dist/encoding.js +27 -0
- package/node_modules/@sigstore/core/dist/index.d.ts +9 -0
- package/node_modules/@sigstore/core/dist/index.js +66 -0
- package/node_modules/@sigstore/core/dist/json.d.ts +1 -0
- package/node_modules/@sigstore/core/dist/json.js +60 -0
- package/node_modules/@sigstore/core/dist/oid.d.ts +3 -0
- package/node_modules/@sigstore/core/dist/oid.js +20 -0
- package/node_modules/@sigstore/core/dist/pem.d.ts +2 -0
- package/node_modules/@sigstore/core/dist/pem.js +43 -0
- package/node_modules/@sigstore/core/dist/rfc3161/error.d.ts +2 -0
- package/node_modules/@sigstore/core/dist/rfc3161/error.js +21 -0
- package/node_modules/@sigstore/core/dist/rfc3161/index.d.ts +1 -0
- package/node_modules/@sigstore/core/dist/rfc3161/index.js +20 -0
- package/node_modules/@sigstore/core/dist/rfc3161/timestamp.d.ts +36 -0
- package/node_modules/@sigstore/core/dist/rfc3161/timestamp.js +212 -0
- package/node_modules/@sigstore/core/dist/rfc3161/tstinfo.d.ts +12 -0
- package/node_modules/@sigstore/core/dist/rfc3161/tstinfo.js +72 -0
- package/node_modules/@sigstore/core/dist/stream.d.ts +21 -0
- package/node_modules/@sigstore/core/dist/stream.js +117 -0
- package/node_modules/@sigstore/core/dist/x509/cert.d.ts +43 -0
- package/node_modules/@sigstore/core/dist/x509/cert.js +245 -0
- package/node_modules/@sigstore/core/dist/x509/ext.d.ts +41 -0
- package/node_modules/@sigstore/core/dist/x509/ext.js +146 -0
- package/node_modules/@sigstore/core/dist/x509/index.d.ts +2 -0
- package/node_modules/@sigstore/core/dist/x509/index.js +23 -0
- package/node_modules/@sigstore/core/dist/x509/sct.d.ts +25 -0
- package/node_modules/@sigstore/core/dist/x509/sct.js +158 -0
- package/node_modules/@sigstore/core/package.json +31 -0
- package/node_modules/@sigstore/protobuf-specs/LICENSE +202 -0
- package/node_modules/@sigstore/protobuf-specs/README.md +5 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/envelope.d.ts +44 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/envelope.js +59 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/events.d.ts +64 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/events.js +174 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/api/field_behavior.d.ts +74 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/api/field_behavior.js +141 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/any.d.ts +74 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/any.js +35 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/descriptor.d.ts +1309 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/descriptor.js +2191 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/timestamp.d.ts +113 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/timestamp.js +29 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/dsse.d.ts +23 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/dsse.js +55 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/entry.d.ts +43 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/entry.js +81 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/hashedrekord.d.ts +22 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/hashedrekord.js +56 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/verifier.d.ts +35 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/verifier.js +74 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_bundle.d.ts +146 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_bundle.js +103 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_common.d.ts +304 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_common.js +612 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_monitor.d.ts +33 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_monitor.js +55 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_rekor.d.ts +144 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_rekor.js +137 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_trustroot.d.ts +386 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_trustroot.js +284 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_verification.d.ts +191 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_verification.js +281 -0
- package/node_modules/@sigstore/protobuf-specs/dist/index.d.ts +6 -0
- package/node_modules/@sigstore/protobuf-specs/dist/index.js +37 -0
- package/node_modules/@sigstore/protobuf-specs/dist/rekor/v2/index.d.ts +4 -0
- package/node_modules/@sigstore/protobuf-specs/dist/rekor/v2/index.js +35 -0
- package/node_modules/@sigstore/protobuf-specs/package.json +35 -0
- package/node_modules/@sigstore/verify/README.md +9 -0
- package/node_modules/@sigstore/verify/dist/bundle/dsse.d.ts +12 -0
- package/node_modules/@sigstore/verify/dist/bundle/dsse.js +44 -0
- package/node_modules/@sigstore/verify/dist/bundle/index.d.ts +4 -0
- package/node_modules/@sigstore/verify/dist/bundle/index.js +59 -0
- package/node_modules/@sigstore/verify/dist/bundle/message.d.ts +13 -0
- package/node_modules/@sigstore/verify/dist/bundle/message.js +54 -0
- package/node_modules/@sigstore/verify/dist/error.d.ts +16 -0
- package/node_modules/@sigstore/verify/dist/error.js +34 -0
- package/node_modules/@sigstore/verify/dist/index.d.ts +6 -0
- package/node_modules/@sigstore/verify/dist/index.js +28 -0
- package/node_modules/@sigstore/verify/dist/key/certificate.d.ts +21 -0
- package/node_modules/@sigstore/verify/dist/key/certificate.js +216 -0
- package/node_modules/@sigstore/verify/dist/key/index.d.ts +10 -0
- package/node_modules/@sigstore/verify/dist/key/index.js +75 -0
- package/node_modules/@sigstore/verify/dist/key/sct.d.ts +4 -0
- package/node_modules/@sigstore/verify/dist/key/sct.js +78 -0
- package/node_modules/@sigstore/verify/dist/policy.d.ts +5 -0
- package/node_modules/@sigstore/verify/dist/policy.js +50 -0
- package/node_modules/@sigstore/verify/dist/shared.types.d.ts +50 -0
- package/node_modules/@sigstore/verify/dist/shared.types.js +2 -0
- package/node_modules/@sigstore/verify/dist/timestamp/index.d.ts +11 -0
- package/node_modules/@sigstore/verify/dist/timestamp/index.js +24 -0
- package/node_modules/@sigstore/verify/dist/timestamp/tsa.d.ts +3 -0
- package/node_modules/@sigstore/verify/dist/timestamp/tsa.js +63 -0
- package/node_modules/@sigstore/verify/dist/tlog/checkpoint.d.ts +11 -0
- package/node_modules/@sigstore/verify/dist/tlog/checkpoint.js +154 -0
- package/node_modules/@sigstore/verify/dist/tlog/dsse.d.ts +6 -0
- package/node_modules/@sigstore/verify/dist/tlog/dsse.js +106 -0
- package/node_modules/@sigstore/verify/dist/tlog/hashedrekord.d.ts +6 -0
- package/node_modules/@sigstore/verify/dist/tlog/hashedrekord.js +94 -0
- package/node_modules/@sigstore/verify/dist/tlog/index.d.ts +5 -0
- package/node_modules/@sigstore/verify/dist/tlog/index.js +92 -0
- package/node_modules/@sigstore/verify/dist/tlog/intoto.d.ts +3 -0
- package/node_modules/@sigstore/verify/dist/tlog/intoto.js +62 -0
- package/node_modules/@sigstore/verify/dist/tlog/merkle.d.ts +3 -0
- package/node_modules/@sigstore/verify/dist/tlog/merkle.js +104 -0
- package/node_modules/@sigstore/verify/dist/tlog/set.d.ts +3 -0
- package/node_modules/@sigstore/verify/dist/tlog/set.js +60 -0
- package/node_modules/@sigstore/verify/dist/trust/filter.d.ts +8 -0
- package/node_modules/@sigstore/verify/dist/trust/filter.js +23 -0
- package/node_modules/@sigstore/verify/dist/trust/index.d.ts +5 -0
- package/node_modules/@sigstore/verify/dist/trust/index.js +90 -0
- package/node_modules/@sigstore/verify/dist/trust/trust.types.d.ts +29 -0
- package/node_modules/@sigstore/verify/dist/trust/trust.types.js +2 -0
- package/node_modules/@sigstore/verify/dist/verifier.d.ts +31 -0
- package/node_modules/@sigstore/verify/dist/verifier.js +160 -0
- package/node_modules/@sigstore/verify/package.json +36 -0
- package/package.json +37 -4
package/lib/install.js
ADDED
|
@@ -0,0 +1,846 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const {notAllowed} = require('./ceiling');
|
|
3
|
+
// what an upgrade's install says when the home is not the one it judged
|
|
4
|
+
const HOME_CHANGED = 'this home changed while the upgrade was prepared; run it again; nothing was installed';
|
|
5
|
+
// ... and for a reinstall (install with no --pack: the reviewer's high on #124, 5)
|
|
6
|
+
const HOME_CHANGED_REINSTALL = 'this home changed while the reinstall was prepared; run it again; nothing was installed';
|
|
7
|
+
// what install says of a home another user could write into (an automatic
|
|
8
|
+
// upgrade finds its line by this and says it whole: the reviewer on #122)
|
|
9
|
+
const HOME_UNSAFE = require('./home').HOME_OPEN;
|
|
10
|
+
// ch-local install --pack <name> [--from <dir>] [--unreleased-pins <file>]
|
|
11
|
+
// (spec §2, "Install at exact versions"; reviewer, 2026-11-12): every tarball
|
|
12
|
+
// is checked against its pinned version and integrity first. With no --from,
|
|
13
|
+
// the tarballs come from the npm registry (lib/npm-release.js): each matches
|
|
14
|
+
// its pin and passes its provenance, ch-local's own by its provenance alone,
|
|
15
|
+
// before any is written to a temporary release directory, which is then read
|
|
16
|
+
// exactly as --from's is (docs/development/auto-upgrade.md). Then:
|
|
17
|
+
// - the runtime (this launcher and countinghouse) goes into <home>/app as an
|
|
18
|
+
// npm project with its pinned lockfile, by `npm ci --omit=optional`, which
|
|
19
|
+
// checks every dependency against that lockfile too;
|
|
20
|
+
// - each module of the pack, and of every installed pack this release lists,
|
|
21
|
+
// is placed in the module store at this release's pins (lib/module-store.js),
|
|
22
|
+
// or skipped when it is there already; a release is a tested set, so every
|
|
23
|
+
// installed pack moves to its pins, up or down, with no question
|
|
24
|
+
// (lib/install-plan.js, #413 section 9.4).
|
|
25
|
+
// The new app is built beside the old one and replaces it only when it is
|
|
26
|
+
// complete; then <home>/bin/ch-local.js runs it and <home>/modules.json
|
|
27
|
+
// records it (lib/module-record.js). A home an earlier ch-local made
|
|
28
|
+
// (packs.json) is migrated in the same step (section 10).
|
|
29
|
+
const fs = require('node:fs');
|
|
30
|
+
const path = require('node:path');
|
|
31
|
+
const {ALLOWLIST} = require('./allowlist');
|
|
32
|
+
const {layout, ensureHome, homeOwnershipProblem} = require('./home');
|
|
33
|
+
const {writeAtomic} = require('./atomic');
|
|
34
|
+
const {npm} = require('./npm');
|
|
35
|
+
const {tarballName} = require('./unpack');
|
|
36
|
+
const {keepOldTreesAside, collectStore} = require('./gc');
|
|
37
|
+
const {writeRecord, own} = require('./record');
|
|
38
|
+
const {readModulesRecord, writeModulesRecord, buildModulesRecord, writeRecordAsIs, judgedDigest} = require('./module-record');
|
|
39
|
+
const {placeModule, versionState} = require('./module-store');
|
|
40
|
+
const plan = require('./install-plan');
|
|
41
|
+
const {withLock} = require('./lock');
|
|
42
|
+
const {effectiveAllow, UNRELEASED_LINE} = require('./pins');
|
|
43
|
+
const table = require('./pack-table');
|
|
44
|
+
const {chLocal, hintCommand} = require('./command-line');
|
|
45
|
+
|
|
46
|
+
// install --pack under development pins, over a home with packs, meets
|
|
47
|
+
// section 9.4's table as add-pack does (L1b-2: the reviewer's answer, in a
|
|
48
|
+
// development home an added pack meets the table). The packs compared are
|
|
49
|
+
// every installed one, this pack's earlier entry included, and its new pins
|
|
50
|
+
// are judged against the whole record's active versions, so a reinstall
|
|
51
|
+
// never lowers a module silently (the high review of #94, 1). A release
|
|
52
|
+
// compares none: it brings every pack it lists to its pins and withdraws
|
|
53
|
+
// the others (L1a), as do a migration and a runtime-only install.
|
|
54
|
+
const tableFor = (home, eff, runtimeOnly, {pack, allow}) => !runtimeOnly && pack != null && home.record != null && home.migrating == null
|
|
55
|
+
&& table.fromOtherPins(home.record, plan.fromRelease(allow, eff), {except: eff.unreleased === true ? [] : Object.keys(home.record.packs || {})});
|
|
56
|
+
|
|
57
|
+
const SELF = require('../package.json').name;
|
|
58
|
+
// the registry npm ci may take dependencies from, whatever its environment or
|
|
59
|
+
// any .npmrc says, and the lockfile's resolved hosts never replaced
|
|
60
|
+
const NPM_FLAGS = ['--omit=optional', '--ignore-scripts', '--no-audit', '--no-fund', '--registry=https://registry.npmjs.org/', '--replace-registry-host=never'];
|
|
61
|
+
|
|
62
|
+
const {integrityOf} = require('./integrity');
|
|
63
|
+
const {preloadForSwap} = require('./swap-preload');
|
|
64
|
+
|
|
65
|
+
// The tarballs for `packages`, each read once: {problems, bytes}. Only
|
|
66
|
+
// bytes whose integrity is the pinned one are returned, and those same bytes
|
|
67
|
+
// are what is unpacked or handed to npm (reviewer, 2026-11-12), so a file
|
|
68
|
+
// changed after the check is never installed. A tarball no pin names is a
|
|
69
|
+
// problem; another pinned package's tarball (a release directory holds every
|
|
70
|
+
// pack) is not.
|
|
71
|
+
function loadTarballs(from, packages, pins) {
|
|
72
|
+
let files;
|
|
73
|
+
try {
|
|
74
|
+
files = fs.readdirSync(from).filter((f) => f.endsWith('.tgz'));
|
|
75
|
+
} catch (err) {
|
|
76
|
+
return {problems: [`cannot read ${from} (${err.code})`], bytes: {}};
|
|
77
|
+
}
|
|
78
|
+
const known = new Set(Object.entries(pins).map(([name, pin]) => tarballName(name, pin.version)));
|
|
79
|
+
const problems = files.filter((f) => !known.has(f)).map((f) => `${f} is not on this launcher's allowlist`);
|
|
80
|
+
const bytes = {};
|
|
81
|
+
for (const name of packages) {
|
|
82
|
+
const file = tarballName(name, pins[name].version);
|
|
83
|
+
const at = `${name}@${pins[name].version}`;
|
|
84
|
+
if (!files.includes(file)) { problems.push(`${at}: no ${file} in ${from}`); continue; }
|
|
85
|
+
let buf;
|
|
86
|
+
try {
|
|
87
|
+
buf = fs.readFileSync(path.join(from, file));
|
|
88
|
+
} catch (err) {
|
|
89
|
+
problems.push(`${at}: cannot read ${file} (${err.code || err.message})`);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (integrityOf(buf) !== pins[name].integrity) problems.push(`${at}: the tarball's integrity is not the pinned one`);
|
|
93
|
+
else bytes[name] = buf;
|
|
94
|
+
}
|
|
95
|
+
return {problems, bytes};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// The app's package.json: each runtime tarball as a file: dependency. A
|
|
99
|
+
// release generates the runtime's lockfile from exactly this.
|
|
100
|
+
function appManifest(runtime, pins) {
|
|
101
|
+
return {
|
|
102
|
+
name: 'countinghouse-home-app',
|
|
103
|
+
private: true,
|
|
104
|
+
dependencies: Object.fromEntries(runtime.packages.map((name) => [name, `file:tarballs/${tarballName(name, pins[name].version)}`])),
|
|
105
|
+
chLocal: {runtime: Object.fromEntries(runtime.packages.map((name) => [name, pins[name].version]))}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// The launcher written into a home: runs the installed ch-local on THIS home
|
|
110
|
+
// unless COUNTINGHOUSE_HOME names another (an explicit variable, or start's
|
|
111
|
+
// --home, still wins), so a command printed with this launcher's path runs
|
|
112
|
+
// where it says, from any terminal (the reviewer on ch-local#110, 2)
|
|
113
|
+
const shim = (installedBin, home) => `#!/usr/bin/env node
|
|
114
|
+
'use strict';
|
|
115
|
+
// Written by \`ch-local install\`: runs the installed launcher, on this home
|
|
116
|
+
// unless COUNTINGHOUSE_HOME names another. Every install writes it again;
|
|
117
|
+
// edits are lost.
|
|
118
|
+
if (process.env.COUNTINGHOUSE_HOME == null || process.env.COUNTINGHOUSE_HOME === '') process.env.COUNTINGHOUSE_HOME = ${JSON.stringify(home)};
|
|
119
|
+
require(${JSON.stringify(installedBin)}).run();
|
|
120
|
+
`;
|
|
121
|
+
|
|
122
|
+
// fromNpm: {registry, trust}, passed only by a test's own code (a fake
|
|
123
|
+
// registry and its test root); the command never passes it
|
|
124
|
+
// runtimeOnly: an upgrade's install with no pack named: the runtime, and
|
|
125
|
+
// every installed pack this release lists brought to its pins; a pack it no
|
|
126
|
+
// longer lists stays recorded, its modules withdrawn (section 9.7). Held
|
|
127
|
+
// packs are never dropped by an install (nothing is deleted but by
|
|
128
|
+
// remove-pack).
|
|
129
|
+
// An existing home another user could change (lib/home.js homeOpenProblem:
|
|
130
|
+
// POSIX, its owner and mode; Windows, its DACL), which the shared runtime
|
|
131
|
+
// refuses too: its line, with the fix when there is one; null for a home
|
|
132
|
+
// that is fine or not there yet -> line | null
|
|
133
|
+
// principalNames: a test's name lookup (lib/home.js homeOpenProblem), else Windows' own
|
|
134
|
+
function unsafeHomeLine(home, platform = process.platform, {fileAcl = null, principalNames = null} = {}) {
|
|
135
|
+
const p = require('./home').homeOpenProblem(home, {platform, fileAcl, principalNames});
|
|
136
|
+
if (p == null) return null;
|
|
137
|
+
return `this home ${p.why.replace(/^it /, '')}, ${p.consequence || HOME_UNSAFE}${p.fix != null ? `; ${p.fix}${p.final ? '' : ', then install again'}` : ''}`;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// `install` with no --pack (the reviewer on the install hints, 2026-11-21):
|
|
141
|
+
// reinstalls exactly what the home's record lists, at this ch-local's own
|
|
142
|
+
// pins, through install itself (its checks, its lock, its description
|
|
143
|
+
// check). It never adds a pack (the packs are the record's, as an automatic
|
|
144
|
+
// upgrade takes them: lib/packs.js releaseSelection) and never moves the
|
|
145
|
+
// home to another release than this ch-local's (the pins are this
|
|
146
|
+
// release's). Nothing installed: the --pack line. An unreleased home: the
|
|
147
|
+
// full line, since its record keeps neither the directory nor the pins file.
|
|
148
|
+
// No network: install's fetch says the --from line (reinstalling).
|
|
149
|
+
// -> {code} (refused, said) | {pack, runtimeOnly, judged} (what install
|
|
150
|
+
// then installs, itself: install's test-only arguments are never passed on,
|
|
151
|
+
// test/npm-release.test.js)
|
|
152
|
+
function reinstallTarget(unreleasedPins, io, release) {
|
|
153
|
+
const fail = (s) => io.stderr.write(`ch-local: ${s}\n`);
|
|
154
|
+
const say = (s) => io.stdout.write(`${s}\n`);
|
|
155
|
+
if (unreleasedPins != null) { fail('--unreleased-pins reinstalls only with the pack it is for: pass --pack <name> with it'); return {code: 2}; }
|
|
156
|
+
const where = layout(io.env, io.homedir);
|
|
157
|
+
// (a home another user could write into: refused before its record is read)
|
|
158
|
+
const unsafe = unsafeHomeLine(where.home);
|
|
159
|
+
if (unsafe != null) { fail(unsafe); fail('nothing was installed'); return {code: 1}; }
|
|
160
|
+
// an interrupted rollback is finished first, as install --pack says (the
|
|
161
|
+
// reviewer's high on #124, 2)
|
|
162
|
+
if (fs.existsSync(where.journal)) { fail(`a rollback was interrupted; run ${hintCommand(where, 'rollback', io.platform)} to finish it; nothing was installed`); return {code: 1}; }
|
|
163
|
+
// a pack name from the record, printed in a line to copy: only a plain
|
|
164
|
+
// name, else the placeholder (the medium on the install hints, 9)
|
|
165
|
+
const packArg = (n) => (typeof n === 'string' && /^[a-z0-9][a-z0-9-]{0,63}$/.test(n) ? n : '<name>');
|
|
166
|
+
let record;
|
|
167
|
+
try {
|
|
168
|
+
record = readModulesRecord(where);
|
|
169
|
+
} catch (err) {
|
|
170
|
+
// never "run install again" from install itself (the medium, 1): an
|
|
171
|
+
// earlier home, or a record that can't be read, is installed again by
|
|
172
|
+
// pack, which migrates it or sets it aside
|
|
173
|
+
// (permissions or owner: the record's own advice, the file's fix: high, 1)
|
|
174
|
+
if (err.code === 'RECORD_IO') { fail(`${err.message}; nothing was installed`); return {code: 1}; }
|
|
175
|
+
let first = '<name>';
|
|
176
|
+
if (err.code === 'RECORD_EARLIER') {
|
|
177
|
+
try { first = packArg(Object.keys((require('./record').readRecord(where) || {}).packs || {})[0]); } catch (e) { first = '<name>'; }
|
|
178
|
+
}
|
|
179
|
+
fail(`${err.reason || 'this home\'s record could not be read'}: install a pack again with ${hintCommand(where, `install --pack ${first}`, io.platform)}, which ${err.code === 'RECORD_EARLIER' ? 'brings this home to this ch-local' : 'sets this record aside and starts a new one'}; nothing was installed`);
|
|
180
|
+
return {code: 1};
|
|
181
|
+
}
|
|
182
|
+
if (record == null) {
|
|
183
|
+
fail(`nothing is installed here, so there is nothing to reinstall: run ${hintCommand(where, 'install --pack <name>', io.platform)} (with --from <directory of tarballs> for tarballs on disk)`);
|
|
184
|
+
return {code: 2};
|
|
185
|
+
}
|
|
186
|
+
if (record.unreleased === true) {
|
|
187
|
+
fail(`this is an unreleased install (development only): reinstall it with \`${chLocal(where, `install --pack ${packArg(Object.keys(record.packs || {})[0])} --from <release directory> --unreleased-pins <pins file>`)}\`; nothing was installed`);
|
|
188
|
+
return {code: 2};
|
|
189
|
+
}
|
|
190
|
+
// never another release than the home's own, from --from as from npm
|
|
191
|
+
// (the medium, 5): this ch-local must be the one the record names
|
|
192
|
+
const home = record.runtime && record.runtime.versions ? record.runtime.versions[SELF] : undefined;
|
|
193
|
+
const ours = release.release != null ? release.release.version : undefined;
|
|
194
|
+
// this process IS the home's launcher, and the record does not name its
|
|
195
|
+
// release yet (an install or upgrade that did not finish): the install
|
|
196
|
+
// that finishes it, never this command again (high, 3). io.selfVersion:
|
|
197
|
+
// a test's, as lib/packs.js recordRelease reads it.
|
|
198
|
+
const fromHome = io.selfVersion !== undefined ? io.selfVersion != null : require('./packs').runsFromHome(where);
|
|
199
|
+
if (fromHome && typeof ours === 'string' && home !== ours) {
|
|
200
|
+
fail(`this home's record names release ${home || '(unknown)'}, but its launcher is ch-local ${ours}: an install or upgrade did not finish; run \`${chLocal(where, `install --pack ${packArg(Object.keys(record.packs || {})[0])}`)}\` to finish it; nothing was installed`);
|
|
201
|
+
return {code: 2};
|
|
202
|
+
}
|
|
203
|
+
if (typeof home !== 'string' || typeof ours !== 'string' || home !== ours) {
|
|
204
|
+
fail(`this home's ch-local is ${home || '(unknown)'}, and this one is ${ours || '(unknown)'}: a reinstall stays on the home's own release; run \`${chLocal(where, 'install')}\` (the home's own launcher), or \`${chLocal(where, 'upgrade')}\` or \`${chLocal(where, 'rollback')}\` to move it; nothing was installed`);
|
|
205
|
+
return {code: 2};
|
|
206
|
+
}
|
|
207
|
+
const {withdrawn, target} = require('./packs').releaseSelection(record, release, release);
|
|
208
|
+
// a recorded pack this release does not list: said, never silently
|
|
209
|
+
// dropped (the medium, 3); it stays recorded, as an upgrade keeps it
|
|
210
|
+
for (const name of withdrawn) say(`pack ${packArg(name)} is not in this release, so it was not reinstalled; ${require('./packs').removeHint(packArg(name), where)}`);
|
|
211
|
+
// the record judged here: install refuses another under its lock, so a
|
|
212
|
+
// pack removed meanwhile is never put back (the medium, 2)
|
|
213
|
+
return {pack: target.pack, runtimeOnly: target.runtimeOnly === true, judged: judgedDigest(record)};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
async function install({pack, from, unreleasedPins, runtimeOnly = false, judged = null, report = null}, io, release = ALLOWLIST, fromNpm = {}) {
|
|
217
|
+
// no pack: a reinstall of what the record lists (reinstallTarget)
|
|
218
|
+
let reinstalling = false;
|
|
219
|
+
if (pack == null && runtimeOnly !== true) {
|
|
220
|
+
const t = reinstallTarget(unreleasedPins, io, release);
|
|
221
|
+
if (t.code != null) return t.code;
|
|
222
|
+
({pack, runtimeOnly, judged} = t);
|
|
223
|
+
reinstalling = true;
|
|
224
|
+
}
|
|
225
|
+
const say = (s) => io.stdout.write(s + '\n');
|
|
226
|
+
const fail = (s) => io.stderr.write(`ch-local: ${s}\n`);
|
|
227
|
+
// a home another user could change: refused before anything of it is read,
|
|
228
|
+
// loaded (the ceiling's reader is the home's code: the reviewer's high on
|
|
229
|
+
// #126, H1), fetched or placed, the shim included; installFrom checks
|
|
230
|
+
// again once it has made or found the home
|
|
231
|
+
{
|
|
232
|
+
const unsafe0 = unsafeHomeLine(layout(io.env, io.homedir).home);
|
|
233
|
+
if (unsafe0 != null) {
|
|
234
|
+
fail(unsafe0);
|
|
235
|
+
fail('nothing was installed');
|
|
236
|
+
return 1;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const spec = runtimeOnly ? {modules: []} : (own(release.packs, pack) ? release.packs[pack] : null);
|
|
240
|
+
if (spec == null) { fail(`unknown pack "${pack}"; one of: ${Object.keys(release.packs).join(', ')}`); return 2; }
|
|
241
|
+
// the operator's allowlist of packs (the runtime's reader, when one is
|
|
242
|
+
// installed; start enforces it whatever is installed)
|
|
243
|
+
const unlisted = runtimeOnly ? null : notAllowed(layout(io.env, io.homedir), pack, io, spec.modules);
|
|
244
|
+
if (unlisted != null) { fail(unlisted); return 2; }
|
|
245
|
+
if (from == null && unreleasedPins != null) { fail('--unreleased-pins is for tarballs on disk: pass --from <directory of tarballs> with it'); return 2; }
|
|
246
|
+
const eff = effectiveAllow(release, unreleasedPins, io.env);
|
|
247
|
+
if (eff.problem != null) { fail(eff.problem); return 2; }
|
|
248
|
+
let allow = eff.allow;
|
|
249
|
+
const where0 = layout(io.env, io.homedir);
|
|
250
|
+
// what this install takes, read without the lock (installLocked reads it
|
|
251
|
+
// again under it): only the modules the store does not hold at their pin
|
|
252
|
+
// are fetched, so a module already installed is not installed again
|
|
253
|
+
// (a record this cannot read for an error, not its format, refuses the
|
|
254
|
+
// install here, as under the lock: the medium review of the Reviewer's
|
|
255
|
+
// round on #83, 9)
|
|
256
|
+
let home0 = {record: null, migrating: null};
|
|
257
|
+
try { home0 = plan.readHome(where0, {release: allow, eff}); } catch (err) {
|
|
258
|
+
if (err.code === 'RECORD_IO') { fail(`${err.reason}; nothing was installed`); return 1; }
|
|
259
|
+
home0 = {record: null, migrating: null};
|
|
260
|
+
}
|
|
261
|
+
const touched0 = plan.touchedPacks(home0.record, {pack: runtimeOnly ? null : pack, allow, eff, migrating: home0.migrating != null});
|
|
262
|
+
const unpinned = touched0.find((n) => !allow.packs[n].modules.every((m) => allow.pins[m] != null));
|
|
263
|
+
// from npm, ch-local's own pin is the digest its provenance verifies
|
|
264
|
+
const pinned = (name) => allow.pins[name] != null || (from == null && name === SELF);
|
|
265
|
+
if (unpinned != null || !allow.runtime.packages.every(pinned)) { fail(`no release of the pack "${unpinned != null ? unpinned : pack}" is pinned in this ch-local yet`); return 1; }
|
|
266
|
+
// every pack this install moves (a release moves every pack of the record
|
|
267
|
+
// it lists: #413 rev 3 section 9.6), not only the one named, is held to
|
|
268
|
+
// the operator's allowlist: one it refuses refuses the install, nothing
|
|
269
|
+
// moved (the medium on L4, 3)
|
|
270
|
+
for (const n of touched0) {
|
|
271
|
+
if (n === pack) continue;
|
|
272
|
+
const refused = notAllowed(where0, n, io, allow.packs[n].modules);
|
|
273
|
+
if (refused != null) { fail(refused); return 2; }
|
|
274
|
+
}
|
|
275
|
+
// (a migration reinstalls every pack it lists, from these pins' tarballs)
|
|
276
|
+
const wanted0 = plan.planInstall(home0.record, {pack: runtimeOnly ? null : pack, allow, eff, migrating: home0.migrating != null}).modules;
|
|
277
|
+
let names = [...allow.runtime.packages, ...plan.toFetch(where0, wanted0)];
|
|
278
|
+
if (allow.runtime.lockfile == null) { fail('no lockfile is pinned for the runtime: its dependencies would be unpinned'); return 1; }
|
|
279
|
+
// the shim, prepared (from npm: prepareShim's answer, below; from a
|
|
280
|
+
// folder: prepareShimFrom's, now), or null: the one there is set aside (a
|
|
281
|
+
// folder with no shim for this platform, or a release with no shim section)
|
|
282
|
+
let shimReady = null;
|
|
283
|
+
// a prepared folder's own shim, by the sha512 its pins name, as its packs
|
|
284
|
+
// are; refused as a pack is, before the table's questions and anything
|
|
285
|
+
// installed (A-shim-from, and its medium, 7)
|
|
286
|
+
if (from != null && allow.shim != null) {
|
|
287
|
+
shimReady = require('./shim-install').prepareShimFrom({data: {shim: allow.shim, pins: allow.pins}, from, unreleased: eff.unreleased === true});
|
|
288
|
+
if (shimReady != null && shimReady.status === 'refused') {
|
|
289
|
+
fail(shimReady.error.message);
|
|
290
|
+
fail('nothing was installed');
|
|
291
|
+
return 1;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
// the table's questions, asked before the lock and anything written
|
|
295
|
+
// (lib/pack-table.js askAll); checked again under the lock
|
|
296
|
+
let asked = null;
|
|
297
|
+
// the tarballs read now, each once, are installFrom's too
|
|
298
|
+
let preBytes = {};
|
|
299
|
+
if (tableFor(home0, eff, runtimeOnly, {pack, allow})) {
|
|
300
|
+
const before = table.decideBeforeLock(where0, home0.record, pack, spec, allow.pins, (n) => loadTarballs(from, n, allow.pins));
|
|
301
|
+
if (before.problems != null) { for (const p of before.problems) fail(p); fail('nothing was installed'); return 1; }
|
|
302
|
+
preBytes = before.bytes;
|
|
303
|
+
const got = await table.askAll(where0, before.decided, pack, io, fail);
|
|
304
|
+
if (got.code != null) return got.code;
|
|
305
|
+
asked = got.signature;
|
|
306
|
+
// a module the table does not place is not fetched (the high review of #94, 3)
|
|
307
|
+
const notPlaced = new Set(before.decided.rows.filter((r) => !r.place && r.case !== 'same').map((r) => r.module));
|
|
308
|
+
names = names.filter((n) => !notPlaced.has(n));
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
let fetched = null;
|
|
312
|
+
if (from == null && (allow.self == null || allow.release == null || typeof allow.release.version !== 'string')) {
|
|
313
|
+
fail('this ch-local carries no release identity to install from npm with; pass --from <directory of tarballs>');
|
|
314
|
+
return 1;
|
|
315
|
+
}
|
|
316
|
+
if (from == null) {
|
|
317
|
+
// no downgrade from npm: rollback is the way back to an older release
|
|
318
|
+
const rec = home0.record;
|
|
319
|
+
const installed = rec != null && rec.runtime != null && rec.runtime.versions != null ? rec.runtime.versions[SELF] : null;
|
|
320
|
+
const strictGreater = (a, b) => { const re = /^(\d+)\.(\d+)\.(\d+)$/; const x = re.exec(String(a)); const y = re.exec(String(b)); if (x == null || y == null) return false; for (let i = 1; i <= 3; i++) if (Number(x[i]) !== Number(y[i])) return Number(x[i]) > Number(y[i]); return false; };
|
|
321
|
+
if (installed != null && strictGreater(installed, allow.release.version)) {
|
|
322
|
+
fail(`${allow.release.version} is lower than the installed ${installed}: ${chLocal(where0, 'rollback')} is the way back; nothing was installed`);
|
|
323
|
+
return 1;
|
|
324
|
+
}
|
|
325
|
+
fetched = fs.mkdtempSync(path.join(require('node:os').tmpdir(), 'ch-local-release-'));
|
|
326
|
+
try {
|
|
327
|
+
say(`fetching ${names.length} package(s) from the npm registry, each checked against its pin and its provenance`);
|
|
328
|
+
const r = await require('./npm-release').fetchRelease({data: {pins: allow.pins, self: allow.self, runtime: allow.runtime},
|
|
329
|
+
version: allow.release.version, names, dir: path.join(fetched, 'release'), io, verifiedSelf: allow.verifiedSelf || null, ...fromNpm});
|
|
330
|
+
allow = Object.assign({}, allow, {pins: r.pins, runtime: Object.assign({}, allow.runtime, {lockfile: r.lockfile})});
|
|
331
|
+
from = path.join(fetched, 'release');
|
|
332
|
+
// this platform's native shim, fetched and verified now, before the
|
|
333
|
+
// lock; placed and recorded inside the install's one locked record
|
|
334
|
+
// write (the medium on B-shim-allow)
|
|
335
|
+
if (allow.shim != null) shimReady = await require('./shim-install').prepareShim({data: {shim: allow.shim, pins: allow.pins}, record: home0.record, home: where0.home, io, ...fromNpm});
|
|
336
|
+
} catch (err) {
|
|
337
|
+
fs.rmSync(fetched, {recursive: true, force: true});
|
|
338
|
+
// a reinstall that can't reach the registry: one line, with the way
|
|
339
|
+
// that needs no network (the reviewer: never a prompt, since hints are
|
|
340
|
+
// run by agents and scripts too)
|
|
341
|
+
if (reinstalling && err.code === 'FETCH_FAILED' && err.unreachable === true) {
|
|
342
|
+
fail(`could not fetch this release from the npm registry (${err.message}); with no network, run ${hintCommand(where0, 'install --from <release directory>', io.platform)} with this release's tarballs (its packs', its runtime's and this machine's shim's); nothing was installed`);
|
|
343
|
+
return 1;
|
|
344
|
+
}
|
|
345
|
+
fail(`${err.package != null ? `${err.package}: ` : ''}${err.message}${err.code != null ? ` (${err.code})` : ''}`);
|
|
346
|
+
fail('nothing was installed');
|
|
347
|
+
return 1;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
let code;
|
|
351
|
+
try {
|
|
352
|
+
code = await installFrom({pack, spec, eff, allow, names, from, runtimeOnly, asked, preBytes, judged, planned: touched0, shimReady, report, reinstalling}, io, {say, fail});
|
|
353
|
+
} finally {
|
|
354
|
+
if (fetched != null) fs.rmSync(fetched, {recursive: true, force: true});
|
|
355
|
+
}
|
|
356
|
+
return code;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// every line the shim step fails with starts so
|
|
360
|
+
const SHIM_LINE = 'the shared runtime\'s shim';
|
|
361
|
+
|
|
362
|
+
// The shim step, under the lock, after the app is swapped and before the
|
|
363
|
+
// one record write: the plan's shim put in place and named in the record
|
|
364
|
+
// (built.shim), or the one there set aside and the record naming none, so
|
|
365
|
+
// the record always names what is in place and a rollback never restores a
|
|
366
|
+
// shim that was not this release's (the medium on B-shim-allow: one lock,
|
|
367
|
+
// one write; and before a running daemon is asked to restart). A shim that
|
|
368
|
+
// cannot be placed leaves each session its own runtime, said, and fails
|
|
369
|
+
// nothing.
|
|
370
|
+
// report.shim: {placed: true} | {placed: false, why: 'busy' | 'stale' |
|
|
371
|
+
// 'failed' | 'unpinned' | 'unsupported' | 'none', asideFailed?: true (the
|
|
372
|
+
// one before could not be set aside)} -- what an automatic
|
|
373
|
+
// upgrade says, in its own fixed words (never install's lines, which name
|
|
374
|
+
// paths: the reviewer's high on #120, 4)
|
|
375
|
+
function shimStep(where, ready, built, io, {say, fail}, report = null) {
|
|
376
|
+
const si = require('./shim-install');
|
|
377
|
+
const outcome = (o) => { if (report != null) report.shim = Object.assign(o, report.shim != null && report.shim.asideFailed === true ? {asideFailed: true} : {}); };
|
|
378
|
+
const asideFailed = () => { if (report != null && report.shim != null) report.shim.asideFailed = true; };
|
|
379
|
+
outcome({placed: false, why: ready == null ? 'none' : ready.status === 'unpinned' || ready.status === 'unsupported' ? ready.status : 'failed'});
|
|
380
|
+
// (nothing throws past here: the app is already swapped -- the medium on
|
|
381
|
+
// B-shim-allow's round 3, 2)
|
|
382
|
+
try {
|
|
383
|
+
shimStepInner(si, where, ready, built, {say, fail}, outcome, asideFailed);
|
|
384
|
+
} catch (err) {
|
|
385
|
+
// (as any failure: set aside, the record naming none)
|
|
386
|
+
delete built.shim;
|
|
387
|
+
outcome({placed: false, why: 'failed'});
|
|
388
|
+
fail(`${SHIM_LINE} could not be installed (${err != null && err.message != null ? err.message : String(err)}${err != null && err.code != null ? `, ${err.code}` : ''}); each session runs its own runtime`);
|
|
389
|
+
try { si.setAside(where.home); } catch (e) { asideFailed(); fail(`${SHIM_LINE} from before could not be set aside (${e.code || e.message})`); }
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
function shimStepInner(si, where, ready, built, {say, fail}, outcome, asideFailed) {
|
|
393
|
+
const aside = () => {
|
|
394
|
+
try {
|
|
395
|
+
if (si.setAside(where.home)) say('the shared runtime\'s shim from before is set aside: each session runs its own runtime');
|
|
396
|
+
} catch (err) {
|
|
397
|
+
asideFailed();
|
|
398
|
+
fail(`${SHIM_LINE} from before could not be set aside (${err.code || err.message})`);
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
if (ready == null) return aside();
|
|
402
|
+
if (ready.status === 'unsupported' || ready.status === 'unpinned') {
|
|
403
|
+
say(ready.status === 'unpinned' ? 'no shared-runtime shim is pinned for this platform in this release: each session runs its own runtime'
|
|
404
|
+
: 'there is no shared-runtime shim for this platform: each session runs its own runtime');
|
|
405
|
+
return aside();
|
|
406
|
+
}
|
|
407
|
+
const failed = (err) => {
|
|
408
|
+
delete built.shim;
|
|
409
|
+
// (a stale shim never runs: set aside, the record naming none -- the
|
|
410
|
+
// reviewer's ruling (b) on a busy one, with the way back said)
|
|
411
|
+
const code = err != null ? err.code : null;
|
|
412
|
+
outcome({placed: false, why: code === 'SHIM_BUSY' ? 'busy' : code === 'SHIM_STALE' ? 'stale' : 'failed'});
|
|
413
|
+
if (code === 'SHIM_BUSY') fail(`${SHIM_LINE} could not be replaced: a session still uses the old one. Close that session (or the client running it), then run \`${chLocal(where, 'install')}\` to place the new one; until then each session runs its own runtime`);
|
|
414
|
+
// (the shim in place changed since it was judged current, before the
|
|
415
|
+
// lock: another install or a rollback meanwhile -- the medium's round 3)
|
|
416
|
+
else if (code === 'SHIM_STALE') fail(`${SHIM_LINE} in place changed while this install ran: run \`${chLocal(where, 'install')}\` again to place it; until then each session runs its own runtime`);
|
|
417
|
+
else fail(`${SHIM_LINE} could not be installed (${err != null && err.message != null ? err.message : 'an error'}${code != null ? `, ${code}` : ''}); each session runs its own runtime`);
|
|
418
|
+
aside();
|
|
419
|
+
};
|
|
420
|
+
if (ready.status === 'failed') return failed(ready.error);
|
|
421
|
+
try {
|
|
422
|
+
const r = si.placeShim(where.home, ready);
|
|
423
|
+
built.shim = {package: ready.name, version: ready.version};
|
|
424
|
+
outcome({placed: true});
|
|
425
|
+
say(`the shared runtime's shim ${r.version} is at ${r.path}`);
|
|
426
|
+
} catch (err) {
|
|
427
|
+
failed(err);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// (where: the home's layout, for the command's launcher form:
|
|
432
|
+
// lib/command-line.js)
|
|
433
|
+
const shimJsonRepair = (where) => `the relay's settings (shim.json) are missing or invalid, and an automatic upgrade does not write them: run ${chLocal(where, 'install')} to repair the relay's settings`;
|
|
434
|
+
|
|
435
|
+
// a shim.json there that this user wrote and the shim would take
|
|
436
|
+
function shimJsonKept(home, platform) {
|
|
437
|
+
try {
|
|
438
|
+
const bytes = require('./own-file').readOwnFile(path.join(home, 'shim.json'), {max: 64 * 1024, platform});
|
|
439
|
+
return bytes != null && require('./shim-config').shimJsonProblem(JSON.parse(bytes.toString('utf8')), platform) == null;
|
|
440
|
+
} catch (e) {
|
|
441
|
+
return false;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// shimReady: install's prepared shim (see shimStep), carried into the lock;
|
|
446
|
+
// report: the caller's, where the shim's outcome is set
|
|
447
|
+
async function installFrom({pack, spec, eff, allow, names, from, runtimeOnly, asked = null, preBytes = {}, judged = null, planned = null, shimReady = null, report = null, reinstalling = false}, io, {say, fail}) {
|
|
448
|
+
// (a tarball read before the lock is not read or hashed again)
|
|
449
|
+
const loaded = loadTarballs(from, names.filter((n) => preBytes[n] == null), allow.pins);
|
|
450
|
+
const problems = loaded.problems;
|
|
451
|
+
const bytes = {...preBytes, ...loaded.bytes};
|
|
452
|
+
// the lockfile against the runtime tarballs just read: a bundled entry only
|
|
453
|
+
// where its parent's tarball really holds it (lib/lockfile-rules.js)
|
|
454
|
+
if (problems.length === 0) {
|
|
455
|
+
const why = require('./lockfile-rules').lockfileProblem(allow.runtime.lockfile, {runtime: allow.runtime.packages, pins: allow.pins, tarballs: bytes});
|
|
456
|
+
if (why != null) problems.push(why);
|
|
457
|
+
}
|
|
458
|
+
if (problems.length > 0) {
|
|
459
|
+
for (const p of problems) fail(p);
|
|
460
|
+
fail('nothing was installed');
|
|
461
|
+
return 1;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
const where = layout(io.env, io.homedir);
|
|
465
|
+
// The home is install's to create (0700, whatever the umask); the lock
|
|
466
|
+
// only guards it. One that exists and that another user could write into
|
|
467
|
+
// (POSIX: group- or world-writable, or another user's), which the shared
|
|
468
|
+
// runtime refuses too, is refused: nothing is installed into it, and it is
|
|
469
|
+
// never changed, since it is not install's (the medium, 1). The chmod line
|
|
470
|
+
// is given when the mode is the cause and the path can be quoted safely.
|
|
471
|
+
// (Windows: its DACL, which the daemon checks and says.)
|
|
472
|
+
// (made or found, judged again: F3; one made here and refused is removed)
|
|
473
|
+
const madeHome = ensureHome(where.home);
|
|
474
|
+
{
|
|
475
|
+
const unsafe = unsafeHomeLine(where.home);
|
|
476
|
+
if (unsafe != null) {
|
|
477
|
+
if (madeHome) { try { fs.rmdirSync(where.home); } catch (err) { /* not empty: left */ } }
|
|
478
|
+
fail(unsafe);
|
|
479
|
+
fail('nothing was installed');
|
|
480
|
+
return 1;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
// (the packs it moved, as planned under the lock: installLockedInner)
|
|
484
|
+
const moved = {touched: []};
|
|
485
|
+
const code = await withLock(where, io, () => installLocked({pack: runtimeOnly ? null : pack, spec, eff, allow, bytes, where, runtimeOnly, asked, from, moved, judged, planned, shimReady, report, reinstalling}, io, {say, fail}));
|
|
486
|
+
// a running daemon restarts its runtime, or itself, onto what was installed
|
|
487
|
+
// (#236 section 6, "Upgrade"); with none running, nothing is written. After
|
|
488
|
+
// packs.lock is released, never under it: the daemon holds start.lock and
|
|
489
|
+
// waits on packs.lock in its start, so taking start.lock under packs.lock
|
|
490
|
+
// would deadlock (the review of #35).
|
|
491
|
+
if (code === 0) await require('./daemon-requests').requestUpgrade(where.home, {io});
|
|
492
|
+
// each of the pack's modules that needs a credential and has none stored
|
|
493
|
+
// (#413 section 6.2): after the lock, never holding it while someone types
|
|
494
|
+
// (every pack it moved, as planned under the lock, the runtime-only
|
|
495
|
+
// install's included, so a module it brought in is asked for too: the
|
|
496
|
+
// medium on L4, 3; the Reviewer's high on L4, 4 and 5)
|
|
497
|
+
const asking = [...new Set([...(!runtimeOnly && pack != null ? spec.modules : []), ...moved.touched.flatMap((n) => (own(allow.packs, n) ? allow.packs[n].modules : []))])];
|
|
498
|
+
if (code === 0 && asking.length > 0) await require('./credentials-command').askMissing(io, asking);
|
|
499
|
+
return code;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// A record set aside goes back whenever this install ends without writing
|
|
503
|
+
// the new one, a throw included (the medium review of the Reviewer's round
|
|
504
|
+
// on #83, 3): nothing is left with no record and nothing said.
|
|
505
|
+
async function installLocked(args, io, cbs) {
|
|
506
|
+
const guard = {putBack: null, written: false};
|
|
507
|
+
try {
|
|
508
|
+
return await installLockedInner(args, io, cbs, guard);
|
|
509
|
+
} catch (err) {
|
|
510
|
+
if (!guard.written && guard.putBack != null) guard.putBack();
|
|
511
|
+
throw err;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
async function installLockedInner({pack, spec, eff, allow, bytes, where, runtimeOnly = false, asked = null, from = null, moved = {touched: []}, judged = null, planned = null, shimReady = null, report = null, reinstalling = false}, io, {say, fail}, guard) {
|
|
516
|
+
// An interrupted rollback is finished first: its journal says which app is
|
|
517
|
+
// which, and an install would replace one of them (review of rollback-2).
|
|
518
|
+
if (fs.existsSync(where.journal)) { fail(`a rollback was interrupted; run ${hintCommand(where, 'rollback', io.platform)} to finish it; nothing was installed`); return 1; }
|
|
519
|
+
// The home as it is now, the earlier format read for its migration (a
|
|
520
|
+
// migration reinstalls every pack it lists from the pinned tarballs: the
|
|
521
|
+
// Reviewer on #83). A record that cannot be read is never taken for
|
|
522
|
+
// "nothing installed" silently:
|
|
523
|
+
// - a format problem (not JSON, not a record of either shape) is set aside
|
|
524
|
+
// and named, just before the swap, and this install starts a new one,
|
|
525
|
+
// the rollback target kept (#83's high review, 4);
|
|
526
|
+
// - an error reading it (EACCES, EIO, EMFILE, EBUSY: the file may be
|
|
527
|
+
// whole) refuses the install, and drops no pack (the Reviewer's check of
|
|
528
|
+
// #83's fixes, 4);
|
|
529
|
+
// - a home an earlier development launcher made (installed.json only) is
|
|
530
|
+
// installed over, as before.
|
|
531
|
+
let home;
|
|
532
|
+
let setAside = null;
|
|
533
|
+
try {
|
|
534
|
+
home = plan.readHome(where, {release: allow, eff});
|
|
535
|
+
} catch (err) {
|
|
536
|
+
if (err.code === 'RECORD_EARLIER_DEV') {
|
|
537
|
+
home = {record: null, migrating: null};
|
|
538
|
+
} else if (err.code === 'RECORD_FORMAT') {
|
|
539
|
+
setAside = {why: err.reason, moved: []};
|
|
540
|
+
home = {record: null, migrating: null};
|
|
541
|
+
} else {
|
|
542
|
+
fail(`${err.reason || err.message}; nothing was installed`);
|
|
543
|
+
return 1;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
const previous = home.record;
|
|
547
|
+
// an upgrade's install acts only on the record it judged: the preview,
|
|
548
|
+
// what it adds and what moves were said of that one (the Reviewer's high
|
|
549
|
+
// on #101, round 2). Another (a pack added during the question, one
|
|
550
|
+
// removed or a rollback during the fetch) refuses, before anything is
|
|
551
|
+
// planned, so no pack the record here lacks is written back
|
|
552
|
+
if (judged != null && judgedDigest(previous) !== judged) { fail(reinstalling ? HOME_CHANGED_REINSTALL : HOME_CHANGED); return 1; }
|
|
553
|
+
const after = plan.planInstall(previous, {pack, allow, eff, migrating: home.migrating != null});
|
|
554
|
+
// every pack this plan moves is held to the operator's allowlist again,
|
|
555
|
+
// as planned here under the lock: the record read before it may have
|
|
556
|
+
// changed (the Reviewer's high on L4, 5)
|
|
557
|
+
for (const n of after.touched) {
|
|
558
|
+
const refused = notAllowed(where, n, io, allow.packs[n].modules);
|
|
559
|
+
if (refused != null) { fail(refused); return 2; }
|
|
560
|
+
}
|
|
561
|
+
// an install that judged no record (install, add-pack): a pack the record
|
|
562
|
+
// gained since its first read was never fetched for, asked about, nor
|
|
563
|
+
// checked as this install's: nothing is installed, said (an upgrade's
|
|
564
|
+
// digest above covers this and more: the medium on #101 round 2, 2)
|
|
565
|
+
const gained = planned == null ? [] : after.touched.filter((n) => !planned.includes(n));
|
|
566
|
+
if (gained.length > 0) { fail(`this home's packs changed while this install ran (${gained.join(', ')}): run it again; nothing was installed`); return 1; }
|
|
567
|
+
moved.touched = after.touched;
|
|
568
|
+
// under development pins, the table as decided and answered before the
|
|
569
|
+
// lock (a change since is refused): a module never lowered is recorded at
|
|
570
|
+
// the installed version and not placed at the pack's
|
|
571
|
+
let rows = [];
|
|
572
|
+
const tableRan = tableFor(home, eff, runtimeOnly, {pack, allow});
|
|
573
|
+
if (tableRan) {
|
|
574
|
+
const again = table.recheck(where, previous, pack, spec, allow.pins, asked);
|
|
575
|
+
if (again.problem != null) { fail(again.problem); return 1; }
|
|
576
|
+
rows = again.rows;
|
|
577
|
+
for (const r of rows) {
|
|
578
|
+
after.packs[pack].modules[r.module] = r.recordAs;
|
|
579
|
+
if (!r.place && r.case !== 'same') delete after.modules[r.module];
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
// What is placed, before anything is: each module this install takes,
|
|
583
|
+
// from its fetched, integrity-checked tarball, unless the store holds it
|
|
584
|
+
// whole at its pin already. One look at each version's marker and
|
|
585
|
+
// directory in this plan (the Reviewer's check of #83's fixes, 10;
|
|
586
|
+
// placeModule checks again under its own guard as it places); one that
|
|
587
|
+
// cannot be read refuses the install
|
|
588
|
+
const placements = [];
|
|
589
|
+
const lost = [];
|
|
590
|
+
try {
|
|
591
|
+
for (const [m, pin] of Object.entries(after.modules)) {
|
|
592
|
+
const {marker, dir} = versionState(where, m, pin.version);
|
|
593
|
+
if (dir && marker != null && marker.integrity === pin.integrity) continue;
|
|
594
|
+
if (bytes[m] != null) placements.push({m, version: pin.version, integrity: pin.integrity, bytes: bytes[m], pin, marker});
|
|
595
|
+
else lost.push(m);
|
|
596
|
+
}
|
|
597
|
+
} catch (err) {
|
|
598
|
+
fail(`${err.message}; nothing was installed`);
|
|
599
|
+
return 1;
|
|
600
|
+
}
|
|
601
|
+
// a module the table kept before the lock (not read) that it now places,
|
|
602
|
+
// the home having changed meanwhile: read now, as add-pack does (the
|
|
603
|
+
// medium review of the round, 4)
|
|
604
|
+
// (or no longer runs: the packs it compared went)
|
|
605
|
+
if (lost.length > 0 && from != null) {
|
|
606
|
+
const late = loadTarballs(from, lost, allow.pins);
|
|
607
|
+
// (read now: the description check reads them too)
|
|
608
|
+
Object.assign(bytes, late.bytes);
|
|
609
|
+
for (const m of lost.filter((x) => late.bytes[x] != null)) {
|
|
610
|
+
const pin = after.modules[m];
|
|
611
|
+
placements.push({m, version: pin.version, integrity: pin.integrity, bytes: late.bytes[m], pin, marker: versionState(where, m, pin.version).marker});
|
|
612
|
+
}
|
|
613
|
+
lost.splice(0, lost.length, ...lost.filter((x) => late.bytes[x] == null));
|
|
614
|
+
}
|
|
615
|
+
if (lost.length > 0) { fail(`the module store changed while this install ran (${lost.join(', ')}); run it again; nothing was installed`); return 1; }
|
|
616
|
+
// each module as the pins describe it (#413 section 9.3; L5b): what an
|
|
617
|
+
// upgrade showed is what is installed. Before anything is placed.
|
|
618
|
+
// (at the version the record will hold each at: section 9.4's table can
|
|
619
|
+
// keep one installed at another version)
|
|
620
|
+
// (calls resolve to what a start would load once this install is made:
|
|
621
|
+
// the home after it, by start's own rule; the packs it changes at their
|
|
622
|
+
// new versions, a module the new version drops gone: the Reviewer's high
|
|
623
|
+
// review of #98's round 2, 1 and 5)
|
|
624
|
+
// (unreleased as this install writes it: from the pins it runs on alone; a
|
|
625
|
+
// clean install from a release resets it: the medium on the cut, 1)
|
|
626
|
+
const afterState = {...after, unreleased: eff.unreleased === true};
|
|
627
|
+
// (its withdrawn list as the write derives it: the medium on round 2, 2)
|
|
628
|
+
const afterContext = require('./description-check').activeContext({...afterState, withdrawn: require('./module-record').withdrawnOf(afterState, allow)}, allow);
|
|
629
|
+
const notDescribed = require('./description-check').descriptionRefusal(where, Object.keys(after.modules), allow, bytes, (m) => (after.modules[m] != null ? after.modules[m].version : allow.pins[m].version),
|
|
630
|
+
afterContext, {live: new Set(Object.keys(afterContext))});
|
|
631
|
+
if (notDescribed != null) { fail(`${notDescribed}; nothing was installed`); return 1; }
|
|
632
|
+
// Never other contents under a version the record names: a rebuild of one
|
|
633
|
+
// version (development pins) needs a new version (#83's high review, 8).
|
|
634
|
+
// Refused before anything is placed.
|
|
635
|
+
const recorded = new Set();
|
|
636
|
+
for (const r of [previous, (() => { try { return readModulesRecord({modulesRecord: where.previousModulesRecord}); } catch (e) { return null; } })()]) {
|
|
637
|
+
if (r == null) continue;
|
|
638
|
+
for (const e of [...Object.values(r.packs || {}), ...Object.values(r.held || {})]) for (const [m, v] of Object.entries(e.modules || {})) recorded.add(`${m}@${v}`);
|
|
639
|
+
}
|
|
640
|
+
for (const p of placements) {
|
|
641
|
+
if (p.marker != null && p.marker.integrity !== p.integrity && recorded.has(`${p.m}@${p.version}`)) {
|
|
642
|
+
fail(`${p.m} ${p.version} is installed with other contents; a changed module takes a new version (a rebuild of one version is not installed over the one the record names); nothing was installed`);
|
|
643
|
+
return 1;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
const build = `${where.app}.new`;
|
|
647
|
+
const old = `${where.app}.old`;
|
|
648
|
+
const runtimeVersions = Object.fromEntries(allow.runtime.packages.map((name) => [name, allow.pins[name].version]));
|
|
649
|
+
let built = null;
|
|
650
|
+
fs.rmSync(build, {recursive: true, force: true});
|
|
651
|
+
try {
|
|
652
|
+
fs.mkdirSync(path.join(build, 'tarballs'), {recursive: true});
|
|
653
|
+
for (const name of allow.runtime.packages) fs.writeFileSync(path.join(build, 'tarballs', tarballName(name, allow.pins[name].version)), bytes[name]);
|
|
654
|
+
fs.writeFileSync(path.join(build, 'package.json'), JSON.stringify(appManifest(allow.runtime, allow.pins), null, 2) + '\n');
|
|
655
|
+
fs.writeFileSync(path.join(build, 'package-lock.json'), JSON.stringify(allow.runtime.lockfile, null, 2) + '\n');
|
|
656
|
+
say(`npm ci in ${build}`);
|
|
657
|
+
const r = await npm(io, ['ci', ...NPM_FLAGS], build);
|
|
658
|
+
if (r.status !== 0) {
|
|
659
|
+
fail(`npm ci failed (exit ${r.status}); the previous install, if any, is unchanged`);
|
|
660
|
+
if (r.stderr) io.stderr.write(String(r.stderr).split('\n').slice(-20).join('\n') + '\n');
|
|
661
|
+
return 1;
|
|
662
|
+
}
|
|
663
|
+
const installed = path.join(build, 'node_modules', ...SELF.split('/'));
|
|
664
|
+
const got = JSON.parse(fs.readFileSync(path.join(installed, 'package.json'), 'utf8')).version;
|
|
665
|
+
if (got !== runtimeVersions[SELF]) { fail(`the installed ${SELF} is ${got}, not the pinned ${runtimeVersions[SELF]}; nothing was installed`); return 1; }
|
|
666
|
+
// Each module into the module store, or skipped when it is there at its
|
|
667
|
+
// pin; the app holds the runtime only. A module placed here and not
|
|
668
|
+
// recorded (the swap below failing) is collected later.
|
|
669
|
+
try {
|
|
670
|
+
const inUse = plan.inUseFor(where, io);
|
|
671
|
+
for (const p of placements) placeModule(where, p.m, p.bytes, p.pin, {inUse});
|
|
672
|
+
} catch (err) {
|
|
673
|
+
fail(`${err.message}; nothing was installed`);
|
|
674
|
+
return 1;
|
|
675
|
+
}
|
|
676
|
+
// the record this install writes, built and checked now, before anything
|
|
677
|
+
// is swapped: one that would not be valid changes nothing (the medium
|
|
678
|
+
// review of L1a-2, 4)
|
|
679
|
+
try {
|
|
680
|
+
built = buildModulesRecord({runtime: {versions: runtimeVersions}, release: allow.release != null ? allow.release : null, unreleased: eff.unreleased,
|
|
681
|
+
packs: after.packs, held: after.held}, {roleOf: plan.roleFor(where), release: allow});
|
|
682
|
+
} catch (err) {
|
|
683
|
+
fail(`${err.message}; nothing was installed`);
|
|
684
|
+
return 1;
|
|
685
|
+
}
|
|
686
|
+
// An unreadable record is set aside now, as nothing after this refuses
|
|
687
|
+
// but the swap, which puts it back; one that cannot be moved stops the
|
|
688
|
+
// install with nothing changed, never overwritten (the Reviewer's check
|
|
689
|
+
// of #83's fixes, 5)
|
|
690
|
+
// never silent: a record that cannot go back is named, where it is and
|
|
691
|
+
// what to do (the Reviewer's round on #83, 5)
|
|
692
|
+
const putBack = () => {
|
|
693
|
+
for (const [f, to] of setAside != null ? setAside.moved.slice().reverse() : []) {
|
|
694
|
+
try { fs.renameSync(to, f); } catch (e) { fail(`your previous record could not be put back (${e.code || e.message}): it is at ${to}; rename it to ${path.basename(f)}`); }
|
|
695
|
+
}
|
|
696
|
+
};
|
|
697
|
+
guard.putBack = putBack;
|
|
698
|
+
if (setAside != null) {
|
|
699
|
+
const at = new Date().toISOString().replace(/[:.]/g, '-');
|
|
700
|
+
for (const f of [where.modulesRecord, where.packs]) {
|
|
701
|
+
if (!fs.existsSync(f)) continue;
|
|
702
|
+
const to = `${f}.unreadable-${at}`;
|
|
703
|
+
try {
|
|
704
|
+
fs.renameSync(f, to);
|
|
705
|
+
setAside.moved.push([f, to]);
|
|
706
|
+
} catch (e) {
|
|
707
|
+
putBack();
|
|
708
|
+
fail(`${setAside.why}; it could not be set aside (${e.code || e.message}); nothing was installed`);
|
|
709
|
+
return 1;
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
// The swap: the old app moves aside, the new one takes its place; if that
|
|
714
|
+
// fails (a client holding files open on Windows), the old one goes back.
|
|
715
|
+
fs.rmSync(old, {recursive: true, force: true});
|
|
716
|
+
// (everything the code after the swap may require, loaded from this
|
|
717
|
+
// release first: lib/swap-preload.js)
|
|
718
|
+
preloadForSwap();
|
|
719
|
+
const hadApp = fs.existsSync(where.app);
|
|
720
|
+
// (put back once: after it, nothing is left for the guard to put back)
|
|
721
|
+
const busy = (err) => { putBack(); guard.putBack = null; fail(`could not replace ${where.app} (${err.code || err.message}); is a client running it? the previous install is unchanged`); return 1; };
|
|
722
|
+
try {
|
|
723
|
+
if (hadApp) fs.renameSync(where.app, old);
|
|
724
|
+
} catch (err) {
|
|
725
|
+
return busy(err);
|
|
726
|
+
}
|
|
727
|
+
try {
|
|
728
|
+
fs.renameSync(build, where.app);
|
|
729
|
+
} catch (err) {
|
|
730
|
+
if (hadApp) fs.renameSync(old, where.app);
|
|
731
|
+
return busy(err);
|
|
732
|
+
}
|
|
733
|
+
// the new app is in: an unreadable record set aside stays aside (putting
|
|
734
|
+
// it back beside the new app would be worse); the message names it (the
|
|
735
|
+
// medium review of the Reviewer's round, 8), said now. Kept for reference
|
|
736
|
+
// only: what it named is not kept for it (the medium review of #83's
|
|
737
|
+
// fixes, 8)
|
|
738
|
+
guard.putBack = null;
|
|
739
|
+
if (setAside != null) say(`the home's record could not be read (${setAside.why}); it is kept as ${setAside.moved.map(([, to]) => path.basename(to)).join(' and ')} for reference, and this install starts a new one: add the other packs again with \`${chLocal(where, 'install --pack <pack>')}\``);
|
|
740
|
+
// The replaced release's programs are kept, one level, for rollback
|
|
741
|
+
// (<home>/previous: its app and its record). Data is never moved. A
|
|
742
|
+
// reinstall of the same release keeps what was kept: replacing it with a
|
|
743
|
+
// copy of the current release would lose the real rollback target.
|
|
744
|
+
const sameRelease = previous != null && previous.release != null && previous.release.version != null &&
|
|
745
|
+
allow.release != null && previous.release.version === allow.release.version;
|
|
746
|
+
// (a record set aside keeps the rollback target as it was: what this
|
|
747
|
+
// install replaces is not known)
|
|
748
|
+
if (!sameRelease && setAside == null) fs.rmSync(where.previous, {recursive: true, force: true});
|
|
749
|
+
if (!sameRelease && hadApp && previous != null) {
|
|
750
|
+
fs.mkdirSync(where.previous, {recursive: true});
|
|
751
|
+
fs.renameSync(old, where.previousApp);
|
|
752
|
+
// the record as it was, held packs too. A home migrated now keeps its
|
|
753
|
+
// earlier packs.json there, which rollback refuses: the kept release
|
|
754
|
+
// predates the module store (section 10)
|
|
755
|
+
if (home.migrating != null) writeRecord({packs: where.previousRecord}, home.migrating);
|
|
756
|
+
else fs.copyFileSync(where.modulesRecord, where.previousModulesRecord);
|
|
757
|
+
}
|
|
758
|
+
fs.rmSync(old, {recursive: true, force: true});
|
|
759
|
+
} finally {
|
|
760
|
+
fs.rmSync(build, {recursive: true, force: true});
|
|
761
|
+
}
|
|
762
|
+
// (0600 whatever an older one was: the reviewer's high on #126, L6; a
|
|
763
|
+
// launcher that is a link is removed first, never written through: F8)
|
|
764
|
+
try { if (fs.lstatSync(where.launcher).isSymbolicLink()) fs.unlinkSync(where.launcher); } catch (err) { /* none yet */ }
|
|
765
|
+
writeAtomic(where.launcher, shim(path.join(where.app, 'node_modules', ...SELF.split('/'), 'bin', 'ch-local.js'), where.home), {mode: 0o600});
|
|
766
|
+
// (what upgrade --check found was for the release before this one)
|
|
767
|
+
require('./upgrade').forgetAvailable(where);
|
|
768
|
+
// what the shared runtime's native shim runs (countinghouse #236, section 6).
|
|
769
|
+
// The automatic upgrade never writes it: its environment is the session's
|
|
770
|
+
// (a client config's PATH, HOME, TMPDIR), which the shared daemon would
|
|
771
|
+
// give every client (the review of #48). One missing or invalid there is
|
|
772
|
+
// left, recorded and said: an install from the command repairs it.
|
|
773
|
+
if (allow.keepShimJson === true) {
|
|
774
|
+
if (!shimJsonKept(where.home, io.platform)) {
|
|
775
|
+
require('./history').appendHistory(where, {change: 'shim.json', notice: shimJsonRepair(where)});
|
|
776
|
+
say(shimJsonRepair(where));
|
|
777
|
+
}
|
|
778
|
+
} else {
|
|
779
|
+
require('./shim-config').writeShimJson(where.home, {node: io.node, env: io.env, platform: io.platform});
|
|
780
|
+
}
|
|
781
|
+
// the shim, placed (or set aside) and named in the record it writes
|
|
782
|
+
shimStep(where, shimReady, built, io, {say, fail}, report);
|
|
783
|
+
const listedNow = (name) => own(allow.packs || {}, name);
|
|
784
|
+
const written = writeRecordAsIs(where.modulesRecord, built);
|
|
785
|
+
guard.written = true;
|
|
786
|
+
// the migration ends here: modules.json is the home's record, holding
|
|
787
|
+
// only the packs these pins list, reinstalled. Every other pack of the
|
|
788
|
+
// earlier record (unlisted, unpinned, held, withdrawn) is not carried
|
|
789
|
+
// over: named, and the earlier ch-local's packs/ directory is kept whole
|
|
790
|
+
// beside the home, never collected, so nothing is deleted (the Reviewer's
|
|
791
|
+
// round on #83: one rule)
|
|
792
|
+
if (home.migrating != null) {
|
|
793
|
+
fs.rmSync(where.packs, {force: true});
|
|
794
|
+
say('this home\'s record is now modules.json, its packs\' modules in the module store');
|
|
795
|
+
// its pack.* settings become enabled.<module> in the same operation
|
|
796
|
+
// (section 10); a failure here is said, never undoes the install (start
|
|
797
|
+
// still reads pack.<name> as its module's entry, off winning)
|
|
798
|
+
try {
|
|
799
|
+
for (const mv of require('./settings').migratePackSettings(where, written)) say(`${mv.setting} is now ${mv.to}`);
|
|
800
|
+
} catch (err) {
|
|
801
|
+
say(`the settings' pack.* names were not moved (${err.code || err.message}); they are still read as their modules' entries`);
|
|
802
|
+
}
|
|
803
|
+
// each pack of the earlier record not carried over, once, with why
|
|
804
|
+
// (the medium review of the Reviewer's round, 5 to 7)
|
|
805
|
+
const old = home.migrating;
|
|
806
|
+
const named = [...new Set([...Object.keys(old.packs || {}), ...Object.keys(old.held || {})])].filter((n) => !after.touched.includes(n));
|
|
807
|
+
for (const name of named) {
|
|
808
|
+
const spec = own(allow.packs || {}, name) ? allow.packs[name] : null;
|
|
809
|
+
const addAgain = chLocal(where, `install --pack ${name}`);
|
|
810
|
+
const why = spec == null ? `add it again with \`${addAgain}\` once a release lists it`
|
|
811
|
+
: !spec.modules.every((m) => allow.pins[m] != null) ? `these pins do not pin all of its modules; add it again with \`${addAgain}\` with pins that do`
|
|
812
|
+
: `add it again with \`${addAgain}\``;
|
|
813
|
+
say(`not carried over: ${name}; ${why}`);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
// the earlier ch-local's pack trees: never deleted, kept aside whole once
|
|
817
|
+
// no start from before uses them (lib/gc.js keepOldTreesAside)
|
|
818
|
+
const aside = keepOldTreesAside(where, {alive: io.alive, hostname: io.hostname});
|
|
819
|
+
if (aside.keptAt != null) say(`the earlier packs' files are kept at ${aside.keptAt}`);
|
|
820
|
+
else if (aside.waiting === true) say('the earlier packs\' files stay in place while a client from before runs from them; a later install keeps them aside');
|
|
821
|
+
else if (aside.problem != null) fail(aside.problem);
|
|
822
|
+
fs.rmSync(where.installed, {force: true});
|
|
823
|
+
collectStore(where, {alive: io.alive, hostname: io.hostname});
|
|
824
|
+
// a module this pack shares with an installed pack, at the same pin, was
|
|
825
|
+
// not installed again
|
|
826
|
+
const sharedWith = (name) => allow.packs[name].modules.filter((m) => bytes[m] == null && previous != null &&
|
|
827
|
+
Object.entries(previous.packs).some(([p, e]) => p !== name && e.modules[m] === allow.pins[m].version));
|
|
828
|
+
if (pack != null) {
|
|
829
|
+
say(`installed the pack "${pack}" into ${where.moduleStore}; clients run ${where.launcher}`);
|
|
830
|
+
// as the table decided it, when it ran (add-pack's set and text)
|
|
831
|
+
const shared = tableRan ? table.sharedOf(rows) : sharedWith(pack);
|
|
832
|
+
if (shared.length > 0) say(table.sharesText(shared));
|
|
833
|
+
for (const line of table.changedLines(rows, pack, where)) say(line);
|
|
834
|
+
} else {
|
|
835
|
+
say(`installed ${SELF} ${runtimeVersions[SELF]}; clients run ${where.launcher}`);
|
|
836
|
+
}
|
|
837
|
+
for (const name of after.touched) if (name !== pack) say(`the pack "${name}" is at this release's pins`);
|
|
838
|
+
for (const name of Object.keys(written.packs).filter((n) => !listedNow(n) && eff.unreleased !== true)) say(require('./packs').withdrawnStatusLine(name, where));
|
|
839
|
+
// a pack held after a rollback that this release lists: add-pack brings it
|
|
840
|
+
// back (the medium review of L1a-2, 2)
|
|
841
|
+
for (const name of Object.keys(written.held || {}).filter(listedNow)) say(require('./packs').relistedLine(name, where));
|
|
842
|
+
if (eff.unreleased) io.stderr.write(`ch-local: ${UNRELEASED_LINE}\n`);
|
|
843
|
+
return 0;
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
module.exports = {HOME_UNSAFE, unsafeHomeLine, install, tarballName, loadTarballs, appManifest, shimJsonKept, shimJsonRepair, HOME_CHANGED, launcherText: shim};
|