@eloxiv/cli 0.0.0-stage → 0.1.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 +21 -0
- package/README.md +12 -2
- package/dist/AgentSkills.d.ts +51 -0
- package/dist/AgentSkills.d.ts.map +1 -0
- package/dist/AgentSkills.js +264 -0
- package/dist/AgentSkills.js.map +1 -0
- package/dist/AgentWeb.d.ts +83 -0
- package/dist/AgentWeb.d.ts.map +1 -0
- package/dist/AgentWeb.js +436 -0
- package/dist/AgentWeb.js.map +1 -0
- package/dist/App.d.ts +213 -0
- package/dist/App.d.ts.map +1 -0
- package/dist/App.js +357 -0
- package/dist/App.js.map +1 -0
- package/dist/Blueprint.d.ts +47 -0
- package/dist/Blueprint.d.ts.map +1 -0
- package/dist/Blueprint.js +241 -0
- package/dist/Blueprint.js.map +1 -0
- package/dist/Brand.d.ts +42 -0
- package/dist/Brand.d.ts.map +1 -0
- package/dist/Brand.js +370 -0
- package/dist/Brand.js.map +1 -0
- package/dist/Changelog.d.ts +22 -0
- package/dist/Changelog.d.ts.map +1 -0
- package/dist/Changelog.js +117 -0
- package/dist/Changelog.js.map +1 -0
- package/dist/Cli.d.ts +17 -0
- package/dist/Cli.d.ts.map +1 -0
- package/dist/Cli.js +810 -0
- package/dist/Cli.js.map +1 -0
- package/dist/DbAdmin.d.ts +18 -0
- package/dist/DbAdmin.d.ts.map +1 -0
- package/dist/DbAdmin.js +91 -0
- package/dist/DbAdmin.js.map +1 -0
- package/dist/Dependencies.d.ts +53 -0
- package/dist/Dependencies.d.ts.map +1 -0
- package/dist/Dependencies.js +132 -0
- package/dist/Dependencies.js.map +1 -0
- package/dist/Deploy.d.ts +39 -0
- package/dist/Deploy.d.ts.map +1 -0
- package/dist/Deploy.js +458 -0
- package/dist/Deploy.js.map +1 -0
- package/dist/Docs.d.ts +71 -0
- package/dist/Docs.d.ts.map +1 -0
- package/dist/Docs.js +240 -0
- package/dist/Docs.js.map +1 -0
- package/dist/Doctor.d.ts +56 -0
- package/dist/Doctor.d.ts.map +1 -0
- package/dist/Doctor.js +368 -0
- package/dist/Doctor.js.map +1 -0
- package/dist/Dossier.d.ts +23 -0
- package/dist/Dossier.d.ts.map +1 -0
- package/dist/Dossier.js +92 -0
- package/dist/Dossier.js.map +1 -0
- package/dist/Emit.d.ts +26 -0
- package/dist/Emit.d.ts.map +1 -0
- package/dist/Emit.js +51 -0
- package/dist/Emit.js.map +1 -0
- package/dist/Errors.d.ts +26 -0
- package/dist/Errors.d.ts.map +1 -0
- package/dist/Errors.js +17 -0
- package/dist/Errors.js.map +1 -0
- package/dist/Evals.d.ts +52 -0
- package/dist/Evals.d.ts.map +1 -0
- package/dist/Evals.js +126 -0
- package/dist/Evals.js.map +1 -0
- package/dist/Files.d.ts +47 -0
- package/dist/Files.d.ts.map +1 -0
- package/dist/Files.js +145 -0
- package/dist/Files.js.map +1 -0
- package/dist/Generate.d.ts +80 -0
- package/dist/Generate.d.ts.map +1 -0
- package/dist/Generate.js +310 -0
- package/dist/Generate.js.map +1 -0
- package/dist/Guards.d.ts +45 -0
- package/dist/Guards.d.ts.map +1 -0
- package/dist/Guards.js +530 -0
- package/dist/Guards.js.map +1 -0
- package/dist/Inspect.d.ts +125 -0
- package/dist/Inspect.d.ts.map +1 -0
- package/dist/Inspect.js +270 -0
- package/dist/Inspect.js.map +1 -0
- package/dist/Keychain.d.ts +57 -0
- package/dist/Keychain.d.ts.map +1 -0
- package/dist/Keychain.js +73 -0
- package/dist/Keychain.js.map +1 -0
- package/dist/Lock.d.ts +13 -0
- package/dist/Lock.d.ts.map +1 -0
- package/dist/Lock.js +145 -0
- package/dist/Lock.js.map +1 -0
- package/dist/Mcp.d.ts +91 -0
- package/dist/Mcp.d.ts.map +1 -0
- package/dist/Mcp.js +128 -0
- package/dist/Mcp.js.map +1 -0
- package/dist/Merge.d.ts +18 -0
- package/dist/Merge.d.ts.map +1 -0
- package/dist/Merge.js +43 -0
- package/dist/Merge.js.map +1 -0
- package/dist/Migrate.d.ts +78 -0
- package/dist/Migrate.d.ts.map +1 -0
- package/dist/Migrate.js +288 -0
- package/dist/Migrate.js.map +1 -0
- package/dist/Plugins.d.ts +36 -0
- package/dist/Plugins.d.ts.map +1 -0
- package/dist/Plugins.js +304 -0
- package/dist/Plugins.js.map +1 -0
- package/dist/Postgres.d.ts +73 -0
- package/dist/Postgres.d.ts.map +1 -0
- package/dist/Postgres.js +294 -0
- package/dist/Postgres.js.map +1 -0
- package/dist/Publish.d.ts +23 -0
- package/dist/Publish.d.ts.map +1 -0
- package/dist/Publish.js +59 -0
- package/dist/Publish.js.map +1 -0
- package/dist/Registry.d.ts +539 -0
- package/dist/Registry.d.ts.map +1 -0
- package/dist/Registry.js +340 -0
- package/dist/Registry.js.map +1 -0
- package/dist/Remote.d.ts +90 -0
- package/dist/Remote.d.ts.map +1 -0
- package/dist/Remote.js +1006 -0
- package/dist/Remote.js.map +1 -0
- package/dist/Run.d.ts +120 -0
- package/dist/Run.d.ts.map +1 -0
- package/dist/Run.js +477 -0
- package/dist/Run.js.map +1 -0
- package/dist/SyncGen.d.ts +118 -0
- package/dist/SyncGen.d.ts.map +1 -0
- package/dist/SyncGen.js +392 -0
- package/dist/SyncGen.js.map +1 -0
- package/dist/Update.d.ts +301 -0
- package/dist/Update.d.ts.map +1 -0
- package/dist/Update.js +627 -0
- package/dist/Update.js.map +1 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +42 -0
- package/dist/bin.js.map +1 -0
- package/dist/docs/backlog.md +56 -0
- package/dist/docs/ci.md +277 -0
- package/dist/docs/cli.md +696 -0
- package/dist/docs/connectors/google.md +115 -0
- package/dist/docs/connectors/http-openapi.md +7 -0
- package/dist/docs/connectors/mcp.md +8 -0
- package/dist/docs/connectors/microsoft-graph.md +75 -0
- package/dist/docs/connectors/openai.md +25 -0
- package/dist/docs/connectors/slack.md +162 -0
- package/dist/docs/connectors/workos.md +39 -0
- package/dist/docs/contracts/README.md +173 -0
- package/dist/docs/contracts/action-consent.md +92 -0
- package/dist/docs/contracts/action-registry.md +85 -0
- package/dist/docs/contracts/actor.md +100 -0
- package/dist/docs/contracts/agent-resources.md +90 -0
- package/dist/docs/contracts/agent-runtime.md +257 -0
- package/dist/docs/contracts/approvals.md +126 -0
- package/dist/docs/contracts/audit.md +75 -0
- package/dist/docs/contracts/auth-provider.md +74 -0
- package/dist/docs/contracts/calendar-provider.md +46 -0
- package/dist/docs/contracts/client-sdk.md +245 -0
- package/dist/docs/contracts/collab-document.md +151 -0
- package/dist/docs/contracts/command.md +44 -0
- package/dist/docs/contracts/connections.md +235 -0
- package/dist/docs/contracts/context-accounting.md +50 -0
- package/dist/docs/contracts/daemon.md +243 -0
- package/dist/docs/contracts/db-tx.md +53 -0
- package/dist/docs/contracts/delegation.md +68 -0
- package/dist/docs/contracts/device-control.md +103 -0
- package/dist/docs/contracts/directory-provider.md +36 -0
- package/dist/docs/contracts/directory.md +161 -0
- package/dist/docs/contracts/document-source.md +33 -0
- package/dist/docs/contracts/files.md +115 -0
- package/dist/docs/contracts/flags.md +83 -0
- package/dist/docs/contracts/host.md +68 -0
- package/dist/docs/contracts/http-api.md +43 -0
- package/dist/docs/contracts/ingestion.md +130 -0
- package/dist/docs/contracts/ingress.md +141 -0
- package/dist/docs/contracts/invocation.md +260 -0
- package/dist/docs/contracts/local-client.md +108 -0
- package/dist/docs/contracts/locale.md +56 -0
- package/dist/docs/contracts/machine-identity.md +117 -0
- package/dist/docs/contracts/mail-provider.md +49 -0
- package/dist/docs/contracts/memory.md +53 -0
- package/dist/docs/contracts/messaging.md +40 -0
- package/dist/docs/contracts/metering.md +139 -0
- package/dist/docs/contracts/model-provider.md +84 -0
- package/dist/docs/contracts/module-manifest.md +213 -0
- package/dist/docs/contracts/notification-channel.md +90 -0
- package/dist/docs/contracts/notifications.md +123 -0
- package/dist/docs/contracts/outbox.md +80 -0
- package/dist/docs/contracts/privacy.md +110 -0
- package/dist/docs/contracts/progress.md +52 -0
- package/dist/docs/contracts/query-surface.md +108 -0
- package/dist/docs/contracts/readiness.md +63 -0
- package/dist/docs/contracts/release.md +142 -0
- package/dist/docs/contracts/result-rendering.md +61 -0
- package/dist/docs/contracts/sandbox.md +186 -0
- package/dist/docs/contracts/scheduler.md +148 -0
- package/dist/docs/contracts/screen-context.md +81 -0
- package/dist/docs/contracts/search.md +120 -0
- package/dist/docs/contracts/secrets.md +74 -0
- package/dist/docs/contracts/settings.md +109 -0
- package/dist/docs/contracts/sharing.md +77 -0
- package/dist/docs/contracts/slot.md +48 -0
- package/dist/docs/contracts/space.md +67 -0
- package/dist/docs/contracts/storage-adapter.md +45 -0
- package/dist/docs/contracts/storage-backend.md +56 -0
- package/dist/docs/contracts/sync.md +213 -0
- package/dist/docs/contracts/telemetry.md +80 -0
- package/dist/docs/contracts/theme-tokens.md +50 -0
- package/dist/docs/contracts/tool-source.md +58 -0
- package/dist/docs/contracts/versioning.md +99 -0
- package/dist/docs/contracts/view.md +65 -0
- package/dist/docs/contracts/work-items.md +99 -0
- package/dist/docs/contracts/workflow.md +82 -0
- package/dist/docs/decisions.md +163 -0
- package/dist/docs/example-app.md +192 -0
- package/dist/docs/getting-started.md +927 -0
- package/dist/docs/goal.md +54 -0
- package/dist/docs/parity.md +29 -0
- package/dist/docs/performance.md +129 -0
- package/dist/docs/registry/README.md +74 -0
- package/dist/docs/registry/app.md +38 -0
- package/dist/docs/registry/approvals-ui-foldkit.md +28 -0
- package/dist/docs/registry/calendar-ui-foldkit.md +27 -0
- package/dist/docs/registry/calendar.md +35 -0
- package/dist/docs/registry/chat-ui-foldkit.md +30 -0
- package/dist/docs/registry/desktop-rune.md +49 -0
- package/dist/docs/registry/desktop.md +32 -0
- package/dist/docs/registry/eloxiv-action.md +25 -0
- package/dist/docs/registry/eloxiv-connector.md +25 -0
- package/dist/docs/registry/eloxiv-module.md +25 -0
- package/dist/docs/registry/eloxiv-policy.md +25 -0
- package/dist/docs/registry/eloxiv-view.md +25 -0
- package/dist/docs/registry/hello-ui-foldkit.md +29 -0
- package/dist/docs/registry/hello.md +39 -0
- package/dist/docs/registry/home-ui-foldkit.md +27 -0
- package/dist/docs/registry/home.md +29 -0
- package/dist/docs/registry/inbox-ui-foldkit.md +27 -0
- package/dist/docs/registry/mail-ui-foldkit.md +27 -0
- package/dist/docs/registry/mail.md +34 -0
- package/dist/docs/registry/meeting-prep.md +26 -0
- package/dist/docs/registry/members-ui-foldkit.md +28 -0
- package/dist/docs/registry/mobile.md +37 -0
- package/dist/docs/registry/notes-ui-foldkit.md +27 -0
- package/dist/docs/registry/notes.md +26 -0
- package/dist/docs/registry/people-ui-foldkit.md +28 -0
- package/dist/docs/registry/people.md +38 -0
- package/dist/docs/registry/shell-foldkit.md +34 -0
- package/dist/docs/registry/theme.md +25 -0
- package/dist/docs/registry/ui-conformance.md +30 -0
- package/dist/docs/release.md +100 -0
- package/dist/docs/scaffold.md +826 -0
- package/dist/docs/security/threat-model.md +299 -0
- package/dist/docs/upstream/zero-cache-socket-handoff.md +105 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -3
- package/src/AgentSkills.ts +329 -0
- package/src/AgentWeb.ts +507 -0
- package/src/App.ts +435 -0
- package/src/Blueprint.ts +276 -0
- package/src/Brand.ts +415 -0
- package/src/Changelog.ts +136 -0
- package/src/Cli.ts +1458 -0
- package/src/DbAdmin.ts +115 -0
- package/src/Dependencies.ts +170 -0
- package/src/Deploy.ts +563 -0
- package/src/Docs.ts +309 -0
- package/src/Doctor.ts +424 -0
- package/src/Dossier.ts +148 -0
- package/src/Emit.ts +68 -0
- package/src/Errors.ts +18 -0
- package/src/Evals.ts +153 -0
- package/src/Files.ts +152 -0
- package/src/Generate.ts +402 -0
- package/src/Guards.ts +541 -0
- package/src/Inspect.ts +358 -0
- package/src/Keychain.ts +107 -0
- package/src/Lock.ts +174 -0
- package/src/Mcp.ts +159 -0
- package/src/Merge.ts +70 -0
- package/src/Migrate.ts +331 -0
- package/src/Plugins.ts +347 -0
- package/src/Postgres.ts +353 -0
- package/src/Publish.ts +64 -0
- package/src/Registry.ts +405 -0
- package/src/Remote.ts +1158 -0
- package/src/Run.ts +541 -0
- package/src/SyncGen.ts +570 -0
- package/src/Update.ts +873 -0
- package/src/bin.ts +46 -0
- package/src/index.ts +7 -0
package/dist/Update.js
ADDED
|
@@ -0,0 +1,627 @@
|
|
|
1
|
+
import { applyMigrations, formatMigrationChanges, migrationsBetween, } from "./Migrate.js";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { CliError, installItems, lockPath, publishedFiles, readConfig, readLock, readPackage, regenerate, writeLock, writePackage, } from "./App.js";
|
|
4
|
+
import { applyChanges, entriesOf, fieldLabel, formatNpmChange, PACKAGE_FIELDS, planAdded, planMerge, writesPackage, } from "./Dependencies.js";
|
|
5
|
+
import { asText, bytesEqualText, isMergeableText, readAppBytes, removeAppFile, sha256Bytes, writablePath, writeAppFile, } from "./Files.js";
|
|
6
|
+
import { hasConflictMarkers, mergeText, unifiedDiff } from "./Merge.js";
|
|
7
|
+
import { contentHash, decodeItem, deprecationText, fetchDeprecations, fetchItem, readRegistryText, redactToken, RegistryError, resolveItems, targetOf, verifyImmutable, versionPath, } from "./Registry.js";
|
|
8
|
+
const fromRegistry = (e) => new CliError({ message: e.message });
|
|
9
|
+
/** The entries for `names` (every installed item when empty), refusing names that are not installed. */
|
|
10
|
+
export const selectEntries = (lock, names) => Effect.gen(function* () {
|
|
11
|
+
if (names.length === 0)
|
|
12
|
+
return Object.values(lock.items);
|
|
13
|
+
const missing = names.filter((name) => lock.items[name] === undefined);
|
|
14
|
+
if (missing.length > 0)
|
|
15
|
+
return yield* new CliError({ message: `Not installed: ${missing.join(", ")} (use \`eloxiv add\`)` });
|
|
16
|
+
return names.map((name) => lock.items[name]);
|
|
17
|
+
});
|
|
18
|
+
export const kindOf = (entry) => entry.meta?.["kind"] ?? "app";
|
|
19
|
+
/** Fetch the exact version the app installed, and check it is what the lock says was installed. */
|
|
20
|
+
export const fetchBase = Effect.fn("Update.fetchBase")(function* (registry, entry) {
|
|
21
|
+
const relative = entry.item ?? versionPath(entry.name, entry.registryVersion);
|
|
22
|
+
const text = yield* readRegistryText(registry, relative).pipe(Effect.option);
|
|
23
|
+
if (text._tag === "None")
|
|
24
|
+
return undefined;
|
|
25
|
+
const item = yield* decodeItem(text.value, `${entry.name}@${entry.registryVersion}`).pipe(Effect.mapError(fromRegistry));
|
|
26
|
+
const hash = yield* contentHash(item);
|
|
27
|
+
if (hash !== entry.contentHash) {
|
|
28
|
+
return yield* new CliError({
|
|
29
|
+
message: `The registry's ${relative} (sha256 ${hash.slice(0, 12)}) is not what the lock says was installed (${entry.contentHash.slice(0, 12)}); a published version must never change`,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return item;
|
|
33
|
+
});
|
|
34
|
+
const contents = (item) => new Map((item?.files ?? []).map((file) => [targetOf(file), file.content]));
|
|
35
|
+
/** Where the new version of a binary file changed on both sides is written, beside the app's file. */
|
|
36
|
+
export const upstreamCopy = (path) => `${path}.upstream`;
|
|
37
|
+
/**
|
|
38
|
+
* Files of an item holding conflict markers the published version did not have: recorded content
|
|
39
|
+
* conflicts, and any locally edited file (an update that stopped before it could record them).
|
|
40
|
+
*/
|
|
41
|
+
const filesWithMarkers = Effect.fn("Update.filesWithMarkers")(function* (dir, entry) {
|
|
42
|
+
const recorded = new Set((entry.conflicts ?? []).filter((c) => c.reason === "content").map((conflict) => lockPath(conflict.path)));
|
|
43
|
+
const published = new Map(entry.files.map((file) => [lockPath(file.path), file.sha256]));
|
|
44
|
+
const found = [];
|
|
45
|
+
for (const path of new Set([...recorded, ...published.keys()])) {
|
|
46
|
+
const bytes = yield* readAppBytes(dir, path);
|
|
47
|
+
if (bytes === undefined)
|
|
48
|
+
continue;
|
|
49
|
+
const text = asText(bytes);
|
|
50
|
+
if (text === undefined || !hasConflictMarkers(text))
|
|
51
|
+
continue;
|
|
52
|
+
if (recorded.has(path) || (yield* sha256Bytes(bytes)) !== published.get(path))
|
|
53
|
+
found.push(path);
|
|
54
|
+
}
|
|
55
|
+
return found;
|
|
56
|
+
});
|
|
57
|
+
const dependencyChanges = (base, theirs) => {
|
|
58
|
+
const changes = [];
|
|
59
|
+
for (const field of PACKAGE_FIELDS) {
|
|
60
|
+
const before = entriesOf(base, field);
|
|
61
|
+
const after = entriesOf(theirs, field);
|
|
62
|
+
for (const [name, to] of after) {
|
|
63
|
+
const from = before.get(name);
|
|
64
|
+
if (from !== to)
|
|
65
|
+
changes.push(from === undefined ? { field, name, to } : { field, name, from, to });
|
|
66
|
+
}
|
|
67
|
+
for (const [name, from] of before)
|
|
68
|
+
if (!after.has(name))
|
|
69
|
+
changes.push({ field, name, from });
|
|
70
|
+
}
|
|
71
|
+
return changes;
|
|
72
|
+
};
|
|
73
|
+
const registryDependencyChanges = (base, theirs) => {
|
|
74
|
+
const before = new Set(base.registryDependencies ?? []);
|
|
75
|
+
const after = new Set(theirs.registryDependencies ?? []);
|
|
76
|
+
return { added: [...after].filter((d) => !before.has(d)), removed: [...before].filter((d) => !after.has(d)) };
|
|
77
|
+
};
|
|
78
|
+
const diffItem = Effect.fn("Update.diffItem")(function* (dir, registry, entry, deprecations) {
|
|
79
|
+
const deprecation = deprecations[entry.name];
|
|
80
|
+
const deprecated = deprecation === undefined ? {} : { deprecated: deprecationText(entry.name, deprecation) };
|
|
81
|
+
const installed = { version: entry.registryVersion, contentHash: entry.contentHash };
|
|
82
|
+
const empty = { added: [], removed: [] };
|
|
83
|
+
const owner = entry.owner ?? "registry";
|
|
84
|
+
if (owner === "app") {
|
|
85
|
+
return {
|
|
86
|
+
name: entry.name,
|
|
87
|
+
kind: kindOf(entry),
|
|
88
|
+
owner,
|
|
89
|
+
installed,
|
|
90
|
+
latest: null,
|
|
91
|
+
conflicts: [],
|
|
92
|
+
local: [],
|
|
93
|
+
upstream: [],
|
|
94
|
+
dependencies: [],
|
|
95
|
+
registryDependencies: empty,
|
|
96
|
+
baseAvailable: false,
|
|
97
|
+
...deprecated,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
const base = yield* fetchBase(registry, entry);
|
|
101
|
+
const baseFiles = contents(base);
|
|
102
|
+
const label = `${entry.name}@${entry.registryVersion}`;
|
|
103
|
+
const local = [];
|
|
104
|
+
for (const file of entry.files) {
|
|
105
|
+
const path = lockPath(file.path);
|
|
106
|
+
const bytes = yield* readAppBytes(dir, path);
|
|
107
|
+
if (bytes !== undefined && (yield* sha256Bytes(bytes)) === file.sha256)
|
|
108
|
+
continue;
|
|
109
|
+
if (bytes === undefined) {
|
|
110
|
+
local.push({ path, change: "deleted" });
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const current = asText(bytes);
|
|
114
|
+
const before = baseFiles.get(path);
|
|
115
|
+
if (current === undefined)
|
|
116
|
+
local.push({ path, change: "modified", binary: true });
|
|
117
|
+
else if (before === undefined)
|
|
118
|
+
local.push({ path, change: "modified" });
|
|
119
|
+
else
|
|
120
|
+
local.push({
|
|
121
|
+
path,
|
|
122
|
+
change: "modified",
|
|
123
|
+
diff: unifiedDiff(path, before, current, { before: label, after: "app" }),
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
const latestItem = yield* fetchItem(registry, entry.name).pipe(Effect.map((item) => item), Effect.catchTag("RegistryError", () => Effect.succeed(undefined)));
|
|
127
|
+
const latestHash = latestItem === undefined ? undefined : yield* contentHash(latestItem);
|
|
128
|
+
const latest = latestItem === undefined || latestHash === undefined
|
|
129
|
+
? null
|
|
130
|
+
: { version: latestItem.meta.eloxiv.version, contentHash: latestHash };
|
|
131
|
+
const upstream = [];
|
|
132
|
+
let dependencies = [];
|
|
133
|
+
let registryDependencies = empty;
|
|
134
|
+
// Without the base, only the new version number is known: per-file upstream changes need the base.
|
|
135
|
+
if (base !== undefined && latestItem !== undefined && latest !== null && latest.contentHash !== entry.contentHash) {
|
|
136
|
+
const after = contents(latestItem);
|
|
137
|
+
const theirsLabel = `${entry.name}@${latest.version}`;
|
|
138
|
+
for (const path of [...new Set([...baseFiles.keys(), ...after.keys()])].sort()) {
|
|
139
|
+
const before = baseFiles.get(path);
|
|
140
|
+
const next = after.get(path);
|
|
141
|
+
if (before === next)
|
|
142
|
+
continue;
|
|
143
|
+
upstream.push({
|
|
144
|
+
path,
|
|
145
|
+
change: before === undefined ? "added" : next === undefined ? "removed" : "modified",
|
|
146
|
+
diff: unifiedDiff(path, before, next, { before: label, after: theirsLabel }),
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
dependencies = dependencyChanges(base, latestItem);
|
|
150
|
+
registryDependencies = registryDependencyChanges(base, latestItem);
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
name: entry.name,
|
|
154
|
+
kind: kindOf(entry),
|
|
155
|
+
owner,
|
|
156
|
+
installed,
|
|
157
|
+
latest,
|
|
158
|
+
conflicts: entry.conflicts ?? [],
|
|
159
|
+
local,
|
|
160
|
+
upstream,
|
|
161
|
+
dependencies,
|
|
162
|
+
registryDependencies,
|
|
163
|
+
baseAvailable: base !== undefined,
|
|
164
|
+
...deprecated,
|
|
165
|
+
};
|
|
166
|
+
});
|
|
167
|
+
const itemDiffers = (item) => item.owner === "registry" &&
|
|
168
|
+
(item.local.length > 0 ||
|
|
169
|
+
item.conflicts.length > 0 ||
|
|
170
|
+
item.upstream.length > 0 ||
|
|
171
|
+
item.dependencies.length > 0 ||
|
|
172
|
+
item.registryDependencies.added.length > 0 ||
|
|
173
|
+
item.registryDependencies.removed.length > 0 ||
|
|
174
|
+
(item.latest !== null && item.latest.contentHash !== item.installed.contentHash));
|
|
175
|
+
/** Compare installed items with their installed base (local edits) and the registry's latest (upstream). */
|
|
176
|
+
export const diff = Effect.fn("Update.diff")(function* (dir, names) {
|
|
177
|
+
const { registry } = yield* readConfig(dir);
|
|
178
|
+
const lock = yield* readLock(dir);
|
|
179
|
+
const items = [];
|
|
180
|
+
const deprecations = yield* fetchDeprecations(registry).pipe(Effect.mapError(fromRegistry));
|
|
181
|
+
for (const entry of yield* selectEntries(lock, names))
|
|
182
|
+
items.push(yield* diffItem(dir, registry, entry, deprecations));
|
|
183
|
+
return { items, differences: items.some(itemDiffers) };
|
|
184
|
+
});
|
|
185
|
+
export const formatDiff = (report, options) => {
|
|
186
|
+
const out = [];
|
|
187
|
+
for (const item of report.items) {
|
|
188
|
+
const head = `${item.name} (${item.kind}) ${item.installed.version}`;
|
|
189
|
+
if (item.owner === "app") {
|
|
190
|
+
out.push(`${head}: app-owned (eloxiv eject); not compared`);
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
const behind = item.latest !== null && item.latest.contentHash !== item.installed.contentHash;
|
|
194
|
+
const state = [
|
|
195
|
+
item.local.length > 0 ? `${item.local.length} locally edited` : "no local edits",
|
|
196
|
+
item.latest === null
|
|
197
|
+
? "not in the registry any more"
|
|
198
|
+
: behind
|
|
199
|
+
? `${item.latest.version} available`
|
|
200
|
+
: "up to date",
|
|
201
|
+
...(item.conflicts.length > 0 ? [`${item.conflicts.length} unresolved conflicts`] : []),
|
|
202
|
+
];
|
|
203
|
+
out.push(`${head}: ${state.join(", ")}`);
|
|
204
|
+
if (item.deprecated !== undefined)
|
|
205
|
+
out.push(` deprecated ${item.deprecated}`);
|
|
206
|
+
for (const conflict of item.conflicts)
|
|
207
|
+
out.push(` conflict ${conflict.path} (${conflict.reason})`);
|
|
208
|
+
for (const change of item.local)
|
|
209
|
+
out.push(` local ${change.change.padEnd(9)}${change.path}${change.binary === true ? " (binary)" : ""}`);
|
|
210
|
+
for (const change of item.upstream)
|
|
211
|
+
out.push(` upstream ${change.change.padEnd(9)}${change.path}`);
|
|
212
|
+
for (const dep of item.dependencies)
|
|
213
|
+
out.push(` upstream ${fieldLabel(dep.field)} ${dep.name} ${dep.from ?? "(none)"} → ${dep.to ?? "(removed)"}`);
|
|
214
|
+
for (const dep of item.registryDependencies.added)
|
|
215
|
+
out.push(` upstream needs registry item ${dep}`);
|
|
216
|
+
for (const dep of item.registryDependencies.removed)
|
|
217
|
+
out.push(` upstream no longer needs registry item ${dep}`);
|
|
218
|
+
if (!item.baseAvailable)
|
|
219
|
+
out.push(` (the installed version is not published in the registry: local edits are shown without diffs, upstream changes not at all, and update cannot merge)`);
|
|
220
|
+
if (!options.patches)
|
|
221
|
+
continue;
|
|
222
|
+
for (const change of item.local)
|
|
223
|
+
if (change.diff !== undefined && change.diff !== "")
|
|
224
|
+
out.push(change.diff.trimEnd());
|
|
225
|
+
for (const change of item.upstream)
|
|
226
|
+
if (change.diff !== "")
|
|
227
|
+
out.push(change.diff.trimEnd());
|
|
228
|
+
}
|
|
229
|
+
if (report.items.length === 0)
|
|
230
|
+
out.push("no items installed");
|
|
231
|
+
return out.join("\n");
|
|
232
|
+
};
|
|
233
|
+
const CONFLICTS = new Set(["conflict", "conflict-binary", "conflict-deleted-locally"]);
|
|
234
|
+
const planFiles = Effect.fn("Update.planFiles")(function* (dir, entry, base, theirs, ownedElsewhere) {
|
|
235
|
+
const before = contents(base);
|
|
236
|
+
const after = contents(theirs);
|
|
237
|
+
const labels = {
|
|
238
|
+
ours: "app",
|
|
239
|
+
base: `${entry.name}@${entry.registryVersion}`,
|
|
240
|
+
theirs: `${entry.name}@${theirs.meta.eloxiv.version}`,
|
|
241
|
+
};
|
|
242
|
+
const plans = [];
|
|
243
|
+
for (const path of [...new Set([...before.keys(), ...after.keys()])].sort()) {
|
|
244
|
+
// Every path the update may write or delete: refused through a symbolic link before anything is written.
|
|
245
|
+
yield* writablePath(dir, path);
|
|
246
|
+
const b = before.get(path);
|
|
247
|
+
const t = after.get(path);
|
|
248
|
+
const o = yield* readAppBytes(dir, path);
|
|
249
|
+
const is = (text) => o !== undefined && bytesEqualText(o, text);
|
|
250
|
+
if (b !== undefined && t !== undefined) {
|
|
251
|
+
if (o === undefined) {
|
|
252
|
+
if (b !== t)
|
|
253
|
+
plans.push({ path, outcome: "conflict-deleted-locally" });
|
|
254
|
+
else
|
|
255
|
+
plans.push({ path, outcome: "deleted-locally" });
|
|
256
|
+
}
|
|
257
|
+
else if (is(b)) {
|
|
258
|
+
if (t !== b)
|
|
259
|
+
plans.push({ path, outcome: "updated", content: t });
|
|
260
|
+
}
|
|
261
|
+
else if (t === b)
|
|
262
|
+
plans.push({ path, outcome: "kept" });
|
|
263
|
+
else if (is(t))
|
|
264
|
+
plans.push({ path, outcome: "already-updated" });
|
|
265
|
+
else {
|
|
266
|
+
const ours = asText(o);
|
|
267
|
+
if (ours !== undefined && isMergeableText(b) && isMergeableText(t)) {
|
|
268
|
+
const merged = mergeText(ours, b, t, labels);
|
|
269
|
+
plans.push({ path, outcome: merged.clean ? "merged" : "conflict", content: merged.text });
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
// Binary: never line-merged. The app's file stays; the new version goes beside it.
|
|
273
|
+
const upstream = upstreamCopy(path);
|
|
274
|
+
yield* writablePath(dir, upstream);
|
|
275
|
+
const existing = yield* readAppBytes(dir, upstream);
|
|
276
|
+
const owner = ownedElsewhere.get(upstream) ?? (after.has(upstream) ? entry.name : undefined);
|
|
277
|
+
if (owner !== undefined)
|
|
278
|
+
plans.push({ path, outcome: "blocked", detail: `${upstream} (of ${owner})` });
|
|
279
|
+
else if (existing !== undefined && !bytesEqualText(existing, t))
|
|
280
|
+
plans.push({ path, outcome: "blocked", detail: `an unrelated local file at ${upstream}` });
|
|
281
|
+
else
|
|
282
|
+
plans.push({ path, outcome: "conflict-binary", content: t, upstream });
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
else if (b !== undefined) {
|
|
287
|
+
// Removed upstream.
|
|
288
|
+
if (o === undefined)
|
|
289
|
+
continue;
|
|
290
|
+
plans.push({ path, outcome: is(b) ? "removed" : "kept-removed-upstream" });
|
|
291
|
+
}
|
|
292
|
+
else if (t !== undefined) {
|
|
293
|
+
// Added upstream.
|
|
294
|
+
const owner = ownedElsewhere.get(path);
|
|
295
|
+
if (owner !== undefined && !is(t))
|
|
296
|
+
plans.push({ path, outcome: "blocked", detail: `belongs to ${owner}` });
|
|
297
|
+
else if (o === undefined)
|
|
298
|
+
plans.push({ path, outcome: "added", content: t });
|
|
299
|
+
else if (is(t))
|
|
300
|
+
plans.push({ path, outcome: "already-updated" });
|
|
301
|
+
else
|
|
302
|
+
plans.push({ path, outcome: "blocked", detail: "an unrelated local file" });
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return plans;
|
|
306
|
+
});
|
|
307
|
+
const planItem = Effect.fn("Update.planItem")(function* (dir, registry, lock, entry, pkg, deprecations) {
|
|
308
|
+
const from = { version: entry.registryVersion, contentHash: entry.contentHash };
|
|
309
|
+
const deprecation = deprecations[entry.name];
|
|
310
|
+
const unchanged = {
|
|
311
|
+
name: entry.name,
|
|
312
|
+
kind: kindOf(entry),
|
|
313
|
+
from,
|
|
314
|
+
files: [],
|
|
315
|
+
installs: [],
|
|
316
|
+
npm: [],
|
|
317
|
+
...(deprecation === undefined ? {} : { deprecated: deprecationText(entry.name, deprecation) }),
|
|
318
|
+
};
|
|
319
|
+
if (entry.owner === "app")
|
|
320
|
+
return { report: { ...unchanged, status: "app-owned" } };
|
|
321
|
+
if ((entry.conflicts ?? []).length > 0)
|
|
322
|
+
return { report: { ...unchanged, status: "unresolved-conflicts" } };
|
|
323
|
+
const theirs = yield* fetchItem(registry, entry.name).pipe(Effect.mapError(fromRegistry));
|
|
324
|
+
const theirsHash = yield* contentHash(theirs);
|
|
325
|
+
const to = { version: theirs.meta.eloxiv.version, contentHash: theirsHash };
|
|
326
|
+
if (theirsHash === entry.contentHash && to.version === entry.registryVersion)
|
|
327
|
+
return { report: { ...unchanged, status: "up-to-date" } };
|
|
328
|
+
if (to.version === entry.registryVersion) {
|
|
329
|
+
return yield* new CliError({
|
|
330
|
+
message: `The registry republished ${entry.name}@${to.version} with different content (${theirsHash.slice(0, 12)}, installed ${entry.contentHash.slice(0, 12)}); refusing to merge against a changed version`,
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
// The new version becomes the next update's base: it must be exactly its immutable copy.
|
|
334
|
+
yield* verifyImmutable(registry, theirs).pipe(Effect.mapError(fromRegistry));
|
|
335
|
+
// Conflict markers the last update could not record: resolve them before merging anything else in.
|
|
336
|
+
const markers = yield* filesWithMarkers(dir, entry);
|
|
337
|
+
if (markers.length > 0)
|
|
338
|
+
return { report: { ...unchanged, status: "unresolved-conflicts", markers } };
|
|
339
|
+
const base = yield* fetchBase(registry, entry);
|
|
340
|
+
if (base === undefined) {
|
|
341
|
+
return yield* new CliError({
|
|
342
|
+
message: `${entry.name}@${entry.registryVersion}, the version this app installed, is not published in ${redactToken(registry)} (expected ${entry.item ?? versionPath(entry.name, entry.registryVersion)}); cannot merge without it`,
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
const ownedElsewhere = new Map(Object.values(lock.items)
|
|
346
|
+
.filter((other) => other.name !== entry.name)
|
|
347
|
+
.flatMap((other) => other.files.map((file) => [lockPath(file.path), other.name])));
|
|
348
|
+
const files = yield* planFiles(dir, entry, base, theirs, ownedElsewhere);
|
|
349
|
+
const missing = (theirs.registryDependencies ?? []).filter((dep) => lock.items[dep] === undefined);
|
|
350
|
+
const installed = missing.length === 0
|
|
351
|
+
? []
|
|
352
|
+
: (yield* resolveItems(registry, missing).pipe(Effect.mapError(fromRegistry))).filter((item) => lock.items[item.name] === undefined);
|
|
353
|
+
// A dependency this item drops goes only if no other installed item asks for it (at its installed version, or
|
|
354
|
+
// being installed with it); with an item the registry cannot describe (an app-owned one), everything stays.
|
|
355
|
+
const others = [...installed];
|
|
356
|
+
let known = true;
|
|
357
|
+
for (const other of Object.values(lock.items)) {
|
|
358
|
+
if (other.name === entry.name)
|
|
359
|
+
continue;
|
|
360
|
+
const item = other.owner === "app" ? undefined : yield* fetchBase(registry, other);
|
|
361
|
+
if (item === undefined)
|
|
362
|
+
known = false;
|
|
363
|
+
else
|
|
364
|
+
others.push(item);
|
|
365
|
+
}
|
|
366
|
+
const needed = (field, name) => !known || others.some((item) => entriesOf(item, field).has(name));
|
|
367
|
+
// One merge into package.json for the item and the items installed with it, keeping the app's pins.
|
|
368
|
+
const own = planMerge(pkg, base, theirs, needed);
|
|
369
|
+
const npm = [...own, ...planAdded(applyChanges(structuredClone(pkg), own), installed, true)];
|
|
370
|
+
const blocked = files.some((file) => file.outcome === "blocked");
|
|
371
|
+
const conflicted = files.some((file) => CONFLICTS.has(file.outcome));
|
|
372
|
+
const status = blocked ? "blocked" : conflicted ? "conflicts" : "updated";
|
|
373
|
+
return {
|
|
374
|
+
report: {
|
|
375
|
+
name: entry.name,
|
|
376
|
+
kind: kindOf(entry),
|
|
377
|
+
status,
|
|
378
|
+
from,
|
|
379
|
+
to,
|
|
380
|
+
files,
|
|
381
|
+
installs: installed.map((item) => item.name),
|
|
382
|
+
npm,
|
|
383
|
+
patches: [
|
|
384
|
+
...new Set([base, theirs].flatMap((item) => Object.values(item.meta.eloxiv.patchedDependencies ?? {}))),
|
|
385
|
+
],
|
|
386
|
+
},
|
|
387
|
+
theirs,
|
|
388
|
+
theirsHash,
|
|
389
|
+
};
|
|
390
|
+
});
|
|
391
|
+
/** The file outcomes that change what is on disk. */
|
|
392
|
+
const WRITTEN = new Set(["updated", "merged", "conflict", "added", "removed"]);
|
|
393
|
+
/**
|
|
394
|
+
* Whether the package manager must run after an update: an item installed with it, an npm dependency added or
|
|
395
|
+
* changed, or a pnpm patch whose entry or file changed or went (pnpm applies a patch only when it installs).
|
|
396
|
+
*/
|
|
397
|
+
export const needsInstall = (report) => report.items.some((item) => item.installs.length > 0 ||
|
|
398
|
+
item.npm.some((change) => change.outcome === "added" ||
|
|
399
|
+
change.outcome === "changed" ||
|
|
400
|
+
(change.field === "patchedDependencies" && change.outcome === "removed")) ||
|
|
401
|
+
item.files.some((file) => WRITTEN.has(file.outcome) && (item.patches ?? []).includes(file.path)));
|
|
402
|
+
const conflictOf = (file) => ({
|
|
403
|
+
path: file.path,
|
|
404
|
+
reason: file.outcome === "conflict" ? "content" : file.outcome === "conflict-binary" ? "binary" : "deleted-locally",
|
|
405
|
+
});
|
|
406
|
+
/**
|
|
407
|
+
* Merge the registry's latest version of `names` (every installed item when empty) into the app. Nothing is
|
|
408
|
+
* written with `dryRun`. An item with a blocked file is not touched at all.
|
|
409
|
+
*
|
|
410
|
+
* Writes are not transactional. An item's conflicts are recorded in the lock before any of its files is
|
|
411
|
+
* written, so an update that stops half-way leaves the item waiting for `update --continue` rather than
|
|
412
|
+
* conflict markers nobody knows about; `--continue` also finds markers that were never recorded.
|
|
413
|
+
*/
|
|
414
|
+
export const update = Effect.fn("Update.update")(function* (dir, names, options) {
|
|
415
|
+
const { config, registry } = yield* readConfig(dir);
|
|
416
|
+
let lock = yield* readLock(dir);
|
|
417
|
+
const reports = [];
|
|
418
|
+
const deprecations = yield* fetchDeprecations(registry).pipe(Effect.mapError(fromRegistry));
|
|
419
|
+
const pending = [];
|
|
420
|
+
for (const selected of yield* selectEntries(lock, names)) {
|
|
421
|
+
// An earlier item's update may have installed this one's dependencies: plan against the current lock.
|
|
422
|
+
const entry = lock.items[selected.name];
|
|
423
|
+
const pkg = yield* readPackage(dir);
|
|
424
|
+
const planned = yield* planItem(dir, registry, lock, entry, pkg, deprecations);
|
|
425
|
+
reports.push(planned.report);
|
|
426
|
+
const { report, theirs, theirsHash } = planned;
|
|
427
|
+
if (theirs !== undefined && (report.status === "updated" || report.status === "conflicts")) {
|
|
428
|
+
for (const migration of migrationsBetween(theirs.meta.eloxiv.migrations ?? [], entry.registryVersion, theirs.meta.eloxiv.version))
|
|
429
|
+
pending.push({ item: entry.name, migration });
|
|
430
|
+
}
|
|
431
|
+
if (options.dryRun || theirs === undefined || theirsHash === undefined)
|
|
432
|
+
continue;
|
|
433
|
+
if (report.status !== "updated" && report.status !== "conflicts")
|
|
434
|
+
continue;
|
|
435
|
+
const conflicts = report.files.filter((file) => CONFLICTS.has(file.outcome)).map(conflictOf);
|
|
436
|
+
if (conflicts.length > 0) {
|
|
437
|
+
// Intent first: if anything below fails, the item still waits for these to be resolved.
|
|
438
|
+
lock.items[entry.name] = { ...entry, conflicts };
|
|
439
|
+
yield* writeLock(dir, lock);
|
|
440
|
+
}
|
|
441
|
+
if (report.installs.length > 0) {
|
|
442
|
+
yield* installItems(dir, report.installs, false, { packageJson: false });
|
|
443
|
+
lock = yield* readLock(dir);
|
|
444
|
+
}
|
|
445
|
+
for (const file of report.files) {
|
|
446
|
+
if (file.content !== undefined)
|
|
447
|
+
yield* writeAppFile(dir, file.upstream ?? file.path, file.content);
|
|
448
|
+
else if (file.outcome === "removed")
|
|
449
|
+
yield* removeAppFile(dir, file.path);
|
|
450
|
+
}
|
|
451
|
+
if (writesPackage(report.npm))
|
|
452
|
+
yield* writePackage(dir, applyChanges(yield* readPackage(dir), report.npm));
|
|
453
|
+
const { conflicts: _previous, ...rest } = entry;
|
|
454
|
+
lock.items[entry.name] = {
|
|
455
|
+
...rest,
|
|
456
|
+
type: theirs.type,
|
|
457
|
+
registry: config.registry,
|
|
458
|
+
registryVersion: theirs.meta.eloxiv.version,
|
|
459
|
+
contentHash: theirsHash,
|
|
460
|
+
files: yield* publishedFiles(theirs),
|
|
461
|
+
meta: theirs.meta.eloxiv,
|
|
462
|
+
item: versionPath(theirs.name, theirs.meta.eloxiv.version),
|
|
463
|
+
updatedFrom: { registryVersion: entry.registryVersion, contentHash: entry.contentHash },
|
|
464
|
+
updatedAt: new Date().toISOString(),
|
|
465
|
+
...(conflicts.length > 0 ? { conflicts } : {}),
|
|
466
|
+
};
|
|
467
|
+
yield* writeLock(dir, lock);
|
|
468
|
+
}
|
|
469
|
+
if (!options.dryRun && reports.some((r) => r.status === "updated" || r.status === "conflicts"))
|
|
470
|
+
yield* regenerate(dir, lock);
|
|
471
|
+
// Compatibility migrations, over the app's own files: not those the update itself writes (they are the new
|
|
472
|
+
// version's already), nor the composition files the CLI generates.
|
|
473
|
+
const written = new Set(reports.flatMap((r) => r.files.filter((f) => WRITTEN.has(f.outcome) && f.outcome !== "conflict").map((f) => f.path)));
|
|
474
|
+
for (const file of ["eloxiv.modules.ts", "eloxiv.server.ts", "eloxiv.schema.ts", "eloxiv.sync.ts"])
|
|
475
|
+
written.add(file);
|
|
476
|
+
const migrations = applyMigrations(dir, pending, { dryRun: options.dryRun, exclude: written });
|
|
477
|
+
return {
|
|
478
|
+
dryRun: options.dryRun,
|
|
479
|
+
items: reports,
|
|
480
|
+
migrations,
|
|
481
|
+
notes: pending.flatMap((p) => p.migration.note === undefined ? [] : [`${p.item} ${p.migration.since}: ${p.migration.note}`]),
|
|
482
|
+
needsAttention: reports.some((r) => r.status === "conflicts" || r.status === "blocked" || r.status === "unresolved-conflicts") ||
|
|
483
|
+
migrations.some((m) => m.kind === "manual"),
|
|
484
|
+
};
|
|
485
|
+
});
|
|
486
|
+
const OUTCOME_LABEL = {
|
|
487
|
+
updated: "updated",
|
|
488
|
+
kept: "kept",
|
|
489
|
+
merged: "merged",
|
|
490
|
+
conflict: "CONFLICT",
|
|
491
|
+
"conflict-binary": "CONFLICT",
|
|
492
|
+
"already-updated": "same",
|
|
493
|
+
added: "added",
|
|
494
|
+
removed: "removed",
|
|
495
|
+
"kept-removed-upstream": "kept",
|
|
496
|
+
"deleted-locally": "deleted",
|
|
497
|
+
"conflict-deleted-locally": "CONFLICT",
|
|
498
|
+
blocked: "BLOCKED",
|
|
499
|
+
};
|
|
500
|
+
const OUTCOME_NOTE = {
|
|
501
|
+
kept: "local edits; unchanged upstream",
|
|
502
|
+
merged: "local edits merged with upstream changes",
|
|
503
|
+
conflict: "overlapping changes: conflict markers",
|
|
504
|
+
"already-updated": "already matches the new version",
|
|
505
|
+
"kept-removed-upstream": "modified locally, removed upstream: now the app's own file",
|
|
506
|
+
"deleted-locally": "deleted locally; unchanged upstream",
|
|
507
|
+
"conflict-deleted-locally": "deleted locally, changed upstream: restore it or leave it deleted",
|
|
508
|
+
};
|
|
509
|
+
const noteOf = (file) => file.outcome === "blocked"
|
|
510
|
+
? `${file.detail} is in the way; move it and retry`
|
|
511
|
+
: file.outcome === "conflict-binary"
|
|
512
|
+
? `binary, changed on both sides: yours is kept, the new version is in ${file.upstream}`
|
|
513
|
+
: OUTCOME_NOTE[file.outcome];
|
|
514
|
+
export const formatUpdate = (report) => {
|
|
515
|
+
const out = [];
|
|
516
|
+
const would = report.dryRun ? "would " : "";
|
|
517
|
+
for (const item of report.items) {
|
|
518
|
+
const head = `${item.name} (${item.kind})`;
|
|
519
|
+
switch (item.status) {
|
|
520
|
+
case "up-to-date":
|
|
521
|
+
out.push(`${head} ${item.from.version}: up to date`);
|
|
522
|
+
if (item.deprecated !== undefined)
|
|
523
|
+
out.push(` deprecated ${item.deprecated}`);
|
|
524
|
+
continue;
|
|
525
|
+
case "app-owned":
|
|
526
|
+
out.push(`${head} ${item.from.version}: app-owned (eloxiv eject); not updated`);
|
|
527
|
+
continue;
|
|
528
|
+
case "unresolved-conflicts":
|
|
529
|
+
out.push(`${head}: has unresolved conflicts from the last update; resolve them, then run eloxiv update --continue`);
|
|
530
|
+
for (const path of item.markers ?? [])
|
|
531
|
+
out.push(` CONFLICT ${path} (conflict markers)`);
|
|
532
|
+
continue;
|
|
533
|
+
}
|
|
534
|
+
const verb = item.status === "blocked"
|
|
535
|
+
? "not updated (blocked)"
|
|
536
|
+
: item.status === "conflicts"
|
|
537
|
+
? `${would}update with conflicts`
|
|
538
|
+
: `${would}update`;
|
|
539
|
+
out.push(`${head} ${item.from.version} → ${item.to?.version}: ${verb}`);
|
|
540
|
+
for (const file of item.files) {
|
|
541
|
+
const note = noteOf(file);
|
|
542
|
+
out.push(` ${OUTCOME_LABEL[file.outcome].padEnd(9)}${file.path}${note === undefined ? "" : ` (${note})`}`);
|
|
543
|
+
}
|
|
544
|
+
for (const name of item.installs)
|
|
545
|
+
out.push(` ${would}install registry item ${name}`);
|
|
546
|
+
for (const change of item.npm)
|
|
547
|
+
out.push(` ${formatNpmChange(change, would, item.name)}`);
|
|
548
|
+
}
|
|
549
|
+
const conflicted = report.items.filter((item) => item.status === "conflicts");
|
|
550
|
+
if (conflicted.length > 0 && !report.dryRun)
|
|
551
|
+
out.push("Resolve the conflicts (edit out the <<<<<<< ||||||| ======= >>>>>>> markers; for a binary file keep yours or replace it with <file>.upstream, then delete <file>.upstream), then run eloxiv update --continue.");
|
|
552
|
+
if (report.migrations.length > 0) {
|
|
553
|
+
out.push(`compatibility migrations:`);
|
|
554
|
+
out.push(...formatMigrationChanges(report.migrations, report.dryRun));
|
|
555
|
+
}
|
|
556
|
+
for (const note of report.notes)
|
|
557
|
+
out.push(`note: ${note}`);
|
|
558
|
+
if (report.migrations.length > 0) {
|
|
559
|
+
out.push(`compatibility migrations:`);
|
|
560
|
+
out.push(...formatMigrationChanges(report.migrations, report.dryRun));
|
|
561
|
+
}
|
|
562
|
+
for (const note of report.notes)
|
|
563
|
+
out.push(`note: ${note}`);
|
|
564
|
+
if (report.items.length === 0)
|
|
565
|
+
out.push("no items installed");
|
|
566
|
+
return out.join("\n");
|
|
567
|
+
};
|
|
568
|
+
/**
|
|
569
|
+
* Record that the conflicts of the last update are resolved. A content conflict is resolved once its file
|
|
570
|
+
* no longer holds conflict markers, a binary one once `<file>.upstream` is gone, and a file deleted locally
|
|
571
|
+
* and changed upstream by whatever the developer chose (restored or still deleted). Any locally edited file
|
|
572
|
+
* of an item that holds conflict markers, recorded or not, keeps the item unresolved. The lock's per-file
|
|
573
|
+
* hashes already describe the new version as published, so a resolved file simply shows as a local edit.
|
|
574
|
+
*/
|
|
575
|
+
export const continueUpdate = Effect.fn("Update.continueUpdate")(function* (dir, names) {
|
|
576
|
+
const lock = yield* readLock(dir);
|
|
577
|
+
const resolved = [];
|
|
578
|
+
const unresolved = [];
|
|
579
|
+
for (const entry of yield* selectEntries(lock, names)) {
|
|
580
|
+
if (entry.owner === "app" && (entry.conflicts ?? []).length === 0)
|
|
581
|
+
continue;
|
|
582
|
+
const conflicts = entry.conflicts ?? [];
|
|
583
|
+
const remaining = new Set(yield* filesWithMarkers(dir, entry));
|
|
584
|
+
for (const conflict of conflicts)
|
|
585
|
+
if (conflict.reason === "binary" && (yield* readAppBytes(dir, upstreamCopy(conflict.path))) !== undefined)
|
|
586
|
+
remaining.add(lockPath(conflict.path));
|
|
587
|
+
if (remaining.size > 0) {
|
|
588
|
+
unresolved.push({ name: entry.name, paths: [...remaining].sort() });
|
|
589
|
+
continue;
|
|
590
|
+
}
|
|
591
|
+
if (conflicts.length === 0)
|
|
592
|
+
continue;
|
|
593
|
+
const { conflicts: _resolved, ...rest } = entry;
|
|
594
|
+
lock.items[entry.name] = rest;
|
|
595
|
+
resolved.push(entry.name);
|
|
596
|
+
}
|
|
597
|
+
if (resolved.length > 0)
|
|
598
|
+
yield* writeLock(dir, lock);
|
|
599
|
+
return { resolved, unresolved };
|
|
600
|
+
});
|
|
601
|
+
export const formatContinue = (report) => {
|
|
602
|
+
const out = report.resolved.map((name) => `${name}: conflicts resolved`);
|
|
603
|
+
for (const item of report.unresolved)
|
|
604
|
+
for (const path of item.paths)
|
|
605
|
+
out.push(`${item.name}: ${path} is not resolved yet (it still has conflict markers, or ${upstreamCopy(path)} is still there)`);
|
|
606
|
+
if (out.length === 0)
|
|
607
|
+
out.push("no unresolved conflicts");
|
|
608
|
+
return out.join("\n");
|
|
609
|
+
};
|
|
610
|
+
// ---------------------------------------------------------------------------------------------------------
|
|
611
|
+
// eject
|
|
612
|
+
/**
|
|
613
|
+
* Take items over (`owner: "app"`): diff and update leave them alone and report them as app-owned. The
|
|
614
|
+
* provenance stays in the lock, so `undo` hands an item back to the registry and the next update merges
|
|
615
|
+
* from the version it was ejected at.
|
|
616
|
+
*/
|
|
617
|
+
export const eject = Effect.fn("Update.eject")(function* (dir, names, undo) {
|
|
618
|
+
const lock = yield* readLock(dir);
|
|
619
|
+
const entries = yield* selectEntries(lock, names);
|
|
620
|
+
for (const entry of entries) {
|
|
621
|
+
const { owner: _owner, ...rest } = entry;
|
|
622
|
+
lock.items[entry.name] = undo ? rest : { ...rest, owner: "app" };
|
|
623
|
+
}
|
|
624
|
+
yield* writeLock(dir, lock);
|
|
625
|
+
return entries.map((entry) => entry.name);
|
|
626
|
+
});
|
|
627
|
+
//# sourceMappingURL=Update.js.map
|