@git.zone/cli 6.17.2 → 7.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.
@@ -18,6 +18,7 @@ import {
18
18
  assertNpmPackageName,
19
19
  hashReleaseDestination,
20
20
  } from "./helpers.npmartifact.js";
21
+ import { getReleaseNpmPublicationOrder } from "./helpers.npmpackages.js";
21
22
  import {
22
23
  canonicalReleaseJson,
23
24
  type IReleaseQualificationRequest,
@@ -71,8 +72,6 @@ export const assertPackageReleaseRecovery = async (
71
72
  (target) => !["git", "npm", "docker"].includes(target),
72
73
  ) ||
73
74
  !workflow.targets.includes("git") ||
74
- (workflow.targets.includes("npm") &&
75
- workflow.npmPackageSource !== "root") ||
76
75
  !workflow.pushBranch ||
77
76
  !workflow.pushTags ||
78
77
  branch.sourceBranch !== "main" ||
@@ -80,7 +79,7 @@ export const assertPackageReleaseRecovery = async (
80
79
  !branch.remoteMainOid
81
80
  ) {
82
81
  throw new Error(
83
- "Release recover requires configured Git with root npm and/or Docker targets from clean main.",
82
+ "Release recover requires configured Git with npm and/or Docker targets from clean main.",
84
83
  );
85
84
  }
86
85
  const manifest = JSON.parse(
@@ -154,9 +153,9 @@ export const assertPackageReleaseRecovery = async (
154
153
  return manifest.name;
155
154
  };
156
155
 
156
+ /** Every package the recovered release publishes must be absent from every registry. */
157
157
  export const assertRecoveryUnpublished = async (
158
158
  options: IReleasePreparationRecovery,
159
- packageName: string,
160
159
  ): Promise<void> => {
161
160
  const output = await git(options, [
162
161
  "ls-remote",
@@ -168,7 +167,15 @@ export const assertRecoveryUnpublished = async (
168
167
  throw new Error(
169
168
  "Recovery cannot adopt an existing remote release tag. Use its original journal.",
170
169
  );
171
- if (options.workflow.targets.includes("npm")) {
170
+ if (!options.workflow.targets.includes("npm")) return;
171
+ if (!options.workflow.npmPackages) {
172
+ throw new Error(
173
+ "Release recovery cannot prove an unresolved npm package set unpublished.",
174
+ );
175
+ }
176
+ for (const packageName of getReleaseNpmPublicationOrder(
177
+ options.workflow.npmPackages,
178
+ )) {
172
179
  for (const registry of options.workflow.npmRegistries)
173
180
  await assertNpmVersionAbsent(registry, packageName, options.version);
174
181
  }
@@ -329,6 +336,11 @@ export const assertReleaseCheckoutInstallable = async (
329
336
  export interface IIsolatedReleaseCheckout {
330
337
  /** Disposable detached worktree that holds exactly the release commit. */
331
338
  path: string;
339
+ /**
340
+ * Absent canonical path beside the checkout, outside every repository, for
341
+ * packages derived from it; removed together with the checkout.
342
+ */
343
+ preparationPath: string;
332
344
  /** Re-assert that the checkout still is that exact commit, unmodified. */
333
345
  assertExact: () => Promise<void>;
334
346
  }
@@ -412,7 +424,12 @@ export const withIsolatedReleaseCheckout = async <T>(
412
424
  if (options.buildCommand)
413
425
  await run(options.smartshell, checkout, options.buildCommand, "build");
414
426
  await assertExact();
415
- const result = await use({ path: checkout, assertExact });
427
+ // tspublish only prepares into an output whose parent path is canonical.
428
+ const preparationPath = plugins.path.join(
429
+ await plugins.fs.realpath(root),
430
+ "prepared",
431
+ );
432
+ const result = await use({ path: checkout, preparationPath, assertExact });
416
433
  await assertExact();
417
434
  return result;
418
435
  } finally {
@@ -432,10 +449,7 @@ export const withIsolatedReleaseCheckout = async <T>(
432
449
  export const withReleasePreparationRecovery = async <T>(
433
450
  options: IReleasePreparationRecovery,
434
451
  ensureState: () => Promise<void>,
435
- prepare: (
436
- checkout: string,
437
- ensureCheckout: () => Promise<void>,
438
- ) => Promise<T>,
452
+ prepare: (checkout: IIsolatedReleaseCheckout) => Promise<T>,
439
453
  ): Promise<T> => {
440
454
  if (!options.branch.planAncestryVerified) {
441
455
  throw new Error(
@@ -476,7 +490,7 @@ export const withReleasePreparationRecovery = async <T>(
476
490
  },
477
491
  async (checkout) => {
478
492
  await ensureState();
479
- return prepare(checkout.path, checkout.assertExact);
493
+ return prepare(checkout);
480
494
  },
481
495
  );
482
496
  });
@@ -52,6 +52,7 @@ import {
52
52
  } from "./helpers.giteaassets.js";
53
53
  import {
54
54
  assertNoLegacyNpmPublisher,
55
+ assertNoStandaloneTspublishPublisher,
55
56
  assertPnpmReleaseCapability,
56
57
  hashReleaseDestination,
57
58
  normalizeNpmRegistryUrl,
@@ -59,6 +60,10 @@ import {
59
60
  verifyStoredNpmArtifact,
60
61
  type IPnpmReleaseCapability,
61
62
  } from "./helpers.npmartifact.js";
63
+ import {
64
+ describeReleaseNpmPackages,
65
+ planReleaseNpmPackages,
66
+ } from "./helpers.npmpackages.js";
62
67
  import { executeReleasePublication } from "./helpers.releasepublication.js";
63
68
  import { runTstestCleanup } from "../helpers.tstest.js";
64
69
  import {
@@ -166,15 +171,6 @@ const runInternal = async (argvArg: any): Promise<void> => {
166
171
  versionFloor: workflow.versionFloor,
167
172
  });
168
173
  printReleasePlan(workflow, branchContext, versionResolution);
169
- if (
170
- workflow.targets.includes("npm") &&
171
- workflow.npmPackageSource === "tspublish"
172
- ) {
173
- const packagePlan = await planReleasePackages(branchContext.sourceCwd);
174
- console.log("npm packages (dependency order):");
175
- for (const module of packagePlan.modules)
176
- console.log(` ${module.name} (${module.folder})`);
177
- }
178
174
  if (workflow.confirmation === "plan") {
179
175
  return;
180
176
  }
@@ -370,6 +366,7 @@ const runInternal = async (argvArg: any): Promise<void> => {
370
366
  createReleaseJournal({
371
367
  ...journalOptions,
372
368
  npmSourceCwd: checkout.path,
369
+ npmPreparationDirectory: checkout.preparationPath,
373
370
  ensurePublicationState: async () => {
374
371
  await checkout.assertExact();
375
372
  await ensurePublicationState();
@@ -438,6 +435,7 @@ const assertFreshReleaseCapabilities = async (
438
435
  await assertNoLegacyNpmPublisher(cwdArg);
439
436
  }
440
437
  if (workflowArg.targets.includes("npm")) {
438
+ await assertNoStandaloneTspublishPublisher(cwdArg);
441
439
  return assertPnpmReleaseCapability(smartshellArg, cwdArg);
442
440
  }
443
441
  };
@@ -476,14 +474,6 @@ const assertReleaseConfiguration = (
476
474
  if (!workflowArg.targets.includes("npm")) {
477
475
  return;
478
476
  }
479
- if (
480
- workflowArg.npmPackageSource === "tspublish" &&
481
- workflowArg.targets.includes("docker")
482
- ) {
483
- throw new Error(
484
- "tspublish package releases support Git and npm targets; use a separate Docker release repository.",
485
- );
486
- }
487
477
  if (workflowArg.npmRegistries.length === 0) {
488
478
  throw new Error("The npm release target requires at least one registry.");
489
479
  }
@@ -526,6 +516,11 @@ interface ICreateReleaseJournalOptions {
526
516
  * npm tarball, and frozen Gitea asset is taken from.
527
517
  */
528
518
  npmSourceCwd?: string;
519
+ /**
520
+ * Absent path outside every repository, where tspublish materializes the
521
+ * module packages before they are packed.
522
+ */
523
+ npmPreparationDirectory?: string;
529
524
  releasePushUrl?: string;
530
525
  expectedRemoteMainOid?: string;
531
526
  version: string;
@@ -555,18 +550,64 @@ const createDockerQualificationRequest = (
555
550
  version: versionArg,
556
551
  });
557
552
 
558
- export const planReleasePackages = async (
559
- cwdArg: string,
560
- ): Promise<plugins.tspublish.ITsPublishPlan> => {
561
- const plan = await new plugins.tspublish.TsPublish().plan(cwdArg);
562
- for (const module of plan.modules) {
563
- if (module.registries.length !== 1 || module.registries[0] !== "useBase") {
564
- throw new Error(
565
- `${module.name}: GitZone-managed packages must declare registries: ["useBase"]. Configure destinations in release.targets.npm.`,
553
+ /**
554
+ * tspublish materializes the already built modules outside every repository,
555
+ * so each package is packed from its own generated manifest and nothing else.
556
+ */
557
+ const packReleaseModules = async (
558
+ optionsArg: ICreateReleaseJournalOptions,
559
+ sourceCwdArg: string,
560
+ planArg: plugins.tspublish.ITsPublishPlan,
561
+ artifactDirectoryArg: string,
562
+ ): Promise<IReleasePackage[]> => {
563
+ const preparationDirectory = optionsArg.npmPreparationDirectory;
564
+ if (!preparationDirectory) {
565
+ throw new Error(
566
+ "createReleaseJournal requires npmPreparationDirectory when tspublish modules are present.",
567
+ );
568
+ }
569
+ // The directory is removed afterwards, so it must be one this call creates.
570
+ const preparationDirectoryExists = await plugins.fs
571
+ .lstat(preparationDirectory)
572
+ .then(() => true)
573
+ .catch((error: NodeJS.ErrnoException) => {
574
+ if (error.code === "ENOENT") return false;
575
+ throw error;
576
+ });
577
+ if (preparationDirectoryExists) {
578
+ throw new Error(
579
+ "createReleaseJournal requires an absent npmPreparationDirectory, because it removes that directory after packing.",
580
+ );
581
+ }
582
+ try {
583
+ const prepared = await new plugins.tspublish.TsPublish().prepare(
584
+ sourceCwdArg,
585
+ preparationDirectory,
586
+ );
587
+ if (
588
+ JSON.stringify(prepared.map(({ directory, ...module }) => module)) !==
589
+ JSON.stringify(planArg.modules)
590
+ ) {
591
+ throw new Error("tspublish package plan changed during preparation.");
592
+ }
593
+ const packages: IReleasePackage[] = [];
594
+ for (const module of prepared) {
595
+ const packed = await packNpmArtifact(
596
+ optionsArg.smartshell,
597
+ module.directory,
598
+ artifactDirectoryArg,
599
+ optionsArg.version,
600
+ optionsArg.pnpmCapability,
601
+ releasePackageArtifactFile(module.name),
566
602
  );
603
+ if (packed.packageName !== module.name)
604
+ throw new Error("Prepared package identity changed during packing.");
605
+ packages.push({ folder: module.folder, artifact: packed });
567
606
  }
607
+ return packages;
608
+ } finally {
609
+ await plugins.fs.rm(preparationDirectory, { recursive: true, force: true });
568
610
  }
569
- return plan;
570
611
  };
571
612
 
572
613
  export const createReleaseJournal = async (
@@ -599,41 +640,28 @@ export const createReleaseJournal = async (
599
640
  let artifact: IReleaseArtifact | null = null;
600
641
  const packages: IReleasePackage[] = [];
601
642
  if (optionsArg.workflow.targets.includes("npm")) {
602
- if (optionsArg.workflow.npmPackageSource === "tspublish") {
603
- const plan = await planReleasePackages(npmSourceCwd);
604
- if (plan.version !== optionsArg.version)
605
- throw new Error("tspublish plan version differs from the release.");
606
- const outputDirectory = plugins.path.join(
607
- temporaryDirectory,
608
- "prepared",
609
- );
610
- const prepared = await new plugins.tspublish.TsPublish().prepare(
611
- npmSourceCwd,
612
- outputDirectory,
643
+ const { packageSet, plan } = await planReleaseNpmPackages(npmSourceCwd);
644
+ if (
645
+ JSON.stringify(packageSet) !==
646
+ JSON.stringify(optionsArg.workflow.npmPackages)
647
+ ) {
648
+ throw new Error(
649
+ "The release commit carries a different npm package set than the release plan showed, usually because a tspublish.json is ignored or uncommitted. Rerun `gitzone release --plan` against the committed tree.",
613
650
  );
614
- if (
615
- JSON.stringify(prepared.map(({ directory, ...module }) => module)) !==
616
- JSON.stringify(plan.modules)
617
- ) {
618
- throw new Error("tspublish package plan changed during preparation.");
619
- }
620
- for (const module of prepared) {
621
- const packed = await packNpmArtifact(
622
- optionsArg.smartshell,
623
- module.directory,
651
+ }
652
+ if (plan.version !== optionsArg.version)
653
+ throw new Error("tspublish plan version differs from the release.");
654
+ if (plan.modules.length > 0) {
655
+ packages.push(
656
+ ...(await packReleaseModules(
657
+ optionsArg,
658
+ npmSourceCwd,
659
+ plan,
624
660
  temporaryDirectory,
625
- optionsArg.version,
626
- optionsArg.pnpmCapability,
627
- releasePackageArtifactFile(module.name),
628
- );
629
- if (packed.packageName !== module.name)
630
- throw new Error(
631
- "Prepared package identity changed during packing.",
632
- );
633
- packages.push({ folder: module.folder, artifact: packed });
634
- }
635
- await plugins.fs.rm(outputDirectory, { recursive: true, force: true });
636
- } else {
661
+ )),
662
+ );
663
+ }
664
+ if (!packageSet.root.private) {
637
665
  artifact = await packNpmArtifact(
638
666
  optionsArg.smartshell,
639
667
  npmSourceCwd,
@@ -695,10 +723,10 @@ export const createReleaseJournal = async (
695
723
  kind: "gitzone-release-journal",
696
724
  schemaVersion: giteaAssets
697
725
  ? 4
698
- : packages.length
699
- ? 3
700
- : optionsArg.dockerRequest
701
- ? 2
726
+ : optionsArg.dockerRequest
727
+ ? 2
728
+ : packages.length
729
+ ? 3
702
730
  : 1,
703
731
  revision: 1,
704
732
  release: {
@@ -732,14 +760,17 @@ export const createReleaseJournal = async (
732
760
  ? optionsArg.workflow.npmAlreadyPublished
733
761
  : "success",
734
762
  registries: packages.length
735
- ? packages.flatMap((entry) =>
763
+ ? [
764
+ ...packages.map((entry) => entry.artifact),
765
+ ...(artifact ? [artifact] : []),
766
+ ].flatMap((npmArtifact) =>
736
767
  optionsArg.workflow.npmRegistries.map((registry) => ({
737
768
  ...createInitialTargetStatus(true),
738
769
  registry,
739
- packageName: entry.artifact.packageName,
770
+ packageName: npmArtifact.packageName,
740
771
  })),
741
772
  )
742
- : optionsArg.workflow.targets.includes("npm")
773
+ : artifact
743
774
  ? optionsArg.workflow.npmRegistries.map((registryArg) => {
744
775
  const status = createInitialTargetStatus(true);
745
776
  return {
@@ -920,6 +951,10 @@ const runReleaseRecover = async (
920
951
  console.log(
921
952
  `Recover existing ${packageName}@${version}\ncommit: ${refs.mainOid}\ntag object: ${refs.tagOid}\nGit destination: ${branch.gitRemote}\nTargets: ${workflow.targets.join(", ")}\n${workflow.targets.includes("npm") ? `npm registries: ${workflow.npmRegistries.join(", ")}\n` : ""}Run configured checks in an isolated checkout, install its journal, then ${tsdocker ? "qualify Docker before publishing configured targets" : "publish configured targets"}.`,
922
953
  );
954
+ if (workflow.npmPackages) {
955
+ for (const line of describeReleaseNpmPackages(workflow.npmPackages))
956
+ console.log(line);
957
+ }
923
958
  if (argvArg.plan) return;
924
959
  const pnpmCapability = await assertFreshReleaseCapabilities(
925
960
  shell,
@@ -955,7 +990,7 @@ const runReleaseRecover = async (
955
990
  };
956
991
  const ensureUnpublished = async () => {
957
992
  await ensureState();
958
- await assertRecoveryUnpublished(options, packageName);
993
+ await assertRecoveryUnpublished(options);
959
994
  };
960
995
  const context = await withReleasePreparationRecovery(
961
996
  options,
@@ -963,13 +998,14 @@ const runReleaseRecover = async (
963
998
  // The existing tag is authoritative: recovery never re-derives its version,
964
999
  // and the failed run's level override that fed any floor decision is not
965
1000
  // recorded, so a recovered journal carries no version floor record.
966
- async (checkout, ensureCheckout) =>
1001
+ async (checkout) =>
967
1002
  createReleaseJournal({
968
1003
  pnpmCapability,
969
1004
  smartshell: shell,
970
1005
  workflow,
971
1006
  releaseCwd: paths.cwd,
972
- npmSourceCwd: checkout,
1007
+ npmSourceCwd: checkout.path,
1008
+ npmPreparationDirectory: checkout.preparationPath,
973
1009
  releasePushUrl: branch.pushUrl,
974
1010
  expectedRemoteMainOid: branch.remoteMainOid,
975
1011
  version,
@@ -977,7 +1013,7 @@ const runReleaseRecover = async (
977
1013
  dockerRequest,
978
1014
  tsdocker,
979
1015
  ensurePublicationState: async () => {
980
- await ensureCheckout();
1016
+ await checkout.assertExact();
981
1017
  await ensureUnpublished();
982
1018
  },
983
1019
  }),
@@ -1108,6 +1144,7 @@ const runReleaseResume = async (
1108
1144
  paths.cwd,
1109
1145
  );
1110
1146
  await assertNoLegacyNpmPublisher(paths.cwd);
1147
+ await assertNoStandaloneTspublishPublisher(paths.cwd);
1111
1148
  for (const artifact of getReleaseArtifacts(journal)) {
1112
1149
  await verifyStoredNpmArtifact(
1113
1150
  store.getArtifactPath(version, artifact.file),
@@ -1227,8 +1264,6 @@ const assertResumeConfiguration = async (
1227
1264
  ),
1228
1265
  ]) ||
1229
1266
  workflowArg.npmAccessLevel !== journalArg.npm.access ||
1230
- workflowArg.npmPackageSource !==
1231
- (hasReleasePackages(journalArg) ? "tspublish" : "root") ||
1232
1267
  workflowArg.npmAlreadyPublished !== journalArg.npm.alreadyPublished)
1233
1268
  ) {
1234
1269
  throw new Error(
@@ -1680,11 +1715,14 @@ function printReleasePlan(
1680
1715
  console.log(line);
1681
1716
  }
1682
1717
  if (workflow.targets.includes("npm")) {
1683
- console.log(`npm package source: ${workflow.npmPackageSource}`);
1684
1718
  console.log(
1685
1719
  `npm registries: ${workflow.npmRegistries.length > 0 ? workflow.npmRegistries.join(", ") : "none"}`,
1686
1720
  );
1687
1721
  }
1722
+ if (workflow.npmPackages) {
1723
+ for (const line of describeReleaseNpmPackages(workflow.npmPackages))
1724
+ console.log(line);
1725
+ }
1688
1726
  if (workflow.giteaAssets) {
1689
1727
  const assets = workflow.giteaAssets;
1690
1728
  console.log(
@@ -1792,7 +1830,7 @@ export function showHelp(mode?: ICliMode): void {
1792
1830
  {
1793
1831
  flag: "recover <version>",
1794
1832
  description:
1795
- "Recover a local root npm release tag after build or pack failure before journal creation",
1833
+ "Recover a local npm and/or Docker release tag after build or pack failure before journal creation",
1796
1834
  },
1797
1835
  {
1798
1836
  flag: "--recover-attempt <id>",
@@ -1845,7 +1883,7 @@ export function showHelp(mode?: ICliMode): void {
1845
1883
  " resume <version> Resume exact journaled publication without rebuilding or repacking npm artifacts",
1846
1884
  );
1847
1885
  console.log(
1848
- " recover <version> Recover an unpublished root npm release from its existing local tag",
1886
+ " recover <version> Recover an unpublished npm and/or Docker release from its existing local tag",
1849
1887
  );
1850
1888
  console.log(
1851
1889
  " --recover-attempt Recover one exact 32-character hexadecimal attempt ID after proving its publisher stopped",