@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,315 +0,0 @@
1
- /**
2
- * The plan an update carries out: for each install, the version it moves to
3
- * and the exact command that moves it, plus a notice for every copy sous
4
- * found and cannot act on.
5
- *
6
- * Planning has no side effects. What `buildUpdatePlans` returns is exactly
7
- * what a dry run prints and what a real run executes, one confirmation per
8
- * plan (sous-io/sous#135).
9
- */
10
-
11
- import { PACKAGE_NAME } from "../project-install.mjs";
12
- import type { GlobalInstallInfo, InstallDiscovery, ProjectInstallInfo } from "./installs.js";
13
- import {
14
- globalInstall,
15
- manualProjectAdd,
16
- packageSpec,
17
- projectAdd,
18
- type DependencySection,
19
- } from "./managers.js";
20
- import semver from "semver";
21
- import {
22
- chooseVersion,
23
- type RegistryMetadata,
24
- type VersionDirection,
25
- type VersionRequest,
26
- } from "./versions.js";
27
-
28
- /** Which install a plan or a notice is about. */
29
- export type UpdateScope = "global" | "project";
30
-
31
- /** A command to run, where to run it, and nothing run yet. */
32
- export type PlannedCommand = {
33
- command: string;
34
- args: string[];
35
- /** The directory to run it in; undefined for a global install, which runs anywhere. */
36
- cwd?: string;
37
- };
38
-
39
- /** One install, and what an update does to it. */
40
- export type UpdatePlan = {
41
- scope: UpdateScope;
42
- /** The copy's path: the global package directory, or the project's `node_modules` copy. */
43
- location: string;
44
- /** The project root; set only for a project plan. */
45
- projectRoot?: string;
46
- /**
47
- * Set only for a project that uses Yarn Plug'n'Play: the directory holding
48
- * its `.pnp.cjs`. `location` is then that file, and the build runs through Yarn.
49
- */
50
- pnpRoot?: string;
51
- /** The package manager that runs `command` (`npm`, `pnpm`, `yarn`, `yarn@berry`). */
52
- manager: string;
53
- /**
54
- * True when the project's files named no manager and npm is assumed; the
55
- * plan should say so. Always false for a global plan.
56
- */
57
- managerAssumed: boolean;
58
- /** The version installed now. */
59
- installed: string;
60
- /** The version the update installs; equal to `installed` when `direction` is `current`. */
61
- target: string;
62
- /** `current` means there is nothing to do: report it and ask nothing. */
63
- direction: VersionDirection;
64
- /** How the project's package.json declares sous; set only for a project plan. */
65
- declaredIn?: { section: DependencySection; range: string };
66
- /** What installs `target`. Present for a `current` plan too, and not to be run then. */
67
- command: PlannedCommand;
68
- };
69
-
70
- /**
71
- * Why a copy was found and not planned.
72
- *
73
- * - `npx`: the running copy is in npx's cache, which no install updates.
74
- * - `volta`: the running copy is managed by Volta; `manualCommand` is Volta's.
75
- * - `unknown-location`: the running copy is none of the installs (a source checkout, say).
76
- * - `undeclared`: the project has the package in `node_modules` but its package.json does not name it.
77
- * - `unsupported-manager`: the project's manager is one sous does not drive;
78
- * `manualCommand` is that manager's own, when known.
79
- * - `unknown-version`: the copy's package.json names no version sous can compare.
80
- * - `not-found`: the run was narrowed to a scope that has no install.
81
- */
82
- export type UpdateNoticeKind =
83
- | "npx"
84
- | "volta"
85
- | "unknown-location"
86
- | "undeclared"
87
- | "unsupported-manager"
88
- | "unknown-version"
89
- | "not-found";
90
-
91
- /** A copy sous will not act on, with the facts and one plain sentence saying why. */
92
- export type UpdateNotice = {
93
- kind: UpdateNoticeKind;
94
- /** The install the notice is about; undefined for one about the running copy as a whole (npx). */
95
- scope?: UpdateScope;
96
- /** The copy's path, when the notice is about one copy. */
97
- location?: string;
98
- /** A complete sentence saying what was found and why nothing is done to it. */
99
- message: string;
100
- /** The command a person would run by hand, when there is one; run in `cwd` when set. */
101
- manualCommand?: PlannedCommand;
102
- };
103
-
104
- /** Every plan and every notice. */
105
- export type UpdatePlanSet = {
106
- /** Global plans first, then the project plan. */
107
- plans: UpdatePlan[];
108
- notices: UpdateNotice[];
109
- };
110
-
111
- /** Options for `buildUpdatePlans`. */
112
- export type BuildUpdatePlansOptions = {
113
- request: VersionRequest;
114
- /** Whether prereleases count; undefined means "on when the installed version is a prerelease", per install. */
115
- prerelease?: boolean;
116
- /** Plan only this scope (`--global` or `--project`); undefined plans both. */
117
- only?: UpdateScope;
118
- };
119
-
120
- /**
121
- * Works out every plan and every notice, one install at a time, each judged on
122
- * its own installed version.
123
- *
124
- * @throws ConfigError when a `spec` request matches nothing for an install
125
- * (from `chooseVersion`).
126
- */
127
- export function buildUpdatePlans(
128
- discovery: InstallDiscovery,
129
- metadata: RegistryMetadata,
130
- options: BuildUpdatePlansOptions
131
- ): UpdatePlanSet {
132
- const plans: UpdatePlan[] = [];
133
- const notices: UpdateNotice[] = [];
134
- const wants = (scope: UpdateScope): boolean => options.only === undefined || options.only === scope;
135
-
136
- if (wants("global")) {
137
- for (const install of discovery.globals) {
138
- const planned = planGlobal(install, metadata, options);
139
- if ("kind" in planned) notices.push(planned);
140
- else plans.push(planned);
141
- }
142
- }
143
- if (wants("project") && discovery.project !== undefined) {
144
- const planned = planProject(discovery.project, metadata, options);
145
- if ("kind" in planned) notices.push(planned);
146
- else plans.push(planned);
147
- }
148
-
149
- notices.push(...runningNotices(discovery, metadata, options));
150
-
151
- if (options.only === "global" && discovery.globals.length === 0) {
152
- notices.push({
153
- kind: "not-found",
154
- scope: "global",
155
- message: `No global install of ${PACKAGE_NAME} was found with npm, pnpm or Yarn.`,
156
- });
157
- }
158
- if (options.only === "project" && discovery.project === undefined) {
159
- notices.push({
160
- kind: "not-found",
161
- scope: "project",
162
- message: `No project install of ${PACKAGE_NAME} was found in this directory or above it.`,
163
- });
164
- }
165
- return { plans, notices };
166
- }
167
-
168
- /** The plan for one global install, or the notice saying why there is none. */
169
- function planGlobal(
170
- install: GlobalInstallInfo,
171
- metadata: RegistryMetadata,
172
- options: BuildUpdatePlansOptions
173
- ): UpdatePlan | UpdateNotice {
174
- if (semver.valid(install.installed) === null) {
175
- return unknownVersion("global", install.location, install.installed);
176
- }
177
- const choice = choose(install.installed, metadata, options);
178
- return {
179
- scope: "global",
180
- location: install.location,
181
- manager: install.manager,
182
- managerAssumed: false,
183
- installed: install.installed,
184
- target: choice.target,
185
- direction: choice.direction,
186
- command: globalInstall(install.manager, choice.target),
187
- };
188
- }
189
-
190
- /** The plan for the project install, or the notice saying why there is none. */
191
- function planProject(
192
- install: ProjectInstallInfo,
193
- metadata: RegistryMetadata,
194
- options: BuildUpdatePlansOptions
195
- ): UpdatePlan | UpdateNotice {
196
- if (install.declared === undefined) {
197
- return {
198
- kind: "undeclared",
199
- scope: "project",
200
- location: install.location,
201
- message:
202
- `The project at ${install.projectRoot} has ${PACKAGE_NAME} in node_modules, ` +
203
- "but its package.json does not declare it, so sous leaves it alone.",
204
- };
205
- }
206
- if (semver.valid(install.installed) === null) {
207
- return unknownVersion("project", install.location, install.installed);
208
- }
209
- const choice = choose(install.installed, metadata, options);
210
- if (!install.manager.supported) {
211
- const notice: UpdateNotice = {
212
- kind: "unsupported-manager",
213
- scope: "project",
214
- location: install.location,
215
- message:
216
- `The project at ${install.projectRoot} uses ${install.manager.agent}, ` +
217
- "which sous does not drive, so it has to be updated by hand.",
218
- };
219
- const manual = manualProjectAdd(install.manager.agent, choice.target, install.declared.section);
220
- if (manual !== undefined) notice.manualCommand = { ...manual, cwd: install.projectRoot };
221
- return notice;
222
- }
223
- const command = projectAdd(install.manager.agent, choice.target, {
224
- section: install.declared.section,
225
- workspaceRoot: install.workspaceRoot,
226
- });
227
- const plan: UpdatePlan = {
228
- scope: "project",
229
- location: install.location,
230
- projectRoot: install.projectRoot,
231
- manager: install.manager.agent,
232
- managerAssumed: !install.manager.detected,
233
- installed: install.installed,
234
- target: choice.target,
235
- direction: choice.direction,
236
- declaredIn: install.declared,
237
- command: { ...command, cwd: install.projectRoot },
238
- };
239
- if (install.pnpRoot !== undefined) plan.pnpRoot = install.pnpRoot;
240
- return plan;
241
- }
242
-
243
- /**
244
- * The notices about the running copy when it is none of the installs planned:
245
- * npx (always), and Volta or an unknown location (global scope). Volta's
246
- * command names the version the same request chooses for the running copy.
247
- */
248
- function runningNotices(
249
- discovery: InstallDiscovery,
250
- metadata: RegistryMetadata,
251
- options: BuildUpdatePlansOptions
252
- ): UpdateNotice[] {
253
- const { running } = discovery;
254
- if (running.kind === "npx") {
255
- return [
256
- {
257
- kind: "npx",
258
- location: running.realPath,
259
- message:
260
- "This sous is running through npx, which is not an install: " +
261
- "npx keeps its own cache, and no install sous updates changes it.",
262
- },
263
- ];
264
- }
265
- if (options.only === "project") return [];
266
- if (running.kind === "volta") {
267
- const notice: UpdateNotice = {
268
- kind: "volta",
269
- scope: "global",
270
- location: running.realPath,
271
- message: "This sous is managed by Volta, which sous does not drive, so Volta has to update it.",
272
- };
273
- if (semver.valid(running.installed) !== null) {
274
- const { target } = choose(running.installed, metadata, options);
275
- notice.manualCommand = { command: "volta", args: ["install", packageSpec(target)] };
276
- }
277
- return [notice];
278
- }
279
- if (running.kind === "unknown") {
280
- return [
281
- {
282
- kind: "unknown-location",
283
- scope: "global",
284
- location: running.realPath,
285
- message:
286
- "This sous is not the project install or a global install of npm, pnpm or Yarn " +
287
- "(it may be a source checkout), so sous does not update it.",
288
- },
289
- ];
290
- }
291
- return [];
292
- }
293
-
294
- /** Chooses a version for one install. */
295
- function choose(installed: string, metadata: RegistryMetadata, options: BuildUpdatePlansOptions) {
296
- return chooseVersion({
297
- current: installed,
298
- versions: metadata.versions,
299
- distTags: metadata.distTags,
300
- request: options.request,
301
- ...(options.prerelease === undefined ? {} : { prerelease: options.prerelease }),
302
- });
303
- }
304
-
305
- /** The notice for a copy whose version cannot be compared. */
306
- function unknownVersion(scope: UpdateScope, location: string, installed: string): UpdateNotice {
307
- return {
308
- kind: "unknown-version",
309
- scope,
310
- location,
311
- message:
312
- `The ${scope} install at ${location} names its version as "${installed}", ` +
313
- "which sous cannot compare with the published versions, so it has to be updated by hand.",
314
- };
315
- }
@@ -1,99 +0,0 @@
1
- /**
2
- * Asks the npm registry which versions of sous are published.
3
- *
4
- * One request: a GET of the package's abbreviated document, the same small
5
- * answer an install reads. Finding out what is published is the point of an
6
- * update, so a registry that cannot be reached is an error, never a warning.
7
- * The fetch is injectable, so no test reaches the network.
8
- */
9
-
10
- import { PACKAGE_NAME } from "../project-install.mjs";
11
- import { fetchText, type FetchLike } from "../repos/providers/http.js";
12
- import { parseRegistryMetadata, type RegistryMetadata } from "./versions.js";
13
-
14
- /** The registry sous asks when the environment names no other. */
15
- export const DEFAULT_REGISTRY = "https://registry.npmjs.org/";
16
-
17
- /** The media type of the abbreviated package document. */
18
- export const ABBREVIATED_METADATA_TYPE = "application/vnd.npm.install-v1+json";
19
-
20
- /** How long the registry has to answer before the request is abandoned. */
21
- export const REGISTRY_TIMEOUT_MS = 15_000;
22
-
23
- /** The environment variables that name another registry, in the order they are read. */
24
- export const REGISTRY_ENV_NAMES = ["npm_config_registry", "NPM_CONFIG_REGISTRY"] as const;
25
-
26
- /**
27
- * The registry base URL, always ending in `/`: the first non-blank value of
28
- * `REGISTRY_ENV_NAMES`, or `DEFAULT_REGISTRY`. npm sets `npm_config_registry`
29
- * for the scripts it runs, so a project's `.npmrc` registry reaches sous that
30
- * way too.
31
- *
32
- * registryBaseUrl({ npm_config_registry: "https://npm.example.com" })
33
- * // -> "https://npm.example.com/"
34
- */
35
- export function registryBaseUrl(env: Readonly<Record<string, string | undefined>>): string {
36
- for (const name of REGISTRY_ENV_NAMES) {
37
- const value = env[name]?.trim();
38
- if (value !== undefined && value.length > 0) {
39
- return value.endsWith("/") ? value : `${value}/`;
40
- }
41
- }
42
- return DEFAULT_REGISTRY;
43
- }
44
-
45
- /**
46
- * The URL of the package's document on a registry. The scope's slash is
47
- * encoded, which every registry accepts.
48
- *
49
- * packageMetadataUrl("https://registry.npmjs.org/")
50
- * // -> "https://registry.npmjs.org/@sous-io%2fsous"
51
- */
52
- export function packageMetadataUrl(base: string): string {
53
- return `${base}${PACKAGE_NAME.replace("/", "%2f")}`;
54
- }
55
-
56
- /** Options for `fetchPublishedVersions`. */
57
- export type FetchPublishedVersionsOptions = {
58
- /** Where the registry override is read from. Defaults to `process.env`. */
59
- env?: Readonly<Record<string, string | undefined>>;
60
- /** The fetch implementation. Defaults to the global `fetch`. */
61
- fetchImpl?: FetchLike;
62
- /** How long to wait for an answer. Defaults to `REGISTRY_TIMEOUT_MS`. */
63
- timeoutMs?: number;
64
- };
65
-
66
- /**
67
- * Fetches and reads what the registry publishes for `@sous-io/sous`.
68
- *
69
- * @throws ConfigError naming the URL and quoting the reason when the registry
70
- * cannot be reached, answers with an error status, runs past the timeout, or
71
- * sends something that is not a package document.
72
- */
73
- export async function fetchPublishedVersions(
74
- options: FetchPublishedVersionsOptions = {}
75
- ): Promise<RegistryMetadata> {
76
- const url = packageMetadataUrl(registryBaseUrl(options.env ?? process.env));
77
- const fetched = await fetchText(url, {
78
- label: `list of published ${PACKAGE_NAME} versions`,
79
- accept: ABBREVIATED_METADATA_TYPE,
80
- signal: AbortSignal.timeout(options.timeoutMs ?? REGISTRY_TIMEOUT_MS),
81
- statusHints: registryStatusHints,
82
- ...(options.fetchImpl === undefined ? {} : { fetchImpl: options.fetchImpl }),
83
- });
84
- return parseRegistryMetadata(fetched.text, url);
85
- }
86
-
87
- /** What a failed status usually means when the URL is the package's document. */
88
- function registryStatusHints(status: number): string[] {
89
- if (status === 404) {
90
- return [
91
- ` The registry has no package named ${PACKAGE_NAME}. When npm_config_registry ` +
92
- "names a mirror, the mirror may not carry it.",
93
- ];
94
- }
95
- if (status === 401 || status === 403) {
96
- return [" The registry refused the request without credentials, and sous sends none."];
97
- }
98
- return [];
99
- }