@git.zone/cli 9.2.1 → 10.0.0

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 (96) hide show
  1. package/assets/templates/asset_binary_installer/install.sh +109 -34
  2. package/assets/templates/asset_binary_release_gitea/.gitea/workflows/release.yml +20 -6
  3. package/assets/templates/ci_rust/.gitea/workflows/rust_nottags.yaml +29 -0
  4. package/assets/templates/ci_rust/.gitea/workflows/rust_tags.yaml +32 -0
  5. package/assets/templates/gitignore/_gitignore +1 -1
  6. package/assets/templates/gitignore_rust/_gitignore +31 -0
  7. package/assets/templates/license_mit/license +4 -1
  8. package/assets/templates/rust/.smartscaf.yml +16 -0
  9. package/assets/templates/rust/_Cargo.toml +12 -0
  10. package/assets/templates/rust/_crate_Cargo.toml +10 -0
  11. package/assets/templates/rust/_crate_lib.rs +19 -0
  12. package/assets/templates/rust/_smartconfig.json +27 -0
  13. package/assets/templates/rust/readme.md +23 -0
  14. package/dist_ts/00_commitinfo_data.js +2 -2
  15. package/dist_ts/classes.gitzoneconfig.d.ts +3 -1
  16. package/dist_ts/classes.gitzoneconfig.js +9 -1
  17. package/dist_ts/helpers.managedassets.d.ts +1 -1
  18. package/dist_ts/helpers.managedassets.js +58 -14
  19. package/dist_ts/helpers.releasetargets.d.ts +6 -0
  20. package/dist_ts/helpers.releasetargets.js +13 -0
  21. package/dist_ts/helpers.smartconfigmigrations.js +42 -1
  22. package/dist_ts/helpers.toolconfig.d.ts +50 -0
  23. package/dist_ts/helpers.toolconfig.js +212 -0
  24. package/dist_ts/helpers.tssea.d.ts +9 -2
  25. package/dist_ts/helpers.tssea.js +47 -17
  26. package/dist_ts/helpers.tstest.d.ts +27 -8
  27. package/dist_ts/helpers.tstest.js +64 -26
  28. package/dist_ts/helpers.versionsource.d.ts +37 -0
  29. package/dist_ts/helpers.versionsource.js +112 -0
  30. package/dist_ts/helpers.workflow.d.ts +45 -1
  31. package/dist_ts/helpers.workflow.js +120 -5
  32. package/dist_ts/mod_commit/mod.helpers.d.ts +0 -24
  33. package/dist_ts/mod_commit/mod.helpers.js +1 -94
  34. package/dist_ts/mod_config/index.js +131 -18
  35. package/dist_ts/mod_format/formatters/assets.formatter.js +29 -27
  36. package/dist_ts/mod_format/formatters/gitignore.formatter.d.ts +4 -2
  37. package/dist_ts/mod_format/formatters/gitignore.formatter.js +10 -7
  38. package/dist_ts/mod_format/formatters/license.formatter.d.ts +8 -0
  39. package/dist_ts/mod_format/formatters/license.formatter.js +25 -2
  40. package/dist_ts/mod_format/formatters/packagejson.formatter.js +14 -3
  41. package/dist_ts/mod_format/formatters/rustfmt.formatter.d.ts +19 -0
  42. package/dist_ts/mod_format/formatters/rustfmt.formatter.js +97 -0
  43. package/dist_ts/mod_format/formatters/smartconfig.formatter.js +5 -2
  44. package/dist_ts/mod_format/index.js +3 -1
  45. package/dist_ts/mod_format/interfaces.format.js +2 -1
  46. package/dist_ts/mod_release/classes.releasejournal.d.ts +38 -2
  47. package/dist_ts/mod_release/classes.releasejournal.js +238 -66
  48. package/dist_ts/mod_release/helpers.cargorelease.d.ts +52 -0
  49. package/dist_ts/mod_release/helpers.cargorelease.js +195 -0
  50. package/dist_ts/mod_release/helpers.npmpackages.d.ts +18 -0
  51. package/dist_ts/mod_release/helpers.npmpackages.js +40 -2
  52. package/dist_ts/mod_release/helpers.releasecheck.d.ts +73 -0
  53. package/dist_ts/mod_release/helpers.releasecheck.js +269 -0
  54. package/dist_ts/mod_release/helpers.releasepreparation.d.ts +22 -8
  55. package/dist_ts/mod_release/helpers.releasepreparation.js +74 -26
  56. package/dist_ts/mod_release/helpers.releasepublication.d.ts +21 -1
  57. package/dist_ts/mod_release/helpers.releasepublication.js +249 -4
  58. package/dist_ts/mod_release/helpers.releaseversionsource.d.ts +10 -0
  59. package/dist_ts/mod_release/helpers.releaseversionsource.js +18 -0
  60. package/dist_ts/mod_release/helpers.rsrepoengine.d.ts +192 -0
  61. package/dist_ts/mod_release/helpers.rsrepoengine.js +457 -0
  62. package/dist_ts/mod_release/index.d.ts +3 -0
  63. package/dist_ts/mod_release/index.js +177 -65
  64. package/dist_ts/mod_template/index.js +6 -2
  65. package/package.json +1 -1
  66. package/readme.md +237 -21
  67. package/ts/00_commitinfo_data.ts +1 -1
  68. package/ts/classes.gitzoneconfig.ts +10 -1
  69. package/ts/helpers.managedassets.ts +64 -14
  70. package/ts/helpers.releasetargets.ts +13 -0
  71. package/ts/helpers.smartconfigmigrations.ts +48 -0
  72. package/ts/helpers.toolconfig.ts +280 -0
  73. package/ts/helpers.tssea.ts +59 -16
  74. package/ts/helpers.tstest.ts +105 -35
  75. package/ts/helpers.versionsource.ts +169 -0
  76. package/ts/helpers.workflow.ts +197 -5
  77. package/ts/mod_commit/mod.helpers.ts +0 -119
  78. package/ts/mod_config/index.ts +169 -19
  79. package/ts/mod_format/formatters/assets.formatter.ts +28 -27
  80. package/ts/mod_format/formatters/gitignore.formatter.ts +10 -6
  81. package/ts/mod_format/formatters/license.formatter.ts +26 -1
  82. package/ts/mod_format/formatters/packagejson.formatter.ts +14 -2
  83. package/ts/mod_format/formatters/rustfmt.formatter.ts +107 -0
  84. package/ts/mod_format/formatters/smartconfig.formatter.ts +8 -1
  85. package/ts/mod_format/index.ts +2 -0
  86. package/ts/mod_format/interfaces.format.ts +1 -0
  87. package/ts/mod_release/classes.releasejournal.ts +312 -39
  88. package/ts/mod_release/helpers.cargorelease.ts +289 -0
  89. package/ts/mod_release/helpers.npmpackages.ts +76 -1
  90. package/ts/mod_release/helpers.releasecheck.ts +409 -0
  91. package/ts/mod_release/helpers.releasepreparation.ts +116 -36
  92. package/ts/mod_release/helpers.releasepublication.ts +462 -1
  93. package/ts/mod_release/helpers.releaseversionsource.ts +29 -0
  94. package/ts/mod_release/helpers.rsrepoengine.ts +790 -0
  95. package/ts/mod_release/index.ts +277 -84
  96. package/ts/mod_template/index.ts +5 -1
