@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,79 +0,0 @@
1
- import { confirm } from "@inquirer/prompts";
2
- import fs from "node:fs";
3
- import { BaseCommand } from "../base-command.js";
4
- import { resolveStateFilePath } from "../lib/build-service.js";
5
- import { isProtectedPath, StateService } from "../lib/state.js";
6
- import { protectedRepoPaths } from "../lib/repos/links.js";
7
- import { confirmationFlag } from "../utils/flags.js";
8
- import { displayError, footer, heading, log, showCommandVars } from "../utils/formatting.js";
9
-
10
- export default class Clear extends BaseCommand {
11
- static description = "Delete all files and directories written by Sous for a project";
12
-
13
- static examples = [
14
- "<%= config.bin %> clear",
15
- "<%= config.bin %> clear --force",
16
- "<%= config.bin %> clear -y",
17
- ];
18
-
19
- static flags = {
20
- ...BaseCommand.baseFlags,
21
- // `--force` is this command's original spelling, so it stays the primary
22
- // one; `--yes` and `-y` are aliases of it, and the confirmation therefore
23
- // answers the same way here as it does on every other command.
24
- force: confirmationFlag({ primary: "force" }),
25
- };
26
-
27
- async run(): Promise<void> {
28
- const { flags } = await this.parse(Clear);
29
-
30
- const stateFilePath = resolveStateFilePath(this.settings, this.configContext);
31
-
32
- const stateService = new StateService();
33
- const state = await stateService.load(stateFilePath);
34
-
35
- if (!state) {
36
- displayError(
37
- `No state file found at ${stateFilePath}. Run 'sous build' first, then 'sous clear' to recover.`
38
- );
39
- this.exit(1);
40
- }
41
-
42
- showCommandVars({ Project: this.projectLabel, Config: this.configContext.configPath });
43
-
44
- // A linked checkout holds somebody's unpushed edits and the recipe store is
45
- // shared by every project on this machine, so neither is ever clearable,
46
- // whatever a stale state entry claims.
47
- const protectedPaths = protectedRepoPaths(this.configContext.sousDir);
48
- const clearable = state!.files.filter(
49
- (entry) => !isProtectedPath(entry.dest, protectedPaths)
50
- );
51
-
52
- const fileCount = clearable.length;
53
- const dirCount = state!.dirs.length;
54
-
55
- if (!flags.force) {
56
- const confirmed = await confirm({
57
- message: `Delete ${fileCount} file(s) and ${dirCount} director(ies) for '${this.projectLabel}'?`,
58
- default: false,
59
- });
60
- if (!confirmed) {
61
- log("Aborted.");
62
- return;
63
- }
64
- }
65
-
66
- heading("Clearing");
67
-
68
- stateService.deleteTrackedFiles(clearable, state!.dirs, protectedPaths);
69
- for (const entry of clearable) log(` ✗ ${entry.dest}`);
70
-
71
- // Delete state file itself
72
- if (fs.existsSync(stateFilePath)) {
73
- fs.rmSync(stateFilePath);
74
- log(` ✗ ${stateFilePath} (state file)`);
75
- }
76
-
77
- footer();
78
- }
79
- }
@@ -1,155 +0,0 @@
1
- import { Flags } from "@oclif/core";
2
- import { BaseCommand } from "../base-command.js";
3
- import { CompilationService } from "../lib/markdown-compiler.js";
4
- import { resolveCompilation, resolveRootScope } from "../lib/settings.js";
5
- import {
6
- resolveProjectAnswers,
7
- resolveRecipeTargets,
8
- resolveStateFilePath,
9
- withRecipeTargets,
10
- } from "../lib/build-service.js";
11
- import { createProjectNamespaceResolver } from "../lib/repos/locked-namespace-resolver.js";
12
- import { describeLinkedRepos } from "../lib/repos/links.js";
13
- import { buildReloadWatchConfig, startConfigReloadWatch } from "../lib/watch-loop.js";
14
- import { WatchService } from "../lib/watch-service.js";
15
- import {
16
- displayError,
17
- footer,
18
- heading,
19
- log,
20
- showCommandVars,
21
- warning,
22
- } from "../utils/formatting.js";
23
-
24
- export default class Compile extends BaseCommand {
25
- static description = "Compile markdown templates into output files";
26
-
27
- static examples = [
28
- "<%= config.bin %> compile",
29
- "<%= config.bin %> compile --rebuild",
30
- "<%= config.bin %> compile --dry-run",
31
- "<%= config.bin %> compile --strict",
32
- ];
33
-
34
- static flags = {
35
- ...BaseCommand.baseFlags,
36
- strict: Flags.boolean({
37
- description: "Treat compile warnings as errors",
38
- default: false,
39
- }),
40
- rebuild: Flags.boolean({
41
- description: "Ignore cached hashes and reprocess all outputs",
42
- default: false,
43
- }),
44
- "dry-run": Flags.boolean({
45
- description: "Print what would be written without making changes",
46
- default: false,
47
- }),
48
- watch: Flags.boolean({
49
- char: "w",
50
- description: "Watch source files and recompile on changes",
51
- default: false,
52
- }),
53
- };
54
-
55
- async run(): Promise<void> {
56
- const { flags } = await this.parse(Compile);
57
-
58
- // The recipes this project subscribes to contribute compile targets
59
- // alongside its own; both go through the same compiler.
60
- const withRecipes = () => {
61
- const answers = resolveProjectAnswers(this.settings, this.configContext);
62
- const scope = resolveRootScope(this.settings, this.configContext, { answers });
63
- const recipes = resolveRecipeTargets(this.settings, scope, this.configContext, answers);
64
- for (const notice of recipes.warnings) warning(notice);
65
- return withRecipeTargets(
66
- resolveCompilation(this.settings, scope),
67
- recipes,
68
- this.settings,
69
- scope
70
- );
71
- };
72
-
73
- for (const line of describeLinkedRepos(this.configContext.sousDir)) log(line);
74
-
75
- const config = withRecipes();
76
-
77
- if (!config) {
78
- displayError(`No compilation config found in ${this.configContext.configPath}`);
79
- this.exit(1);
80
- }
81
-
82
- const stateFilePath = resolveStateFilePath(this.settings, this.configContext);
83
-
84
- showCommandVars({
85
- Project: this.projectLabel,
86
- Config: this.configContext.configPath,
87
- Strict: flags.strict,
88
- Rebuild: flags.rebuild,
89
- "Dry Run": flags["dry-run"],
90
- });
91
-
92
- heading("Compiling");
93
-
94
- // Rebuilt on every compile rather than captured once: a watch-mode reload
95
- // may follow a subscribe, and the lockfile is what this reads.
96
- const namespaceResolver = () =>
97
- createProjectNamespaceResolver({
98
- sousDir: this.configContext.sousDir,
99
- settings: this.settings,
100
- });
101
-
102
- const compilerOptions = {
103
- strict: flags.strict,
104
- rebuild: flags.rebuild,
105
- dryRun: flags["dry-run"],
106
- };
107
-
108
- const compiler = new CompilationService({
109
- ...compilerOptions,
110
- namespaceResolver: namespaceResolver(),
111
- });
112
- const success = await compiler.compile(config!, stateFilePath);
113
-
114
- footer();
115
-
116
- if (!success && !flags.watch) {
117
- this.exit(1);
118
- }
119
-
120
- if (flags.watch) {
121
- const watchService = new WatchService();
122
-
123
- // Recompiles using the command's CURRENT settings. Called for partial
124
- // rebuilds (a changed source) and, after a clean reload, for full
125
- // rebuilds. The compilation config and state-file path are re-resolved
126
- // each time so a config reload takes effect. Owns the "Recompiling"
127
- // heading/footer. (`changedFile` is accepted for parity with build and
128
- // logged by the watch loop; compile always does a full recompile.)
129
- const rebuild = async (_changedFile?: string) => {
130
- const currentConfig = withRecipes();
131
- if (!currentConfig) {
132
- displayError(`No compilation config found in ${this.configContext.configPath}`);
133
- return;
134
- }
135
- const currentStateFilePath = resolveStateFilePath(this.settings, this.configContext);
136
- heading("Recompiling");
137
- const recompiler = new CompilationService({
138
- ...compilerOptions,
139
- namespaceResolver: namespaceResolver(),
140
- });
141
- await recompiler.compile(currentConfig, currentStateFilePath);
142
- footer();
143
- };
144
-
145
- startConfigReloadWatch({
146
- watchService,
147
- buildWatchConfig: () => buildReloadWatchConfig(this.settings, this.configContext),
148
- rebuild,
149
- reloadConfig: () => this.reloadDiscoveredConfig(),
150
- });
151
-
152
- await new Promise(() => {}); // keep process alive
153
- }
154
- }
155
- }
@@ -1,110 +0,0 @@
1
- import path from "node:path";
2
- import { Args, Flags } from "@oclif/core";
3
- import { ConfigCommand } from "../../config-command.js";
4
- import { ConfigError, loadSettingsWithLayers } from "../../lib/settings.js";
5
- import {
6
- isScalar,
7
- lookupPath,
8
- NOT_FOUND,
9
- parsePath,
10
- renderJson,
11
- truncateJson,
12
- } from "../../lib/config-inspect.js";
13
-
14
- export default class ConfigGet extends ConfigCommand {
15
- static description =
16
- "Print one value from the merged config by dot-path (e.g. compilation.targets[0].entryPoint)";
17
-
18
- /**
19
- * The other spelling of the topic. It lives under a hidden topic, so it is
20
- * typable everywhere without ever reaching the top-level listing.
21
- */
22
- static aliases = ["configs:get"];
23
-
24
- static examples = [
25
- "<%= config.bin %> config get name",
26
- "<%= config.bin %> config get compilation.targets[0].entryPoint",
27
- "<%= config.bin %> config get compilation --layers",
28
- ];
29
-
30
- static args = {
31
- path: Args.string({
32
- description: "Dot-path into the config, with [n] for array indices",
33
- required: true,
34
- }),
35
- };
36
-
37
- static flags = {
38
- ...ConfigCommand.baseFlags,
39
- layers: Flags.boolean({
40
- description: "Show which config layer set the value (per-layer provenance)",
41
- default: false,
42
- }),
43
- };
44
-
45
- async run(): Promise<void> {
46
- const { args, flags } = await this.parse(ConfigGet);
47
- const segments = parsePath(args.path);
48
-
49
- if (flags.layers) {
50
- await this.showLayers(args.path, segments);
51
- return;
52
- }
53
-
54
- const value = lookupPath(this.settings, segments);
55
- if (value === NOT_FOUND) {
56
- throw new ConfigError(
57
- `No value at config path '${args.path}'.\n` +
58
- ` It is not present in the merged config (${this.configContext.configPath}).\n` +
59
- ` Run 'sous config show' to see the whole config.`
60
- );
61
- }
62
-
63
- // Scalars print raw (no quotes) so the output is directly usable; objects and
64
- // arrays print as pretty JSON, colorized only for a TTY.
65
- if (isScalar(value)) {
66
- process.stdout.write(`${String(value)}\n`);
67
- } else {
68
- process.stdout.write(`${renderJson(value, Boolean(process.stdout.isTTY))}\n`);
69
- }
70
- }
71
-
72
- /**
73
- * Prints one line per config layer whose cumulative snapshot CHANGED the value
74
- * at `pathStr`, showing old -> new (JSON-encoded, truncated). The first layer
75
- * counts as a change from (unset).
76
- */
77
- private async showLayers(pathStr: string, segments: (string | number)[]): Promise<void> {
78
- const { layers } = await loadSettingsWithLayers(this.discovered, { trace: true });
79
- const sousDir = this.configContext.sousDir;
80
-
81
- let previous: unknown = NOT_FOUND;
82
- let printedAny = false;
83
-
84
- for (const layer of layers) {
85
- const current = lookupPath(layer.config, segments);
86
- // JSON round-trip so structurally-equal values compare equal.
87
- const unchanged =
88
- current !== NOT_FOUND
89
- ? previous !== NOT_FOUND && JSON.stringify(current) === JSON.stringify(previous)
90
- : previous === NOT_FOUND;
91
- if (unchanged) continue;
92
-
93
- const rel = path.relative(sousDir, layer.path);
94
- const label = rel && !rel.startsWith("..") ? rel : layer.path;
95
- const oldStr = previous === NOT_FOUND ? "(unset)" : truncateJson(previous);
96
- const newStr = current === NOT_FOUND ? "(unset)" : truncateJson(current);
97
- process.stdout.write(`${label}: ${oldStr} -> ${newStr}\n`);
98
-
99
- previous = current;
100
- printedAny = true;
101
- }
102
-
103
- if (!printedAny) {
104
- throw new ConfigError(
105
- `No value at config path '${pathStr}' in any config layer.\n` +
106
- ` Run 'sous config show' to see the whole merged config.`
107
- );
108
- }
109
- }
110
- }
@@ -1,32 +0,0 @@
1
- import { ConfigCommand } from "../../config-command.js";
2
- import { renderJson } from "../../lib/config-inspect.js";
3
-
4
- export default class ConfigShow extends ConfigCommand {
5
- static description =
6
- "Print the merged config (all conf.d layers merged, before variable resolution) as JSON";
7
-
8
- /**
9
- * The other spelling of the topic. It lives under a hidden topic, so it is
10
- * typable everywhere without ever reaching the top-level listing.
11
- */
12
- static aliases = ["configs:show"];
13
-
14
- static examples = [
15
- "<%= config.bin %> config show",
16
- "<%= config.bin %> config show | jq .compilation",
17
- ];
18
-
19
- static flags = {
20
- ...ConfigCommand.baseFlags,
21
- };
22
-
23
- async run(): Promise<void> {
24
- await this.parse(ConfigShow);
25
-
26
- // this.settings is the merged config as written: every conf.d layer has been
27
- // deep-merged and the whole thing schema-validated, but no ${var} has been
28
- // resolved yet. Colorize only for a TTY so piped output stays valid JSON.
29
- const useColor = Boolean(process.stdout.isTTY);
30
- process.stdout.write(`${renderJson(this.settings, useColor)}\n`);
31
- }
32
- }
@@ -1,53 +0,0 @@
1
- import { BaseCommand } from "../../base-command.js";
2
- import {
3
- resolveCompilation,
4
- resolveRootScope,
5
- resolveTools,
6
- resolveWatchConfig,
7
- } from "../../lib/settings.js";
8
- import { footer, heading, showVariables } from "../../utils/formatting.js";
9
-
10
- export default class ConfigValidate extends BaseCommand {
11
- static description =
12
- "Validate the merged config: schema, then full variable resolution (fixpoint + substitution)";
13
-
14
- /**
15
- * The other spelling of the topic. It lives under a hidden topic, so it is
16
- * typable everywhere without ever reaching the top-level listing.
17
- */
18
- static aliases = ["configs:validate"];
19
-
20
- static examples = ["<%= config.bin %> config validate"];
21
-
22
- static flags = {
23
- ...BaseCommand.baseFlags,
24
- };
25
-
26
- async run(): Promise<void> {
27
- await this.parse(ConfigValidate);
28
-
29
- // Discovery, the config kernel, assertFlatConfig and zod validation have all
30
- // already run in BaseCommand.init(); a failure there exits before we get here.
31
- // Running the resolvers now surfaces the errors validation alone cannot:
32
- // fixpoint cycles, undefined ${vars}, and unresolved substitutions. Any
33
- // ConfigError they throw is rendered by BaseCommand.catch (non-zero exit).
34
- const rootScope = resolveRootScope(this.settings, this.configContext);
35
- resolveCompilation(this.settings, rootScope);
36
- const tools = resolveTools(this.settings, rootScope);
37
- resolveWatchConfig(this.settings, rootScope);
38
-
39
- const layerCount = this.configContext.layerPaths?.length ?? 1;
40
- const targetCount = this.settings.compilation?.targets.length ?? 0;
41
- const toolNames = Object.keys(tools);
42
-
43
- heading("Config is valid");
44
- showVariables({
45
- "Config File": this.configContext.configPath,
46
- Layers: layerCount,
47
- Targets: targetCount,
48
- Tools: toolNames.length > 0 ? toolNames.join(", ") : "(none)",
49
- });
50
-
51
- footer();
52
- }
53
- }
@@ -1,46 +0,0 @@
1
- /**
2
- * `sous help`, `sous help <command>`, `sous help <topic>`, `sous help <topic> <command>`.
3
- *
4
- * The word form of `--help`, and deliberately the same screen: it hands the
5
- * arguments straight to the help class oclif itself uses for `--help`, so there
6
- * is exactly one help renderer and no second copy to fall out of date.
7
- *
8
- * This exists because `sous help build` is what people type, and without a
9
- * command by that name oclif answers "command help not found", which reads like
10
- * sous has no help at all. Adding it here rather than installing
11
- * `@oclif/plugin-help` keeps the dependency list as it is.
12
- *
13
- * It does not extend `BaseCommand`: reading the help must work from anywhere,
14
- * including a directory with no `.sous/` above it, and `BaseCommand` requires a
15
- * discoverable config.
16
- */
17
-
18
- import { Args, Command, loadHelpClass } from "@oclif/core";
19
-
20
- export default class Help extends Command {
21
- static description = "Print the help for sous, or for one command or topic";
22
-
23
- static examples = [
24
- "<%= config.bin %> help",
25
- "<%= config.bin %> help build",
26
- "<%= config.bin %> help repo",
27
- "<%= config.bin %> help repo add",
28
- ];
29
-
30
- /** A command id is one or more words, so the argument list is open-ended. */
31
- static strict = false;
32
-
33
- static args = {
34
- command: Args.string({
35
- description: "The command or topic to describe, such as 'build' or 'repo add'",
36
- required: false,
37
- }),
38
- };
39
-
40
- async run(): Promise<void> {
41
- const { argv } = await this.parse(Help);
42
- const HelpClass = await loadHelpClass(this.config);
43
- const help = new HelpClass(this.config, this.config.pjson.oclif.helpOptions);
44
- await help.showHelp(argv as string[]);
45
- }
46
- }