@sous-io/sous 0.2.37 → 1.0.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 +14 -256
- package/dist/bin.js +11 -0
- package/dist/sous.js +1093 -0
- package/docs/markdown/README.md +5 -4
- package/docs/markdown/_sidebar.md +21 -1
- package/docs/markdown/commands.md +294 -431
- package/docs/markdown/config-discovery.md +25 -14
- package/docs/markdown/config-inspection.md +53 -31
- package/docs/markdown/config-layers.md +168 -66
- package/docs/markdown/config-variables.md +44 -11
- package/docs/markdown/configuration.md +104 -17
- package/docs/markdown/design-principles.md +4 -1
- package/docs/markdown/repositories-authoring.md +30 -0
- package/docs/markdown/repositories-consuming.md +72 -14
- package/docs/markdown/repositories-file-formats.md +31 -13
- package/docs/markdown/repositories-providers.md +48 -57
- package/docs/markdown/repositories-quickstart.md +3 -2
- package/docs/markdown/repositories-troubleshooting.md +27 -1
- package/docs/markdown/repositories-variables.md +6 -1
- package/docs/markdown/repositories.md +18 -8
- package/package.json +48 -107
- package/recipes/core/sous-skills/skills/about-liquid-templates/SKILL.tpl.md +4 -6
- package/recipes/core/sous-skills/skills/about-liquid-templates/references/liquid-filters.tpl.md +2 -0
- package/recipes/core/sous-skills/skills/about-sous/SKILL.tpl.md +10 -9
- package/recipes/core/sous-skills/skills/about-sous-configuration/SKILL.tpl.md +35 -14
- package/recipes/core/sous-skills/skills/about-sous-recipes/SKILL.tpl.md +51 -20
- package/recipes/core/sous-skills/sous.recipe.yaml +1 -1
- package/sous.config.schema.json +351 -132
- package/bin/run.js +0 -51
- package/src/base-command.ts +0 -457
- package/src/commands/build.ts +0 -181
- package/src/commands/clear.ts +0 -79
- package/src/commands/compile.ts +0 -155
- package/src/commands/config/get.ts +0 -110
- package/src/commands/config/show.ts +0 -32
- package/src/commands/config/validate.ts +0 -53
- package/src/commands/help.ts +0 -46
- package/src/commands/init.ts +0 -289
- package/src/commands/launch.ts +0 -139
- package/src/commands/lock/rebuild.ts +0 -239
- package/src/commands/lock/show.ts +0 -115
- package/src/commands/namespace/list.ts +0 -138
- package/src/commands/namespace/show.ts +0 -130
- package/src/commands/prune.ts +0 -43
- package/src/commands/recipe/list.ts +0 -112
- package/src/commands/recipe/show.ts +0 -439
- package/src/commands/repo/add.ts +0 -145
- package/src/commands/repo/contribute.ts +0 -604
- package/src/commands/repo/gc.ts +0 -173
- package/src/commands/repo/init.ts +0 -136
- package/src/commands/repo/link.ts +0 -899
- package/src/commands/repo/list.ts +0 -236
- package/src/commands/repo/release.ts +0 -685
- package/src/commands/repo/remove.ts +0 -194
- package/src/commands/repo/search.ts +0 -243
- package/src/commands/repo/submit.ts +0 -341
- package/src/commands/repo/unlink.ts +0 -461
- package/src/commands/subscription/add.ts +0 -286
- package/src/commands/subscription/list.ts +0 -208
- package/src/commands/subscription/remove.ts +0 -182
- package/src/commands/subscription/update.ts +0 -216
- package/src/commands/update.ts +0 -178
- package/src/commands/vars/ask.ts +0 -417
- package/src/commands/vars/index.ts +0 -79
- package/src/commands/vars/list.ts +0 -67
- package/src/commands/vars/show.ts +0 -77
- package/src/config-command.ts +0 -30
- package/src/lib/build-preparation.ts +0 -128
- package/src/lib/build-service.ts +0 -580
- package/src/lib/config-discovery.ts +0 -378
- package/src/lib/config-inspect.ts +0 -145
- package/src/lib/config-kernel.mjs +0 -379
- package/src/lib/config-schema.ts +0 -401
- package/src/lib/env-file.ts +0 -328
- package/src/lib/env-local.ts +0 -212
- package/src/lib/errors.ts +0 -32
- package/src/lib/glob-pattern.ts +0 -24
- package/src/lib/include-resolver.ts +0 -523
- package/src/lib/interactive.ts +0 -165
- package/src/lib/markdown-compiler.ts +0 -947
- package/src/lib/package-info.ts +0 -25
- package/src/lib/pid-service.ts +0 -99
- package/src/lib/project-install.d.mts +0 -44
- package/src/lib/project-install.mjs +0 -234
- package/src/lib/project-scaffold/index.ts +0 -332
- package/src/lib/project-scaffold/templates.ts +0 -240
- package/src/lib/repos/catalog-display.ts +0 -215
- package/src/lib/repos/catalog-inputs.ts +0 -288
- package/src/lib/repos/catalog.ts +0 -842
- package/src/lib/repos/contribute.ts +0 -452
- package/src/lib/repos/core-recipe.ts +0 -105
- package/src/lib/repos/declarations.ts +0 -187
- package/src/lib/repos/defaults.ts +0 -175
- package/src/lib/repos/formats/common.ts +0 -440
- package/src/lib/repos/formats/index-file.ts +0 -253
- package/src/lib/repos/formats/links-map.ts +0 -98
- package/src/lib/repos/formats/lockfile.ts +0 -169
- package/src/lib/repos/formats/patterns.ts +0 -57
- package/src/lib/repos/formats/recipe-manifest.ts +0 -205
- package/src/lib/repos/formats/repo-manifest.ts +0 -97
- package/src/lib/repos/formats/store-entry.ts +0 -84
- package/src/lib/repos/formats/variable-definition.ts +0 -268
- package/src/lib/repos/freshness.ts +0 -264
- package/src/lib/repos/git-clone.ts +0 -850
- package/src/lib/repos/identity.ts +0 -89
- package/src/lib/repos/index.ts +0 -57
- package/src/lib/repos/links.ts +0 -356
- package/src/lib/repos/load-manifest.ts +0 -237
- package/src/lib/repos/lock-service.ts +0 -454
- package/src/lib/repos/locked-namespace-resolver.ts +0 -232
- package/src/lib/repos/locked-recipe-lookup.ts +0 -123
- package/src/lib/repos/locked-recipes.ts +0 -254
- package/src/lib/repos/managed-layer.ts +0 -422
- package/src/lib/repos/memories-hash-name.ts +0 -33
- package/src/lib/repos/namespace-resolver.ts +0 -527
- package/src/lib/repos/providers/base.ts +0 -268
- package/src/lib/repos/providers/git.ts +0 -245
- package/src/lib/repos/providers/github.ts +0 -589
- package/src/lib/repos/providers/gitlab.ts +0 -332
- package/src/lib/repos/providers/http.ts +0 -128
- package/src/lib/repos/providers/index-cache.ts +0 -421
- package/src/lib/repos/providers/index.ts +0 -106
- package/src/lib/repos/providers/local.ts +0 -410
- package/src/lib/repos/providers/provider.ts +0 -615
- package/src/lib/repos/recipe-config-layers.ts +0 -316
- package/src/lib/repos/recipe-key-matcher.ts +0 -62
- package/src/lib/repos/recipe-memories.ts +0 -178
- package/src/lib/repos/recipe-targets.ts +0 -236
- package/src/lib/repos/ref-search.ts +0 -46
- package/src/lib/repos/release/bump.ts +0 -161
- package/src/lib/repos/release/changelog.ts +0 -461
- package/src/lib/repos/release/git-state.ts +0 -460
- package/src/lib/repos/release/index-builder.ts +0 -1108
- package/src/lib/repos/release/index.ts +0 -19
- package/src/lib/repos/release/plan.ts +0 -521
- package/src/lib/repos/release/settle.ts +0 -154
- package/src/lib/repos/release/submissions.ts +0 -214
- package/src/lib/repos/release/submit-checkout.ts +0 -290
- package/src/lib/repos/release/submit-questions.ts +0 -153
- package/src/lib/repos/release/submit-service.ts +0 -898
- package/src/lib/repos/release/tags.ts +0 -239
- package/src/lib/repos/release/validate.ts +0 -463
- package/src/lib/repos/resolver.ts +0 -1028
- package/src/lib/repos/scaffold/index.ts +0 -245
- package/src/lib/repos/scaffold/templates.ts +0 -517
- package/src/lib/repos/seed.ts +0 -473
- package/src/lib/repos/store/contract.ts +0 -64
- package/src/lib/repos/store/hash.ts +0 -191
- package/src/lib/repos/store/recipe-store.ts +0 -599
- package/src/lib/repos/store/settings.ts +0 -58
- package/src/lib/repos/subscription-service.ts +0 -3859
- package/src/lib/repos/trust.ts +0 -447
- package/src/lib/repos/update-plan.ts +0 -235
- package/src/lib/self-update/index.ts +0 -14
- package/src/lib/self-update/installs.ts +0 -413
- package/src/lib/self-update/managers.ts +0 -126
- package/src/lib/self-update/plan.ts +0 -315
- package/src/lib/self-update/registry.ts +0 -99
- package/src/lib/self-update/run.ts +0 -506
- package/src/lib/self-update/versions.ts +0 -243
- package/src/lib/settings.ts +0 -1107
- package/src/lib/sous-home.ts +0 -104
- package/src/lib/state.ts +0 -167
- package/src/lib/vars/answers.ts +0 -192
- package/src/lib/vars/ask.ts +0 -1152
- package/src/lib/vars/definition-source.ts +0 -261
- package/src/lib/vars/display.ts +0 -231
- package/src/lib/vars/index.ts +0 -20
- package/src/lib/vars/ladder.ts +0 -282
- package/src/lib/vars/mappings.ts +0 -260
- package/src/lib/vars/names.ts +0 -94
- package/src/lib/vars/preanswers.ts +0 -395
- package/src/lib/vars/question-plan.ts +0 -241
- package/src/lib/vars/report.ts +0 -228
- package/src/lib/vars/safe-regex.ts +0 -235
- package/src/lib/vars/secrets.ts +0 -131
- package/src/lib/vars/validate.ts +0 -312
- package/src/lib/version-report.ts +0 -90
- package/src/lib/watch-loop.ts +0 -148
- package/src/lib/watch-service.ts +0 -116
- package/src/services/ref-resolver/container.ts +0 -107
- package/src/services/ref-resolver/dependency.ts +0 -60
- package/src/services/ref-resolver/format.ts +0 -197
- package/src/services/ref-resolver/glob.ts +0 -115
- package/src/services/ref-resolver/hash-names.ts +0 -155
- package/src/services/ref-resolver/index.ts +0 -55
- package/src/services/ref-resolver/injectable.ts +0 -36
- package/src/services/ref-resolver/location.ts +0 -62
- package/src/services/ref-resolver/lookups/cached-index-lookup.ts +0 -53
- package/src/services/ref-resolver/lookups/catalog-lookup.ts +0 -23
- package/src/services/ref-resolver/lookups/catalog-matcher.ts +0 -261
- package/src/services/ref-resolver/lookups/chained-lookup.ts +0 -27
- package/src/services/ref-resolver/lookups/env-var-lookup.ts +0 -65
- package/src/services/ref-resolver/lookups/fetched-index-lookup.ts +0 -150
- package/src/services/ref-resolver/lookups/recorded-dependency-lookup.ts +0 -62
- package/src/services/ref-resolver/lookups/ref-lookup.ts +0 -54
- package/src/services/ref-resolver/lookups/variable-lookup.ts +0 -123
- package/src/services/ref-resolver/named-refs.ts +0 -144
- package/src/services/ref-resolver/parser/env-var-splitter.ts +0 -27
- package/src/services/ref-resolver/parser/location-splitter.ts +0 -239
- package/src/services/ref-resolver/parser/name-path-splitter.ts +0 -200
- package/src/services/ref-resolver/parser/partial-ref.ts +0 -84
- package/src/services/ref-resolver/parser/query-splitter.ts +0 -61
- package/src/services/ref-resolver/parser/range-splitter.ts +0 -52
- package/src/services/ref-resolver/parser/ref-parser.ts +0 -115
- package/src/services/ref-resolver/parser/repo-qualifier-splitter.ts +0 -51
- package/src/services/ref-resolver/parts.ts +0 -115
- package/src/services/ref-resolver/pruners/command-line-pruner.ts +0 -47
- package/src/services/ref-resolver/pruners/include-pruner.ts +0 -66
- package/src/services/ref-resolver/pruners/manifest-pruner.ts +0 -130
- package/src/services/ref-resolver/pruners/ref-pruner.ts +0 -135
- package/src/services/ref-resolver/pruners/rule-helpers.ts +0 -44
- package/src/services/ref-resolver/pruners/stored-key-pruner.ts +0 -136
- package/src/services/ref-resolver/ref-helpers.ts +0 -62
- package/src/services/ref-resolver/ref-picker-service.ts +0 -204
- package/src/services/ref-resolver/ref-report.ts +0 -84
- package/src/services/ref-resolver/ref-resolve-arguments.ts +0 -47
- package/src/services/ref-resolver/ref-resolve-result.ts +0 -36
- package/src/services/ref-resolver/ref-resolver-service.ts +0 -323
- package/src/services/ref-resolver/source.ts +0 -48
- package/src/services/ref-resolver/tokens.ts +0 -25
- package/src/services/ref-resolver/types.ts +0 -155
- package/src/templating/filters/bullet-list.ts +0 -9
- package/src/templating/filters/index.ts +0 -8
- package/src/templating/init-liquid-engine.ts +0 -139
- package/src/templating/lib/glob-files.ts +0 -74
- package/src/templating/lib/import-export.ts +0 -32
- package/src/templating/lib/secret-scope.ts +0 -41
- package/src/templating/lib/tag-args.ts +0 -19
- package/src/templating/tags/exportScalarVarsJs.ts +0 -46
- package/src/templating/tags/getFiles.ts +0 -89
- package/src/templating/tags/index.ts +0 -14
- package/src/templating/tags/listFiles.ts +0 -54
- package/src/templating/tags/showVars.ts +0 -28
- package/src/utils/choice-prompt.ts +0 -143
- package/src/utils/command-errors.ts +0 -186
- package/src/utils/command-help.ts +0 -45
- package/src/utils/confirm-prompt.ts +0 -110
- package/src/utils/flags.ts +0 -177
- package/src/utils/formatting.ts +0 -849
- package/src/utils/prompts.ts +0 -53
- package/src/utils/sous-directory.ts +0 -245
- package/src/utils/table.ts +0 -603
- package/src/utils/value-prompt.ts +0 -119
|
@@ -1,316 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Config layers that come from subscribed recipes.
|
|
3
|
-
*
|
|
4
|
-
* A recipe may contribute `config` content: files that are merged into the
|
|
5
|
-
* subscribing project's configuration rather than written anywhere in it. They
|
|
6
|
-
* are loaded AFTER the primary config and BEFORE the `conf.d/` drop-ins, so a
|
|
7
|
-
* recipe can supply defaults and the project always wins over them.
|
|
8
|
-
*
|
|
9
|
-
* This has to work before variable resolution, and before the settings even
|
|
10
|
-
* exist, because these layers are part of what the settings are built from. It
|
|
11
|
-
* therefore reads nothing but the lockfile, the links map and the store, all of
|
|
12
|
-
* which are locatable from the `.sous/` directory and the environment alone.
|
|
13
|
-
*
|
|
14
|
-
* A recipe layer is JSON (`.json`, or `.jsonc` for JSON with comments) or YAML
|
|
15
|
-
* only. The config kernel would happily import a
|
|
16
|
-
* `.js` layer, and a repository's whole trust story rests on sous being able to
|
|
17
|
-
* read what it publishes without running any of it, so an executable layer from
|
|
18
|
-
* a recipe is refused rather than loaded.
|
|
19
|
-
*
|
|
20
|
-
* A recipe layer is also read HERE rather than by the config kernel, and only
|
|
21
|
-
* the keys on the allowlist below survive the reading. A recipe is content you
|
|
22
|
-
* subscribed to; it does not get to decide what sous trusts or what sous runs.
|
|
23
|
-
* See RECIPE_CONFIG_ALLOWED_KEYS.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
import fs from "node:fs";
|
|
27
|
-
import path from "node:path";
|
|
28
|
-
import { globSync } from "glob";
|
|
29
|
-
import { parse as parseYaml } from "yaml";
|
|
30
|
-
import { toGlobPattern } from "../glob-pattern.js";
|
|
31
|
-
import { parseJsoncText } from "./load-manifest.js";
|
|
32
|
-
import { listLockedRecipes, readRecipeManifestIn } from "./locked-recipes.js";
|
|
33
|
-
|
|
34
|
-
/** The layer extensions a recipe may contribute; the executable ones are refused. */
|
|
35
|
-
export const RECIPE_LAYER_EXTENSIONS = [".json", ".jsonc", ".yaml", ".yml"] as const;
|
|
36
|
-
|
|
37
|
-
/** Extensions sous can load as a config layer but deliberately will not take from a recipe. */
|
|
38
|
-
export const RECIPE_LAYER_EXECUTABLE_EXTENSIONS = [".js", ".mjs", ".cjs", ".ts"] as const;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* The only top-level config keys a recipe's config layer may set.
|
|
42
|
-
*
|
|
43
|
-
* A recipe layer is merged into the project's configuration, so without this
|
|
44
|
-
* allowlist a recipe could add a repository to `repos:` (granting itself, and
|
|
45
|
-
* anything published beside it, trust the person never gave), add a
|
|
46
|
-
* subscription, or point a `tools.<name>.command` at a program that `sous
|
|
47
|
-
* launch` then spawns. Every key here is inert with respect to trust and to
|
|
48
|
-
* what sous executes: a recipe can supply variables, aliases, compilation
|
|
49
|
-
* targets, runtime context, where recipe output lands, store knobs and variable
|
|
50
|
-
* mappings, and nothing else.
|
|
51
|
-
*
|
|
52
|
-
* Anything not on this list is dropped with a warning naming the recipe and the
|
|
53
|
-
* key, including keys sous does not recognise at all.
|
|
54
|
-
*/
|
|
55
|
-
export const RECIPE_CONFIG_ALLOWED_KEYS = [
|
|
56
|
-
"_aliases",
|
|
57
|
-
"_vars",
|
|
58
|
-
"compilation",
|
|
59
|
-
"recipes",
|
|
60
|
-
"runtimeContext",
|
|
61
|
-
"store",
|
|
62
|
-
"varMappings",
|
|
63
|
-
] as const;
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* The keys under `recipes` a recipe's config layer may set. `recipes.memories`
|
|
67
|
-
* decides which memories the project includes and in what order, which is the
|
|
68
|
-
* project's own choice, so a recipe may not set it.
|
|
69
|
-
*/
|
|
70
|
-
export const RECIPE_CONFIG_ALLOWED_RECIPES_KEYS = ["skills"] as const;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Plain-language reasons for the refused keys a recipe is most likely to try,
|
|
74
|
-
* so the warning says why rather than only that.
|
|
75
|
-
*/
|
|
76
|
-
const REFUSAL_REASONS: Record<string, string> = {
|
|
77
|
-
repos:
|
|
78
|
-
"only you decide which repositories this project trusts, so a recipe may not add one",
|
|
79
|
-
subscriptions:
|
|
80
|
-
"only you decide what this project subscribes to, so a recipe may not subscribe on your behalf",
|
|
81
|
-
tools:
|
|
82
|
-
"a tool entry names a program sous launches, so a recipe may not add one or change one",
|
|
83
|
-
_env: "an _env mapping decides which environment variables reach the build",
|
|
84
|
-
version: "the config version is the project's own to declare",
|
|
85
|
-
name: "the project's display name is the project's own to declare",
|
|
86
|
-
$schema: "the schema binding is the project's own editor setting",
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
/** One recipe config layer, already read and already filtered. */
|
|
90
|
-
export type RecipeConfigLayer = {
|
|
91
|
-
/** Absolute path of the file it was read from, used for reporting and tracing. */
|
|
92
|
-
path: string;
|
|
93
|
-
/** The `namespace/recipe` key of the recipe that contributed it. */
|
|
94
|
-
recipeKey: string;
|
|
95
|
-
/** The layer's content, with every key outside the allowlist removed. */
|
|
96
|
-
config: Record<string, unknown>;
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
/** What a recipe's config contents came to. */
|
|
100
|
-
export type RecipeConfigLayers = {
|
|
101
|
-
/** The layers, in the order they should be merged. */
|
|
102
|
-
layers: RecipeConfigLayer[];
|
|
103
|
-
/** Absolute paths of those layers, in the same order. */
|
|
104
|
-
paths: string[];
|
|
105
|
-
/** Complete, plain-language sentences about anything that was skipped. */
|
|
106
|
-
warnings: string[];
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Removes every top-level key a recipe is not allowed to set.
|
|
111
|
-
*
|
|
112
|
-
* Pure, so the rule can be tested on its own: give it whatever a layer file
|
|
113
|
-
* parsed to and it returns what may be merged, plus a sentence for everything
|
|
114
|
-
* it took out.
|
|
115
|
-
*
|
|
116
|
-
* @param recipeKey - The `namespace/recipe` key, named in every warning.
|
|
117
|
-
* @param layerPath - The layer file, named in every warning.
|
|
118
|
-
* @param raw - Whatever the layer file parsed to.
|
|
119
|
-
*/
|
|
120
|
-
export function filterRecipeConfigLayer(
|
|
121
|
-
recipeKey: string,
|
|
122
|
-
layerPath: string,
|
|
123
|
-
raw: unknown
|
|
124
|
-
): { config: Record<string, unknown>; warnings: string[] } {
|
|
125
|
-
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
|
|
126
|
-
return {
|
|
127
|
-
config: {},
|
|
128
|
-
warnings: [
|
|
129
|
-
`The recipe ${recipeKey} contributes a config layer that is not a set of ` +
|
|
130
|
-
`configuration keys, so none of it was merged:\n ${layerPath}\n` +
|
|
131
|
-
`A config layer has to be an object with configuration keys at its top level.`,
|
|
132
|
-
],
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const warnings: string[] = [];
|
|
137
|
-
const allowed = new Set<string>(RECIPE_CONFIG_ALLOWED_KEYS);
|
|
138
|
-
const config: Record<string, unknown> = {};
|
|
139
|
-
|
|
140
|
-
for (const key of Object.keys(raw)) {
|
|
141
|
-
if (key === "recipes") {
|
|
142
|
-
const value = (raw as Record<string, unknown>)[key];
|
|
143
|
-
const kept: Record<string, unknown> = {};
|
|
144
|
-
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
145
|
-
for (const sub of Object.keys(value)) {
|
|
146
|
-
if ((RECIPE_CONFIG_ALLOWED_RECIPES_KEYS as readonly string[]).includes(sub)) {
|
|
147
|
-
kept[sub] = (value as Record<string, unknown>)[sub];
|
|
148
|
-
continue;
|
|
149
|
-
}
|
|
150
|
-
warnings.push(
|
|
151
|
-
`The recipe ${recipeKey} tried to set 'recipes.${sub}' in a config layer, and sous ` +
|
|
152
|
-
`removed it before merging anything:\n ${layerPath}\n` +
|
|
153
|
-
`That key is not one a recipe may set (it configures the project, not the recipe). ` +
|
|
154
|
-
`Under 'recipes' a recipe's config layer may set only: ` +
|
|
155
|
-
`${RECIPE_CONFIG_ALLOWED_RECIPES_KEYS.join(", ")}.`
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
config[key] = kept;
|
|
160
|
-
continue;
|
|
161
|
-
}
|
|
162
|
-
if (allowed.has(key)) {
|
|
163
|
-
config[key] = (raw as Record<string, unknown>)[key];
|
|
164
|
-
continue;
|
|
165
|
-
}
|
|
166
|
-
const reason =
|
|
167
|
-
REFUSAL_REASONS[key] ?? "sous does not recognise it as a key a recipe may set";
|
|
168
|
-
warnings.push(
|
|
169
|
-
`The recipe ${recipeKey} tried to set '${key}' in a config layer, and sous ` +
|
|
170
|
-
`removed it before merging anything:\n ${layerPath}\n` +
|
|
171
|
-
`That key is not one a recipe may set (${reason}). A recipe's config layer may ` +
|
|
172
|
-
`set only: ${RECIPE_CONFIG_ALLOWED_KEYS.join(", ")}.`
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return { config, warnings };
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Every config layer the recipes this project subscribes to contribute, read
|
|
181
|
-
* and filtered, ordered by recipe key and then by path so the merge order is
|
|
182
|
-
* the same on every machine.
|
|
183
|
-
*
|
|
184
|
-
* Only recipes held through `subscribes` contribute; a build dependency is
|
|
185
|
-
* addressable from the recipe that declared it and changes nothing about the
|
|
186
|
-
* project, its configuration included.
|
|
187
|
-
*
|
|
188
|
-
* @param sousDir - The project's `.sous/` directory.
|
|
189
|
-
* @param env - The environment to read; decides where the store is.
|
|
190
|
-
*/
|
|
191
|
-
export function listRecipeConfigLayers(
|
|
192
|
-
sousDir: string,
|
|
193
|
-
env: NodeJS.ProcessEnv = process.env
|
|
194
|
-
): RecipeConfigLayers {
|
|
195
|
-
const result: RecipeConfigLayers = { layers: [], paths: [], warnings: [] };
|
|
196
|
-
|
|
197
|
-
let locked;
|
|
198
|
-
try {
|
|
199
|
-
locked = listLockedRecipes({ sousDir, env });
|
|
200
|
-
} catch {
|
|
201
|
-
// Config discovery runs before anything can report a problem nicely. A
|
|
202
|
-
// lockfile that does not parse is reported by every other reader of it, so
|
|
203
|
-
// contributing no layers here is the quiet, correct answer.
|
|
204
|
-
return result;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
const executable: string[] = [];
|
|
208
|
-
const unsupported: string[] = [];
|
|
209
|
-
|
|
210
|
-
for (const recipe of locked) {
|
|
211
|
-
if (recipe.kind !== "subscribes") continue;
|
|
212
|
-
if (!recipe.present) continue;
|
|
213
|
-
|
|
214
|
-
let manifest;
|
|
215
|
-
try {
|
|
216
|
-
manifest = readRecipeManifestIn(recipe.dir);
|
|
217
|
-
} catch {
|
|
218
|
-
continue;
|
|
219
|
-
}
|
|
220
|
-
if (manifest === undefined) continue;
|
|
221
|
-
|
|
222
|
-
const found: string[] = [];
|
|
223
|
-
|
|
224
|
-
for (const content of manifest.contents) {
|
|
225
|
-
if (content.kind !== "config") continue;
|
|
226
|
-
|
|
227
|
-
const ignore = (content.exclude ?? []).map((pattern) =>
|
|
228
|
-
toGlobPattern(path.join(recipe.dir, pattern))
|
|
229
|
-
);
|
|
230
|
-
|
|
231
|
-
for (const include of content.include) {
|
|
232
|
-
for (const filePath of globSync(toGlobPattern(path.join(recipe.dir, include)), {
|
|
233
|
-
absolute: true,
|
|
234
|
-
ignore,
|
|
235
|
-
})) {
|
|
236
|
-
if (!isFile(filePath)) continue;
|
|
237
|
-
const extension = path.extname(filePath).toLowerCase();
|
|
238
|
-
if (
|
|
239
|
-
(RECIPE_LAYER_EXECUTABLE_EXTENSIONS as readonly string[]).includes(extension)
|
|
240
|
-
) {
|
|
241
|
-
executable.push(filePath);
|
|
242
|
-
continue;
|
|
243
|
-
}
|
|
244
|
-
if (!(RECIPE_LAYER_EXTENSIONS as readonly string[]).includes(extension)) {
|
|
245
|
-
unsupported.push(filePath);
|
|
246
|
-
continue;
|
|
247
|
-
}
|
|
248
|
-
found.push(path.normalize(filePath));
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
for (const layerPath of [...new Set(found)].sort()) {
|
|
254
|
-
let raw: unknown;
|
|
255
|
-
try {
|
|
256
|
-
raw = readLayerFile(layerPath);
|
|
257
|
-
} catch (error) {
|
|
258
|
-
result.warnings.push(
|
|
259
|
-
`The recipe ${recipe.key} contributes a config layer sous could not read, so ` +
|
|
260
|
-
`none of it was merged:\n ${layerPath}\n` +
|
|
261
|
-
`${error instanceof Error ? error.message : String(error)}`
|
|
262
|
-
);
|
|
263
|
-
continue;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
const filtered = filterRecipeConfigLayer(recipe.key, layerPath, raw);
|
|
267
|
-
result.warnings.push(...filtered.warnings);
|
|
268
|
-
result.layers.push({
|
|
269
|
-
path: layerPath,
|
|
270
|
-
recipeKey: recipe.key,
|
|
271
|
-
config: filtered.config,
|
|
272
|
-
});
|
|
273
|
-
result.paths.push(layerPath);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
if (executable.length > 0) {
|
|
278
|
-
result.warnings.push(
|
|
279
|
-
`Some subscribed recipes contribute config layers that are program code, and sous ` +
|
|
280
|
-
`refused to load them:\n` +
|
|
281
|
-
executable.map((entry) => ` ${entry}`).join("\n") +
|
|
282
|
-
`\nSous must be able to read everything a repository publishes without running ` +
|
|
283
|
-
`any of it, so an executable layer from a recipe is never loaded. Publish the ` +
|
|
284
|
-
`same settings as ${RECIPE_LAYER_EXTENSIONS.join(", ")} instead.`
|
|
285
|
-
);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
if (unsupported.length > 0) {
|
|
289
|
-
result.warnings.push(
|
|
290
|
-
`Some subscribed recipes contribute config layers written in a format sous does ` +
|
|
291
|
-
`not read, and they were skipped:\n` +
|
|
292
|
-
unsupported.map((entry) => ` ${entry}`).join("\n") +
|
|
293
|
-
`\nA recipe's config layer is written as ${RECIPE_LAYER_EXTENSIONS.join(", ")}.`
|
|
294
|
-
);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
return result;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/** Reads and parses one recipe config layer according to its extension. */
|
|
301
|
-
function readLayerFile(layerPath: string): unknown {
|
|
302
|
-
const text = fs.readFileSync(layerPath, "utf8");
|
|
303
|
-
const extension = path.extname(layerPath).toLowerCase();
|
|
304
|
-
if (extension === ".jsonc") return parseJsoncText(text, layerPath);
|
|
305
|
-
if (extension === ".json") return JSON.parse(text);
|
|
306
|
-
return parseYaml(text);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
/** True when the path is a regular file. */
|
|
310
|
-
function isFile(candidate: string): boolean {
|
|
311
|
-
try {
|
|
312
|
-
return fs.statSync(candidate).isFile();
|
|
313
|
-
} catch {
|
|
314
|
-
return false;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Matching recipe keys (`namespace/recipe`) against the lists a config holds, such
|
|
3
|
-
* as `recipes.memories.first` and `recipes.memories.exclude`.
|
|
4
|
-
*
|
|
5
|
-
* Each entry of such a list is a glob (`communication/*`), or, when it is
|
|
6
|
-
* written between two slashes (`/^tool-usage\//`), a regular expression. A
|
|
7
|
-
* regular expression is written as a string because the config kernel passes
|
|
8
|
-
* every layer through JSON, which has no way to carry a `RegExp`.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { minimatch } from "minimatch";
|
|
12
|
-
import { ConfigError } from "../errors.js";
|
|
13
|
-
|
|
14
|
-
/** True when the string is written `/.../`, the spelling of a regular expression. */
|
|
15
|
-
export function isRegexSpelling(entry: string): boolean {
|
|
16
|
-
return entry.length >= 3 && entry.startsWith("/") && entry.endsWith("/");
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Compiles one entry of a recipe key list into a matcher.
|
|
21
|
-
*
|
|
22
|
-
* @param entry - A glob, or a regular expression written `/.../`.
|
|
23
|
-
* @param where - The config key the entry came from, named in the error, such as
|
|
24
|
-
* `recipes.memories.exclude`.
|
|
25
|
-
* @throws ConfigError when the entry is a regular expression that does not compile.
|
|
26
|
-
*/
|
|
27
|
-
function compileEntry(entry: string, where: string): (key: string) => boolean {
|
|
28
|
-
if (isRegexSpelling(entry)) {
|
|
29
|
-
let expression: RegExp;
|
|
30
|
-
try {
|
|
31
|
-
expression = new RegExp(entry.slice(1, -1));
|
|
32
|
-
} catch (error) {
|
|
33
|
-
const reason = error instanceof Error ? error.message : String(error);
|
|
34
|
-
throw new ConfigError(
|
|
35
|
-
`The value ${JSON.stringify(entry)} in '${where}' is written as a regular ` +
|
|
36
|
-
`expression, but it is not a valid one: ${reason}`
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
return (key) => expression.test(key);
|
|
40
|
-
}
|
|
41
|
-
return (key) => minimatch(key, entry);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Compiles a list of globs and `/.../` regular expressions into one matcher over
|
|
46
|
-
* recipe keys. The matcher is true when ANY entry matches; an empty or missing
|
|
47
|
-
* list matches nothing.
|
|
48
|
-
*
|
|
49
|
-
* compileRecipeKeyMatcher(["communication/*", "/^tool-usage\\//"], "recipes.memories.first")("communication/tone");
|
|
50
|
-
* // -> true
|
|
51
|
-
*
|
|
52
|
-
* @param entries - The configured list.
|
|
53
|
-
* @param where - The config key the list came from, named in any error.
|
|
54
|
-
* @throws ConfigError when an entry is an invalid regular expression.
|
|
55
|
-
*/
|
|
56
|
-
export function compileRecipeKeyMatcher(
|
|
57
|
-
entries: readonly string[] | undefined,
|
|
58
|
-
where: string
|
|
59
|
-
): (recipeKey: string) => boolean {
|
|
60
|
-
const matchers = (entries ?? []).map((entry) => compileEntry(entry, where));
|
|
61
|
-
return (recipeKey) => matchers.some((matches) => matches(recipeKey));
|
|
62
|
-
}
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The memories the project's active recipes publish, listed for the `#memories`
|
|
3
|
-
* view and for the build's check that every one of them reached an output.
|
|
4
|
-
*
|
|
5
|
-
* A recipe is ACTIVE when the project holds it directly or a co-subscription
|
|
6
|
-
* does (its lockfile kind is `subscribes`); a recipe held only through
|
|
7
|
-
* `depends` is a library and contributes nothing. A memory is a file matched by
|
|
8
|
-
* an include pattern of a manifest `contents` entry of `kind: memories`, and its
|
|
9
|
-
* virtual path is `<namespace>/<recipe>/<path>`, the path being relative to the
|
|
10
|
-
* static base of that pattern.
|
|
11
|
-
*
|
|
12
|
-
* Order: a recipe comes after every pinned recipe it depends on or subscribes
|
|
13
|
-
* to, ties go to the recipe key (bytewise), and the recipes matching
|
|
14
|
-
* `recipes.memories.first` move to the front in that same relative order. Within
|
|
15
|
-
* a recipe, files are in bytewise path order. Recipes matching
|
|
16
|
-
* `recipes.memories.exclude` are not listed.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import fs from "node:fs";
|
|
20
|
-
import path from "node:path";
|
|
21
|
-
import { globSync } from "glob";
|
|
22
|
-
import { compareBytewise } from "../../services/ref-resolver/index.js";
|
|
23
|
-
import { realPathInside } from "../include-resolver.js";
|
|
24
|
-
import { inferGlobBase } from "../markdown-compiler.js";
|
|
25
|
-
import { toGlobPattern } from "../glob-pattern.js";
|
|
26
|
-
import { compileRecipeKeyMatcher } from "./recipe-key-matcher.js";
|
|
27
|
-
import {
|
|
28
|
-
listLockedRecipes,
|
|
29
|
-
readRecipeManifestIn,
|
|
30
|
-
type LockedRecipeLocation,
|
|
31
|
-
} from "./locked-recipes.js";
|
|
32
|
-
|
|
33
|
-
/** One memory file an active recipe publishes. */
|
|
34
|
-
export type MemoryFile = {
|
|
35
|
-
/** The recipe key, `namespace/recipe`. */
|
|
36
|
-
recipe: string;
|
|
37
|
-
/** The path inside the `#memories` view, without the `#memories/` prefix. */
|
|
38
|
-
path: string;
|
|
39
|
-
/** The real file's absolute path. */
|
|
40
|
-
file: string;
|
|
41
|
-
/** The file's path relative to its recipe's directory, for messages. */
|
|
42
|
-
relative: string;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/** What listing the memories needs. */
|
|
46
|
-
export type MemoryListingOptions = {
|
|
47
|
-
/** The project's `.sous/` directory. */
|
|
48
|
-
sousDir: string;
|
|
49
|
-
/** The environment to read; decides where the store is. */
|
|
50
|
-
env?: NodeJS.ProcessEnv;
|
|
51
|
-
/** `recipes.memories.first`: recipes whose memories lead. */
|
|
52
|
-
first?: readonly string[] | undefined;
|
|
53
|
-
/** `recipes.memories.exclude`: recipes whose memories are left out. */
|
|
54
|
-
exclude?: readonly string[] | undefined;
|
|
55
|
-
/** The locked recipes, when the caller has already located them. */
|
|
56
|
-
locked?: LockedRecipeLocation[];
|
|
57
|
-
/**
|
|
58
|
-
* Receives a sentence for each memory skipped because its real path is
|
|
59
|
-
* outside its recipe's directory. Defaults to one line on stderr per file.
|
|
60
|
-
*/
|
|
61
|
-
onWarning?: (message: string) => void;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
/** Files already warned about by the default sink, so a repeated listing warns once. */
|
|
65
|
-
const warnedFiles = new Set<string>();
|
|
66
|
-
|
|
67
|
-
/** The default warning sink: one line on stderr, once per file. */
|
|
68
|
-
function warnOnce(message: string): void {
|
|
69
|
-
if (warnedFiles.has(message)) return;
|
|
70
|
-
warnedFiles.add(message);
|
|
71
|
-
process.stderr.write(`Warning: ${message}\n`);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Orders recipe keys so each comes after every pinned recipe it depends on or
|
|
76
|
-
* subscribes to, ties by key. A lockfile entry's `requestedBy` names the recipes
|
|
77
|
-
* that asked for it, which is the dependency edge read backwards. A cycle (which
|
|
78
|
-
* a resolved lockfile should not hold) leaves its members in key order at the end.
|
|
79
|
-
*
|
|
80
|
-
* @param locked - Every pinned recipe.
|
|
81
|
-
*/
|
|
82
|
-
export function dependencyOrder(locked: readonly LockedRecipeLocation[]): string[] {
|
|
83
|
-
// A recipe waits for every pinned recipe that lists it among its holders.
|
|
84
|
-
const waitingOn = new Map<string, Set<string>>();
|
|
85
|
-
for (const recipe of locked) waitingOn.set(recipe.key, new Set());
|
|
86
|
-
for (const dependency of locked) {
|
|
87
|
-
for (const holder of dependency.requestedBy) {
|
|
88
|
-
if (holder !== dependency.key) waitingOn.get(holder)?.add(dependency.key);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const ordered: string[] = [];
|
|
93
|
-
const done = new Set<string>();
|
|
94
|
-
const remaining = [...waitingOn.keys()].sort(compareBytewise);
|
|
95
|
-
while (remaining.length > 0) {
|
|
96
|
-
const index = remaining.findIndex((key) => [...waitingOn.get(key)!].every((dep) => done.has(dep)));
|
|
97
|
-
if (index === -1) {
|
|
98
|
-
ordered.push(...remaining);
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
const [key] = remaining.splice(index, 1);
|
|
102
|
-
ordered.push(key!);
|
|
103
|
-
done.add(key!);
|
|
104
|
-
}
|
|
105
|
-
return ordered;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Lists the memories of every active recipe, in view order, with the recipes
|
|
110
|
-
* that `exclude` names left out.
|
|
111
|
-
*
|
|
112
|
-
* @param options - The project, and the `first` and `exclude` lists.
|
|
113
|
-
*/
|
|
114
|
-
export function listMemories(options: MemoryListingOptions): MemoryFile[] {
|
|
115
|
-
const locked =
|
|
116
|
-
options.locked ??
|
|
117
|
-
listLockedRecipes({
|
|
118
|
-
sousDir: options.sousDir,
|
|
119
|
-
...(options.env === undefined ? {} : { env: options.env }),
|
|
120
|
-
});
|
|
121
|
-
if (locked.length === 0) return [];
|
|
122
|
-
|
|
123
|
-
const isFirst = compileRecipeKeyMatcher(options.first, "recipes.memories.first");
|
|
124
|
-
const isExcluded = compileRecipeKeyMatcher(options.exclude, "recipes.memories.exclude");
|
|
125
|
-
const byKey = new Map(locked.map((recipe) => [recipe.key, recipe]));
|
|
126
|
-
|
|
127
|
-
const order = dependencyOrder(locked);
|
|
128
|
-
const leading = order.filter((key) => isFirst(key));
|
|
129
|
-
const rest = order.filter((key) => !isFirst(key));
|
|
130
|
-
|
|
131
|
-
const files: MemoryFile[] = [];
|
|
132
|
-
for (const key of [...leading, ...rest]) {
|
|
133
|
-
const recipe = byKey.get(key)!;
|
|
134
|
-
if (recipe.kind !== "subscribes" || !recipe.present || isExcluded(key)) continue;
|
|
135
|
-
const manifest = readRecipeManifestIn(recipe.dir);
|
|
136
|
-
if (manifest === undefined) continue;
|
|
137
|
-
|
|
138
|
-
const mine = new Map<string, MemoryFile>();
|
|
139
|
-
for (const content of manifest.contents) {
|
|
140
|
-
if (content.kind !== "memories") continue;
|
|
141
|
-
const ignore = (content.exclude ?? []).map((pattern) =>
|
|
142
|
-
toGlobPattern(path.join(recipe.dir, pattern))
|
|
143
|
-
);
|
|
144
|
-
for (const include of content.include) {
|
|
145
|
-
const pattern = toGlobPattern(path.join(recipe.dir, include));
|
|
146
|
-
const base = inferGlobBase(pattern);
|
|
147
|
-
for (const file of globSync(pattern, { absolute: true, ignore, dot: true })) {
|
|
148
|
-
if (!isFile(file)) continue;
|
|
149
|
-
if (!realPathInside(file, recipe.dir)) {
|
|
150
|
-
(options.onWarning ?? warnOnce)(
|
|
151
|
-
`The memory ${file} of the recipe ${key} was left out, because it is a link ` +
|
|
152
|
-
`that leads outside the recipe's directory. Replace the link with the file itself.`
|
|
153
|
-
);
|
|
154
|
-
continue;
|
|
155
|
-
}
|
|
156
|
-
const inside = path.relative(base, file).split(path.sep).join("/");
|
|
157
|
-
mine.set(file, {
|
|
158
|
-
recipe: key,
|
|
159
|
-
path: `${key}/${inside}`,
|
|
160
|
-
file,
|
|
161
|
-
relative: path.relative(recipe.dir, file).split(path.sep).join("/"),
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
files.push(...[...mine.values()].sort((a, b) => compareBytewise(a.path, b.path)));
|
|
167
|
-
}
|
|
168
|
-
return files;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/** True when the path is a regular file. */
|
|
172
|
-
function isFile(candidate: string): boolean {
|
|
173
|
-
try {
|
|
174
|
-
return fs.statSync(candidate).isFile();
|
|
175
|
-
} catch {
|
|
176
|
-
return false;
|
|
177
|
-
}
|
|
178
|
-
}
|