@sous-io/sous 0.2.37 → 1.0.2

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.
Files changed (244) hide show
  1. package/README.md +14 -256
  2. package/dist/bin.js +11 -0
  3. package/dist/sous.js +1094 -0
  4. package/docs/markdown/README.md +5 -4
  5. package/docs/markdown/_sidebar.md +21 -1
  6. package/docs/markdown/commands.md +294 -431
  7. package/docs/markdown/config-discovery.md +25 -14
  8. package/docs/markdown/config-inspection.md +53 -31
  9. package/docs/markdown/config-layers.md +168 -66
  10. package/docs/markdown/config-variables.md +44 -11
  11. package/docs/markdown/configuration.md +104 -17
  12. package/docs/markdown/design-principles.md +4 -1
  13. package/docs/markdown/repositories-authoring.md +30 -0
  14. package/docs/markdown/repositories-consuming.md +72 -14
  15. package/docs/markdown/repositories-file-formats.md +31 -13
  16. package/docs/markdown/repositories-providers.md +48 -57
  17. package/docs/markdown/repositories-quickstart.md +3 -2
  18. package/docs/markdown/repositories-troubleshooting.md +27 -1
  19. package/docs/markdown/repositories-variables.md +6 -1
  20. package/docs/markdown/repositories.md +18 -8
  21. package/package.json +48 -107
  22. package/recipes/core/sous-skills/skills/about-liquid-templates/SKILL.tpl.md +4 -6
  23. package/recipes/core/sous-skills/skills/about-liquid-templates/references/liquid-filters.tpl.md +2 -0
  24. package/recipes/core/sous-skills/skills/about-sous/SKILL.tpl.md +10 -9
  25. package/recipes/core/sous-skills/skills/about-sous-configuration/SKILL.tpl.md +35 -14
  26. package/recipes/core/sous-skills/skills/about-sous-recipes/SKILL.tpl.md +51 -20
  27. package/recipes/core/sous-skills/sous.recipe.yaml +1 -1
  28. package/sous.config.schema.json +351 -132
  29. package/bin/run.js +0 -51
  30. package/src/base-command.ts +0 -457
  31. package/src/commands/build.ts +0 -181
  32. package/src/commands/clear.ts +0 -79
  33. package/src/commands/compile.ts +0 -155
  34. package/src/commands/config/get.ts +0 -110
  35. package/src/commands/config/show.ts +0 -32
  36. package/src/commands/config/validate.ts +0 -53
  37. package/src/commands/help.ts +0 -46
  38. package/src/commands/init.ts +0 -289
  39. package/src/commands/launch.ts +0 -139
  40. package/src/commands/lock/rebuild.ts +0 -239
  41. package/src/commands/lock/show.ts +0 -115
  42. package/src/commands/namespace/list.ts +0 -138
  43. package/src/commands/namespace/show.ts +0 -130
  44. package/src/commands/prune.ts +0 -43
  45. package/src/commands/recipe/list.ts +0 -112
  46. package/src/commands/recipe/show.ts +0 -439
  47. package/src/commands/repo/add.ts +0 -145
  48. package/src/commands/repo/contribute.ts +0 -604
  49. package/src/commands/repo/gc.ts +0 -173
  50. package/src/commands/repo/init.ts +0 -136
  51. package/src/commands/repo/link.ts +0 -899
  52. package/src/commands/repo/list.ts +0 -236
  53. package/src/commands/repo/release.ts +0 -685
  54. package/src/commands/repo/remove.ts +0 -194
  55. package/src/commands/repo/search.ts +0 -243
  56. package/src/commands/repo/submit.ts +0 -341
  57. package/src/commands/repo/unlink.ts +0 -461
  58. package/src/commands/subscription/add.ts +0 -286
  59. package/src/commands/subscription/list.ts +0 -208
  60. package/src/commands/subscription/remove.ts +0 -182
  61. package/src/commands/subscription/update.ts +0 -216
  62. package/src/commands/update.ts +0 -178
  63. package/src/commands/vars/ask.ts +0 -417
  64. package/src/commands/vars/index.ts +0 -79
  65. package/src/commands/vars/list.ts +0 -67
  66. package/src/commands/vars/show.ts +0 -77
  67. package/src/config-command.ts +0 -30
  68. package/src/lib/build-preparation.ts +0 -128
  69. package/src/lib/build-service.ts +0 -580
  70. package/src/lib/config-discovery.ts +0 -378
  71. package/src/lib/config-inspect.ts +0 -145
  72. package/src/lib/config-kernel.mjs +0 -379
  73. package/src/lib/config-schema.ts +0 -401
  74. package/src/lib/env-file.ts +0 -328
  75. package/src/lib/env-local.ts +0 -212
  76. package/src/lib/errors.ts +0 -32
  77. package/src/lib/glob-pattern.ts +0 -24
  78. package/src/lib/include-resolver.ts +0 -523
  79. package/src/lib/interactive.ts +0 -165
  80. package/src/lib/markdown-compiler.ts +0 -947
  81. package/src/lib/package-info.ts +0 -25
  82. package/src/lib/pid-service.ts +0 -99
  83. package/src/lib/project-install.d.mts +0 -44
  84. package/src/lib/project-install.mjs +0 -234
  85. package/src/lib/project-scaffold/index.ts +0 -332
  86. package/src/lib/project-scaffold/templates.ts +0 -240
  87. package/src/lib/repos/catalog-display.ts +0 -215
  88. package/src/lib/repos/catalog-inputs.ts +0 -288
  89. package/src/lib/repos/catalog.ts +0 -842
  90. package/src/lib/repos/contribute.ts +0 -452
  91. package/src/lib/repos/core-recipe.ts +0 -105
  92. package/src/lib/repos/declarations.ts +0 -187
  93. package/src/lib/repos/defaults.ts +0 -175
  94. package/src/lib/repos/formats/common.ts +0 -440
  95. package/src/lib/repos/formats/index-file.ts +0 -253
  96. package/src/lib/repos/formats/links-map.ts +0 -98
  97. package/src/lib/repos/formats/lockfile.ts +0 -169
  98. package/src/lib/repos/formats/patterns.ts +0 -57
  99. package/src/lib/repos/formats/recipe-manifest.ts +0 -205
  100. package/src/lib/repos/formats/repo-manifest.ts +0 -97
  101. package/src/lib/repos/formats/store-entry.ts +0 -84
  102. package/src/lib/repos/formats/variable-definition.ts +0 -268
  103. package/src/lib/repos/freshness.ts +0 -264
  104. package/src/lib/repos/git-clone.ts +0 -850
  105. package/src/lib/repos/identity.ts +0 -89
  106. package/src/lib/repos/index.ts +0 -57
  107. package/src/lib/repos/links.ts +0 -356
  108. package/src/lib/repos/load-manifest.ts +0 -237
  109. package/src/lib/repos/lock-service.ts +0 -454
  110. package/src/lib/repos/locked-namespace-resolver.ts +0 -232
  111. package/src/lib/repos/locked-recipe-lookup.ts +0 -123
  112. package/src/lib/repos/locked-recipes.ts +0 -254
  113. package/src/lib/repos/managed-layer.ts +0 -422
  114. package/src/lib/repos/memories-hash-name.ts +0 -33
  115. package/src/lib/repos/namespace-resolver.ts +0 -527
  116. package/src/lib/repos/providers/base.ts +0 -268
  117. package/src/lib/repos/providers/git.ts +0 -245
  118. package/src/lib/repos/providers/github.ts +0 -589
  119. package/src/lib/repos/providers/gitlab.ts +0 -332
  120. package/src/lib/repos/providers/http.ts +0 -128
  121. package/src/lib/repos/providers/index-cache.ts +0 -421
  122. package/src/lib/repos/providers/index.ts +0 -106
  123. package/src/lib/repos/providers/local.ts +0 -410
  124. package/src/lib/repos/providers/provider.ts +0 -615
  125. package/src/lib/repos/recipe-config-layers.ts +0 -316
  126. package/src/lib/repos/recipe-key-matcher.ts +0 -62
  127. package/src/lib/repos/recipe-memories.ts +0 -178
  128. package/src/lib/repos/recipe-targets.ts +0 -236
  129. package/src/lib/repos/ref-search.ts +0 -46
  130. package/src/lib/repos/release/bump.ts +0 -161
  131. package/src/lib/repos/release/changelog.ts +0 -461
  132. package/src/lib/repos/release/git-state.ts +0 -460
  133. package/src/lib/repos/release/index-builder.ts +0 -1108
  134. package/src/lib/repos/release/index.ts +0 -19
  135. package/src/lib/repos/release/plan.ts +0 -521
  136. package/src/lib/repos/release/settle.ts +0 -154
  137. package/src/lib/repos/release/submissions.ts +0 -214
  138. package/src/lib/repos/release/submit-checkout.ts +0 -290
  139. package/src/lib/repos/release/submit-questions.ts +0 -153
  140. package/src/lib/repos/release/submit-service.ts +0 -898
  141. package/src/lib/repos/release/tags.ts +0 -239
  142. package/src/lib/repos/release/validate.ts +0 -463
  143. package/src/lib/repos/resolver.ts +0 -1028
  144. package/src/lib/repos/scaffold/index.ts +0 -245
  145. package/src/lib/repos/scaffold/templates.ts +0 -517
  146. package/src/lib/repos/seed.ts +0 -473
  147. package/src/lib/repos/store/contract.ts +0 -64
  148. package/src/lib/repos/store/hash.ts +0 -191
  149. package/src/lib/repos/store/recipe-store.ts +0 -599
  150. package/src/lib/repos/store/settings.ts +0 -58
  151. package/src/lib/repos/subscription-service.ts +0 -3859
  152. package/src/lib/repos/trust.ts +0 -447
  153. package/src/lib/repos/update-plan.ts +0 -235
  154. package/src/lib/self-update/index.ts +0 -14
  155. package/src/lib/self-update/installs.ts +0 -413
  156. package/src/lib/self-update/managers.ts +0 -126
  157. package/src/lib/self-update/plan.ts +0 -315
  158. package/src/lib/self-update/registry.ts +0 -99
  159. package/src/lib/self-update/run.ts +0 -506
  160. package/src/lib/self-update/versions.ts +0 -243
  161. package/src/lib/settings.ts +0 -1107
  162. package/src/lib/sous-home.ts +0 -104
  163. package/src/lib/state.ts +0 -167
  164. package/src/lib/vars/answers.ts +0 -192
  165. package/src/lib/vars/ask.ts +0 -1152
  166. package/src/lib/vars/definition-source.ts +0 -261
  167. package/src/lib/vars/display.ts +0 -231
  168. package/src/lib/vars/index.ts +0 -20
  169. package/src/lib/vars/ladder.ts +0 -282
  170. package/src/lib/vars/mappings.ts +0 -260
  171. package/src/lib/vars/names.ts +0 -94
  172. package/src/lib/vars/preanswers.ts +0 -395
  173. package/src/lib/vars/question-plan.ts +0 -241
  174. package/src/lib/vars/report.ts +0 -228
  175. package/src/lib/vars/safe-regex.ts +0 -235
  176. package/src/lib/vars/secrets.ts +0 -131
  177. package/src/lib/vars/validate.ts +0 -312
  178. package/src/lib/version-report.ts +0 -90
  179. package/src/lib/watch-loop.ts +0 -148
  180. package/src/lib/watch-service.ts +0 -116
  181. package/src/services/ref-resolver/container.ts +0 -107
  182. package/src/services/ref-resolver/dependency.ts +0 -60
  183. package/src/services/ref-resolver/format.ts +0 -197
  184. package/src/services/ref-resolver/glob.ts +0 -115
  185. package/src/services/ref-resolver/hash-names.ts +0 -155
  186. package/src/services/ref-resolver/index.ts +0 -55
  187. package/src/services/ref-resolver/injectable.ts +0 -36
  188. package/src/services/ref-resolver/location.ts +0 -62
  189. package/src/services/ref-resolver/lookups/cached-index-lookup.ts +0 -53
  190. package/src/services/ref-resolver/lookups/catalog-lookup.ts +0 -23
  191. package/src/services/ref-resolver/lookups/catalog-matcher.ts +0 -261
  192. package/src/services/ref-resolver/lookups/chained-lookup.ts +0 -27
  193. package/src/services/ref-resolver/lookups/env-var-lookup.ts +0 -65
  194. package/src/services/ref-resolver/lookups/fetched-index-lookup.ts +0 -150
  195. package/src/services/ref-resolver/lookups/recorded-dependency-lookup.ts +0 -62
  196. package/src/services/ref-resolver/lookups/ref-lookup.ts +0 -54
  197. package/src/services/ref-resolver/lookups/variable-lookup.ts +0 -123
  198. package/src/services/ref-resolver/named-refs.ts +0 -144
  199. package/src/services/ref-resolver/parser/env-var-splitter.ts +0 -27
  200. package/src/services/ref-resolver/parser/location-splitter.ts +0 -239
  201. package/src/services/ref-resolver/parser/name-path-splitter.ts +0 -200
  202. package/src/services/ref-resolver/parser/partial-ref.ts +0 -84
  203. package/src/services/ref-resolver/parser/query-splitter.ts +0 -61
  204. package/src/services/ref-resolver/parser/range-splitter.ts +0 -52
  205. package/src/services/ref-resolver/parser/ref-parser.ts +0 -115
  206. package/src/services/ref-resolver/parser/repo-qualifier-splitter.ts +0 -51
  207. package/src/services/ref-resolver/parts.ts +0 -115
  208. package/src/services/ref-resolver/pruners/command-line-pruner.ts +0 -47
  209. package/src/services/ref-resolver/pruners/include-pruner.ts +0 -66
  210. package/src/services/ref-resolver/pruners/manifest-pruner.ts +0 -130
  211. package/src/services/ref-resolver/pruners/ref-pruner.ts +0 -135
  212. package/src/services/ref-resolver/pruners/rule-helpers.ts +0 -44
  213. package/src/services/ref-resolver/pruners/stored-key-pruner.ts +0 -136
  214. package/src/services/ref-resolver/ref-helpers.ts +0 -62
  215. package/src/services/ref-resolver/ref-picker-service.ts +0 -204
  216. package/src/services/ref-resolver/ref-report.ts +0 -84
  217. package/src/services/ref-resolver/ref-resolve-arguments.ts +0 -47
  218. package/src/services/ref-resolver/ref-resolve-result.ts +0 -36
  219. package/src/services/ref-resolver/ref-resolver-service.ts +0 -323
  220. package/src/services/ref-resolver/source.ts +0 -48
  221. package/src/services/ref-resolver/tokens.ts +0 -25
  222. package/src/services/ref-resolver/types.ts +0 -155
  223. package/src/templating/filters/bullet-list.ts +0 -9
  224. package/src/templating/filters/index.ts +0 -8
  225. package/src/templating/init-liquid-engine.ts +0 -139
  226. package/src/templating/lib/glob-files.ts +0 -74
  227. package/src/templating/lib/import-export.ts +0 -32
  228. package/src/templating/lib/secret-scope.ts +0 -41
  229. package/src/templating/lib/tag-args.ts +0 -19
  230. package/src/templating/tags/exportScalarVarsJs.ts +0 -46
  231. package/src/templating/tags/getFiles.ts +0 -89
  232. package/src/templating/tags/index.ts +0 -14
  233. package/src/templating/tags/listFiles.ts +0 -54
  234. package/src/templating/tags/showVars.ts +0 -28
  235. package/src/utils/choice-prompt.ts +0 -143
  236. package/src/utils/command-errors.ts +0 -186
  237. package/src/utils/command-help.ts +0 -45
  238. package/src/utils/confirm-prompt.ts +0 -110
  239. package/src/utils/flags.ts +0 -177
  240. package/src/utils/formatting.ts +0 -849
  241. package/src/utils/prompts.ts +0 -53
  242. package/src/utils/sous-directory.ts +0 -245
  243. package/src/utils/table.ts +0 -603
  244. package/src/utils/value-prompt.ts +0 -119