@@ -202,7 +202,10 @@ export const readBinaryExtras = async (assetsArg: Record<string, unknown>, conte
202
202
 
203
203
  const outDir = contextArg.binaryBuild.outDir;
204
204
  const reserved = new Map<string, string>([['SHA256SUMS.txt', 'the release checksums']]);
205
- reserved.set(contextArg.installerAssetName, 'the installer');
205
+ // The release publishes the installer exactly when it is enabled; a disabled installer leaves its name free.
206
+ if (installer.enabled !== false) {
207
+ reserved.set(contextArg.installerAssetName, 'the installer');
208
+ }
206
209
  for (const target of contextArg.binaryBuild.targets) {
207
210
  reserved.set(target.name, `the ${target.target} executable`);
208
211
  for (const noticeFile of target.noticeFiles) {
@@ -256,7 +259,8 @@ export const readBinaryExtras = async (assetsArg: Record<string, unknown>, conte
256
259
  return { assets, installed };
257
260
  };
258
261
 
259
- const removedIn = 'was removed in @git.zone/cli 9';
262
+ /** The phrase of a removed key's migration error: the @git.zone/cli major that removed it. */
263
+ const removedIn = (majorArg: number): string => `was removed in @git.zone/cli ${majorArg}`;
260
264
 
261
265
  /** The value at a key path inside `@git.zone/cli.assets`; undefined when any segment is missing. */
262
266
  const valueAt = (rootArg: Record<string, unknown>, pathArg: string[]): unknown => {
@@ -270,36 +274,42 @@ const valueAt = (rootArg: Record<string, unknown>, pathArg: string[]): unknown =
270
274
  return value;
271
275
  };
272
276
 
273
- /** Keys of the binary asset model that @git.zone/cli 9 removed, with the key that replaces each. */
274
- const removedBinaryCliKeys: ReadonlyArray<{ path: string[]; replacement: string }> = [
277
+ /** Keys of the binary asset model that a @git.zone/cli major removed, with the major and what replaces each. */
278
+ const removedBinaryCliKeys: ReadonlyArray<{ path: string[]; removedIn: number; replacement: string }> = [
275
279
  {
276
280
  path: ['binary', 'targets'],
281
+ removedIn: 9,
277
282
  replacement: 'binaryCli builds the targets of @git.zone/tssea.targets',
278
283
  },
279
284
  {
280
285
  path: ['binary', 'outDir'],
286
+ removedIn: 9,
281
287
  replacement: 'binaryCli reads the output directory from @git.zone/tssea.outDir',
282
288
  },
283
- { path: ['releaseAssets'], replacement: 'use @git.zone/cli.assets.releaseWorkflow' },
284
- { path: ['rawBranch'], replacement: 'use @git.zone/cli.assets.repository.branch' },
285
- { path: ['repository', 'rawBranch'], replacement: 'use @git.zone/cli.assets.repository.branch' },
286
- { path: ['installer', 'delivery'], replacement: 'use @git.zone/cli.assets.installer.distribution' },
287
- { path: ['installer', 'defaultMode'], replacement: 'use @git.zone/cli.assets.installer.modes.default' },
288
- { path: ['installer', 'source'], replacement: 'use @git.zone/cli.assets.installer.modes.source' },
289
+ { path: ['releaseAssets'], removedIn: 9, replacement: 'use @git.zone/cli.assets.releaseWorkflow' },
290
+ { path: ['rawBranch'], removedIn: 9, replacement: 'the installer is published as a release asset only; remove the key' },
291
+ { path: ['repository', 'rawBranch'], removedIn: 9, replacement: 'the installer is published as a release asset only; remove the key' },
292
+ { path: ['installer', 'delivery'], removedIn: 9, replacement: 'the installer is published as a release asset only; remove the key' },
293
+ { path: ['installer', 'defaultMode'], removedIn: 9, replacement: 'use @git.zone/cli.assets.installer.modes.default' },
294
+ { path: ['installer', 'source'], removedIn: 9, replacement: 'use @git.zone/cli.assets.installer.modes.source' },
289
295
  {
290
296
  path: ['installer', 'modes', 'source', 'validateCommand'],
297
+ removedIn: 9,
291
298
  replacement: 'use @git.zone/cli.assets.installer.modes.source.validate',
292
299
  },
293
300
  {
294
301
  path: ['installer', 'service', 'legacyUnitNames'],
302
+ removedIn: 9,
295
303
  replacement: 'use @git.zone/cli.assets.installer.service.removeLegacyUnits',
296
304
  },
297
305
  {
298
306
  path: ['releaseWorkflow', 'assetGlobs'],
307
+ removedIn: 9,
299
308
  replacement: 'list further release files in @git.zone/cli.assets.releaseWorkflow.extraAssets (exact repository files, no globs)',
300
309
  },
301
310
  {
302
311
  path: ['releaseWorkflow', 'include'],
312
+ removedIn: 9,
303
313
  replacement: 'list further release files in @git.zone/cli.assets.releaseWorkflow.extraAssets (exact repository files, no globs)',
304
314
  },
305
315
  ];
@@ -311,27 +321,67 @@ const renamedTemplates: Readonly<Record<string, string>> = {
311
321
  asset_deno_binary_release_gitea: 'asset_binary_release_gitea',
312
322
  };
313
323
 
324
+ /**
325
+ * The errors of the installer keys @git.zone/cli 10 removed, for the values `gitzone format` cannot remove on
326
+ * its own because removing them would change what the release publishes. `migrateSmartconfigData` removes the
327
+ * others: `installer.distribution: "releaseAsset"` and an `includeInstallerAsset` equal to whether the
328
+ * installer is enabled. The two must stay in step.
329
+ */
330
+ const getRetiredInstallerKeyErrors = (assetsArg: Record<string, unknown>): string[] => {
331
+ const errors: string[] = [];
332
+ const installer = isPlainObject(assetsArg.installer) ? assetsArg.installer : {};
333
+ const distribution = installer.distribution;
334
+ if (distribution === 'rawBranch') {
335
+ errors.push(
336
+ `@git.zone/cli.assets.installer.distribution ${removedIn(10)}: "rawBranch" pointed the installer's usage text and the release notes at raw/branch/<branch>/<file>, which code.foss.global serves to signed-in users only. The installer is published as a release asset only; remove the key.`,
337
+ );
338
+ } else if (distribution !== undefined && distribution !== 'releaseAsset') {
339
+ errors.push(
340
+ `@git.zone/cli.assets.installer.distribution ${removedIn(10)}: the installer is published as a release asset only, so ${JSON.stringify(distribution)} is no distribution; remove the key.`,
341
+ );
342
+ }
343
+ const releaseWorkflow = isPlainObject(assetsArg.releaseWorkflow) ? assetsArg.releaseWorkflow : {};
344
+ const includeInstallerAsset = releaseWorkflow.includeInstallerAsset;
345
+ const installerEnabled = installer.enabled !== false;
346
+ if (includeInstallerAsset !== undefined && includeInstallerAsset !== installerEnabled) {
347
+ const key = `@git.zone/cli.assets.releaseWorkflow.includeInstallerAsset ${removedIn(10)}: the release uploads the installer exactly when the installer is enabled`;
348
+ if (includeInstallerAsset === false) {
349
+ errors.push(
350
+ `${key}, and false would leave out the release asset its usage text and the release notes name (releases/download/<tag>/<installer>). Remove the key, or disable the installer with installer.enabled: false.`,
351
+ );
352
+ } else if (includeInstallerAsset === true) {
353
+ errors.push(
354
+ `${key}, and the installer is disabled. Remove the key; to publish an installer that is not managed, list it in releaseWorkflow.extraAssets.`,
355
+ );
356
+ } else {
357
+ errors.push(`${key}; remove the key (found ${JSON.stringify(includeInstallerAsset)}).`);
358
+ }
359
+ }
360
+ return errors;
361
+ };
362
+
314
363
  /**
315
364
  * The configuration errors of an enabled `@git.zone/cli.assets` object that come from
316
- * keys @git.zone/cli 9 removed or renamed. Each message names the migration.
365
+ * keys @git.zone/cli 9 or 10 removed or renamed. Each message names the migration.
317
366
  */
318
367
  export const getManagedAssetsMigrationErrors = (assetsArg: Record<string, unknown>): string[] => {
319
368
  const errors: string[] = [];
320
369
  if (assetsArg.kind === 'denoBinaryCli') {
321
370
  errors.push(
322
- `Managed asset kind "denoBinaryCli" ${removedIn}: set @git.zone/cli.assets.kind to "binaryCli" and move @git.zone/tsdeno.compileTargets to @git.zone/tssea.targets (see "Migrating from tsdeno" in the @git.zone/tssea readme).`,
371
+ `Managed asset kind "denoBinaryCli" ${removedIn(9)}: set @git.zone/cli.assets.kind to "binaryCli" and move @git.zone/tsdeno.compileTargets to @git.zone/tssea.targets (see "Migrating from tsdeno" in the @git.zone/tssea readme).`,
323
372
  );
324
373
  }
325
374
  if (assetsArg.kind === 'binaryCli' || assetsArg.kind === 'denoBinaryCli') {
326
375
  for (const removed of removedBinaryCliKeys) {
327
376
  if (valueAt(assetsArg, removed.path) !== undefined) {
328
- errors.push(`@git.zone/cli.assets.${removed.path.join('.')} ${removedIn}: ${removed.replacement}.`);
377
+ errors.push(`@git.zone/cli.assets.${removed.path.join('.')} ${removedIn(removed.removedIn)}: ${removed.replacement}.`);
329
378
  }
330
379
  }
331
380
  }
381
+ errors.push(...getRetiredInstallerKeyErrors(assetsArg));
332
382
  if (isPlainObject(assetsArg.sealedRelease) && assetsArg.sealedRelease.denoVersion !== undefined) {
333
383
  errors.push(
334
- `@git.zone/cli.assets.sealedRelease.denoVersion ${removedIn}: set sealedRelease.nodeVersion to the exact Node.js release (x.y.z) that runs the prepare and verify commands.`,
384
+ `@git.zone/cli.assets.sealedRelease.denoVersion ${removedIn(9)}: set sealedRelease.nodeVersion to the exact Node.js release (x.y.z) that runs the prepare and verify commands.`,
335
385
  );
336
386
  }
337
387
  if (Array.isArray(assetsArg.managed)) {
@@ -0,0 +1,13 @@
1
+ import { isPlainObject } from './helpers.objects.js';
2
+
3
+ /**
4
+ * Whether `@git.zone/cli.release.targets.npm` makes npm a release target: its `enabled` when set,
5
+ * otherwise whether it configures registries (a non-empty array, or any other value, which the release
6
+ * then refuses). `resolveReleaseWorkflow` decides `npmEnabled` by the same rule, as a truthy value.
7
+ */
8
+ export const isNpmReleaseTargetEnabled = (npmTargetConfigArg: unknown): boolean => {
9
+ const npmTargetConfig = isPlainObject(npmTargetConfigArg) ? npmTargetConfigArg : {};
10
+ const registries = npmTargetConfig.registries;
11
+ const registriesConfigured = Array.isArray(registries) ? registries.length > 0 : registries !== undefined;
12
+ return Boolean(npmTargetConfig.enabled ?? registriesConfigured);
13
+ };
@@ -152,6 +152,53 @@ const migrateShipzoneNamespace = (smartconfigJson: Record<string, any>): boolean
152
152
  return migrated;
153
153
  };
154
154
 
155
+ /**
156
+ * Removes the managed asset keys @git.zone/cli 10 retired where removing them
157
+ * changes nothing: `repository.branch`, which nothing reads,
158
+ * `installer.distribution: "releaseAsset"`, the only distribution left, and
159
+ * `releaseWorkflow.includeInstallerAsset` when it equals whether the installer
160
+ * is enabled, since the release uploads the installer exactly then. Any other
161
+ * value of the last two stays for `getManagedAssetsMigrationErrors` to name,
162
+ * because removing it would change what the release publishes. A parent this
163
+ * step empties is removed with it. Like `migrateShipzoneNamespace` the step is
164
+ * not tied to a schema version; a second run changes nothing.
165
+ */
166
+ const migrateRetiredAssetKeys = (smartconfigJson: Record<string, any>): boolean => {
167
+ const cliConfig = smartconfigJson[CLI_NAMESPACE];
168
+ const assets = isPlainObject(cliConfig) ? cliConfig.assets : undefined;
169
+ if (!isPlainObject(assets)) {
170
+ return false;
171
+ }
172
+ let migrated = false;
173
+ const removeKey = (parentKeyArg: string, keyArg: string): void => {
174
+ const parent = assets[parentKeyArg];
175
+ delete parent[keyArg];
176
+ if (Object.keys(parent).length === 0) {
177
+ delete assets[parentKeyArg];
178
+ }
179
+ migrated = true;
180
+ };
181
+
182
+ if (isPlainObject(assets.repository) && "branch" in assets.repository) {
183
+ removeKey("repository", "branch");
184
+ }
185
+
186
+ const installer = assets.installer;
187
+ if (isPlainObject(installer) && installer.distribution === "releaseAsset") {
188
+ removeKey("installer", "distribution");
189
+ }
190
+
191
+ const installerEnabled = isPlainObject(installer) ? installer.enabled !== false : true;
192
+ if (
193
+ isPlainObject(assets.releaseWorkflow) &&
194
+ assets.releaseWorkflow.includeInstallerAsset === installerEnabled
195
+ ) {
196
+ removeKey("releaseWorkflow", "includeInstallerAsset");
197
+ }
198
+
199
+ return migrated;
200
+ };
201
+
155
202
  const migrateToV2 = (smartconfigJson: Record<string, any>): boolean => {
156
203
  const cliConfig = ensureObject(smartconfigJson, CLI_NAMESPACE);
157
204
  let migrated = migrateLegacyReleaseArray(smartconfigJson);
@@ -301,6 +348,7 @@ export const migrateSmartconfigData = (
301
348
  // configuration carries takes precedence over the copy of szci's.
302
349
  if (targetVersion >= 2) {
303
350
  migrated = migrateShipzoneNamespace(smartconfigJson) || migrated;
351
+ migrated = migrateRetiredAssetKeys(smartconfigJson) || migrated;
304
352
  }
305
353
 
306
354
  if (targetVersion === CURRENT_GITZONE_CLI_SCHEMA_VERSION && cliConfig.schemaVersion !== targetVersion) {
@@ -0,0 +1,280 @@
1
+ /**
2
+ * The `.smartconfig.json` sections of the consolidated build tools.
3
+ *
4
+ * `@git.zone/tsrepo` carries one subsection per tool, each with exactly the
5
+ * shape of that tool's legacy section; `@git.zone/rsrepo` carries the tsrust
6
+ * fields plus the generic Cargo flows. Both tools read a new subsection first,
7
+ * fall back to the legacy section, and refuse a project that carries both,
8
+ * because the two are never merged silently.
9
+ */
10
+
11
+ export const tsrepoNamespace = "@git.zone/tsrepo";
12
+ export const rsrepoNamespace = "@git.zone/rsrepo";
13
+ export const tsrustNamespace = "@git.zone/tsrust";
14
+
15
+ export type TTsrepoSubsection =
16
+ | "build"
17
+ | "test"
18
+ | "bundle"
19
+ | "docs"
20
+ | "watch"
21
+ | "sea";
22
+
23
+ /** Each tsrepo subsection and the legacy section it replaces; build has none. */
24
+ export const tsrepoLegacySections: Readonly<
25
+ Record<TTsrepoSubsection, string | null>
26
+ > = {
27
+ build: null,
28
+ test: "@git.zone/tstest",
29
+ bundle: "@git.zone/tsbundle",
30
+ docs: "@git.zone/tsdoc",
31
+ watch: "@git.zone/tswatch",
32
+ sea: "@git.zone/tssea",
33
+ };
34
+
35
+ const tsrepoSubsections = Object.keys(
36
+ tsrepoLegacySections,
37
+ ) as TTsrepoSubsection[];
38
+
39
+ /** The tsrust fields, then the generic Cargo flow settings. */
40
+ export const rsrepoConfigKeys = [
41
+ "targets",
42
+ "targetsByHost",
43
+ "locked",
44
+ "static",
45
+ "rustflags",
46
+ "targetDir",
47
+ "pruneAfterBuild",
48
+ "matrix",
49
+ "notices",
50
+ "features",
51
+ "toolchains",
52
+ "members",
53
+ ] as const;
54
+
55
+ export type TToolConfigFindingLevel = "ok" | "warn" | "error";
56
+
57
+ export interface IToolConfigFinding {
58
+ level: TToolConfigFindingLevel;
59
+ message: string;
60
+ fix?: string;
61
+ }
62
+
63
+ const isPlainObject = (
64
+ valueArg: unknown,
65
+ ): valueArg is Record<string, unknown> =>
66
+ typeof valueArg === "object" && valueArg !== null && !Array.isArray(valueArg);
67
+
68
+ const isStringArray = (valueArg: unknown): valueArg is string[] =>
69
+ Array.isArray(valueArg) && valueArg.every((entry) => typeof entry === "string");
70
+
71
+ /** True when package.json names the package as a dependency or devDependency. */
72
+ export const declaresPackage = (
73
+ packageJsonArg: unknown,
74
+ packageNameArg: string,
75
+ ): boolean =>
76
+ isPlainObject(packageJsonArg) &&
77
+ (["dependencies", "devDependencies"] as const).some((fieldArg) => {
78
+ const dependencies = packageJsonArg[fieldArg];
79
+ return (
80
+ isPlainObject(dependencies) && Object.hasOwn(dependencies, packageNameArg)
81
+ );
82
+ });
83
+
84
+ /**
85
+ * One tsrepo tool section by tsrepo's own rule: the subsection when it
86
+ * exists, otherwise the legacy section; both present is an error.
87
+ */
88
+ export const readTsrepoToolSection = (
89
+ smartconfigDataArg: Record<string, unknown>,
90
+ subsectionArg: TTsrepoSubsection,
91
+ ): Record<string, unknown> | undefined => {
92
+ const tsrepoSection = smartconfigDataArg[tsrepoNamespace];
93
+ const subsection = isPlainObject(tsrepoSection)
94
+ ? tsrepoSection[subsectionArg]
95
+ : undefined;
96
+ const legacyKey = tsrepoLegacySections[subsectionArg];
97
+ const legacy = legacyKey ? smartconfigDataArg[legacyKey] : undefined;
98
+ if (subsection !== undefined && legacy !== undefined) {
99
+ throw new Error(
100
+ `.smartconfig.json carries both ${tsrepoNamespace}.${subsectionArg} and ${legacyKey}; tsrepo never merges them. Keep one of them.`,
101
+ );
102
+ }
103
+ const section = subsection ?? legacy;
104
+ return isPlainObject(section) ? section : undefined;
105
+ };
106
+
107
+ const collectTsrepoFindings = (
108
+ smartconfigDataArg: Record<string, unknown>,
109
+ declaresTsrepoArg: boolean,
110
+ ): IToolConfigFinding[] => {
111
+ const findings: IToolConfigFinding[] = [];
112
+ const section = smartconfigDataArg[tsrepoNamespace];
113
+ if (section !== undefined) {
114
+ if (!isPlainObject(section)) {
115
+ return [
116
+ {
117
+ level: "error",
118
+ message: `${tsrepoNamespace} must be an object`,
119
+ fix: `Give it the subsections ${tsrepoSubsections.join(", ")}.`,
120
+ },
121
+ ];
122
+ }
123
+ const unknownKeys = Object.keys(section).filter(
124
+ (keyArg) => !tsrepoSubsections.includes(keyArg as TTsrepoSubsection),
125
+ );
126
+ if (unknownKeys.length > 0) {
127
+ findings.push({
128
+ level: "error",
129
+ message: `${tsrepoNamespace} has unknown subsections: ${unknownKeys.join(", ")}`,
130
+ fix: `Use only ${tsrepoSubsections.join(", ")}.`,
131
+ });
132
+ }
133
+ for (const subsection of tsrepoSubsections) {
134
+ if (section[subsection] !== undefined && !isPlainObject(section[subsection]))
135
+ findings.push({
136
+ level: "error",
137
+ message: `${tsrepoNamespace}.${subsection} must be an object`,
138
+ });
139
+ }
140
+ if (!declaresTsrepoArg) {
141
+ findings.push({
142
+ level: "warn",
143
+ message: `${tsrepoNamespace} is configured, but package.json does not declare @git.zone/tsrepo; the single tools do not read it`,
144
+ fix: "Install @git.zone/tsrepo, or keep the settings in the single tools' sections.",
145
+ });
146
+ }
147
+ }
148
+ for (const subsection of tsrepoSubsections) {
149
+ const legacyKey = tsrepoLegacySections[subsection];
150
+ if (!legacyKey || smartconfigDataArg[legacyKey] === undefined) continue;
151
+ if (isPlainObject(section) && section[subsection] !== undefined) {
152
+ findings.push({
153
+ level: "error",
154
+ message: `Both ${tsrepoNamespace}.${subsection} and ${legacyKey} are present; tsrepo refuses to merge them`,
155
+ fix: `Keep ${tsrepoNamespace}.${subsection} and remove ${legacyKey}.`,
156
+ });
157
+ } else if (declaresTsrepoArg) {
158
+ findings.push({
159
+ level: "warn",
160
+ message: `${legacyKey} belongs in ${tsrepoNamespace}.${subsection} now that package.json declares @git.zone/tsrepo`,
161
+ fix: "Run `gitzone config fix` to move it.",
162
+ });
163
+ }
164
+ }
165
+ if (findings.length === 0 && section !== undefined) {
166
+ findings.push({ level: "ok", message: `${tsrepoNamespace} is valid` });
167
+ }
168
+ return findings;
169
+ };
170
+
171
+ const collectRsrepoFindings = (
172
+ smartconfigDataArg: Record<string, unknown>,
173
+ ): IToolConfigFinding[] => {
174
+ const section = smartconfigDataArg[rsrepoNamespace];
175
+ if (section === undefined) return [];
176
+ if (!isPlainObject(section)) {
177
+ return [{ level: "error", message: `${rsrepoNamespace} must be an object` }];
178
+ }
179
+ const findings: IToolConfigFinding[] = [];
180
+ if (smartconfigDataArg[tsrustNamespace] !== undefined) {
181
+ findings.push({
182
+ level: "error",
183
+ message: `Both ${rsrepoNamespace} and ${tsrustNamespace} are present; rsrepo refuses to merge them`,
184
+ fix: `Keep ${rsrepoNamespace} and remove ${tsrustNamespace}.`,
185
+ });
186
+ }
187
+ const unknownKeys = Object.keys(section).filter(
188
+ (keyArg) =>
189
+ !(rsrepoConfigKeys as readonly string[]).includes(keyArg),
190
+ );
191
+ if (unknownKeys.length > 0) {
192
+ findings.push({
193
+ level: "error",
194
+ message: `${rsrepoNamespace} has unknown keys: ${unknownKeys.join(", ")}`,
195
+ fix: `Use only ${rsrepoConfigKeys.join(", ")}.`,
196
+ });
197
+ }
198
+ const typeChecks: Array<[string, (valueArg: unknown) => boolean, string]> = [
199
+ ["targets", isStringArray, "a list of target names"],
200
+ [
201
+ "targetsByHost",
202
+ (valueArg) =>
203
+ isPlainObject(valueArg) && Object.values(valueArg).every(isStringArray),
204
+ "an object of target name lists",
205
+ ],
206
+ ["locked", (valueArg) => typeof valueArg === "boolean", "true or false"],
207
+ ["static", (valueArg) => typeof valueArg === "boolean", "true or false"],
208
+ ["rustflags", isStringArray, "a list of strings"],
209
+ ["targetDir", (valueArg) => typeof valueArg === "string" && valueArg !== "", "a non-empty path"],
210
+ ["pruneAfterBuild", (valueArg) => typeof valueArg === "boolean", "true or false"],
211
+ ["matrix", isPlainObject, "an object"],
212
+ ["notices", isPlainObject, "an object"],
213
+ ["features", Array.isArray, "a list of feature sets"],
214
+ ["toolchains", isStringArray, "a list of toolchain names"],
215
+ ["members", isStringArray, "a list of crate names"],
216
+ ];
217
+ for (const [key, check, expected] of typeChecks) {
218
+ if (section[key] !== undefined && !check(section[key])) {
219
+ findings.push({
220
+ level: "error",
221
+ message: `${rsrepoNamespace}.${key} must be ${expected}`,
222
+ });
223
+ }
224
+ }
225
+ if (findings.length === 0) {
226
+ findings.push({ level: "ok", message: `${rsrepoNamespace} is valid` });
227
+ }
228
+ return findings;
229
+ };
230
+
231
+ /** Doctor findings for the tsrepo and rsrepo sections. */
232
+ export const collectToolConfigFindings = (
233
+ smartconfigDataArg: Record<string, unknown>,
234
+ packageJsonArg: unknown,
235
+ ): IToolConfigFinding[] => [
236
+ ...collectTsrepoFindings(
237
+ smartconfigDataArg,
238
+ declaresPackage(packageJsonArg, "@git.zone/tsrepo"),
239
+ ),
240
+ ...collectRsrepoFindings(smartconfigDataArg),
241
+ ];
242
+
243
+ /** What `moveLegacyToolSectionsIntoTsrepo` moved, and what it left for a person to merge. */
244
+ export interface ILegacyToolSectionMove {
245
+ /** Legacy keys now in their `@git.zone/tsrepo` subsection. */
246
+ moved: string[];
247
+ /** Legacy keys left in place, because their subsection already exists. */
248
+ conflicts: Array<{ legacyKey: string; subsection: TTsrepoSubsection }>;
249
+ }
250
+
251
+ /**
252
+ * Moves every legacy tool section into its `@git.zone/tsrepo` subsection.
253
+ * Only a project that declares `@git.zone/tsrepo` may run this, because the
254
+ * single tools do not read the new key. A subsection that already exists
255
+ * beside its legacy section is never merged: both stay as they are and the
256
+ * conflict is returned for the caller to report.
257
+ */
258
+ export const moveLegacyToolSectionsIntoTsrepo = (
259
+ smartconfigDataArg: Record<string, unknown>,
260
+ ): ILegacyToolSectionMove => {
261
+ const existing = smartconfigDataArg[tsrepoNamespace];
262
+ if (existing !== undefined && !isPlainObject(existing)) {
263
+ throw new Error(`${tsrepoNamespace} must be an object.`);
264
+ }
265
+ const result: ILegacyToolSectionMove = { moved: [], conflicts: [] };
266
+ const section: Record<string, unknown> = { ...(existing ?? {}) };
267
+ for (const subsection of tsrepoSubsections) {
268
+ const legacyKey = tsrepoLegacySections[subsection];
269
+ if (!legacyKey || smartconfigDataArg[legacyKey] === undefined) continue;
270
+ if (section[subsection] !== undefined) {
271
+ result.conflicts.push({ legacyKey, subsection });
272
+ continue;
273
+ }
274
+ section[subsection] = smartconfigDataArg[legacyKey];
275
+ delete smartconfigDataArg[legacyKey];
276
+ result.moved.push(legacyKey);
277
+ }
278
+ if (result.moved.length > 0) smartconfigDataArg[tsrepoNamespace] = section;
279
+ return result;
280
+ };
@@ -1,6 +1,7 @@
1
1
  import type { ITsseaOutputs, resolveOutputs } from '@git.zone/tssea/config';
2
2
  import * as plugins from './plugins.js';
3
3
  import { isPlainObject } from './helpers.objects.js';
4
+ import { readTsrepoToolSection, tsrepoNamespace } from './helpers.toolconfig.js';
4
5
 
5
6
  export type { ITsseaOutput, ITsseaOutputs } from '@git.zone/tssea/config';
6
7
 
@@ -10,25 +11,58 @@ export const tsseaPackageName = '@git.zone/tssea';
10
11
  /** The `@git.zone/tssea` versions whose `./config` export this CLI reads: `^1.1.0`. */
11
12
  export const supportedTsseaRange = '^1.1.0';
12
13
 
14
+ /**
15
+ * `@git.zone/tsrepo` carries tssea as its `sea` module; its `./sea/config` export is
16
+ * tssea's `./config` contract. This CLI reads it from tsrepo `^1.0.0`.
17
+ */
18
+ export const supportedTsrepoRange = '^1.0.0';
19
+
13
20
  /** The `./config` module of the project's tssea; loaded at run time from the project, typed from the CLI's devDependency. */
14
21
  interface ITsseaConfigModule {
15
22
  resolveOutputs: typeof resolveOutputs;
16
23
  }
17
24
 
25
+ /** Where a project's executables are resolved: the package, its config export and the supported versions. */
26
+ interface ISeaConfigProvider {
27
+ packageName: string;
28
+ configExport: string;
29
+ range: string;
30
+ isSupportedVersion: (versionArg: string) => boolean;
31
+ /** The project's raw sea configuration, by the provider's own rule. */
32
+ readConfig: (smartconfigDataArg: Record<string, unknown>) => unknown;
33
+ }
34
+
18
35
  /** A tssea failure, recognized by shape: `instanceof` fails across package copies. */
19
36
  const isTsseaError = (errorArg: unknown): errorArg is Error & { code: string } =>
20
37
  errorArg instanceof Error &&
21
38
  errorArg.name === 'TsseaError' &&
22
39
  typeof (errorArg as Error & { code?: unknown }).code === 'string';
23
40
 
24
- /** Whether an exact `x.y.z` version satisfies `^1.1.0`; prereleases do not. */
25
- const isSupportedTsseaVersion = (versionArg: string): boolean => {
41
+ /** Whether an exact `x.y.z` version has the given major and at least the given minor; prereleases do not. */
42
+ const isStableVersionInMajor = (versionArg: string, majorArg: number, minimumMinorArg: number): boolean => {
26
43
  const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(versionArg);
27
44
  if (!match) {
28
45
  return false;
29
46
  }
30
47
  const [major, minor] = [Number(match[1]), Number(match[2])];
31
- return major === 1 && minor >= 1;
48
+ return major === majorArg && minor >= minimumMinorArg;
49
+ };
50
+
51
+ const tsseaProvider: ISeaConfigProvider = {
52
+ packageName: tsseaPackageName,
53
+ configExport: `${tsseaPackageName}/config`,
54
+ range: supportedTsseaRange,
55
+ isSupportedVersion: (versionArg) => isStableVersionInMajor(versionArg, 1, 1),
56
+ readConfig: (smartconfigDataArg) => smartconfigDataArg[tsseaPackageName],
57
+ };
58
+
59
+ const tsrepoProvider: ISeaConfigProvider = {
60
+ packageName: tsrepoNamespace,
61
+ configExport: `${tsrepoNamespace}/sea/config`,
62
+ range: supportedTsrepoRange,
63
+ isSupportedVersion: (versionArg) => isStableVersionInMajor(versionArg, 1, 0),
64
+ // tsrepo reads `@git.zone/tsrepo.sea`, falls back to `@git.zone/tssea` and refuses both.
65
+ readConfig: (smartconfigDataArg) => readTsrepoToolSection(smartconfigDataArg, 'sea'),
32
66
  };
33
67
 
34
68
  const readProjectManifest = async (projectDirArg: string): Promise<Record<string, unknown>> => {
@@ -55,47 +89,56 @@ const declaresDependency = (manifestArg: Record<string, unknown>, nameArg: strin
55
89
  });
56
90
 
57
91
  /**
58
- * Resolves the executables of the project's `@git.zone/tssea` configuration with the tssea
59
- * the project itself installs, so the project's tssea version interprets its own config.
92
+ * Resolves the executables of the project's sea configuration with the package the project
93
+ * itself installs, so the project's version interprets its own config: `@git.zone/tsrepo`
94
+ * (`./sea/config`, config `@git.zone/tsrepo.sea` or the legacy `@git.zone/tssea`) when the
95
+ * project declares it, otherwise `@git.zone/tssea` (`./config`, config `@git.zone/tssea`).
60
96
  */
61
97
  export const resolveProjectTsseaOutputs = async (
62
98
  projectDirArg: string,
63
99
  smartconfigDataArg: Record<string, unknown>,
64
100
  ): Promise<ITsseaOutputs> => {
65
101
  const manifest = await readProjectManifest(projectDirArg);
66
- if (!declaresDependency(manifest, tsseaPackageName)) {
102
+ const provider = declaresDependency(manifest, tsrepoProvider.packageName)
103
+ ? tsrepoProvider
104
+ : declaresDependency(manifest, tsseaProvider.packageName)
105
+ ? tsseaProvider
106
+ : undefined;
107
+ if (!provider) {
67
108
  throw new Error(
68
- `binaryCli builds with ${tsseaPackageName}; \`pnpm install --save-dev ${tsseaPackageName}\`, then rerun.`,
109
+ `binaryCli builds with ${tsseaPackageName} or ${tsrepoNamespace}; \`pnpm install --save-dev ${tsseaPackageName}\`, then rerun.`,
69
110
  );
70
111
  }
112
+ const { packageName, range } = provider;
71
113
  // The project's own direct link, never one an ancestor folder would resolve.
72
- const installPath = plugins.path.join(projectDirArg, 'node_modules', ...tsseaPackageName.split('/'));
114
+ const installPath = plugins.path.join(projectDirArg, 'node_modules', ...packageName.split('/'));
73
115
  try {
74
116
  await plugins.fs.lstat(installPath);
75
117
  } catch {
76
- throw new Error(`${tsseaPackageName} is declared but not installed in ${projectDirArg}: run \`pnpm install\`, then rerun.`);
118
+ throw new Error(`${packageName} is declared but not installed in ${projectDirArg}: run \`pnpm install\`, then rerun.`);
77
119
  }
78
120
  const projectRequire = plugins.nodeModule.createRequire(plugins.path.join(projectDirArg, 'package.json'));
79
- const installedManifest: unknown = projectRequire(`${tsseaPackageName}/package.json`);
121
+ const installedManifest: unknown = projectRequire(`${packageName}/package.json`);
80
122
  const installedVersion =
81
123
  isPlainObject(installedManifest) && typeof installedManifest.version === 'string'
82
124
  ? installedManifest.version
83
125
  : 'unknown';
84
- if (!isSupportedTsseaVersion(installedVersion)) {
126
+ if (!provider.isSupportedVersion(installedVersion)) {
85
127
  const newerMajor = /^(\d+)\./.exec(installedVersion);
86
128
  throw new Error(
87
129
  newerMajor && Number(newerMajor[1]) > 1
88
- ? `The project installs ${tsseaPackageName} ${installedVersion}, but this @git.zone/cli supports ${supportedTsseaRange}: update @git.zone/cli.`
89
- : `The project installs ${tsseaPackageName} ${installedVersion}, but this @git.zone/cli supports ${supportedTsseaRange}: upgrade ${tsseaPackageName} in the project.`,
130
+ ? `The project installs ${packageName} ${installedVersion}, but this @git.zone/cli supports ${range}: update @git.zone/cli.`
131
+ : `The project installs ${packageName} ${installedVersion}, but this @git.zone/cli supports ${range}: upgrade ${packageName} in the project.`,
90
132
  );
91
133
  }
92
- const configModuleUrl = plugins.nodeUrl.pathToFileURL(projectRequire.resolve(`${tsseaPackageName}/config`)).href;
134
+ const rawConfig = provider.readConfig(smartconfigDataArg);
135
+ const configModuleUrl = plugins.nodeUrl.pathToFileURL(projectRequire.resolve(provider.configExport)).href;
93
136
  const configModule = (await import(configModuleUrl)) as ITsseaConfigModule;
94
137
  try {
95
- return configModule.resolveOutputs(smartconfigDataArg[tsseaPackageName], projectDirArg);
138
+ return configModule.resolveOutputs(rawConfig, projectDirArg);
96
139
  } catch (error) {
97
140
  if (isTsseaError(error)) {
98
- throw new Error(`${tsseaPackageName}: ${error.message} [${error.code}]`, { cause: error });
141
+ throw new Error(`${packageName}: ${error.message} [${error.code}]`, { cause: error });
99
142
  }
100
143
  throw error;
101
144
  }