@seasb/metafab 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/README.md +47 -2
- package/dist/cli.d.ts +11 -0
- package/dist/cli.js +317 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/build.d.ts +2 -0
- package/dist/commands/build.js +70 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/check.d.ts +2 -0
- package/dist/commands/check.js +41 -0
- package/dist/commands/check.js.map +1 -0
- package/dist/commands/create.d.ts +2 -0
- package/dist/commands/create.js +74 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/detach.d.ts +2 -0
- package/dist/commands/detach.js +24 -0
- package/dist/commands/detach.js.map +1 -0
- package/dist/commands/diff.d.ts +2 -0
- package/dist/commands/diff.js +35 -0
- package/dist/commands/diff.js.map +1 -0
- package/dist/commands/import.d.ts +2 -0
- package/dist/commands/import.js +107 -0
- package/dist/commands/import.js.map +1 -0
- package/dist/commands/init.d.ts +2 -0
- package/dist/commands/init.js +77 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/map.d.ts +2 -0
- package/dist/commands/map.js +43 -0
- package/dist/commands/map.js.map +1 -0
- package/dist/commands/not-implemented.d.ts +2 -0
- package/dist/commands/not-implemented.js +19 -0
- package/dist/commands/not-implemented.js.map +1 -0
- package/dist/commands/pipeline-add.d.ts +2 -0
- package/dist/commands/pipeline-add.js +67 -0
- package/dist/commands/pipeline-add.js.map +1 -0
- package/dist/commands/pipeline-remove.d.ts +2 -0
- package/dist/commands/pipeline-remove.js +44 -0
- package/dist/commands/pipeline-remove.js.map +1 -0
- package/dist/commands/publish.d.ts +2 -0
- package/dist/commands/publish.js +147 -0
- package/dist/commands/publish.js.map +1 -0
- package/dist/commands/types.d.ts +45 -0
- package/dist/commands/types.js +2 -0
- package/dist/commands/types.js.map +1 -0
- package/dist/commands/update.d.ts +2 -0
- package/dist/commands/update.js +97 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/core/adopt.d.ts +53 -0
- package/dist/core/adopt.js +676 -0
- package/dist/core/adopt.js.map +1 -0
- package/dist/core/build/agents.d.ts +23 -0
- package/dist/core/build/agents.js +60 -0
- package/dist/core/build/agents.js.map +1 -0
- package/dist/core/build/index.d.ts +4 -0
- package/dist/core/build/index.js +5 -0
- package/dist/core/build/index.js.map +1 -0
- package/dist/core/build/markers.d.ts +34 -0
- package/dist/core/build/markers.js +97 -0
- package/dist/core/build/markers.js.map +1 -0
- package/dist/core/build/plan.d.ts +48 -0
- package/dist/core/build/plan.js +792 -0
- package/dist/core/build/plan.js.map +1 -0
- package/dist/core/build/skill.d.ts +60 -0
- package/dist/core/build/skill.js +275 -0
- package/dist/core/build/skill.js.map +1 -0
- package/dist/core/check/drift.d.ts +13 -0
- package/dist/core/check/drift.js +205 -0
- package/dist/core/check/drift.js.map +1 -0
- package/dist/core/check/index.d.ts +12 -0
- package/dist/core/check/index.js +78 -0
- package/dist/core/check/index.js.map +1 -0
- package/dist/core/check/markers.d.ts +9 -0
- package/dist/core/check/markers.js +220 -0
- package/dist/core/check/markers.js.map +1 -0
- package/dist/core/config/destinations.d.ts +5 -0
- package/dist/core/config/destinations.js +20 -0
- package/dist/core/config/destinations.js.map +1 -0
- package/dist/core/config/load.d.ts +4 -0
- package/dist/core/config/load.js +41 -0
- package/dist/core/config/load.js.map +1 -0
- package/dist/core/config/parse.d.ts +8 -0
- package/dist/core/config/parse.js +198 -0
- package/dist/core/config/parse.js.map +1 -0
- package/dist/core/config/source.d.ts +14 -0
- package/dist/core/config/source.js +44 -0
- package/dist/core/config/source.js.map +1 -0
- package/dist/core/config/types.d.ts +48 -0
- package/dist/core/config/types.js +2 -0
- package/dist/core/config/types.js.map +1 -0
- package/dist/core/config/validate.d.ts +11 -0
- package/dist/core/config/validate.js +351 -0
- package/dist/core/config/validate.js.map +1 -0
- package/dist/core/config/writers.d.ts +14 -0
- package/dist/core/config/writers.js +261 -0
- package/dist/core/config/writers.js.map +1 -0
- package/dist/core/config.d.ts +7 -0
- package/dist/core/config.js +8 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/discovery.d.ts +34 -0
- package/dist/core/discovery.js +272 -0
- package/dist/core/discovery.js.map +1 -0
- package/dist/core/edit/create.d.ts +18 -0
- package/dist/core/edit/create.js +190 -0
- package/dist/core/edit/create.js.map +1 -0
- package/dist/core/edit/document.d.ts +4 -0
- package/dist/core/edit/document.js +16 -0
- package/dist/core/edit/document.js.map +1 -0
- package/dist/core/edit/factory-yaml.d.ts +17 -0
- package/dist/core/edit/factory-yaml.js +211 -0
- package/dist/core/edit/factory-yaml.js.map +1 -0
- package/dist/core/edit/files.d.ts +6 -0
- package/dist/core/edit/files.js +47 -0
- package/dist/core/edit/files.js.map +1 -0
- package/dist/core/edit/index.d.ts +9 -0
- package/dist/core/edit/index.js +10 -0
- package/dist/core/edit/index.js.map +1 -0
- package/dist/core/edit/map.d.ts +24 -0
- package/dist/core/edit/map.js +82 -0
- package/dist/core/edit/map.js.map +1 -0
- package/dist/core/edit/names.d.ts +2 -0
- package/dist/core/edit/names.js +17 -0
- package/dist/core/edit/names.js.map +1 -0
- package/dist/core/edit/paths.d.ts +8 -0
- package/dist/core/edit/paths.js +76 -0
- package/dist/core/edit/paths.js.map +1 -0
- package/dist/core/edit/pipeline.d.ts +19 -0
- package/dist/core/edit/pipeline.js +146 -0
- package/dist/core/edit/pipeline.js.map +1 -0
- package/dist/core/edit/skill.d.ts +1 -0
- package/dist/core/edit/skill.js +10 -0
- package/dist/core/edit/skill.js.map +1 -0
- package/dist/core/factory/discovery.d.ts +9 -0
- package/dist/core/factory/discovery.js +139 -0
- package/dist/core/factory/discovery.js.map +1 -0
- package/dist/core/factory/factory-yaml.d.ts +16 -0
- package/dist/core/factory/factory-yaml.js +375 -0
- package/dist/core/factory/factory-yaml.js.map +1 -0
- package/dist/core/factory/index.d.ts +5 -0
- package/dist/core/factory/index.js +6 -0
- package/dist/core/factory/index.js.map +1 -0
- package/dist/core/factory/lines.d.ts +8 -0
- package/dist/core/factory/lines.js +11 -0
- package/dist/core/factory/lines.js.map +1 -0
- package/dist/core/factory/load.d.ts +4 -0
- package/dist/core/factory/load.js +81 -0
- package/dist/core/factory/load.js.map +1 -0
- package/dist/core/factory/requires.d.ts +9 -0
- package/dist/core/factory/requires.js +123 -0
- package/dist/core/factory/requires.js.map +1 -0
- package/dist/core/factory/types.d.ts +45 -0
- package/dist/core/factory/types.js +2 -0
- package/dist/core/factory/types.js.map +1 -0
- package/dist/core/factory/validate.d.ts +41 -0
- package/dist/core/factory/validate.js +441 -0
- package/dist/core/factory/validate.js.map +1 -0
- package/dist/core/hooks/index.d.ts +8 -0
- package/dist/core/hooks/index.js +15 -0
- package/dist/core/hooks/index.js.map +1 -0
- package/dist/core/hooks/script.d.ts +21 -0
- package/dist/core/hooks/script.js +34 -0
- package/dist/core/hooks/script.js.map +1 -0
- package/dist/core/hooks/sync.d.ts +17 -0
- package/dist/core/hooks/sync.js +262 -0
- package/dist/core/hooks/sync.js.map +1 -0
- package/dist/core/import/conflicts.d.ts +82 -0
- package/dist/core/import/conflicts.js +256 -0
- package/dist/core/import/conflicts.js.map +1 -0
- package/dist/core/import/copy.d.ts +10 -0
- package/dist/core/import/copy.js +76 -0
- package/dist/core/import/copy.js.map +1 -0
- package/dist/core/import/file-tree.d.ts +43 -0
- package/dist/core/import/file-tree.js +107 -0
- package/dist/core/import/file-tree.js.map +1 -0
- package/dist/core/import/index.d.ts +5 -0
- package/dist/core/import/index.js +6 -0
- package/dist/core/import/index.js.map +1 -0
- package/dist/core/import/pipeline-changes.d.ts +8 -0
- package/dist/core/import/pipeline-changes.js +89 -0
- package/dist/core/import/pipeline-changes.js.map +1 -0
- package/dist/core/import/run.d.ts +76 -0
- package/dist/core/import/run.js +258 -0
- package/dist/core/import/run.js.map +1 -0
- package/dist/core/init/gitattributes.d.ts +20 -0
- package/dist/core/init/gitattributes.js +89 -0
- package/dist/core/init/gitattributes.js.map +1 -0
- package/dist/core/init/index.d.ts +4 -0
- package/dist/core/init/index.js +5 -0
- package/dist/core/init/index.js.map +1 -0
- package/dist/core/init/name.d.ts +1 -0
- package/dist/core/init/name.js +4 -0
- package/dist/core/init/name.js.map +1 -0
- package/dist/core/init/run.d.ts +51 -0
- package/dist/core/init/run.js +261 -0
- package/dist/core/init/run.js.map +1 -0
- package/dist/core/init/targets.d.ts +17 -0
- package/dist/core/init/targets.js +87 -0
- package/dist/core/init/targets.js.map +1 -0
- package/dist/core/merge.d.ts +88 -0
- package/dist/core/merge.js +239 -0
- package/dist/core/merge.js.map +1 -0
- package/dist/core/publish/exclude.d.ts +9 -0
- package/dist/core/publish/exclude.js +32 -0
- package/dist/core/publish/exclude.js.map +1 -0
- package/dist/core/publish/git-target.d.ts +32 -0
- package/dist/core/publish/git-target.js +447 -0
- package/dist/core/publish/git-target.js.map +1 -0
- package/dist/core/publish/index.d.ts +10 -0
- package/dist/core/publish/index.js +11 -0
- package/dist/core/publish/index.js.map +1 -0
- package/dist/core/publish/npm-target.d.ts +15 -0
- package/dist/core/publish/npm-target.js +170 -0
- package/dist/core/publish/npm-target.js.map +1 -0
- package/dist/core/publish/package-json.d.ts +31 -0
- package/dist/core/publish/package-json.js +74 -0
- package/dist/core/publish/package-json.js.map +1 -0
- package/dist/core/publish/prepare.d.ts +24 -0
- package/dist/core/publish/prepare.js +93 -0
- package/dist/core/publish/prepare.js.map +1 -0
- package/dist/core/publish/provenance.d.ts +1 -0
- package/dist/core/publish/provenance.js +20 -0
- package/dist/core/publish/provenance.js.map +1 -0
- package/dist/core/publish/publish.d.ts +13 -0
- package/dist/core/publish/publish.js +130 -0
- package/dist/core/publish/publish.js.map +1 -0
- package/dist/core/publish/readme.d.ts +22 -0
- package/dist/core/publish/readme.js +112 -0
- package/dist/core/publish/readme.js.map +1 -0
- package/dist/core/publish/stage.d.ts +19 -0
- package/dist/core/publish/stage.js +333 -0
- package/dist/core/publish/stage.js.map +1 -0
- package/dist/core/publish/types.d.ts +71 -0
- package/dist/core/publish/types.js +2 -0
- package/dist/core/publish/types.js.map +1 -0
- package/dist/core/requires/check.d.ts +15 -0
- package/dist/core/requires/check.js +83 -0
- package/dist/core/requires/check.js.map +1 -0
- package/dist/core/requires/index.d.ts +4 -0
- package/dist/core/requires/index.js +5 -0
- package/dist/core/requires/index.js.map +1 -0
- package/dist/core/requires/inspect.d.ts +44 -0
- package/dist/core/requires/inspect.js +114 -0
- package/dist/core/requires/inspect.js.map +1 -0
- package/dist/core/requires/paths.d.ts +29 -0
- package/dist/core/requires/paths.js +83 -0
- package/dist/core/requires/paths.js.map +1 -0
- package/dist/core/requires/setup.d.ts +37 -0
- package/dist/core/requires/setup.js +147 -0
- package/dist/core/requires/setup.js.map +1 -0
- package/dist/core/setup.d.ts +27 -0
- package/dist/core/setup.js +84 -0
- package/dist/core/setup.js.map +1 -0
- package/dist/core/sources/cache.d.ts +38 -0
- package/dist/core/sources/cache.js +200 -0
- package/dist/core/sources/cache.js.map +1 -0
- package/dist/core/sources/containment.d.ts +21 -0
- package/dist/core/sources/containment.js +50 -0
- package/dist/core/sources/containment.js.map +1 -0
- package/dist/core/sources/env.d.ts +12 -0
- package/dist/core/sources/env.js +28 -0
- package/dist/core/sources/env.js.map +1 -0
- package/dist/core/sources/extract.d.ts +25 -0
- package/dist/core/sources/extract.js +676 -0
- package/dist/core/sources/extract.js.map +1 -0
- package/dist/core/sources/git-process.d.ts +26 -0
- package/dist/core/sources/git-process.js +51 -0
- package/dist/core/sources/git-process.js.map +1 -0
- package/dist/core/sources/git.d.ts +41 -0
- package/dist/core/sources/git.js +511 -0
- package/dist/core/sources/git.js.map +1 -0
- package/dist/core/sources/https.d.ts +21 -0
- package/dist/core/sources/https.js +208 -0
- package/dist/core/sources/https.js.map +1 -0
- package/dist/core/sources/index.d.ts +13 -0
- package/dist/core/sources/index.js +14 -0
- package/dist/core/sources/index.js.map +1 -0
- package/dist/core/sources/npm-cli.d.ts +19 -0
- package/dist/core/sources/npm-cli.js +43 -0
- package/dist/core/sources/npm-cli.js.map +1 -0
- package/dist/core/sources/npm.d.ts +29 -0
- package/dist/core/sources/npm.js +386 -0
- package/dist/core/sources/npm.js.map +1 -0
- package/dist/core/sources/parse.d.ts +32 -0
- package/dist/core/sources/parse.js +389 -0
- package/dist/core/sources/parse.js.map +1 -0
- package/dist/core/sources/path.d.ts +10 -0
- package/dist/core/sources/path.js +316 -0
- package/dist/core/sources/path.js.map +1 -0
- package/dist/core/sources/redact.d.ts +2 -0
- package/dist/core/sources/redact.js +70 -0
- package/dist/core/sources/redact.js.map +1 -0
- package/dist/core/sources/resolve.d.ts +9 -0
- package/dist/core/sources/resolve.js +29 -0
- package/dist/core/sources/resolve.js.map +1 -0
- package/dist/core/sources/types.d.ts +86 -0
- package/dist/core/sources/types.js +2 -0
- package/dist/core/sources/types.js.map +1 -0
- package/dist/core/sources/validate.d.ts +9 -0
- package/dist/core/sources/validate.js +111 -0
- package/dist/core/sources/validate.js.map +1 -0
- package/dist/core/summary.d.ts +77 -0
- package/dist/core/summary.js +405 -0
- package/dist/core/summary.js.map +1 -0
- package/dist/core/update/clashes.d.ts +63 -0
- package/dist/core/update/clashes.js +192 -0
- package/dist/core/update/clashes.js.map +1 -0
- package/dist/core/update/detach.d.ts +21 -0
- package/dist/core/update/detach.js +38 -0
- package/dist/core/update/detach.js.map +1 -0
- package/dist/core/update/diff.d.ts +58 -0
- package/dist/core/update/diff.js +180 -0
- package/dist/core/update/diff.js.map +1 -0
- package/dist/core/update/fetch.d.ts +34 -0
- package/dist/core/update/fetch.js +73 -0
- package/dist/core/update/fetch.js.map +1 -0
- package/dist/core/update/index.d.ts +6 -0
- package/dist/core/update/index.js +7 -0
- package/dist/core/update/index.js.map +1 -0
- package/dist/core/update/restore.d.ts +20 -0
- package/dist/core/update/restore.js +195 -0
- package/dist/core/update/restore.js.map +1 -0
- package/dist/core/update/run.d.ts +113 -0
- package/dist/core/update/run.js +1132 -0
- package/dist/core/update/run.js.map +1 -0
- package/dist/core/update/select.d.ts +39 -0
- package/dist/core/update/select.js +157 -0
- package/dist/core/update/select.js.map +1 -0
- package/dist/core/update/spelling.d.ts +51 -0
- package/dist/core/update/spelling.js +185 -0
- package/dist/core/update/spelling.js.map +1 -0
- package/dist/core/update/trees.d.ts +24 -0
- package/dist/core/update/trees.js +72 -0
- package/dist/core/update/trees.js.map +1 -0
- package/dist/errors.d.ts +29 -0
- package/dist/errors.js +24 -0
- package/dist/errors.js.map +1 -0
- package/dist/help.d.ts +46 -0
- package/dist/help.js +103 -0
- package/dist/help.js.map +1 -0
- package/dist/input.d.ts +25 -0
- package/dist/input.js +173 -0
- package/dist/input.js.map +1 -0
- package/dist/output.d.ts +21 -0
- package/dist/output.js +37 -0
- package/dist/output.js.map +1 -0
- package/dist/util/frontmatter.d.ts +12 -0
- package/dist/util/frontmatter.js +58 -0
- package/dist/util/frontmatter.js.map +1 -0
- package/dist/util/fs.d.ts +32 -0
- package/dist/util/fs.js +126 -0
- package/dist/util/fs.js.map +1 -0
- package/dist/util/git-names.d.ts +8 -0
- package/dist/util/git-names.js +25 -0
- package/dist/util/git-names.js.map +1 -0
- package/dist/util/git.d.ts +12 -0
- package/dist/util/git.js +33 -0
- package/dist/util/git.js.map +1 -0
- package/dist/util/suggest.d.ts +6 -0
- package/dist/util/suggest.js +48 -0
- package/dist/util/suggest.js.map +1 -0
- package/dist/util/text.d.ts +8 -0
- package/dist/util/text.js +19 -0
- package/dist/util/text.js.map +1 -0
- package/dist/util/version.d.ts +7 -0
- package/dist/util/version.js +13 -0
- package/dist/util/version.js.map +1 -0
- package/dist/util/yaml.d.ts +30 -0
- package/dist/util/yaml.js +201 -0
- package/dist/util/yaml.js.map +1 -0
- package/package.json +51 -4
- package/resources/metafab-skill/SKILL.md +99 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { MetafabError } from "../../errors.js";
|
|
2
|
+
import { parseSource } from "../sources/parse.js";
|
|
3
|
+
import { fetchFab, resolve } from "../sources/resolve.js";
|
|
4
|
+
import { resolveGit } from "../sources/git.js";
|
|
5
|
+
import { resolveNpm } from "../sources/npm.js";
|
|
6
|
+
import { gitSpecOf } from "./select.js";
|
|
7
|
+
/**
|
|
8
|
+
* Resolves the version or revision a recorded upstream entry names.
|
|
9
|
+
*
|
|
10
|
+
* This is the base of an update and the other half of `metafab diff`: it always
|
|
11
|
+
* resolves the recorded version or commit, never a newer one.
|
|
12
|
+
*/
|
|
13
|
+
export async function resolveRecorded(upstream, options) {
|
|
14
|
+
switch (upstream.kind) {
|
|
15
|
+
case "npm":
|
|
16
|
+
return resolveNpm({ kind: "npm", name: upstream.source }, { ...options, to: upstream.version, recorded: true });
|
|
17
|
+
case "git":
|
|
18
|
+
return resolveGit(gitSpecOf(upstream, options.cwd), {
|
|
19
|
+
...options,
|
|
20
|
+
to: upstream.commit,
|
|
21
|
+
});
|
|
22
|
+
case "unversioned":
|
|
23
|
+
return resolve(parseSource(upstream.source, { cwd: options.cwd }), options);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Fetches the recorded base, so a caller can compare it with the local factory
|
|
28
|
+
* or merge it. The caller must call `cleanup` on the result in a `finally`.
|
|
29
|
+
*
|
|
30
|
+
* A failure here is either a base that no longer exists at its source (see
|
|
31
|
+
* `recordedBaseGone`) or a fetch that failed for another reason. The caller
|
|
32
|
+
* decides which: `update` merges without a base only in the first case.
|
|
33
|
+
*/
|
|
34
|
+
export async function fetchRecordedBase(upstream, options) {
|
|
35
|
+
return fetchFab(await resolveRecorded(upstream, options), options);
|
|
36
|
+
}
|
|
37
|
+
/** The error code a Git source uses when the named ref, tag or commit is absent. */
|
|
38
|
+
const GIT_NOT_FOUND = "fetch-not-found";
|
|
39
|
+
/**
|
|
40
|
+
* What npm reports when a package or a version is missing. The npm source
|
|
41
|
+
* raises `fetch-failed` for every failure, so a gone version is recognised by
|
|
42
|
+
* the registry's E404 or by the resolver's own wording for a version absent
|
|
43
|
+
* from the registry's list.
|
|
44
|
+
*/
|
|
45
|
+
const NPM_GONE = /\bE404\b|\b404 Not Found\b|no version matches|has no published versions/;
|
|
46
|
+
/** The command's own output, where npm and Git put the reason for a failure. */
|
|
47
|
+
function failureOutput(error) {
|
|
48
|
+
const cause = error.cause;
|
|
49
|
+
if (typeof cause !== "object" || cause === null)
|
|
50
|
+
return "";
|
|
51
|
+
const { stderr, stdout } = cause;
|
|
52
|
+
return [stderr, stdout].filter((value) => typeof value === "string").join("\n");
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* True only when the recorded base no longer exists at its source: a Git ref
|
|
56
|
+
* or commit that was removed by a force push, or an npm package or version
|
|
57
|
+
* that was unpublished or removed.
|
|
58
|
+
*
|
|
59
|
+
* Every other fetch failure — an unreachable remote, a rejected credential, a
|
|
60
|
+
* cache or filesystem problem, an attribute-write failure — is not a missing
|
|
61
|
+
* base. `update` must abort on it, with the original problem and exit code,
|
|
62
|
+
* before it writes anything; `diff` must report it as it is.
|
|
63
|
+
*/
|
|
64
|
+
export function recordedBaseGone(error) {
|
|
65
|
+
if (!(error instanceof MetafabError))
|
|
66
|
+
return false;
|
|
67
|
+
if (error.code === GIT_NOT_FOUND)
|
|
68
|
+
return true;
|
|
69
|
+
if (error.code !== "fetch-failed")
|
|
70
|
+
return false;
|
|
71
|
+
return NPM_GONE.test(`${error.message}\n${failureOutput(error)}`);
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../../src/core/update/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAG1D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAA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AAI;QAAE,OAAO,EAAE,CAAC;IAC3D,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,KAA+C,CAAC;IAC3E,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACnG,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,IAAI,CAAC,CAAC,KAAK,YAAY,YAAY,CAAC;QAAE,OAAO,KAAK,CAAC;IACnD,IAAI,KAAK,CAAC,IAAI,KAAK,aAAa;QAAE,OAAO,IAAI,CAAC;IAC9C,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc;QAAE,OAAO,KAAK,CAAC;IAChD,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,OAAO,KAAK,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AACpE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/update/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What `.factory/` held before an update wrote: every file's bytes and full
|
|
3
|
+
* permission mode, every link's target, and every directory, empty ones
|
|
4
|
+
* included, with the exact spelling of each name.
|
|
5
|
+
*/
|
|
6
|
+
export interface FactoryCapture {
|
|
7
|
+
/** Make `.factory/` match the capture again, then leave the capture in place. */
|
|
8
|
+
restore(): Promise<void>;
|
|
9
|
+
/** Remove the captured bytes. Safe to call more than once. */
|
|
10
|
+
discard(): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Records `.factory/` so an update that fails partway can put it back.
|
|
14
|
+
*
|
|
15
|
+
* Call it just before the first write. `restore` makes the directory match the
|
|
16
|
+
* record exactly, so a half-applied merge never leaves upstream content behind
|
|
17
|
+
* while the old version stays recorded. Not `snapshotFactory`: `import/file-tree.ts`
|
|
18
|
+
* already exports that name with another meaning.
|
|
19
|
+
*/
|
|
20
|
+
export declare function captureFactory(factoryDir: string): Promise<FactoryCapture>;
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { chmod, lstat, mkdir, mkdtemp, readFile, readlink, rename, rm, symlink, writeFile, } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { readdirTyped } from "../../util/fs.js";
|
|
5
|
+
async function lstatIfExists(target) {
|
|
6
|
+
try {
|
|
7
|
+
return await lstat(target);
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
if (error.code === "ENOENT")
|
|
11
|
+
return undefined;
|
|
12
|
+
throw error;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Records every entry under `dir`, in the order the filesystem lists it, and
|
|
17
|
+
* copies each file's bytes into `staging`.
|
|
18
|
+
*
|
|
19
|
+
* A socket or other special entry is not factory content an update writes, so
|
|
20
|
+
* it is not recorded; restore never creates one, and removes one only when it
|
|
21
|
+
* sits on a recorded path.
|
|
22
|
+
*/
|
|
23
|
+
async function captureDirectory(dir, staging, counter) {
|
|
24
|
+
const children = new Map();
|
|
25
|
+
for (const entry of await readdirTyped(dir)) {
|
|
26
|
+
const target = path.join(dir, entry.name);
|
|
27
|
+
const info = await lstat(target);
|
|
28
|
+
if (info.isSymbolicLink()) {
|
|
29
|
+
children.set(entry.name, { kind: "link", target: await readlink(target) });
|
|
30
|
+
}
|
|
31
|
+
else if (info.isDirectory()) {
|
|
32
|
+
children.set(entry.name, {
|
|
33
|
+
kind: "directory",
|
|
34
|
+
children: await captureDirectory(target, staging, counter),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
else if (info.isFile()) {
|
|
38
|
+
const source = path.join(staging, String(counter.next));
|
|
39
|
+
counter.next += 1;
|
|
40
|
+
await writeFile(source, await readFile(target));
|
|
41
|
+
children.set(entry.name, { kind: "file", mode: info.mode & 0o7777, source });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return children;
|
|
45
|
+
}
|
|
46
|
+
/** Creates `target` as a directory, removing a file or link in its way. */
|
|
47
|
+
async function ensureDirectory(target) {
|
|
48
|
+
const info = await lstatIfExists(target);
|
|
49
|
+
if (info !== undefined) {
|
|
50
|
+
if (info.isDirectory())
|
|
51
|
+
return;
|
|
52
|
+
await rm(target, { recursive: true, force: true });
|
|
53
|
+
}
|
|
54
|
+
await mkdir(target, { recursive: true });
|
|
55
|
+
}
|
|
56
|
+
async function sameBytes(left, right) {
|
|
57
|
+
const [a, b] = await Promise.all([readFile(left), readFile(right)]);
|
|
58
|
+
return a.equals(b);
|
|
59
|
+
}
|
|
60
|
+
/** Rewrites a file whose bytes or mode differ, recreating it when absent. */
|
|
61
|
+
async function restoreFile(target, node) {
|
|
62
|
+
const info = await lstatIfExists(target);
|
|
63
|
+
if (info !== undefined) {
|
|
64
|
+
if (info.isFile()) {
|
|
65
|
+
if ((info.mode & 0o7777) === node.mode && (await sameBytes(target, node.source)))
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
await rm(target, { recursive: true, force: true });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
await writeFile(target, await readFile(node.source), { mode: node.mode });
|
|
73
|
+
await chmod(target, node.mode);
|
|
74
|
+
}
|
|
75
|
+
/** Recreates a link, or repoints one whose target differs. */
|
|
76
|
+
async function restoreLink(target, node) {
|
|
77
|
+
const info = await lstatIfExists(target);
|
|
78
|
+
if (info !== undefined) {
|
|
79
|
+
if (info.isSymbolicLink() && (await readlink(target)) === node.target)
|
|
80
|
+
return;
|
|
81
|
+
await rm(target, { recursive: true, force: true });
|
|
82
|
+
}
|
|
83
|
+
await symlink(node.target, target);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Classifies an entry with lstat, as capture does. A `Dirent` may report an
|
|
87
|
+
* unknown type on some filesystems, which would make a real file or link look
|
|
88
|
+
* special, so its type is not trusted here.
|
|
89
|
+
*/
|
|
90
|
+
async function classifyEntry(target) {
|
|
91
|
+
const info = await lstatIfExists(target);
|
|
92
|
+
if (info === undefined)
|
|
93
|
+
return undefined;
|
|
94
|
+
if (info.isSymbolicLink())
|
|
95
|
+
return "link";
|
|
96
|
+
if (info.isDirectory())
|
|
97
|
+
return "directory";
|
|
98
|
+
if (info.isFile())
|
|
99
|
+
return "file";
|
|
100
|
+
return "special";
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Makes `currentDir` hold exactly the recorded children.
|
|
104
|
+
*
|
|
105
|
+
* Extras are deleted, a name whose spelling differs only in case is renamed
|
|
106
|
+
* back, and every recorded child is recreated or repaired: a missing file, link
|
|
107
|
+
* or directory is created, including an empty directory, and a file whose bytes
|
|
108
|
+
* or mode differ is rewritten. A special entry was never recorded, so it is
|
|
109
|
+
* left in place rather than mistaken for something an update wrote, unless it
|
|
110
|
+
* sits on a recorded path, which is restored over it.
|
|
111
|
+
*/
|
|
112
|
+
async function restoreDirectory(currentDir, record) {
|
|
113
|
+
const entries = await readdirTyped(currentDir);
|
|
114
|
+
const present = new Set(entries.map((entry) => entry.name));
|
|
115
|
+
const recorded = new Set(record.keys());
|
|
116
|
+
const special = new Set();
|
|
117
|
+
for (const entry of entries) {
|
|
118
|
+
if ((await classifyEntry(path.join(currentDir, entry.name))) === "special") {
|
|
119
|
+
special.add(entry.name);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// A case-only difference is one logical entry, so rename it back instead of
|
|
123
|
+
// deleting and recreating it. Only an unambiguous candidate is renamed; the
|
|
124
|
+
// rest are extras and are deleted below.
|
|
125
|
+
for (const name of recorded) {
|
|
126
|
+
if (present.has(name))
|
|
127
|
+
continue;
|
|
128
|
+
const matches = entries.filter((entry) => present.has(entry.name) &&
|
|
129
|
+
!recorded.has(entry.name) &&
|
|
130
|
+
!special.has(entry.name) &&
|
|
131
|
+
entry.name.toLowerCase() === name.toLowerCase());
|
|
132
|
+
if (matches.length !== 1)
|
|
133
|
+
continue;
|
|
134
|
+
const currentName = matches[0].name;
|
|
135
|
+
await rename(path.join(currentDir, currentName), path.join(currentDir, name));
|
|
136
|
+
present.delete(currentName);
|
|
137
|
+
present.add(name);
|
|
138
|
+
}
|
|
139
|
+
for (const entry of entries) {
|
|
140
|
+
const name = entry.name;
|
|
141
|
+
if (!present.has(name) || recorded.has(name))
|
|
142
|
+
continue;
|
|
143
|
+
if (special.has(name))
|
|
144
|
+
continue;
|
|
145
|
+
await rm(path.join(currentDir, name), { recursive: true, force: true });
|
|
146
|
+
}
|
|
147
|
+
for (const [name, node] of record) {
|
|
148
|
+
const target = path.join(currentDir, name);
|
|
149
|
+
if (node.kind === "directory") {
|
|
150
|
+
await ensureDirectory(target);
|
|
151
|
+
await restoreDirectory(target, node.children);
|
|
152
|
+
}
|
|
153
|
+
else if (node.kind === "file") {
|
|
154
|
+
await restoreFile(target, node);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
await restoreLink(target, node);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Records `.factory/` so an update that fails partway can put it back.
|
|
163
|
+
*
|
|
164
|
+
* Call it just before the first write. `restore` makes the directory match the
|
|
165
|
+
* record exactly, so a half-applied merge never leaves upstream content behind
|
|
166
|
+
* while the old version stays recorded. Not `snapshotFactory`: `import/file-tree.ts`
|
|
167
|
+
* already exports that name with another meaning.
|
|
168
|
+
*/
|
|
169
|
+
export async function captureFactory(factoryDir) {
|
|
170
|
+
const staging = await mkdtemp(path.join(tmpdir(), "metafab-restore-"));
|
|
171
|
+
let record;
|
|
172
|
+
try {
|
|
173
|
+
record = await captureDirectory(factoryDir, staging, { next: 0 });
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
await rm(staging, { recursive: true, force: true });
|
|
177
|
+
throw error;
|
|
178
|
+
}
|
|
179
|
+
let discarded = false;
|
|
180
|
+
return {
|
|
181
|
+
async restore() {
|
|
182
|
+
await mkdir(factoryDir, { recursive: true });
|
|
183
|
+
await restoreDirectory(factoryDir, record);
|
|
184
|
+
},
|
|
185
|
+
async discard() {
|
|
186
|
+
if (discarded)
|
|
187
|
+
return;
|
|
188
|
+
discarded = true;
|
|
189
|
+
// Failing to remove a temporary directory must not change the result of
|
|
190
|
+
// the update, so the cleanup never throws.
|
|
191
|
+
await rm(staging, { recursive: true, force: true }).catch(() => undefined);
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=restore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"restore.js","sourceRoot":"","sources":["../../../src/core/update/restore.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,EAAE,EACF,OAAO,EACP,SAAS,GACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AA0BhD,KAAK,UAAU,aAAa,CAAC,MAAc;IACzC,IAAI,CAAC;QACH,OAAO,MAAM,KAAK,CAAC,MAAM,CAAC,CAAC;IAC7B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ;YAAE,OAAO,SAAS,CAAC;QACzE,MAAM,KA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AAc,CAAC,UAAkB;IACrD,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,kBAAkB,CAAC,CAAC,CAAC;IACvE,IAAI,MAAiC,CAAC;IAEtC,IAAI,CAAC;QACH,MAAM,GAAG,MAAM,gBAAgB,CAAC,UAAU,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;IACpE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACpD,MAAM,KAAK,CAAC;IACd,CAAC;IAED,IAAI,SAAS,GAAG,KAAK,CAAC;IACtB,OAAO;QACL,KAAK,CAAC,OAAO;YACX,MAAM,KAAK,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAC7C,MAAM,gBAAgB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;QAC7C,CAAC;QACD,KAAK,CAAC,OAAO;YACX,IAAI,SAAS;gBAAE,OAAO;YACtB,SAAS,GAAG,IAAI,CAAC;YACjB,wEAAwE;YACxE,2CAA2C;YAC3C,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC7E,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { Problem } from "../../errors.js";
|
|
2
|
+
import type { InputIO } from "../../input.js";
|
|
3
|
+
import type { BuildChange } from "../build/index.js";
|
|
4
|
+
import type { UpstreamEntry } from "../config/types.js";
|
|
5
|
+
import type { HookChange } from "../hooks/index.js";
|
|
6
|
+
import type { FileEntry, FileTree } from "../import/file-tree.js";
|
|
7
|
+
import type { MergeLabels } from "../merge.js";
|
|
8
|
+
import type { RequirementResult } from "../requires/inspect.js";
|
|
9
|
+
import type { SourceOptions } from "../sources/index.js";
|
|
10
|
+
import type { Summary } from "../summary.js";
|
|
11
|
+
export interface UpdateOptions {
|
|
12
|
+
/** Repository root that contains `.factory/`. */
|
|
13
|
+
root: string;
|
|
14
|
+
/** `--to`: a version, range, or Git ref. */
|
|
15
|
+
to?: string;
|
|
16
|
+
dryRun?: boolean;
|
|
17
|
+
noBuild?: boolean;
|
|
18
|
+
/** Create the files new requirements need: `true` for `--setup`, `false` for `--no-setup`. */
|
|
19
|
+
setup?: boolean;
|
|
20
|
+
/** Injected input and output, so tests answer without a terminal. */
|
|
21
|
+
io?: InputIO;
|
|
22
|
+
/** Let Git prompt for credentials; the command enables it for a TTY. */
|
|
23
|
+
interactive?: boolean;
|
|
24
|
+
/** Injected source settings, used by tests for a local registry or transport. */
|
|
25
|
+
sourceOptions?: SourceOptions;
|
|
26
|
+
}
|
|
27
|
+
export type UpdateStatus = "updated" | "up-to-date" | "pinned";
|
|
28
|
+
export interface UpdateReport {
|
|
29
|
+
root: string;
|
|
30
|
+
status: UpdateStatus;
|
|
31
|
+
/** The line to print for `up-to-date` and `pinned`; absent for an update. */
|
|
32
|
+
message?: string;
|
|
33
|
+
versioned: boolean;
|
|
34
|
+
previous: UpstreamEntry;
|
|
35
|
+
/** The upstream entry now recorded, or the unchanged one. */
|
|
36
|
+
upstream: UpstreamEntry;
|
|
37
|
+
from?: string;
|
|
38
|
+
to?: string;
|
|
39
|
+
/** Files the unversioned flow replaces. */
|
|
40
|
+
replaced: string[];
|
|
41
|
+
/** The `--to` range now recorded in the upstream entry, when no update ran. */
|
|
42
|
+
requested?: string;
|
|
43
|
+
/** Local edits the merge kept. */
|
|
44
|
+
preserved: string[];
|
|
45
|
+
/** Paths whose content matches upstream but whose executable bit differs. */
|
|
46
|
+
modeOnly: string[];
|
|
47
|
+
/** Paths left with conflict markers or a `.upstream` side file. */
|
|
48
|
+
conflicts: string[];
|
|
49
|
+
sideFiles: string[];
|
|
50
|
+
added: string[];
|
|
51
|
+
updated: string[];
|
|
52
|
+
removed: string[];
|
|
53
|
+
/** The requirements new in this update, in `factory.yaml` order. */
|
|
54
|
+
requires: RequirementResult[];
|
|
55
|
+
/** Human notes for the review summary. */
|
|
56
|
+
notes: string[];
|
|
57
|
+
problems: Problem[];
|
|
58
|
+
built: boolean;
|
|
59
|
+
changed: BuildChange[];
|
|
60
|
+
/** Git hooks created, updated, or removed by the closing build. */
|
|
61
|
+
hooks: HookChange[];
|
|
62
|
+
review?: Summary;
|
|
63
|
+
}
|
|
64
|
+
type PlannedWrite = {
|
|
65
|
+
kind: "write";
|
|
66
|
+
path: string;
|
|
67
|
+
entry: FileEntry;
|
|
68
|
+
} | {
|
|
69
|
+
kind: "remove";
|
|
70
|
+
path: string;
|
|
71
|
+
} | {
|
|
72
|
+
kind: "side-file";
|
|
73
|
+
path: string;
|
|
74
|
+
content: Buffer;
|
|
75
|
+
mode: number;
|
|
76
|
+
};
|
|
77
|
+
interface MergePlan {
|
|
78
|
+
after: FileTree;
|
|
79
|
+
writes: PlannedWrite[];
|
|
80
|
+
preserved: string[];
|
|
81
|
+
modeOnly: string[];
|
|
82
|
+
conflicts: string[];
|
|
83
|
+
sideFiles: string[];
|
|
84
|
+
notes: string[];
|
|
85
|
+
/**
|
|
86
|
+
* Paths upstream renamed while changing only their case. The update realigns
|
|
87
|
+
* the filesystem and the review to one spelling for them, even when the merge
|
|
88
|
+
* writes nothing, so they must reach the spelling realignment too.
|
|
89
|
+
*/
|
|
90
|
+
realigned: string[];
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Applies the merge table to every path in base, yours, or theirs.
|
|
94
|
+
*
|
|
95
|
+
* The returned `after` tree is the planned state of `.factory/` before the
|
|
96
|
+
* spelling realignment: the caller aligns it the way the writes realign the
|
|
97
|
+
* filesystem, so the review matches the files a real run leaves behind.
|
|
98
|
+
*/
|
|
99
|
+
export declare function planMerge(base: FileTree, yours: FileTree, theirs: FileTree, labels: MergeLabels, options?: {
|
|
100
|
+
baseUnavailable?: boolean;
|
|
101
|
+
}): MergePlan;
|
|
102
|
+
/**
|
|
103
|
+
* Runs `metafab update`.
|
|
104
|
+
*
|
|
105
|
+
* A versioned upstream is merged three-way: the recorded version is the base,
|
|
106
|
+
* the working `.factory/` is yours, and the selected newer version is theirs.
|
|
107
|
+
* An unversioned upstream is copied over the local files instead. A dry run
|
|
108
|
+
* computes the same plan and writes nothing.
|
|
109
|
+
*/
|
|
110
|
+
export declare function runUpdate(options: UpdateOptions): Promise<UpdateReport>;
|
|
111
|
+
/** Human-readable report for `update`. */
|
|
112
|
+
export declare function describeUpdate(report: UpdateReport): string;
|
|
113
|
+
export {};
|