@@ -1,461 +0,0 @@
1
- /**
2
- * The changelog `sous repo submit` writes under a proposal's description.
3
- *
4
- * A maintainer reviewing a proposal needs to know what merging it does to the
5
- * people who subscribe to the repository: which recipes appear, disappear or
6
- * change version, which changed their files without raising their version
7
- * (a release run with `--ci` refuses those), which namespaces come and go, and which
8
- * variables change. None of that is in a commit message, and all of it can be
9
- * read from the manifests, so sous reads them: the ones the change carries,
10
- * compared with the ones on the default branch.
11
- *
12
- * The changelog explains; it never refuses. Whether a change is acceptable is
13
- * the repository's own checks' business, so a change that affects subscribers
14
- * is described here, with a warning where one is due, and never blocked.
15
- *
16
- * Reading the default branch's manifests goes through git and the injectable
17
- * runner; everything after that is pure, so the comparison is tested without a
18
- * repository at all.
19
- */
20
-
21
- import path from "node:path";
22
- import {
23
- MANIFEST_EXTENSIONS,
24
- RECIPE_MANIFEST_BASENAME,
25
- REPO_MANIFEST_BASENAME,
26
- } from "../formats/common.js";
27
- import {
28
- parseRecipeManifest,
29
- recipeManifestKey,
30
- type RecipeManifest,
31
- type VariableDefinition,
32
- } from "../formats/recipe-manifest.js";
33
- import { parseRepoManifest, type RepoManifest } from "../formats/repo-manifest.js";
34
- import { parseJsoncText, parseYamlText } from "../load-manifest.js";
35
- import type { RunOptions } from "../providers/git.js";
36
- import { pathsInside } from "./submissions.js";
37
- import { readFileAtTag } from "./tags.js";
38
- import type { RepoValidation } from "./validate.js";
39
-
40
- /** The manifests as they stood at one commit. */
41
- export type ManifestSnapshot = {
42
- /** The repo manifest. */
43
- repo: RepoManifest;
44
- /** Every recipe manifest that could be read, keyed by recipe key. */
45
- recipes: Map<string, { path: string; manifest: RecipeManifest }>;
46
- };
47
-
48
- /** One recipe that appeared or disappeared. */
49
- export type RecipeEntry = { key: string; version: string };
50
-
51
- /** One recipe whose declared version moved. */
52
- export type VersionChange = { key: string; from: string; to: string };
53
-
54
- /** One recipe whose files changed while its version stayed where it was. */
55
- export type UnraisedChange = { key: string; version: string };
56
-
57
- /** One variable that was added, removed or changed. */
58
- export type VariableChange = {
59
- /** The recipe that declares it. */
60
- recipe: string;
61
- /** The variable's name. */
62
- name: string;
63
- /** What happened to it. */
64
- change: "added" | "removed" | "changed";
65
- /** The fields that changed, for a changed variable. */
66
- fields?: string[];
67
- /** True when the change usually breaks a subscriber: a removal, or a tighter rule. */
68
- breaking: boolean;
69
- };
70
-
71
- /** Everything merging a change would do, as the manifests describe it. */
72
- export type Changelog = {
73
- /** The branch the change was compared with. */
74
- baseBranch: string;
75
- /** False when there was nothing to compare with; every list is then empty. */
76
- compared: boolean;
77
- namespacesAdded: string[];
78
- namespacesRemoved: string[];
79
- recipesAdded: RecipeEntry[];
80
- recipesRemoved: RecipeEntry[];
81
- versionChanges: VersionChange[];
82
- unraised: UnraisedChange[];
83
- variables: VariableChange[];
84
- };
85
-
86
- /**
87
- * Reads the repo manifest and every recipe manifest it lists as they stood at
88
- * one commit. Returns undefined when that commit holds no repo manifest sous
89
- * can read; a recipe manifest it cannot read is left out rather than failing
90
- * the whole comparison.
91
- *
92
- * @param rootDir - The repository's root directory.
93
- * @param commit - The commit to read at.
94
- * @param options - The command runner to use.
95
- */
96
- export async function readManifestsAt(
97
- rootDir: string,
98
- commit: string,
99
- options: RunOptions = {}
100
- ): Promise<ManifestSnapshot | undefined> {
101
- const repoRaw = await readManifestAt(rootDir, commit, "", REPO_MANIFEST_BASENAME, options);
102
- if (repoRaw === undefined) return undefined;
103
-
104
- let repo: RepoManifest;
105
- try {
106
- repo = parseRepoManifest(repoRaw.value, `${repoRaw.file} at ${commit.slice(0, 12)}`);
107
- } catch {
108
- return undefined;
109
- }
110
-
111
- const recipes = new Map<string, { path: string; manifest: RecipeManifest }>();
112
- for (const recipePath of repo.recipes) {
113
- const raw = await readManifestAt(rootDir, commit, recipePath, RECIPE_MANIFEST_BASENAME, options);
114
- if (raw === undefined) continue;
115
- try {
116
- const manifest = parseRecipeManifest(raw.value, `${raw.file} at ${commit.slice(0, 12)}`);
117
- recipes.set(recipeManifestKey(manifest), { path: recipePath, manifest });
118
- } catch {
119
- continue;
120
- }
121
- }
122
-
123
- return { repo, recipes };
124
- }
125
-
126
- /**
127
- * The manifests the working tree holds, in the same shape a commit's are read
128
- * into, so the two can be compared.
129
- *
130
- * @param validation - The validated repository.
131
- */
132
- export function snapshotOf(validation: RepoValidation): ManifestSnapshot {
133
- const recipes = new Map<string, { path: string; manifest: RecipeManifest }>();
134
- for (const recipe of validation.recipes) {
135
- recipes.set(recipe.key, { path: recipe.path, manifest: recipe.manifest });
136
- }
137
- return { repo: validation.manifest, recipes };
138
- }
139
-
140
- /**
141
- * Compares the manifests a change carries with the ones on the default branch.
142
- *
143
- * @param input.baseBranch - The branch the change is compared with, for the record.
144
- * @param input.base - The manifests on that branch, or undefined when there was nothing to read.
145
- * @param input.head - The manifests the change carries.
146
- * @param input.changedPaths - Every path the change touched, relative to the repository root.
147
- */
148
- export function buildChangelog(input: {
149
- baseBranch: string;
150
- base: ManifestSnapshot | undefined;
151
- head: ManifestSnapshot;
152
- changedPaths: ReadonlyArray<string>;
153
- }): Changelog {
154
- const { baseBranch, base, head, changedPaths } = input;
155
- const changelog: Changelog = {
156
- baseBranch,
157
- compared: base !== undefined,
158
- namespacesAdded: [],
159
- namespacesRemoved: [],
160
- recipesAdded: [],
161
- recipesRemoved: [],
162
- versionChanges: [],
163
- unraised: [],
164
- variables: [],
165
- };
166
- if (base === undefined) return changelog;
167
-
168
- const baseNamespaces = Object.keys(base.repo.namespaces);
169
- const headNamespaces = Object.keys(head.repo.namespaces);
170
- changelog.namespacesAdded = headNamespaces.filter((name) => !baseNamespaces.includes(name)).sort();
171
- changelog.namespacesRemoved = baseNamespaces
172
- .filter((name) => !headNamespaces.includes(name))
173
- .sort();
174
-
175
- for (const [key, entry] of sortedEntries(head.recipes)) {
176
- const before = base.recipes.get(key);
177
- if (before === undefined) {
178
- changelog.recipesAdded.push({ key, version: entry.manifest.version });
179
- continue;
180
- }
181
-
182
- const from = before.manifest.version;
183
- const to = entry.manifest.version;
184
- if (from !== to) {
185
- changelog.versionChanges.push({ key, from, to });
186
- } else if (pathsInside(entry.path, changedPaths).length > 0) {
187
- changelog.unraised.push({ key, version: to });
188
- }
189
-
190
- changelog.variables.push(
191
- ...compareVariables(key, before.manifest.variables ?? [], entry.manifest.variables ?? [])
192
- );
193
- }
194
-
195
- for (const [key, entry] of sortedEntries(base.recipes)) {
196
- if (!head.recipes.has(key)) {
197
- changelog.recipesRemoved.push({ key, version: entry.manifest.version });
198
- }
199
- }
200
-
201
- return changelog;
202
- }
203
-
204
- /** True when the changelog found nothing that merging would change. */
205
- export function changelogIsEmpty(changelog: Changelog): boolean {
206
- return (
207
- changelog.namespacesAdded.length === 0 &&
208
- changelog.namespacesRemoved.length === 0 &&
209
- changelog.recipesAdded.length === 0 &&
210
- changelog.recipesRemoved.length === 0 &&
211
- changelog.versionChanges.length === 0 &&
212
- changelog.unraised.length === 0 &&
213
- changelog.variables.length === 0
214
- );
215
- }
216
-
217
- /**
218
- * The warning a change to a recipe's files without a version raise carries.
219
- * It is a warning and not a refusal: whether the merge's release raises the
220
- * version, refuses the change, or runs some other way is the repository's own
221
- * business, so the changelog states the fact and leaves the decision there.
222
- */
223
- export const UNRAISED_VERSION_WARNING =
224
- "A recipe listed above changed without raising its version. A release run with `--ci`, " +
225
- "as the workflow `sous repo init` scaffolds runs it after a merge, refuses a changed " +
226
- "recipe whose version was not raised, so its version has to be raised in its manifest " +
227
- "before that release can publish it.";
228
-
229
- /** The warning a breaking variable change carries. */
230
- export const BREAKING_VARIABLE_WARNING =
231
- "Removing a variable or tightening its validation is usually a major change: a " +
232
- "subscriber's stored answer may no longer be read, or no longer be accepted.";
233
-
234
- /**
235
- * The changelog as Markdown, the way it is appended to a proposal's body and a
236
- * commit message. Every section is left out when it has nothing to say.
237
- *
238
- * @param changelog - The comparison to describe.
239
- */
240
- export function renderChangelog(changelog: Changelog): string {
241
- const lines = ["## What merging this changes", ""];
242
-
243
- if (!changelog.compared) {
244
- lines.push(
245
- `Sous could not compare this change with the branch '${changelog.baseBranch}', because ` +
246
- "this checkout holds no copy of it, so no changelog was generated."
247
- );
248
- return lines.join("\n");
249
- }
250
-
251
- lines.push(
252
- `Generated by \`sous repo submit\` from the manifests this change carries, compared with ` +
253
- `the branch '${changelog.baseBranch}'.`
254
- );
255
-
256
- if (changelogIsEmpty(changelog)) {
257
- lines.push("", "Merging changes no recipe, namespace, version or variable.");
258
- return lines.join("\n");
259
- }
260
-
261
- const section = (title: string, entries: string[]) => {
262
- if (entries.length === 0) return;
263
- lines.push("", `**${title}**`, "", ...entries.map((entry) => `- ${entry}`));
264
- };
265
-
266
- section(
267
- "Recipes added",
268
- changelog.recipesAdded.map((entry) => `\`${entry.key}\`, at version ${entry.version}`)
269
- );
270
- section(
271
- "Recipes retired",
272
- changelog.recipesRemoved.map(
273
- (entry) => `\`${entry.key}\`, last at version ${entry.version}`
274
- )
275
- );
276
- section(
277
- "Version changes",
278
- changelog.versionChanges.map(
279
- (entry) => `\`${entry.key}\`: ${entry.from} becomes ${entry.to}`
280
- )
281
- );
282
- section(
283
- "Changed without a version raise",
284
- changelog.unraised.map(
285
- (entry) =>
286
- `\`${entry.key}\`: its files changed and its version is still ${entry.version}`
287
- )
288
- );
289
- if (changelog.unraised.length > 0) {
290
- lines.push("", `**Warning:** ${UNRAISED_VERSION_WARNING}`);
291
- }
292
- section("Namespaces added", changelog.namespacesAdded.map((name) => `\`${name}\``));
293
- section("Namespaces removed", changelog.namespacesRemoved.map((name) => `\`${name}\``));
294
- section("Variables", changelog.variables.map(describeVariableChange));
295
-
296
- if (changelog.variables.some((entry) => entry.breaking)) {
297
- lines.push("", `**Warning:** ${BREAKING_VARIABLE_WARNING}`);
298
- }
299
-
300
- return lines.join("\n");
301
- }
302
-
303
- /**
304
- * Composes a proposal's body: the contributor's own description, then the
305
- * changelog sous generated.
306
- *
307
- * @param description - What the contributor wrote.
308
- * @param changelog - The comparison to append.
309
- */
310
- export function composeProposalBody(description: string, changelog: Changelog): string {
311
- return `${description.trim()}\n\n${renderChangelog(changelog)}\n`;
312
- }
313
-
314
- // --- Variables ----------------------------------------------------------------------------------
315
-
316
- /**
317
- * Compares one recipe's variable definitions before and after a change.
318
- *
319
- * @param recipe - The recipe key.
320
- * @param before - The definitions on the default branch.
321
- * @param after - The definitions the change carries.
322
- */
323
- export function compareVariables(
324
- recipe: string,
325
- before: ReadonlyArray<VariableDefinition>,
326
- after: ReadonlyArray<VariableDefinition>
327
- ): VariableChange[] {
328
- const changes: VariableChange[] = [];
329
- const beforeByName = new Map(before.map((definition) => [definition.name, definition]));
330
- const afterByName = new Map(after.map((definition) => [definition.name, definition]));
331
-
332
- for (const definition of after) {
333
- const previous = beforeByName.get(definition.name);
334
- if (previous === undefined) {
335
- changes.push({ recipe, name: definition.name, change: "added", breaking: false });
336
- continue;
337
- }
338
- const fields = changedFields(previous, definition);
339
- if (fields.length === 0) continue;
340
- changes.push({
341
- recipe,
342
- name: definition.name,
343
- change: "changed",
344
- fields,
345
- breaking: isTightened(previous, definition),
346
- });
347
- }
348
-
349
- for (const definition of before) {
350
- if (!afterByName.has(definition.name)) {
351
- changes.push({ recipe, name: definition.name, change: "removed", breaking: true });
352
- }
353
- }
354
-
355
- return changes;
356
- }
357
-
358
- /**
359
- * True when a changed definition accepts less than it did: a different type, a
360
- * newly required answer, or a validation rule that rejects something the old
361
- * one accepted. A changed pattern counts, since sous cannot prove one regular
362
- * expression accepts everything another did.
363
- *
364
- * isTightened({ ..., validate: { maxLength: 10 } }, { ..., validate: { maxLength: 5 } });
365
- * // -> true
366
- *
367
- * @param before - The definition on the default branch.
368
- * @param after - The definition the change carries.
369
- */
370
- export function isTightened(before: VariableDefinition, after: VariableDefinition): boolean {
371
- if (before.type !== after.type) return true;
372
- if (!before.required && after.required) return true;
373
-
374
- const was = before.validate ?? {};
375
- const now = after.validate ?? {};
376
-
377
- if (now.pattern !== undefined && now.pattern !== was.pattern) return true;
378
- if (raised(was.minLength, now.minLength)) return true;
379
- if (lowered(was.maxLength, now.maxLength)) return true;
380
- if (raised(was.min, now.min)) return true;
381
- if (lowered(was.max, now.max)) return true;
382
- if (now.enum !== undefined) {
383
- if (was.enum === undefined) return true;
384
- if (was.enum.some((option) => !now.enum!.includes(option))) return true;
385
- }
386
- return false;
387
- }
388
-
389
- /** True when a lower bound was added or moved up. */
390
- function raised(was: number | undefined, now: number | undefined): boolean {
391
- return now !== undefined && (was === undefined || now > was);
392
- }
393
-
394
- /** True when an upper bound was added or moved down. */
395
- function lowered(was: number | undefined, now: number | undefined): boolean {
396
- return now !== undefined && (was === undefined || now < was);
397
- }
398
-
399
- /** The top-level fields of a definition that differ, by name, in a stable order. */
400
- function changedFields(before: VariableDefinition, after: VariableDefinition): string[] {
401
- const keys = new Set([...Object.keys(before), ...Object.keys(after)]);
402
- const fields: string[] = [];
403
- for (const key of [...keys].sort()) {
404
- const was = (before as Record<string, unknown>)[key];
405
- const now = (after as Record<string, unknown>)[key];
406
- if (JSON.stringify(was) !== JSON.stringify(now)) fields.push(key);
407
- }
408
- return fields;
409
- }
410
-
411
- /** One variable change, as a changelog line. */
412
- function describeVariableChange(entry: VariableChange): string {
413
- const subject = `\`${entry.recipe}\`: the variable \`${entry.name}\``;
414
- if (entry.change === "added") return `${subject} was added`;
415
- if (entry.change === "removed") return `${subject} was removed (usually a major change)`;
416
- const fields = (entry.fields ?? []).map((field) => `\`${field}\``).join(", ");
417
- return (
418
- `${subject} changed its ${fields}` +
419
- (entry.breaking ? " and now accepts less than before (usually a major change)" : "")
420
- );
421
- }
422
-
423
- // --- Reading at a commit ------------------------------------------------------------------------
424
-
425
- /**
426
- * Reads one manifest at a commit, trying each supported file name in turn.
427
- *
428
- * @param rootDir - The repository's root directory.
429
- * @param commit - The commit to read at.
430
- * @param folder - The folder holding it, relative to the repository root ("" for the root).
431
- * @param basename - The manifest's name without an extension.
432
- * @param options - The command runner to use.
433
- */
434
- async function readManifestAt(
435
- rootDir: string,
436
- commit: string,
437
- folder: string,
438
- basename: string,
439
- options: RunOptions
440
- ): Promise<{ file: string; value: unknown } | undefined> {
441
- for (const extension of MANIFEST_EXTENSIONS) {
442
- const file = folder.length === 0 ? `${basename}${extension}` : path.posix.join(folder, `${basename}${extension}`);
443
- const text = await readFileAtTag(rootDir, commit, file, options);
444
- if (text === undefined) continue;
445
- try {
446
- const value =
447
- extension === ".yaml" || extension === ".yml"
448
- ? parseYamlText(text, file)
449
- : parseJsoncText(text, file);
450
- return { file, value };
451
- } catch {
452
- return undefined;
453
- }
454
- }
455
- return undefined;
456
- }
457
-
458
- /** A map's entries, sorted by key, so the changelog reads the same every time. */
459
- function sortedEntries<T>(map: Map<string, T>): Array<[string, T]> {
460
- return [...map.entries()].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
461
- }