@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,60 @@
|
|
|
1
|
+
import type { Problem } from "../../errors.js";
|
|
2
|
+
/** What a failed import reports, on the directive's line in the importing file. */
|
|
3
|
+
export interface ImportFailure {
|
|
4
|
+
ok: false;
|
|
5
|
+
message: string;
|
|
6
|
+
fix: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ImportCache {
|
|
9
|
+
/** Absolute `.factory` directory, native separators. */
|
|
10
|
+
factoryDir: string;
|
|
11
|
+
/** `realpath` of `.factory`, computed once. */
|
|
12
|
+
factoryReal?: string;
|
|
13
|
+
/**
|
|
14
|
+
* By realpath: what does not depend on the route a file was imported through,
|
|
15
|
+
* so a partial imported by ten files is read once per cache.
|
|
16
|
+
*/
|
|
17
|
+
files: Map<string, LoadedImport>;
|
|
18
|
+
}
|
|
19
|
+
export interface LoadedImport {
|
|
20
|
+
/** Repository-relative POSIX path of the file itself, such as `.factory/partials/sub-agents.md`. */
|
|
21
|
+
file: string;
|
|
22
|
+
/** The body, frontmatter removed, and one trailing newline dropped so the import replaces one line. */
|
|
23
|
+
text: string;
|
|
24
|
+
/** Line number of the body's first line in the file. */
|
|
25
|
+
firstLine: number;
|
|
26
|
+
/** The imported file's own problems: a directive in its frontmatter. */
|
|
27
|
+
problems: Problem[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A cache of imported files for one build or one `loadFactory`. Every file is
|
|
31
|
+
* keyed by its realpath, so an edited partial is always reread by the next run.
|
|
32
|
+
*/
|
|
33
|
+
export declare function createImportCache(factoryDir: string): ImportCache;
|
|
34
|
+
/**
|
|
35
|
+
* Rules 1 to 5 for an import: the path is relative to the importing file, uses
|
|
36
|
+
* `/`, ends in `.md`, and stays inside `.factory/` once normalised. Pure: it
|
|
37
|
+
* works on factory-relative POSIX paths only, so a Windows-style path gives the
|
|
38
|
+
* same answer on every platform and nothing here touches the disk.
|
|
39
|
+
*/
|
|
40
|
+
export declare function importTarget(from: string, argument: string): {
|
|
41
|
+
ok: true;
|
|
42
|
+
target: string;
|
|
43
|
+
} | ImportFailure;
|
|
44
|
+
/**
|
|
45
|
+
* The repository-relative `.factory/<path>` name of a realpath, for messages
|
|
46
|
+
* such as an import loop's chain.
|
|
47
|
+
*/
|
|
48
|
+
export declare function realDisplayPath(cache: ImportCache, real: string): string;
|
|
49
|
+
/**
|
|
50
|
+
* Resolves an import to the file's realpath and its loaded content, reporting
|
|
51
|
+
* every path rule of the spec on the directive's line. The walk reads directory
|
|
52
|
+
* listings and matches names exactly, so a wrong-case path fails the same way on
|
|
53
|
+
* a case-insensitive file system as on a case-sensitive one. Symbolic links, for
|
|
54
|
+
* the file and for any parent, must resolve inside the real `.factory/`.
|
|
55
|
+
*/
|
|
56
|
+
export declare function resolveImport(from: string, argument: string, cache: ImportCache): Promise<{
|
|
57
|
+
ok: true;
|
|
58
|
+
real: string;
|
|
59
|
+
loaded: LoadedImport;
|
|
60
|
+
} | ImportFailure>;
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { readFile, realpath, stat } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { readdirTyped } from "../../util/fs.js";
|
|
4
|
+
import { toLF } from "../../util/text.js";
|
|
5
|
+
import { isInside, textContent } from "../build/skill.js";
|
|
6
|
+
import { directiveLines } from "./directives.js";
|
|
7
|
+
import { markdownParts } from "./markdown.js";
|
|
8
|
+
const FRONTMATTER_MESSAGE = "Directives are not allowed in frontmatter";
|
|
9
|
+
const FRONTMATTER_FIX = "Move the directive below the closing ---; name and description stay the same in every environment";
|
|
10
|
+
const NEEDS_PATH_FIX = "Write <!-- factory:import <path> -->";
|
|
11
|
+
const RELATIVE_FIX = "Write a path relative to this file, such as ../partials/x.md";
|
|
12
|
+
const SLASH_FIX = "Write it with / instead of \\";
|
|
13
|
+
const MARKDOWN_FIX = "Import a .md file, such as ../partials/x.md";
|
|
14
|
+
const INSIDE_FIX = "Import a file inside .factory/";
|
|
15
|
+
const MISSING_FIX = "Add the file, or write the path of a file in .factory/";
|
|
16
|
+
const DIRECTORY_FIX = "Import a .md file inside it";
|
|
17
|
+
const READ_FIX = "Check its permissions";
|
|
18
|
+
const TEXT_FIX = "Replace it with a UTF-8 text file";
|
|
19
|
+
const UNTERMINATED_FIX = "Add a line that contains only --- after the frontmatter";
|
|
20
|
+
/**
|
|
21
|
+
* A cache of imported files for one build or one `loadFactory`. Every file is
|
|
22
|
+
* keyed by its realpath, so an edited partial is always reread by the next run.
|
|
23
|
+
*/
|
|
24
|
+
export function createImportCache(factoryDir) {
|
|
25
|
+
return { factoryDir, files: new Map() };
|
|
26
|
+
}
|
|
27
|
+
function failure(message, fix) {
|
|
28
|
+
return { ok: false, message, fix };
|
|
29
|
+
}
|
|
30
|
+
function missing(given) {
|
|
31
|
+
return failure(`Import "${given}" does not exist`, MISSING_FIX);
|
|
32
|
+
}
|
|
33
|
+
function cannotRead(given) {
|
|
34
|
+
return failure(`Import "${given}" cannot be read`, READ_FIX);
|
|
35
|
+
}
|
|
36
|
+
/** A read error that means the path is not there, rather than that it is unreadable. */
|
|
37
|
+
function isMissing(error) {
|
|
38
|
+
const code = error.code;
|
|
39
|
+
return code === "ENOENT" || code === "ENOTDIR";
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Rules 1 to 5 for an import: the path is relative to the importing file, uses
|
|
43
|
+
* `/`, ends in `.md`, and stays inside `.factory/` once normalised. Pure: it
|
|
44
|
+
* works on factory-relative POSIX paths only, so a Windows-style path gives the
|
|
45
|
+
* same answer on every platform and nothing here touches the disk.
|
|
46
|
+
*/
|
|
47
|
+
export function importTarget(from, argument) {
|
|
48
|
+
const given = argument.trim();
|
|
49
|
+
if (given === "")
|
|
50
|
+
return failure("factory:import needs a path", NEEDS_PATH_FIX);
|
|
51
|
+
if (path.win32.isAbsolute(given)) {
|
|
52
|
+
return failure(`Import path "${given}" must be relative to this file`, RELATIVE_FIX);
|
|
53
|
+
}
|
|
54
|
+
if (given.includes("\\"))
|
|
55
|
+
return failure(`Import path "${given}" must use /`, SLASH_FIX);
|
|
56
|
+
if (path.posix.extname(given).toLowerCase() !== ".md") {
|
|
57
|
+
return failure(`Import path "${given}" must name a .md file`, MARKDOWN_FIX);
|
|
58
|
+
}
|
|
59
|
+
const target = path.posix.normalize(`${path.posix.dirname(from)}/${given}`);
|
|
60
|
+
if (target === ".." || target.startsWith("../")) {
|
|
61
|
+
return failure(`Import "${given}" leaves .factory/`, INSIDE_FIX);
|
|
62
|
+
}
|
|
63
|
+
return { ok: true, target };
|
|
64
|
+
}
|
|
65
|
+
async function factoryRealPath(cache) {
|
|
66
|
+
if (cache.factoryReal !== undefined)
|
|
67
|
+
return cache.factoryReal;
|
|
68
|
+
try {
|
|
69
|
+
cache.factoryReal = await realpath(cache.factoryDir);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
return cache.factoryReal;
|
|
75
|
+
}
|
|
76
|
+
/** `.factory/<path>`, the name a file's own problems carry, from its realpath. */
|
|
77
|
+
function realFile(factoryReal, real) {
|
|
78
|
+
const relative = path.relative(factoryReal, real).split(path.sep).join("/");
|
|
79
|
+
return `.factory/${relative}`;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The repository-relative `.factory/<path>` name of a realpath, for messages
|
|
83
|
+
* such as an import loop's chain.
|
|
84
|
+
*/
|
|
85
|
+
export function realDisplayPath(cache, real) {
|
|
86
|
+
return realFile(cache.factoryReal ?? cache.factoryDir, real);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Resolves an import to the file's realpath and its loaded content, reporting
|
|
90
|
+
* every path rule of the spec on the directive's line. The walk reads directory
|
|
91
|
+
* listings and matches names exactly, so a wrong-case path fails the same way on
|
|
92
|
+
* a case-insensitive file system as on a case-sensitive one. Symbolic links, for
|
|
93
|
+
* the file and for any parent, must resolve inside the real `.factory/`.
|
|
94
|
+
*/
|
|
95
|
+
export async function resolveImport(from, argument, cache) {
|
|
96
|
+
const target = importTarget(from, argument);
|
|
97
|
+
if (!target.ok)
|
|
98
|
+
return target;
|
|
99
|
+
const given = argument.trim();
|
|
100
|
+
const segments = target.target.split("/");
|
|
101
|
+
let current = cache.factoryDir;
|
|
102
|
+
let file = "";
|
|
103
|
+
let real;
|
|
104
|
+
for (const [index, segment] of segments.entries()) {
|
|
105
|
+
const last = index === segments.length - 1;
|
|
106
|
+
let entries;
|
|
107
|
+
try {
|
|
108
|
+
entries = await readdirTyped(current);
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
return isMissing(error) ? missing(given) : cannotRead(given);
|
|
112
|
+
}
|
|
113
|
+
const exact = entries.find((entry) => entry.name === segment);
|
|
114
|
+
const found = exact ?? entries.find((entry) => entry.name.toLowerCase() === segment.toLowerCase());
|
|
115
|
+
if (found === undefined)
|
|
116
|
+
return missing(given);
|
|
117
|
+
if (exact === undefined) {
|
|
118
|
+
const actual = [...segments.slice(0, index), found.name, ...segments.slice(index + 1)];
|
|
119
|
+
return failure(`Import "${given}" differs in letter case from "${found.name}"`, `Write "${actual.join("/")}"`);
|
|
120
|
+
}
|
|
121
|
+
const full = path.join(current, found.name);
|
|
122
|
+
if (!found.isSymbolicLink()) {
|
|
123
|
+
if (found.isDirectory()) {
|
|
124
|
+
if (last)
|
|
125
|
+
return failure(`Import "${given}" is a directory`, DIRECTORY_FIX);
|
|
126
|
+
current = full;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (!found.isFile())
|
|
130
|
+
return cannotRead(given);
|
|
131
|
+
if (!last)
|
|
132
|
+
return missing(given);
|
|
133
|
+
file = full;
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
// A link may point anywhere, so its target is checked against the real
|
|
137
|
+
// `.factory/` before the walk continues by listing what it points to.
|
|
138
|
+
let resolved;
|
|
139
|
+
try {
|
|
140
|
+
resolved = await realpath(full);
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
return isMissing(error) ? missing(given) : cannotRead(given);
|
|
144
|
+
}
|
|
145
|
+
const factoryReal = await factoryRealPath(cache);
|
|
146
|
+
if (factoryReal === undefined)
|
|
147
|
+
return cannotRead(given);
|
|
148
|
+
if (!isInside(factoryReal, resolved)) {
|
|
149
|
+
return failure(`Import "${given}" resolves outside .factory/`, INSIDE_FIX);
|
|
150
|
+
}
|
|
151
|
+
let info;
|
|
152
|
+
try {
|
|
153
|
+
info = await stat(resolved);
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
return isMissing(error) ? missing(given) : cannotRead(given);
|
|
157
|
+
}
|
|
158
|
+
if (last) {
|
|
159
|
+
if (info.isDirectory())
|
|
160
|
+
return failure(`Import "${given}" is a directory`, DIRECTORY_FIX);
|
|
161
|
+
if (!info.isFile())
|
|
162
|
+
return cannotRead(given);
|
|
163
|
+
file = resolved;
|
|
164
|
+
real = resolved;
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
if (!info.isDirectory())
|
|
168
|
+
return missing(given);
|
|
169
|
+
current = resolved;
|
|
170
|
+
}
|
|
171
|
+
if (real === undefined) {
|
|
172
|
+
try {
|
|
173
|
+
real = await realpath(file);
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
return isMissing(error) ? missing(given) : cannotRead(given);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
const cached = cache.files.get(real);
|
|
180
|
+
if (cached !== undefined)
|
|
181
|
+
return { ok: true, real, loaded: cached };
|
|
182
|
+
let data;
|
|
183
|
+
try {
|
|
184
|
+
data = await readFile(file);
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
return cannotRead(given);
|
|
188
|
+
}
|
|
189
|
+
const decoded = textContent(data);
|
|
190
|
+
if (decoded === undefined) {
|
|
191
|
+
return failure(`Import "${given}" is not a UTF-8 text file`, TEXT_FIX);
|
|
192
|
+
}
|
|
193
|
+
const text = toLF(decoded.startsWith("\uFEFF") ? decoded.slice(1) : decoded);
|
|
194
|
+
const parts = markdownParts(text);
|
|
195
|
+
if (!parts.closed) {
|
|
196
|
+
return failure(`Import "${given}" has unterminated frontmatter`, UNTERMINATED_FIX);
|
|
197
|
+
}
|
|
198
|
+
const factoryReal = await factoryRealPath(cache);
|
|
199
|
+
if (factoryReal === undefined)
|
|
200
|
+
return cannotRead(given);
|
|
201
|
+
const problems = [];
|
|
202
|
+
if (parts.frontmatter !== undefined) {
|
|
203
|
+
const file = realFile(factoryReal, real);
|
|
204
|
+
for (const line of directiveLines(parts.frontmatter, 2)) {
|
|
205
|
+
problems.push({ level: "error", file, line, message: FRONTMATTER_MESSAGE, fix: FRONTMATTER_FIX });
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
const loaded = {
|
|
209
|
+
file: realFile(factoryReal, real),
|
|
210
|
+
text: parts.body.endsWith("\n") ? parts.body.slice(0, -1) : parts.body,
|
|
211
|
+
firstLine: parts.firstLine,
|
|
212
|
+
problems,
|
|
213
|
+
};
|
|
214
|
+
cache.files.set(real, loaded);
|
|
215
|
+
return { ok: true, real, loaded };
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=imports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imports.js","sourceRoot":"","sources":["../../../src/core/env/imports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,mBAAmB,GAAG,2CAA2C,CAAC;AACxE,MAAM,eAAe,GACnB,mGAAmG,CAAC;AACtG,MAAM,cAAc,GAAG,sCAAsC,CAAC;AAC9D,MAAM,YAAY,GAAG,8DAA8D,CAAC;AACpF,MAAM,SAAS,GAAG,+BAA+B,CAAC;AAClD,MAAM,YAAY,GAAG,6CA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AChC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface MarkdownParts {
|
|
2
|
+
/** The frontmatter lines, without their `---` fences, when the file starts with one. */
|
|
3
|
+
frontmatter?: string;
|
|
4
|
+
/** False when a file that starts with `---` has no closing `---` line. */
|
|
5
|
+
closed: boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Everything before `body`, byte for byte, including the newline that ends a
|
|
8
|
+
* frontmatter block; "" when the file has none. `prefix + body` is `text`.
|
|
9
|
+
*/
|
|
10
|
+
prefix: string;
|
|
11
|
+
body: string;
|
|
12
|
+
/** Line number of the body's first line in the file. */
|
|
13
|
+
firstLine: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Splits frontmatter from body the way `build` handles every Markdown file it
|
|
17
|
+
* renders: a file that starts with a `---` line has frontmatter up to the next
|
|
18
|
+
* `---` line. Without a closing `---` the rest of the file is frontmatter, so no
|
|
19
|
+
* directive in it is live. Validation and rendering split with this one
|
|
20
|
+
* function, so a fence in frontmatter cannot hide a directive in the body.
|
|
21
|
+
*/
|
|
22
|
+
export declare function markdownParts(text: string): MarkdownParts;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits frontmatter from body the way `build` handles every Markdown file it
|
|
3
|
+
* renders: a file that starts with a `---` line has frontmatter up to the next
|
|
4
|
+
* `---` line. Without a closing `---` the rest of the file is frontmatter, so no
|
|
5
|
+
* directive in it is live. Validation and rendering split with this one
|
|
6
|
+
* function, so a fence in frontmatter cannot hide a directive in the body.
|
|
7
|
+
*/
|
|
8
|
+
export function markdownParts(text) {
|
|
9
|
+
const lines = text.split("\n");
|
|
10
|
+
if (lines[0] !== "---")
|
|
11
|
+
return { closed: true, prefix: "", body: text, firstLine: 1 };
|
|
12
|
+
const closing = lines.indexOf("---", 1);
|
|
13
|
+
if (closing === -1) {
|
|
14
|
+
return {
|
|
15
|
+
frontmatter: lines.slice(1).join("\n"),
|
|
16
|
+
closed: false,
|
|
17
|
+
prefix: text,
|
|
18
|
+
body: "",
|
|
19
|
+
firstLine: lines.length + 1,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const fence = lines.slice(0, closing + 1).join("\n");
|
|
23
|
+
return {
|
|
24
|
+
frontmatter: lines.slice(1, closing).join("\n"),
|
|
25
|
+
closed: true,
|
|
26
|
+
// A file that ends at its closing `---` has no newline to keep, so the
|
|
27
|
+
// prefix is the whole text and the body is empty.
|
|
28
|
+
prefix: closing === lines.length - 1 ? fence : `${fence}\n`,
|
|
29
|
+
body: lines.slice(closing + 1).join("\n"),
|
|
30
|
+
firstLine: closing + 2,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=markdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.js","sourceRoot":"","sources":["../../../src/core/env/markdown.ts"],"names":[],"mappings":"AAeA;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/B,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK;QAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;IAEtF,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACxC,IAAI,OAAO,KAAK,CAAC,CAAC,EAAE,CAAC;QACnB,OAAO;YACL,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;YACtC,MAAM,EAAE,KAAK;YACb,MAAM,EAAE,IAAI;YACZ,IAAI,EAAE,EAAE;YACR,SAAS,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC;SAC5B,CAAC;IACJ,CAAC;IAED,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrD,OAAO;QACL,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QAC/C,MAAM,EAAE,IAAI;QACZ,uEAAuE;QACvE,kDAAkD;QAClD,MAAM,EAAE,OAAO,KAAK,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI;QAC3D,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QACzC,SAAS,EAAE,OAAO,GAAG,CAAC;KACvB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { MarkdownDocument } from "./directives.js";
|
|
2
|
+
import type { EnvSelection, EnvVariable } from "./types.js";
|
|
3
|
+
export interface RenderContext {
|
|
4
|
+
variables: readonly EnvVariable[];
|
|
5
|
+
selection: EnvSelection;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Renders a parsed Markdown document for the selection: a block that applies to
|
|
9
|
+
* every scenario is kept unlabelled, one that applies to none is removed, and a
|
|
10
|
+
* partial match is kept after its label line. Directive lines are gone already,
|
|
11
|
+
* and text lines are written unchanged.
|
|
12
|
+
*/
|
|
13
|
+
export declare function renderDocument(document: MarkdownDocument, context: RenderContext): string;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { classify } from "./scenarios.js";
|
|
2
|
+
/**
|
|
3
|
+
* Renders a parsed Markdown document for the selection: a block that applies to
|
|
4
|
+
* every scenario is kept unlabelled, one that applies to none is removed, and a
|
|
5
|
+
* partial match is kept after its label line. Directive lines are gone already,
|
|
6
|
+
* and text lines are written unchanged.
|
|
7
|
+
*/
|
|
8
|
+
export function renderDocument(document, context) {
|
|
9
|
+
return renderNodes(document.nodes, [], context).join("\n");
|
|
10
|
+
}
|
|
11
|
+
function renderNodes(nodes, enclosing, context) {
|
|
12
|
+
const lines = [];
|
|
13
|
+
for (const node of nodes) {
|
|
14
|
+
if (node.kind === "text") {
|
|
15
|
+
lines.push(node.text);
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
// An import has no text of its own: its children are rendered in place,
|
|
19
|
+
// classified with the conditions that enclose the import line.
|
|
20
|
+
if (node.kind === "import") {
|
|
21
|
+
lines.push(...renderNodes(node.children, enclosing, context));
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (node.kind === "when") {
|
|
25
|
+
const applies = classify(node.condition, enclosing, context.selection, context.variables);
|
|
26
|
+
if (applies.kind === "none")
|
|
27
|
+
continue;
|
|
28
|
+
const inner = renderNodes(node.children, [...enclosing, node.condition], context);
|
|
29
|
+
if (inner.length === 0)
|
|
30
|
+
continue;
|
|
31
|
+
if (applies.kind === "some")
|
|
32
|
+
lines.push(`${node.indent}**${applies.label}:**`);
|
|
33
|
+
lines.push(...inner);
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
for (const branch of node.branches) {
|
|
37
|
+
const condition = branchCondition(node, branch);
|
|
38
|
+
const applies = classify(condition, enclosing, context.selection, context.variables);
|
|
39
|
+
if (applies.kind === "none")
|
|
40
|
+
continue;
|
|
41
|
+
const inner = renderNodes(branch.children, [...enclosing, condition], context);
|
|
42
|
+
if (inner.length === 0)
|
|
43
|
+
continue;
|
|
44
|
+
if (applies.kind === "some")
|
|
45
|
+
lines.push(`${branch.indent}**${applies.label}:**`);
|
|
46
|
+
lines.push(...inner);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return lines;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* A branch as the condition it stands for: `env.<variable> in [<its values>]`,
|
|
53
|
+
* and for `default` the negation over every value the switch's cases name.
|
|
54
|
+
*/
|
|
55
|
+
function branchCondition(node, branch) {
|
|
56
|
+
return {
|
|
57
|
+
kind: "test",
|
|
58
|
+
variable: node.variable,
|
|
59
|
+
values: branch.kind === "case"
|
|
60
|
+
? [...branch.values]
|
|
61
|
+
: node.branches.flatMap((entry) => entry.values),
|
|
62
|
+
negate: branch.kind === "default",
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../../src/core/env/render.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAU1C;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,QAA0B,EAAE,OAAsB;IAC/E,OAAO,WAAW,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC7D,CAAC;AAED,SAAS,WAAW,CAClB,KAAsB,EACtB,SAA+B,EAC/B,OAAsB;IAEtB,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YACzB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACtB,SAAS;QACX,CAAC;QAED,wEAAwE;QACxE,+DAA+D;QAC/D,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC3B,KAAK,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;YAC9D,SAAS;QACX,CAAC;QAED,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,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AI,CAAC,GAAG,KAAK,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;GAGG;AACH,SAAS,eAAe,CAAC,IAAgB,EAAE,MAAc;IACvD,OAAO;QACL,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,MAAM,EACJ,MAAM,CAAC,IAAI,KAAK,MAAM;YACpB,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;YACpB,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC;QACpD,MAAM,EAAE,MAAM,CAAC,IAAI,KAAK,SAAS;KAClC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { EnvVariable, GitConfigScope, ResolvedSelection, SelectionSource } from "./types.js";
|
|
2
|
+
export interface EnvValueReport {
|
|
3
|
+
name: string;
|
|
4
|
+
label: string;
|
|
5
|
+
}
|
|
6
|
+
/** One variable of `metafab env` and `build --json`'s `env`. */
|
|
7
|
+
export interface EnvVariableReport {
|
|
8
|
+
name: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
values: EnvValueReport[];
|
|
11
|
+
/** Value names, in the order `values` declares them. */
|
|
12
|
+
selected: string[];
|
|
13
|
+
source: SelectionSource;
|
|
14
|
+
/** The Git config scope, for `git`. */
|
|
15
|
+
scope?: GitConfigScope;
|
|
16
|
+
/** The `FACTORY_ENV_<VAR>` variable that supplied the selection, for `environment`. */
|
|
17
|
+
from?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The `variables` list `env` reports and `build --json` adds, in declaration
|
|
21
|
+
* order, with each variable's values and where its selection came from.
|
|
22
|
+
*/
|
|
23
|
+
export declare function describeSelection(variables: readonly EnvVariable[], resolved: ResolvedSelection): EnvVariableReport[];
|
|
24
|
+
/** The source words `metafab env` prints in its last column. */
|
|
25
|
+
export declare function sourceWord(resolved: {
|
|
26
|
+
source: SelectionSource;
|
|
27
|
+
scope?: GitConfigScope;
|
|
28
|
+
from?: string;
|
|
29
|
+
}): string;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `variables` list `env` reports and `build --json` adds, in declaration
|
|
3
|
+
* order, with each variable's values and where its selection came from.
|
|
4
|
+
*/
|
|
5
|
+
export function describeSelection(variables, resolved) {
|
|
6
|
+
const byName = new Map(resolved.variables.map((variable) => [variable.variable, variable]));
|
|
7
|
+
const reports = [];
|
|
8
|
+
for (const variable of variables) {
|
|
9
|
+
const selection = byName.get(variable.name);
|
|
10
|
+
if (selection === undefined)
|
|
11
|
+
continue;
|
|
12
|
+
reports.push({
|
|
13
|
+
name: variable.name,
|
|
14
|
+
...(variable.description === undefined ? {} : { description: variable.description }),
|
|
15
|
+
values: variable.values.map((value) => ({ name: value.name, label: value.label })),
|
|
16
|
+
selected: [...selection.values],
|
|
17
|
+
source: selection.source,
|
|
18
|
+
...(selection.scope === undefined ? {} : { scope: selection.scope }),
|
|
19
|
+
...(selection.from === undefined ? {} : { from: selection.from }),
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return reports;
|
|
23
|
+
}
|
|
24
|
+
/** The source words `metafab env` prints in its last column. */
|
|
25
|
+
export function sourceWord(resolved) {
|
|
26
|
+
switch (resolved.source) {
|
|
27
|
+
case "option":
|
|
28
|
+
return "--env";
|
|
29
|
+
case "environment":
|
|
30
|
+
return resolved.from ?? "process environment";
|
|
31
|
+
case "git":
|
|
32
|
+
return `Git config (${resolved.scope ?? "unknown"})`;
|
|
33
|
+
case "default":
|
|
34
|
+
return "default in factory.yaml";
|
|
35
|
+
case "all":
|
|
36
|
+
return "every value (nothing selected)";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=report.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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,EAAE,SAAS,CAAC,IAAI,EAAE,CAAC;SAClE,CAAC,CAAC;IACL,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,UAAU,CAAC,QAI1B;IACC,QAAQ,QAAQ,CAAC,MAAM,EAAE,CAAC;QACxB,KAAK,QAAQ;YACX,OAAO,OAAO,CAAC;QACjB,KAAK,aAAa;YAChB,OAAO,QAAQ,CAAC,IAAI,IAAI,qBAAqB,CAAC;QAChD,KAAK,KAAK;YACR,OAAO,eAAe,QAAQ,CAAC,KAAK,IAAI,SAAS,GAAG,CAAC;QACvD,KAAK,SAAS;YACZ,OAAO,yBAAyB,CAAC;QACnC,KAAK,KAAK;YACR,OAAO,gCAAgC,CAAC;IAC5C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Condition } from "./condition.js";
|
|
2
|
+
import type { EnvSelection, EnvVariable } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* The most scenarios a block may span over the variables it and its enclosing
|
|
5
|
+
* conditions name. A document that needs more is an error, so rendering and the
|
|
6
|
+
* all-values root block stay cheap however many variables a factory declares.
|
|
7
|
+
*/
|
|
8
|
+
export declare const MAX_COMBINATIONS = 1024;
|
|
9
|
+
/** One selected value for each of a block's variables. */
|
|
10
|
+
export type Scenario = ReadonlyMap<string, string>;
|
|
11
|
+
/** How a block applies to the selection. */
|
|
12
|
+
export type Applies = {
|
|
13
|
+
kind: "all";
|
|
14
|
+
} | {
|
|
15
|
+
kind: "none";
|
|
16
|
+
} | {
|
|
17
|
+
kind: "some";
|
|
18
|
+
label: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Product of the declared value counts of `variables`: the all-values case,
|
|
22
|
+
* independent of the selection. A variable the factory does not declare has no
|
|
23
|
+
* declared values, so the product is 0.
|
|
24
|
+
*/
|
|
25
|
+
export declare function combinations(variables: Iterable<string>, declared: readonly EnvVariable[]): number;
|
|
26
|
+
/**
|
|
27
|
+
* Every scenario over `variables`, in declaration order: the product of the
|
|
28
|
+
* selected values, with the first variable varying slowest. A variable the
|
|
29
|
+
* selection does not give a value for contributes none.
|
|
30
|
+
*/
|
|
31
|
+
export declare function scenarios(selection: EnvSelection, variables: Iterable<string>): Scenario[];
|
|
32
|
+
/**
|
|
33
|
+
* Classifies a condition in the scenarios where its enclosing conditions are
|
|
34
|
+
* true: `all` when it holds in every one, `none` when it holds in none, else
|
|
35
|
+
* `some` with the label its kept text takes. No other variable is enumerated,
|
|
36
|
+
* because no other variable can change the result.
|
|
37
|
+
*/
|
|
38
|
+
export declare function classify(condition: Condition, enclosing: readonly Condition[], selection: EnvSelection, variables: readonly EnvVariable[]): Applies;
|
|
39
|
+
/** The selection with every declared value of every variable: the root `AGENTS.md` render. */
|
|
40
|
+
export declare function allValues(variables: readonly EnvVariable[]): EnvSelection;
|