@seasb/metafab 0.0.1 → 2.0.0-next.1
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 +46 -1
- package/dist/cli.d.ts +11 -0
- package/dist/cli.js +419 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/build.d.ts +31 -0
- package/dist/commands/build.js +156 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/check.d.ts +2 -0
- package/dist/commands/check.js +52 -0
- package/dist/commands/check.js.map +1 -0
- package/dist/commands/create.d.ts +2 -0
- package/dist/commands/create.js +75 -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/env.d.ts +4 -0
- package/dist/commands/env.js +362 -0
- package/dist/commands/env.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 +42 -0
- package/dist/commands/map.js.map +1 -0
- package/dist/commands/pipeline-add.d.ts +2 -0
- package/dist/commands/pipeline-add.js +68 -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 +45 -0
- package/dist/commands/pipeline-remove.js.map +1 -0
- package/dist/commands/publish.d.ts +2 -0
- package/dist/commands/publish.js +153 -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 +26 -0
- package/dist/core/build/agents.js +67 -0
- package/dist/core/build/agents.js.map +1 -0
- package/dist/core/build/index.d.ts +5 -0
- package/dist/core/build/index.js +6 -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 +82 -0
- package/dist/core/build/plan.js +912 -0
- package/dist/core/build/plan.js.map +1 -0
- package/dist/core/build/preview.d.ts +39 -0
- package/dist/core/build/preview.js +344 -0
- package/dist/core/build/preview.js.map +1 -0
- package/dist/core/build/skill.d.ts +99 -0
- package/dist/core/build/skill.js +354 -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 +16 -0
- package/dist/core/check/index.js +84 -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 +201 -0
- package/dist/core/config/parse.js.map +1 -0
- package/dist/core/config/source.d.ts +25 -0
- package/dist/core/config/source.js +67 -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 +389 -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 +269 -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 +213 -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 +81 -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 +152 -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/env/condition.d.ts +40 -0
- package/dist/core/env/condition.js +283 -0
- package/dist/core/env/condition.js.map +1 -0
- package/dist/core/env/declarations.d.ts +16 -0
- package/dist/core/env/declarations.js +328 -0
- package/dist/core/env/declarations.js.map +1 -0
- package/dist/core/env/directives.d.ts +75 -0
- package/dist/core/env/directives.js +429 -0
- package/dist/core/env/directives.js.map +1 -0
- package/dist/core/env/git-config.d.ts +15 -0
- package/dist/core/env/git-config.js +110 -0
- package/dist/core/env/git-config.js.map +1 -0
- package/dist/core/env/imports.d.ts +60 -0
- package/dist/core/env/imports.js +217 -0
- package/dist/core/env/imports.js.map +1 -0
- package/dist/core/env/index.d.ts +6 -0
- package/dist/core/env/index.js +7 -0
- package/dist/core/env/index.js.map +1 -0
- package/dist/core/env/markdown.d.ts +22 -0
- package/dist/core/env/markdown.js +33 -0
- package/dist/core/env/markdown.js.map +1 -0
- package/dist/core/env/render.d.ts +13 -0
- package/dist/core/env/render.js +65 -0
- package/dist/core/env/render.js.map +1 -0
- package/dist/core/env/report.d.ts +29 -0
- package/dist/core/env/report.js +39 -0
- package/dist/core/env/report.js.map +1 -0
- package/dist/core/env/scenarios.d.ts +40 -0
- package/dist/core/env/scenarios.js +124 -0
- package/dist/core/env/scenarios.js.map +1 -0
- package/dist/core/env/select.d.ts +30 -0
- package/dist/core/env/select.js +191 -0
- package/dist/core/env/select.js.map +1 -0
- package/dist/core/env/types.d.ts +38 -0
- package/dist/core/env/types.js +2 -0
- package/dist/core/env/types.js.map +1 -0
- package/dist/core/env/validate.d.ts +25 -0
- package/dist/core/env/validate.js +212 -0
- package/dist/core/env/validate.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 +29 -0
- package/dist/core/factory/factory-yaml.js +538 -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 +83 -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 +58 -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 +44 -0
- package/dist/core/factory/validate.js +460 -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 +275 -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 +460 -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 +177 -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 +35 -0
- package/dist/core/publish/prepare.js +102 -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 +143 -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 +109 -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 +264 -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 +639 -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 +525 -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 +218 -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 +51 -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 +411 -0
- package/dist/core/sources/npm.js.map +1 -0
- package/dist/core/sources/parse.d.ts +46 -0
- package/dist/core/sources/parse.js +446 -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 +331 -0
- package/dist/core/sources/path.js.map +1 -0
- package/dist/core/sources/problems.d.ts +29 -0
- package/dist/core/sources/problems.js +36 -0
- package/dist/core/sources/problems.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 +116 -0
- package/dist/core/sources/validate.js.map +1 -0
- package/dist/core/summary.d.ts +79 -0
- package/dist/core/summary.js +411 -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 +1135 -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 +39 -0
- package/dist/errors.js +24 -0
- package/dist/errors.js.map +1 -0
- package/dist/help.d.ts +51 -0
- package/dist/help.js +117 -0
- package/dist/help.js.map +1 -0
- package/dist/input.d.ts +25 -0
- package/dist/input.js +174 -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 +38 -0
- package/dist/util/fs.js +135 -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 -3
- package/resources/metafab-skill/SKILL.md +173 -0
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { chmod, lstat, mkdir, readFile, readlink, stat, unlink, writeFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { runGit } from "../../util/git.js";
|
|
4
|
+
import { toLF } from "../../util/text.js";
|
|
5
|
+
import { HOOK_NAMES, HOOK_START_MARKER, hookCommand, hookScript } from "./script.js";
|
|
6
|
+
const CONFIG_FILE = ".factory/metafab.yaml";
|
|
7
|
+
const CD_LINE = /^cd "\$\(git rev-parse --show-toplevel\)\/(.*)"/;
|
|
8
|
+
function noGitWarning() {
|
|
9
|
+
return {
|
|
10
|
+
level: "warning",
|
|
11
|
+
file: CONFIG_FILE,
|
|
12
|
+
message: "git-hooks is true, but this is not a Git repository or git is not installed",
|
|
13
|
+
fix: "Install Git, or set git-hooks: false",
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function foreignWarning(file, factoryRelDir, cliVersion) {
|
|
17
|
+
return {
|
|
18
|
+
level: "warning",
|
|
19
|
+
file,
|
|
20
|
+
message: `${file} exists and was not written by Metafab`,
|
|
21
|
+
fix: `Add this line to ${file}: ${hookCommand(factoryRelDir, cliVersion)}`,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function linkWarning(file, target, factoryRelDir, cliVersion) {
|
|
25
|
+
return {
|
|
26
|
+
level: "warning",
|
|
27
|
+
file,
|
|
28
|
+
message: `${file} is a symbolic link to ${target}, so Metafab did not change it`,
|
|
29
|
+
fix: `Add this line to ${target}: ${hookCommand(factoryRelDir, cliVersion)}, or replace the link with a regular file and run metafab build again`,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function danglingLinkWarning(file, target) {
|
|
33
|
+
return {
|
|
34
|
+
level: "warning",
|
|
35
|
+
file,
|
|
36
|
+
message: `${file} is a symbolic link to ${target}, which does not exist, so Metafab did not change it`,
|
|
37
|
+
fix: "Remove the link, then run metafab build again",
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function notRegularFileWarning(file) {
|
|
41
|
+
return {
|
|
42
|
+
level: "warning",
|
|
43
|
+
file,
|
|
44
|
+
message: `${file} is not a regular file, so Metafab did not change it`,
|
|
45
|
+
fix: "Remove it, then run metafab build again",
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function hooksPathWarning(hooksPath, factoryRelDir, cliVersion) {
|
|
49
|
+
return {
|
|
50
|
+
level: "warning",
|
|
51
|
+
file: CONFIG_FILE,
|
|
52
|
+
message: "core.hooksPath is set, so Metafab did not install Git hooks",
|
|
53
|
+
fix: `Add this line to post-checkout, post-merge and post-rewrite in ${hooksPath}: ${hookCommand(factoryRelDir, cliVersion)}`,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function otherFactoryWarning(file, otherDir) {
|
|
57
|
+
return {
|
|
58
|
+
level: "warning",
|
|
59
|
+
file,
|
|
60
|
+
message: `${file} runs metafab build for ${otherDir}`,
|
|
61
|
+
fix: "Git hooks support one factory per repository; set git-hooks: false in one of them",
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function unreadableHooksPathWarning() {
|
|
65
|
+
return {
|
|
66
|
+
level: "warning",
|
|
67
|
+
file: CONFIG_FILE,
|
|
68
|
+
message: "core.hooksPath could not be read, so Metafab did not install Git hooks",
|
|
69
|
+
fix: "Run git config --get core.hooksPath, fix the error, then run metafab build again",
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function fileWarning(file, error) {
|
|
73
|
+
const code = error.code ?? "error";
|
|
74
|
+
return {
|
|
75
|
+
level: "warning",
|
|
76
|
+
file,
|
|
77
|
+
message: `Cannot update ${file}: ${code}`,
|
|
78
|
+
fix: "Check the file's permissions, then run metafab build again",
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
async function gitOutput(args, cwd) {
|
|
82
|
+
try {
|
|
83
|
+
const result = await runGit(args, { cwd });
|
|
84
|
+
return result.exitCode === 0 ? result.stdout : undefined;
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Reads a hook without following a symbolic link.
|
|
92
|
+
*
|
|
93
|
+
* A link is reported with the target text it stores and whether that target
|
|
94
|
+
* exists. Anything else that is not a regular file is reported as `other`:
|
|
95
|
+
* Metafab never writes, chmods or deletes through a hook path, so a file
|
|
96
|
+
* elsewhere in the system is left alone.
|
|
97
|
+
*/
|
|
98
|
+
async function readHook(hookPath) {
|
|
99
|
+
let stats;
|
|
100
|
+
try {
|
|
101
|
+
stats = await lstat(hookPath);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
if (error.code === "ENOENT")
|
|
105
|
+
return { kind: "missing" };
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
if (stats.isSymbolicLink()) {
|
|
109
|
+
const target = await readlink(hookPath);
|
|
110
|
+
let dangling = false;
|
|
111
|
+
try {
|
|
112
|
+
await stat(hookPath);
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
if (error.code !== "ENOENT")
|
|
116
|
+
throw error;
|
|
117
|
+
dangling = true;
|
|
118
|
+
}
|
|
119
|
+
return { kind: "link", target, dangling };
|
|
120
|
+
}
|
|
121
|
+
if (!stats.isFile())
|
|
122
|
+
return { kind: "other" };
|
|
123
|
+
return { kind: "regular", text: await readFile(hookPath, "utf8") };
|
|
124
|
+
}
|
|
125
|
+
function isOwned(text) {
|
|
126
|
+
return toLF(text).split("\n").includes(HOOK_START_MARKER);
|
|
127
|
+
}
|
|
128
|
+
/** The factory directory an owned hook serves, or `undefined` when it cannot be parsed. */
|
|
129
|
+
function hookFactoryDir(text) {
|
|
130
|
+
for (const line of toLF(text).split("\n")) {
|
|
131
|
+
const match = CD_LINE.exec(line);
|
|
132
|
+
if (match !== null)
|
|
133
|
+
return match[1];
|
|
134
|
+
}
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
function relativePath(root, target) {
|
|
138
|
+
return path.relative(root, target).split(path.sep).join("/");
|
|
139
|
+
}
|
|
140
|
+
async function writeHook(target, content) {
|
|
141
|
+
await writeFile(target, content, { mode: 0o755 });
|
|
142
|
+
await chmod(target, 0o755);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Applies the Git hooks rules in docs/specs/building.md#git-hooks.
|
|
146
|
+
*
|
|
147
|
+
* Never throws for Git problems: a missing `git`, a directory outside a
|
|
148
|
+
* repository, and any other Git failure become warnings or a no-op.
|
|
149
|
+
*/
|
|
150
|
+
export async function syncGitHooks(root, enabled, cliVersion) {
|
|
151
|
+
const changed = [];
|
|
152
|
+
const warnings = [];
|
|
153
|
+
const topLevel = await gitOutput(["rev-parse", "--show-toplevel"], root);
|
|
154
|
+
const commonDir = await gitOutput(["rev-parse", "--git-common-dir"], root);
|
|
155
|
+
if (topLevel === undefined || commonDir === undefined) {
|
|
156
|
+
if (enabled)
|
|
157
|
+
warnings.push(noGitWarning());
|
|
158
|
+
return { changed, warnings };
|
|
159
|
+
}
|
|
160
|
+
let hooksPath;
|
|
161
|
+
try {
|
|
162
|
+
const result = await runGit(["config", "--get", "core.hooksPath"], { cwd: root });
|
|
163
|
+
if (result.exitCode === 0) {
|
|
164
|
+
hooksPath = result.stdout.trim();
|
|
165
|
+
}
|
|
166
|
+
else if (result.exitCode !== 1) {
|
|
167
|
+
warnings.push(unreadableHooksPathWarning());
|
|
168
|
+
return { changed, warnings };
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
if (enabled)
|
|
173
|
+
warnings.push(noGitWarning());
|
|
174
|
+
return { changed, warnings };
|
|
175
|
+
}
|
|
176
|
+
const prefix = await gitOutput(["rev-parse", "--show-prefix"], root);
|
|
177
|
+
const factoryRelDir = prefix === undefined ? "." : prefix.trim().replace(/\/+$/, "") || ".";
|
|
178
|
+
const hooksDir = path.join(path.resolve(root, commonDir.trim()), "hooks");
|
|
179
|
+
const canWrite = enabled && hooksPath === undefined;
|
|
180
|
+
if (hooksPath !== undefined && enabled) {
|
|
181
|
+
warnings.push(hooksPathWarning(hooksPath, factoryRelDir, cliVersion));
|
|
182
|
+
}
|
|
183
|
+
if (canWrite) {
|
|
184
|
+
try {
|
|
185
|
+
await mkdir(hooksDir, { recursive: true });
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
warnings.push(fileWarning(relativePath(root, hooksDir), error));
|
|
189
|
+
return { changed, warnings };
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
for (const hook of HOOK_NAMES) {
|
|
193
|
+
const target = path.join(hooksDir, hook);
|
|
194
|
+
const file = relativePath(root, target);
|
|
195
|
+
try {
|
|
196
|
+
const state = await readHook(target);
|
|
197
|
+
if (state.kind === "missing") {
|
|
198
|
+
if (!canWrite)
|
|
199
|
+
continue;
|
|
200
|
+
await writeHook(target, hookScript(hook, factoryRelDir, cliVersion));
|
|
201
|
+
changed.push({ hook, action: "created" });
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
// A symbolic link, or anything else that is not a regular file, is not
|
|
205
|
+
// a hook Metafab wrote. Leave it and warn: a link may point at an older
|
|
206
|
+
// Metafab hook or at nothing at all, so the foreign-hook fix would be
|
|
207
|
+
// wrong.
|
|
208
|
+
if (state.kind === "link") {
|
|
209
|
+
if (enabled) {
|
|
210
|
+
warnings.push(state.dangling
|
|
211
|
+
? danglingLinkWarning(file, state.target)
|
|
212
|
+
: linkWarning(file, state.target, factoryRelDir, cliVersion));
|
|
213
|
+
}
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
if (state.kind === "other") {
|
|
217
|
+
if (enabled)
|
|
218
|
+
warnings.push(notRegularFileWarning(file));
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
const existing = state.text;
|
|
222
|
+
if (!isOwned(existing)) {
|
|
223
|
+
if (enabled)
|
|
224
|
+
warnings.push(foreignWarning(file, factoryRelDir, cliVersion));
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
const otherDir = hookFactoryDir(existing);
|
|
228
|
+
if (otherDir !== undefined && otherDir !== factoryRelDir) {
|
|
229
|
+
if (enabled)
|
|
230
|
+
warnings.push(otherFactoryWarning(file, otherDir));
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
if (!enabled) {
|
|
234
|
+
await unlink(target);
|
|
235
|
+
changed.push({ hook, action: "removed" });
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
if (!canWrite)
|
|
239
|
+
continue;
|
|
240
|
+
const desired = hookScript(hook, factoryRelDir, cliVersion);
|
|
241
|
+
if (toLF(existing) !== desired) {
|
|
242
|
+
await writeHook(target, desired);
|
|
243
|
+
changed.push({ hook, action: "updated" });
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
// The content matches, but Git does not run a hook without the
|
|
247
|
+
// executable bits. Windows has no permission bits to compare.
|
|
248
|
+
if (process.platform === "win32")
|
|
249
|
+
continue;
|
|
250
|
+
const mode = (await lstat(target)).mode & 0o777;
|
|
251
|
+
if (mode === 0o755)
|
|
252
|
+
continue;
|
|
253
|
+
await chmod(target, 0o755);
|
|
254
|
+
changed.push({ hook, action: "updated" });
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
warnings.push(fileWarning(file, error));
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return { changed, warnings };
|
|
261
|
+
}
|
|
262
|
+
//# sourceMappingURL=sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../../../src/core/hooks/sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAEpG,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAarF,MAAM,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AG,CAAC,MAAM,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,GAAG,KAAK,CAAC;YAChD,IAAI,IAAI,KAAK,KAAK;gBAAE,SAAS;YAE7B,MAAM,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YAC3B,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;QAC5C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { Problem } from "../../errors.js";
|
|
2
|
+
import type { FileEntry } from "./file-tree.js";
|
|
3
|
+
import type { AdoptionMove } from "../adopt.js";
|
|
4
|
+
/** A file that an incoming fab path would replace, with the path to report. */
|
|
5
|
+
export interface LocalFile {
|
|
6
|
+
entry: FileEntry;
|
|
7
|
+
file: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The local paths an import would write over, keyed by the factory-relative
|
|
11
|
+
* path the incoming fab uses for them.
|
|
12
|
+
*/
|
|
13
|
+
export interface LocalPaths {
|
|
14
|
+
files: Map<string, LocalFile>;
|
|
15
|
+
/** Every existing local directory, empty ones included: `key` to local path. */
|
|
16
|
+
directories: Map<string, string>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Local paths indexed the way the filesystem compares them: ignoring case, with
|
|
20
|
+
* every spelling kept. A case-sensitive filesystem can hold two entries that
|
|
21
|
+
* fold to one name, and both callers must see both rather than silently
|
|
22
|
+
* choosing one.
|
|
23
|
+
*/
|
|
24
|
+
export interface Indexed<T> {
|
|
25
|
+
key: string;
|
|
26
|
+
value: T;
|
|
27
|
+
}
|
|
28
|
+
/** One list of entries per folded name, each entry keeping its local spelling. */
|
|
29
|
+
export declare function indexOf<T>(entries: Iterable<[string, T]>): Map<string, Indexed<T>[]>;
|
|
30
|
+
export declare function ancestors(relativePath: string): string[];
|
|
31
|
+
/** The one wording for a local entry that differs only in case from an incoming path. */
|
|
32
|
+
export declare function differentSpelling(file: string, incoming: string, command: "import" | "update"): Problem;
|
|
33
|
+
/**
|
|
34
|
+
* The problem for an incoming path that several local spellings fold to.
|
|
35
|
+
*
|
|
36
|
+
* The clash preflight and the realignment both refuse this case, so the text is
|
|
37
|
+
* built here once and both paths report it identically.
|
|
38
|
+
*/
|
|
39
|
+
export declare function ambiguousSpellingProblem(files: readonly string[], incoming: string, command: "import" | "update"): Problem;
|
|
40
|
+
/**
|
|
41
|
+
* The local paths an import could write over: the factory, plus the files of
|
|
42
|
+
* each skill adoption will move into it. Keys are factory-relative paths, so a
|
|
43
|
+
* planned move of `release` maps `.claude/skills/release/SKILL.md` to
|
|
44
|
+
* `skills/release/SKILL.md`, where the incoming fab writes.
|
|
45
|
+
*
|
|
46
|
+
* Directories are listed too, empty ones included: a snapshot has none, so
|
|
47
|
+
* without this an incoming file could quietly delete one.
|
|
48
|
+
*/
|
|
49
|
+
export declare function localFilesForImport(root: string, factoryDir: string, moves: readonly AdoptionMove[], hasFactory: boolean): Promise<LocalPaths>;
|
|
50
|
+
/** The problems an import preflight finds, split by whether `--force` helps. */
|
|
51
|
+
export interface ImportConflicts {
|
|
52
|
+
/** Replacements `--force` may make. */
|
|
53
|
+
conflicts: Problem[];
|
|
54
|
+
/** Paths `--force` cannot resolve, because several local spellings fold to one incoming path. */
|
|
55
|
+
ambiguities: Problem[];
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Every incoming path that would replace or remove local content: a file, link
|
|
59
|
+
* or directory whose content differs, or a local path that differs only in
|
|
60
|
+
* case. Content is compared without line-ending changes counting as a
|
|
61
|
+
* difference, and without case: a path that differs only in case still lands on
|
|
62
|
+
* the same entry on a case-insensitive filesystem. An incoming file or link at
|
|
63
|
+
* the path of an existing local directory is a conflict too, empty directories
|
|
64
|
+
* included, because the copy would delete it. A path that would replace a file
|
|
65
|
+
* with a directory, a directory with a file, or a link with a file, is a
|
|
66
|
+
* conflict, so the copy can never fail on it or delete local content.
|
|
67
|
+
*
|
|
68
|
+
* Every incoming path is folded against its local ancestors as well as the
|
|
69
|
+
* path itself, so a case-only clash with a local file, link or directory at any
|
|
70
|
+
* depth is refused. Without that, an incoming `templates/` would slip past a
|
|
71
|
+
* local `Templates/` on a case-insensitive filesystem and split in two on a
|
|
72
|
+
* case-sensitive one.
|
|
73
|
+
*
|
|
74
|
+
* A clash is reported once per clashing component, not once per incoming file
|
|
75
|
+
* beneath it: a local `Templates/` against three incoming files gives one
|
|
76
|
+
* problem that names `templates`.
|
|
77
|
+
*
|
|
78
|
+
* Two local entries that fold to one incoming component are an ambiguity, not
|
|
79
|
+
* a conflict: only a case-sensitive filesystem can hold both, and no rename can
|
|
80
|
+
* choose between them safely. `--force` never overrides an ambiguity.
|
|
81
|
+
*/
|
|
82
|
+
export declare function findImportConflicts(incomingDir: string, local: LocalPaths): Promise<ImportConflicts>;
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { snapshotDirectories, snapshotTree } from "./file-tree.js";
|
|
3
|
+
/** One list of entries per folded name, each entry keeping its local spelling. */
|
|
4
|
+
export function indexOf(entries) {
|
|
5
|
+
const index = new Map();
|
|
6
|
+
for (const [key, value] of entries) {
|
|
7
|
+
const folded = key.toLowerCase();
|
|
8
|
+
const indexed = index.get(folded);
|
|
9
|
+
if (indexed === undefined)
|
|
10
|
+
index.set(folded, [{ key, value }]);
|
|
11
|
+
else
|
|
12
|
+
indexed.push({ key, value });
|
|
13
|
+
}
|
|
14
|
+
return index;
|
|
15
|
+
}
|
|
16
|
+
function absolute(root, relativePath) {
|
|
17
|
+
return path.join(root, ...relativePath.split("/"));
|
|
18
|
+
}
|
|
19
|
+
export function ancestors(relativePath) {
|
|
20
|
+
const parts = relativePath.split("/");
|
|
21
|
+
const prefixes = [];
|
|
22
|
+
for (let index = 1; index < parts.length; index += 1) {
|
|
23
|
+
prefixes.push(parts.slice(0, index).join("/"));
|
|
24
|
+
}
|
|
25
|
+
return prefixes;
|
|
26
|
+
}
|
|
27
|
+
function replaced(file) {
|
|
28
|
+
return {
|
|
29
|
+
level: "error",
|
|
30
|
+
file,
|
|
31
|
+
message: `The incoming fab would replace ${file}`,
|
|
32
|
+
fix: "Keep the local file, or run metafab import --force to replace it",
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function blocked(file) {
|
|
36
|
+
return {
|
|
37
|
+
level: "error",
|
|
38
|
+
file,
|
|
39
|
+
message: `The incoming fab would replace ${file} with a different kind of entry`,
|
|
40
|
+
fix: "Move the local entry away, or run metafab import --force to replace it",
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** The one wording for a local entry that differs only in case from an incoming path. */
|
|
44
|
+
export function differentSpelling(file, incoming, command) {
|
|
45
|
+
const importing = command === "import";
|
|
46
|
+
return {
|
|
47
|
+
level: "error",
|
|
48
|
+
file,
|
|
49
|
+
message: importing
|
|
50
|
+
? `The incoming fab writes ${incoming}, which differs only in case from ${file}`
|
|
51
|
+
: `The update writes ${incoming}, which differs only in case from ${file}`,
|
|
52
|
+
fix: importing
|
|
53
|
+
? "Keep the local file, or run metafab import --force to replace it"
|
|
54
|
+
: "Move the local entry away, then run metafab update again",
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The problem for an incoming path that several local spellings fold to.
|
|
59
|
+
*
|
|
60
|
+
* The clash preflight and the realignment both refuse this case, so the text is
|
|
61
|
+
* built here once and both paths report it identically.
|
|
62
|
+
*/
|
|
63
|
+
export function ambiguousSpellingProblem(files, incoming, command) {
|
|
64
|
+
const importing = command === "import";
|
|
65
|
+
return {
|
|
66
|
+
level: "error",
|
|
67
|
+
file: files[0] ?? incoming,
|
|
68
|
+
message: importing
|
|
69
|
+
? `The incoming fab writes ${incoming}, but these local entries differ only in case: ${files.join(", ")}`
|
|
70
|
+
: `The update writes ${incoming}, but these local entries differ only in case: ${files.join(", ")}`,
|
|
71
|
+
fix: importing
|
|
72
|
+
? "Move all but one of the local entries away, then run metafab import again"
|
|
73
|
+
: "Move all but one of the local entries away, then run metafab update again",
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function addTree(files, tree, prefix, sourceDirectory) {
|
|
77
|
+
for (const [relativePath, entry] of Object.entries(tree)) {
|
|
78
|
+
const key = prefix === "" ? relativePath : `${prefix}/${relativePath}`;
|
|
79
|
+
if (files.has(key))
|
|
80
|
+
continue;
|
|
81
|
+
files.set(key, { entry, file: `${sourceDirectory}/${relativePath}` });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function addDirectories(directories, relativePaths, prefix, sourceDirectory) {
|
|
85
|
+
for (const relativePath of relativePaths) {
|
|
86
|
+
const key = prefix === "" ? relativePath : `${prefix}/${relativePath}`;
|
|
87
|
+
if (directories.has(key))
|
|
88
|
+
continue;
|
|
89
|
+
directories.set(key, `${sourceDirectory}/${relativePath}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The local paths an import could write over: the factory, plus the files of
|
|
94
|
+
* each skill adoption will move into it. Keys are factory-relative paths, so a
|
|
95
|
+
* planned move of `release` maps `.claude/skills/release/SKILL.md` to
|
|
96
|
+
* `skills/release/SKILL.md`, where the incoming fab writes.
|
|
97
|
+
*
|
|
98
|
+
* Directories are listed too, empty ones included: a snapshot has none, so
|
|
99
|
+
* without this an incoming file could quietly delete one.
|
|
100
|
+
*/
|
|
101
|
+
export async function localFilesForImport(root, factoryDir, moves, hasFactory) {
|
|
102
|
+
const paths = { files: new Map(), directories: new Map() };
|
|
103
|
+
if (hasFactory) {
|
|
104
|
+
addTree(paths.files, await snapshotTree(factoryDir), "", ".factory");
|
|
105
|
+
addDirectories(paths.directories, await snapshotDirectories(factoryDir), "", ".factory");
|
|
106
|
+
}
|
|
107
|
+
for (const move of moves) {
|
|
108
|
+
const primary = move.from[0];
|
|
109
|
+
if (primary === undefined)
|
|
110
|
+
continue;
|
|
111
|
+
let tree;
|
|
112
|
+
let directories;
|
|
113
|
+
try {
|
|
114
|
+
[tree, directories] = await Promise.all([
|
|
115
|
+
snapshotTree(absolute(root, primary)),
|
|
116
|
+
snapshotDirectories(absolute(root, primary)),
|
|
117
|
+
]);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
addTree(paths.files, tree, `skills/${move.name}`, primary);
|
|
123
|
+
addDirectories(paths.directories, directories, `skills/${move.name}`, primary);
|
|
124
|
+
}
|
|
125
|
+
return paths;
|
|
126
|
+
}
|
|
127
|
+
function localIndex(local) {
|
|
128
|
+
return {
|
|
129
|
+
files: indexOf(local.files.entries()),
|
|
130
|
+
directories: indexOf(local.directories.entries()),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Every incoming path that would replace or remove local content: a file, link
|
|
135
|
+
* or directory whose content differs, or a local path that differs only in
|
|
136
|
+
* case. Content is compared without line-ending changes counting as a
|
|
137
|
+
* difference, and without case: a path that differs only in case still lands on
|
|
138
|
+
* the same entry on a case-insensitive filesystem. An incoming file or link at
|
|
139
|
+
* the path of an existing local directory is a conflict too, empty directories
|
|
140
|
+
* included, because the copy would delete it. A path that would replace a file
|
|
141
|
+
* with a directory, a directory with a file, or a link with a file, is a
|
|
142
|
+
* conflict, so the copy can never fail on it or delete local content.
|
|
143
|
+
*
|
|
144
|
+
* Every incoming path is folded against its local ancestors as well as the
|
|
145
|
+
* path itself, so a case-only clash with a local file, link or directory at any
|
|
146
|
+
* depth is refused. Without that, an incoming `templates/` would slip past a
|
|
147
|
+
* local `Templates/` on a case-insensitive filesystem and split in two on a
|
|
148
|
+
* case-sensitive one.
|
|
149
|
+
*
|
|
150
|
+
* A clash is reported once per clashing component, not once per incoming file
|
|
151
|
+
* beneath it: a local `Templates/` against three incoming files gives one
|
|
152
|
+
* problem that names `templates`.
|
|
153
|
+
*
|
|
154
|
+
* Two local entries that fold to one incoming component are an ambiguity, not
|
|
155
|
+
* a conflict: only a case-sensitive filesystem can hold both, and no rename can
|
|
156
|
+
* choose between them safely. `--force` never overrides an ambiguity.
|
|
157
|
+
*/
|
|
158
|
+
export async function findImportConflicts(incomingDir, local) {
|
|
159
|
+
const [incoming, incomingDirectories] = await Promise.all([
|
|
160
|
+
snapshotTree(incomingDir),
|
|
161
|
+
snapshotDirectories(incomingDir),
|
|
162
|
+
]);
|
|
163
|
+
const index = localIndex(local);
|
|
164
|
+
const conflicts = [];
|
|
165
|
+
const ambiguities = [];
|
|
166
|
+
const reported = new Set();
|
|
167
|
+
function report(into, problem) {
|
|
168
|
+
const id = `${problem.file}\u0000${problem.message}`;
|
|
169
|
+
if (reported.has(id))
|
|
170
|
+
return;
|
|
171
|
+
reported.add(id);
|
|
172
|
+
into.push(problem);
|
|
173
|
+
}
|
|
174
|
+
/** One problem for a component that several local spellings fold to. */
|
|
175
|
+
function ambiguity(files, incoming) {
|
|
176
|
+
report(ambiguities, ambiguousSpellingProblem(files, incoming, "import"));
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Reports the first local entry on the path itself, or among its ancestors,
|
|
180
|
+
* that the incoming entry would replace. Case-only clashes name the local
|
|
181
|
+
* entry and the incoming component; an exact spelling that changes the kind
|
|
182
|
+
* of entry is reported as blocked.
|
|
183
|
+
*/
|
|
184
|
+
function checkLocalPath(relativePath, incomingDirectory) {
|
|
185
|
+
const folded = relativePath.toLowerCase();
|
|
186
|
+
const existingFiles = index.files.get(folded);
|
|
187
|
+
if (existingFiles !== undefined && existingFiles.length > 0) {
|
|
188
|
+
if (existingFiles.length > 1) {
|
|
189
|
+
ambiguity(existingFiles.map((entry) => entry.value.file), relativePath);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const existingFile = existingFiles[0];
|
|
193
|
+
if (existingFile.key !== relativePath) {
|
|
194
|
+
report(conflicts, differentSpelling(existingFile.value.file, relativePath, "import"));
|
|
195
|
+
}
|
|
196
|
+
else if (incomingDirectory) {
|
|
197
|
+
report(conflicts, blocked(existingFile.value.file));
|
|
198
|
+
}
|
|
199
|
+
else if (existingFile.value.entry.hash !== incoming[relativePath].hash) {
|
|
200
|
+
report(conflicts, replaced(existingFile.value.file));
|
|
201
|
+
}
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
for (const prefix of ancestors(relativePath)) {
|
|
205
|
+
const foldedPrefix = prefix.toLowerCase();
|
|
206
|
+
const ancestorFiles = index.files.get(foldedPrefix);
|
|
207
|
+
if (ancestorFiles !== undefined) {
|
|
208
|
+
if (ancestorFiles.length > 1) {
|
|
209
|
+
ambiguity(ancestorFiles.map((entry) => entry.value.file), prefix);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const ancestorFile = ancestorFiles[0];
|
|
213
|
+
report(conflicts, ancestorFile.key === prefix
|
|
214
|
+
? blocked(ancestorFile.value.file)
|
|
215
|
+
: differentSpelling(ancestorFile.value.file, prefix, "import"));
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const ancestorDirectories = index.directories.get(foldedPrefix);
|
|
219
|
+
if (ancestorDirectories !== undefined) {
|
|
220
|
+
if (ancestorDirectories.length > 1) {
|
|
221
|
+
ambiguity(ancestorDirectories.map((entry) => entry.value), prefix);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const ancestorDirectory = ancestorDirectories[0];
|
|
225
|
+
if (ancestorDirectory.key !== prefix) {
|
|
226
|
+
report(conflicts, differentSpelling(ancestorDirectory.value, prefix, "import"));
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const existingDirectories = index.directories.get(folded);
|
|
232
|
+
if (existingDirectories === undefined)
|
|
233
|
+
return;
|
|
234
|
+
if (existingDirectories.length > 1) {
|
|
235
|
+
ambiguity(existingDirectories.map((entry) => entry.value), relativePath);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
const existingDirectory = existingDirectories[0];
|
|
239
|
+
if (existingDirectory.key !== relativePath) {
|
|
240
|
+
report(conflicts, differentSpelling(existingDirectory.value, relativePath, "import"));
|
|
241
|
+
}
|
|
242
|
+
else if (!incomingDirectory) {
|
|
243
|
+
report(conflicts, blocked(existingDirectory.value));
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
for (const relativePath of Object.keys(incoming).sort()) {
|
|
247
|
+
checkLocalPath(relativePath, false);
|
|
248
|
+
}
|
|
249
|
+
// Directories are checked too: an incoming empty directory can clash with a
|
|
250
|
+
// local one, or replace a local file or link, just as a file can.
|
|
251
|
+
for (const relativePath of [...incomingDirectories].sort()) {
|
|
252
|
+
checkLocalPath(relativePath, true);
|
|
253
|
+
}
|
|
254
|
+
return { conflicts, ambiguities };
|
|
255
|
+
}
|
|
256
|
+
//# sourceMappingURL=conflicts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conflicts.js","sourceRoot":"","sources":["../../../src/core/import/conflicts.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AA+BnE,kFAAkF;AAClF,MAAM,UAAU,OAAO,CAAI,OAA8B;IACvD,MAAM,KAAK,GAAG,IAAI,GAAG,EAAwB,CAAC;IAC9C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,OAAO,EAAE,CAAC;QACnC,MAAM,MAAM,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;QACjC,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAClC,IAAI,OAAO,KAAK,SAAS;YAAE,KAAK,CAAC,GAA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4EAA4E;IAC5E,kEAAkE;IAClE,KAAK,MAAM,YAAY,IAAI,CAAC,GAAG,mBAAmB,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;QAC3D,cAAc,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;IACrC,CAAC;IAED,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Files the fab carries for its own repository, never for the receiver. */
|
|
2
|
+
export declare const FAB_ROOT_EXCLUDES: ReadonlySet<string>;
|
|
3
|
+
/**
|
|
4
|
+
* Copy a fetched fab's `.factory/` into the local `.factory/`, keeping modes.
|
|
5
|
+
*
|
|
6
|
+
* `metafab.yaml` and `.factory/README.md` belong to the fab's repository and are
|
|
7
|
+
* never copied. The source tree was validated by the fetch, so links point
|
|
8
|
+
* inside the factory and can be recreated as they are.
|
|
9
|
+
*/
|
|
10
|
+
export declare function copyFactoryTree(sourceDir: string, destinationDir: string): Promise<string[]>;
|