shiplane 0.3.0 → 0.4.1

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.
@@ -1,9 +1,9 @@
1
1
  import { a as releaseFlow, i as backendService, n as publishedPackage, r as mobileApp, t as webApp } from "./web-app.module-6KrXIU7j.js";
2
- import { A as expandPatterns, C as cameWithRelease, D as releaseTags, O as tagFormatNamed, S as TAG_FORMATS, T as firstRelease, a as CommandFailed, c as onlyVersionFiles, d as appBumps, f as changesetApps, g as unreleasedChangesets, h as unreleasedApps, i as minutesBudget, j as workspacePatterns, k as tagName, l as shipsFrom, m as splitChangesets, o as deployRunTitle, p as packageBumps, r as deployEstimate, u as webShip, w as changelogSection, x as DEFAULT_TAG_FORMAT, y as releaseSource } from "./budget-CTjB1v-Z.js";
2
+ import { A as workspacePatterns, C as changelogSection, D as tagFormatNamed, E as releaseTags, O as tagName, S as cameWithRelease, _ as nextVersion, a as CommandFailed, b as DEFAULT_TAG_FORMAT, c as onlyVersionFiles, d as appBumps, f as changesetApps, i as minutesBudget, k as expandPatterns, l as shipsFrom, m as splitChangesets, o as deployRunTitle, p as packageBumps, r as deployEstimate, u as webShip, v as releaseSource, w as firstRelease, x as TAG_FORMATS } from "./budget-BTnKtGF6.js";
3
3
  import { z } from "zod";
4
- import { styleText } from "node:util";
5
4
  import fs from "node:fs";
6
5
  import path from "node:path";
6
+ import { styleText } from "node:util";
7
7
  import { Document, LineCounter, isMap, isScalar, isSeq, parseDocument } from "yaml";
8
8
  import { fileURLToPath } from "node:url";
9
9
  import { createJiti } from "jiti";
@@ -419,18 +419,27 @@ const afterShipContext = (context) => ({
419
419
  return commits.filter(({ files }) => filter(files).length > 0).map(({ subject }) => subject);
420
420
  }
421
421
  });
422
+ /** A package registry has no staging and nothing deploys a release-only unit: no environment. */
423
+ const hasNoEnvironment = ({ kind, releaseOnly }) => kind === "published-package" || releaseOnly === true;
422
424
  /**
423
- * What the person reads for an environment: a package registry has no staging, so when every unit
424
- * is a published package, preview is where users install it — it reads "live".
425
+ * What the person reads for an environment: when no unit has one, preview is where users get them,
426
+ * so it reads "live". Naming no unit asks about the whole repository.
425
427
  */
426
428
  const environmentLabel = (context, units, environment) => {
427
429
  if (environment !== "preview") return environment;
428
- const names = [...units];
430
+ const named = [...units];
431
+ const names = named.length > 0 ? named : context.release.units.map(({ name }) => name);
429
432
  return names.length > 0 && names.every((name) => {
430
433
  const unit = context.release.units.find((candidate) => candidate.name === name);
431
- return unit !== void 0 && moduleOf(context, unit)?.kind === "published-package";
434
+ const module = unit && moduleOf(context, unit);
435
+ return module !== void 0 && hasNoEnvironment(module);
432
436
  }) ? "live" : environment;
433
437
  };
438
+ /** Where a sentence sends units: "to preview", or "live" when none of them has an environment. */
439
+ const destination = (context, units, environment) => {
440
+ const label = environmentLabel(context, units, environment);
441
+ return label === "live" ? label : `to ${label}`;
442
+ };
434
443
  //#endregion
435
444
  //#region src/application/requirements.ts
436
445
  /**
@@ -554,6 +563,30 @@ const DEFAULT_FLOW = {
554
563
  from: pluginPackage("changesets")
555
564
  }
556
565
  };
566
+ /** Versioning from commits: same plugin, and setup offers it when no changesets config exists. */
567
+ const COMMITS_VERSIONING = {
568
+ factory: "commitsVersioning",
569
+ from: pluginPackage("changesets")
570
+ };
571
+ /** Both ways of versioning run on changesets. Private packages, such as plugins, version too. */
572
+ const CHANGESETS_CONFIG = `${JSON.stringify({
573
+ changelog: "@changesets/cli/changelog",
574
+ commit: false,
575
+ fixed: [],
576
+ linked: [],
577
+ access: "restricted",
578
+ baseBranch: "main",
579
+ updateInternalDependencies: "patch",
580
+ ignore: [],
581
+ privatePackages: {
582
+ version: true,
583
+ tag: false
584
+ }
585
+ }, null, 2)}\n`;
586
+ const CHANGESETS_CLI = {
587
+ name: "@changesets/cli",
588
+ version: "^3.0.1"
589
+ };
557
590
  /** A root config with this flow (today's by default) and these modules, in the order given. */
558
591
  const renderConfig = (entries, pkg = INSTALLED, flow = DEFAULT_FLOW, units) => {
559
592
  const byPlugin = /* @__PURE__ */ new Map();
@@ -1126,11 +1159,6 @@ const tagFormatOf = (tag) => {
1126
1159
  }
1127
1160
  return format;
1128
1161
  };
1129
- const releasesCommitsOf = (choice) => {
1130
- if (choice === void 0 || choice === "ignore") return false;
1131
- if (choice === "release") return true;
1132
- throw new Error("commitsWithoutChangeset is \"release\" or \"ignore\"");
1133
- };
1134
1162
  const readConfig = async (file, aliases) => {
1135
1163
  const loaded = await createJiti(import.meta.url, {
1136
1164
  alias: aliases,
@@ -1156,8 +1184,7 @@ const readConfig = async (file, aliases) => {
1156
1184
  verbose: flag(display.verbose),
1157
1185
  mascot: mascotOf(display.mascot)
1158
1186
  },
1159
- tagFormat: tagFormatOf(loaded.tag),
1160
- releasesCommits: releasesCommitsOf(loaded.commitsWithoutChangeset)
1187
+ tagFormat: tagFormatOf(loaded.tag)
1161
1188
  };
1162
1189
  };
1163
1190
  /** A config's mascot: true, false, frames per mood, or a function; anything else is ignored. */
@@ -1277,8 +1304,7 @@ const loadRelease = async (root, options = {}) => {
1277
1304
  problems: sortProblems(problems),
1278
1305
  display: config.display,
1279
1306
  renames: [path.basename(configFile), ...ordered.map(({ unit }) => unit.file)].flatMap((file) => renameOf(file) ?? []),
1280
- tagFormat: config.tagFormat,
1281
- releasesCommits: config.releasesCommits
1307
+ tagFormat: config.tagFormat
1282
1308
  };
1283
1309
  };
1284
1310
  //#endregion
@@ -1392,12 +1418,12 @@ const newAdapter = async (context, name) => {
1392
1418
  * Where `pnpm shiplane` picks up, from what main and GitHub hold right now. A merged release is
1393
1419
  * tagged and shipped before the next one is opened.
1394
1420
  */
1395
- const nextStep = ({ pending, releasePrs, untagged, unreleased }) => {
1421
+ const nextStep = ({ pending, releasePrs, untagged }) => {
1396
1422
  if (releasePrs.length > 0) return {
1397
1423
  step: "wait-merge",
1398
1424
  prs: releasePrs
1399
1425
  };
1400
- if ((pending > 0 || unreleased > 0) && untagged === 0) return { step: "release-pr" };
1426
+ if (pending > 0 && untagged === 0) return { step: "release-pr" };
1401
1427
  return { step: "ship" };
1402
1428
  };
1403
1429
  const RELEASE_BRANCH_PREFIX = "shiplane/release-";
@@ -1482,8 +1508,11 @@ const releaseCommitBody = (bumps) => bumps.map(({ app, to, notes, movedWith }) =
1482
1508
  const lines = notes.length > 0 ? notes : movedWith.length > 0 ? [`Moves with ${movedWith.join(", ")}.`] : [];
1483
1509
  return [`${app} ${to}`, ...lines.map(bullet)].join("\n");
1484
1510
  }).join("\n\n");
1485
- /** The release PR's body; `onMerge` says what happens to each unit once it is merged. */
1486
- const releasePrBody = (bumps, onMerge) => {
1511
+ /**
1512
+ * The release PR's body; `onMerge` says what happens to each unit once it is merged, `where` where
1513
+ * the run ships them, such as "to preview".
1514
+ */
1515
+ const releasePrBody = (bumps, onMerge, where) => {
1487
1516
  const appWidth = Math.max(3, ...bumps.map(({ app }) => app.length));
1488
1517
  const versionWidth = Math.max(7, ...bumps.map(({ from, to }) => `${from} → ${to}`.length));
1489
1518
  const row = (cells) => `| ${cells.join(" | ")} |`;
@@ -1513,7 +1542,7 @@ const releasePrBody = (bumps, onMerge) => {
1513
1542
  return [
1514
1543
  "## 🎯 What & why",
1515
1544
  "",
1516
- "Versions the changesets merged since the last release. Squash and merge it by hand: `pnpm shiplane`, still running or run again, tags and ships to preview once it is merged.",
1545
+ `Versions the changesets merged since the last release. Squash and merge it by hand: \`pnpm shiplane\`, still running or run again, tags and ships ${where} once it is merged.`,
1517
1546
  "",
1518
1547
  ...bumps.length > 0 ? table : ["Internal packages only: changelogs, nothing ships."],
1519
1548
  ...notes,
@@ -1556,6 +1585,47 @@ const WAIT_KEYS = {
1556
1585
  /** What a key does while the release waits for its pull request to merge. */
1557
1586
  const waitKey = (name) => name && WAIT_KEYS[name] || null;
1558
1587
  //#endregion
1588
+ //#region src/domain/versionChoice.ts
1589
+ /** Biggest first: up the list is a bigger version, down a smaller one. */
1590
+ const LEVELS = [
1591
+ "major",
1592
+ "minor",
1593
+ "patch"
1594
+ ];
1595
+ const PLAIN_VERSION = /^\d+\.\d+\.\d+$/;
1596
+ /**
1597
+ * The versions a release can go to, when everything it moves lands on one version: a single unit
1598
+ * or a fixed group. Null when units move apart, or on a version no bump explains, a prerelease.
1599
+ */
1600
+ const versionChoices = (bumps) => {
1601
+ const [first] = bumps;
1602
+ if (!first || !PLAIN_VERSION.test(first.from)) return null;
1603
+ if (bumps.some(({ from, to }) => from !== first.from || to !== first.to)) return null;
1604
+ const { from, to } = first;
1605
+ const versions = {
1606
+ major: nextVersion(from, "major"),
1607
+ minor: nextVersion(from, "minor"),
1608
+ patch: nextVersion(from, "patch")
1609
+ };
1610
+ const computed = LEVELS.find((level) => versions[level] === to);
1611
+ return computed ? {
1612
+ computed,
1613
+ versions
1614
+ } : null;
1615
+ };
1616
+ /** The person's choice, as what the release adds: `packages` are all those it moves. */
1617
+ const forcedVersion = ({ computed, versions }, level, reason, packages) => ({
1618
+ level,
1619
+ changeset: {
1620
+ id: `forced-${versions[level]}`,
1621
+ releases: packages.map((name) => ({
1622
+ name,
1623
+ type: level
1624
+ })),
1625
+ summary: `Version forced to ${versions[level]} instead of ${versions[computed]}: ${reason}`
1626
+ }
1627
+ });
1628
+ //#endregion
1559
1629
  //#region src/domain/companions.ts
1560
1630
  /** The shortest chain of moving packages from `from` to one a changeset names, breadth first. */
1561
1631
  const chainTo = (from, dependencies, moving, named) => {
@@ -1661,19 +1731,6 @@ const unitRefs = (units) => units.map(({ name, packageName }) => ({
1661
1731
  }));
1662
1732
  /** The units the pending changesets name. */
1663
1733
  const namedUnits = async ({ release, services }) => new Set((await services.versioning.pending()).flatMap(({ text }) => changesetApps(text, unitRefs(release.units))));
1664
- /** Units whose folder moved since their current version, that no changeset or bump ships. */
1665
- const findUnreleased = async ({ release, services: { sourceControl: source } }, named) => {
1666
- if (!release.releasesCommits) return [];
1667
- return unreleasedApps((await Promise.all(release.units.map(async ({ name, dir, version }) => {
1668
- const since = await source.tagCommit(tagName(name, version, release.tagFormat)) ?? (await source.versionCommit(dir, "package.json", version))?.sha;
1669
- if (!since) return [];
1670
- return [{
1671
- app: name,
1672
- version,
1673
- commits: await source.subjectsSince(since, dir, UNIT_FILES)
1674
- }];
1675
- }))).flat(), named);
1676
- };
1677
1734
  /** A tag's deploy on an environment, from every record the host keeps. */
1678
1735
  const deployedOn = (history, tag, environment) => {
1679
1736
  const states = history.filter(({ title }) => title === deployRunTitle(tag, environment)).map(({ state }) => state);
@@ -1689,7 +1746,6 @@ const readScope = async (context, environment) => {
1689
1746
  const pending = await services.versioning.pending();
1690
1747
  const refs = unitRefs(release.units);
1691
1748
  const named = pending.map(({ text }) => changesetApps(text, refs));
1692
- const unreleased = await findUnreleased(context, new Set(named.flat()));
1693
1749
  const [deployed, tags] = await Promise.all([services.codeHost.deployments().catch(() => []), services.sourceControl.tags()]);
1694
1750
  return Promise.all(release.units.map(async (unit) => {
1695
1751
  const tag = tagName(unit.name, unit.version, context.release.tagFormat);
@@ -1711,7 +1767,6 @@ const readScope = async (context, environment) => {
1711
1767
  app: unit.name,
1712
1768
  version: unit.version,
1713
1769
  changesets: named.filter((apps) => apps.includes(unit.name)).length,
1714
- commits: unreleased.find((entry) => entry.app === unit.name)?.commits.length ?? 0,
1715
1770
  tagged,
1716
1771
  versioned: commit !== null && cameWithRelease({
1717
1772
  app: unit.name,
@@ -1722,7 +1777,8 @@ const readScope = async (context, environment) => {
1722
1777
  onChannel: await live(environment),
1723
1778
  onPreview: await live("preview"),
1724
1779
  ...decidedBy ? { decidedBy } : {},
1725
- ...target?.releaseOnly ? { releaseOnly: true } : {}
1780
+ ...target?.releaseOnly ? { releaseOnly: true } : {},
1781
+ ...target && hasNoEnvironment(target) ? { noEnvironment: true } : {}
1726
1782
  };
1727
1783
  }));
1728
1784
  };
@@ -1769,7 +1825,7 @@ const contributionsOf = async (context, scope, bumps, known = {}) => {
1769
1825
  return contributions;
1770
1826
  };
1771
1827
  /** What a release PR covering `scope` would version, computed without writing anything. */
1772
- const prepareRelease = async (context, scope, known = {}) => {
1828
+ const prepareRelease = async (context, scope, known = {}, forced) => {
1773
1829
  const { release, services } = context;
1774
1830
  const refs = unitRefs(release.units);
1775
1831
  const [dependencies, named, base, pendingFiles] = await Promise.all([
@@ -1778,23 +1834,19 @@ const prepareRelease = async (context, scope, known = {}) => {
1778
1834
  services.versioning.plan([], []),
1779
1835
  services.versioning.pending()
1780
1836
  ]);
1781
- const baseBumps = appBumps(base, dependencies, refs);
1782
- const unreleased = await findUnreleased(context, new Set([...named, ...baseBumps.map(({ app }) => app)]));
1783
1837
  const held = [...named].filter((app) => !scope.has(app));
1784
- const adopted = unreleased.filter(({ app }) => scope.has(app)).flatMap(({ app, version, commits }) => {
1785
- const ref = refs.find(({ name }) => name === app);
1786
- return ref ? unreleasedChangesets(ref, version, commits) : [];
1787
- });
1788
1838
  const split = held.length > 0 ? splitChangesets(base.changesets, held, refs) : NOTHING_HELD;
1789
- const picked = held.length > 0 || adopted.length > 0 ? await services.versioning.plan(adopted, split.waits) : base;
1839
+ const own = forced ? [forced.changeset] : [];
1840
+ const ceiling = forced?.level;
1841
+ const picked = held.length > 0 || forced ? await services.versioning.plan(own, split.waits, ceiling) : base;
1790
1842
  const contributions = await contributionsOf(context, scope, appBumps(picked, dependencies, refs), known);
1791
- const contributed = Object.values(contributions).flatMap(({ added }) => added);
1792
- const added = [...adopted, ...contributed];
1793
- const plan = contributed.length > 0 ? await services.versioning.plan(added, split.waits) : picked;
1843
+ const added = [...own, ...Object.values(contributions).flatMap((contribution) => contribution.added)];
1844
+ const plan = added.length > own.length ? await services.versioning.plan(added, split.waits, ceiling) : picked;
1794
1845
  return {
1846
+ scope,
1847
+ forced,
1795
1848
  pending: (held.length > 0 ? split.ships.length : pendingFiles.length) + added.length,
1796
1849
  held,
1797
- unreleased: unreleased.filter(({ app }) => !scope.has(app)),
1798
1850
  split,
1799
1851
  bumps: appBumps(plan, dependencies, refs),
1800
1852
  companions: draggedUnits(plan, dependencies, refs, scope),
@@ -1805,6 +1857,42 @@ const prepareRelease = async (context, scope, known = {}) => {
1805
1857
  };
1806
1858
  };
1807
1859
  //#endregion
1860
+ //#region src/application/chooseVersion.ts
1861
+ /** The release again at `level`, or null with why when versioning cannot land there. */
1862
+ const forceVersion = async (context, prepared, choices, level, reason) => {
1863
+ const packages = prepared.bumps.flatMap(({ app }) => context.release.units.filter(({ name }) => name === app).map((unit) => unit.packageName));
1864
+ const forced = await prepareRelease(context, prepared.scope, {}, forcedVersion(choices, level, reason, packages));
1865
+ const version = choices.versions[level];
1866
+ const elsewhere = forced.bumps.find(({ to }) => to !== version);
1867
+ if (elsewhere) {
1868
+ fail(context, `Can't force ${version}`, `${elsewhere.app} would go to ${elsewhere.to}.`);
1869
+ return null;
1870
+ }
1871
+ context.output.line(` ${paint(["bold", "yellow"], "!")} ${version} instead of ${choices.versions[choices.computed]}: ${reason}`);
1872
+ return forced;
1873
+ };
1874
+ /**
1875
+ * The release to open: as computed, or at the version the person chose instead with why. Null when
1876
+ * they cancel. A plain yes when no one version covers the release, under --yes or with no terminal.
1877
+ */
1878
+ const chooseVersion = async (context, prepared, where) => {
1879
+ const { prompter, options } = context;
1880
+ const choices = versionChoices(prepared.bumps);
1881
+ if (!choices || options.yes || !prompter.interactive) return await confirm(context, `Release these ${where}?`, true) ? prepared : null;
1882
+ const { computed, versions } = choices;
1883
+ const picks = LEVELS.map((level) => ({
1884
+ value: level,
1885
+ label: `${versions[level]} ${level}${level === computed ? ", computed" : ""}`
1886
+ }));
1887
+ for (;;) {
1888
+ const level = await prompter.select(`Release these ${where} as (Esc cancels)`, picks, computed);
1889
+ if (!level) return null;
1890
+ if (level === computed) return prepared;
1891
+ const reason = await prompter.text(`Why ${versions[level]}? Tell users what changed, in one line.`);
1892
+ if (reason?.trim()) return forceVersion(context, prepared, choices, level, reason.trim());
1893
+ }
1894
+ };
1895
+ //#endregion
1808
1896
  //#region src/application/steps.ts
1809
1897
  const MAX_OUTPUT_LINES = 40;
1810
1898
  const reasonOf$1 = (error) => error instanceof Error ? error.message : String(error);
@@ -1909,15 +1997,17 @@ const openPrStep = ({ services: { codeHost: host } }, label, open) => {
1909
1997
  //#endregion
1910
1998
  //#region src/application/openReleasePr.ts
1911
1999
  const plural$2 = (count, word) => `${count} ${word}${count === 1 ? "" : "s"}`;
1912
- /** What happens to a unit once the release PR merges: its module ships the version to preview. */
2000
+ /** What happens to a unit once the release PR merges: its module ships the version. */
1913
2001
  const shipsOnMerge = (context, { contributions, companions }) => (bump) => {
1914
2002
  const contributed = contributions[bump.app]?.onMerge;
1915
2003
  if (contributed) return contributed;
1916
2004
  const unit = context.release.units.find(({ name }) => name === bump.app);
1917
2005
  const along = companions.find(({ app }) => app === bump.app);
1918
2006
  const reason = along ? ` (not picked: ${along.why})` : bump.movedWith.length > 0 ? ` (moved with ${bump.movedWith.join(", ")})` : "";
1919
- return `${environmentLabel(context, [bump.app], "preview") === "live" ? "Ship live" : "Ship to preview"} with ${(unit && moduleOf(context, unit)?.provider) ?? "its target"}${reason}`;
2007
+ return `Ship ${destination(context, [bump.app], "preview")} with ${(unit && moduleOf(context, unit)?.provider) ?? "its target"}${reason}`;
1920
2008
  };
2009
+ /** Where a release sends what it moves. */
2010
+ const whereTo = (context, { bumps }) => destination(context, bumps.map(({ app }) => app), "preview");
1921
2011
  /** Units going out unpicked, each with the package that takes it along. */
1922
2012
  const printCompanions = ({ output, release }, { companions, split }) => {
1923
2013
  if (companions.length === 0) return;
@@ -1935,23 +2025,21 @@ const printCompanions = ({ output, release }, { companions, split }) => {
1935
2025
  /** The table a person reads before anything is written: each unit, its move, what ships. */
1936
2026
  const printSummary = (context, prepared) => {
1937
2027
  const { output, release } = context;
1938
- const { bumps, packages, pending, held, unreleased, contributions, companions } = prepared;
2028
+ const { bumps, packages, pending, held, contributions, companions } = prepared;
1939
2029
  const dot = paint("dim", "·");
1940
2030
  const stays = held.filter((app) => !bumps.some((bump) => bump.app === app));
1941
2031
  const heldLabel = stays.length > 0 ? ` ${dot} ${stays.join(", ")} held` : "";
1942
- const where = environmentLabel(context, bumps.map(({ app }) => app), "preview");
2032
+ const moving = bumps.map(({ app }) => app);
1943
2033
  output.line();
1944
- output.line(` ${paint("bold", "Release")} ${dot} ${where} ${dot} ${plural$2(pending, "changeset")}${heldLabel}`);
2034
+ output.line(` ${paint("bold", "Release")} ${dot} ${environmentLabel(context, moving, "preview")} ${dot} ${plural$2(pending, "changeset")}${heldLabel}`);
1945
2035
  output.line();
1946
2036
  const width = Math.max(13, ...release.units.map(({ name }) => name.length)) + 2;
1947
- output.line(paint("dim", ` ${"Unit".padEnd(width)}${"Version".padEnd(20)}${where === "live" ? "Ships live" : "Ships to preview"}`));
2037
+ output.line(paint("dim", ` ${"Unit".padEnd(width)}${"Version".padEnd(20)}Ships ${destination(context, moving, "preview")}`));
1948
2038
  release.units.forEach((unit) => {
1949
2039
  const bump = bumps.find(({ app }) => app === unit.name);
1950
2040
  const version = bump ? `${bump.from} → ${bump.to}` : unit.version;
1951
- const left = unreleased.find(({ app }) => app === unit.name);
1952
2041
  const ships = (() => {
1953
2042
  if (held.includes(unit.name) && !bump) return paint("yellow", "⏸ held, its changesets stay pending");
1954
- if (left && !bump) return paint("yellow", `! ${plural$2(left.commits.length, "commit")} since ${left.version}, no changeset: not in this release`);
1955
2043
  const contributed = contributions[unit.name]?.summary;
1956
2044
  if (contributed && contributed.length > 0) return contributed.join(`\n ${" ".repeat(width + 20)}`);
1957
2045
  if (!bump) return paint("dim", "– nothing changed");
@@ -1964,6 +2052,12 @@ const printSummary = (context, prepared) => {
1964
2052
  output.line();
1965
2053
  printCompanions(context, prepared);
1966
2054
  };
2055
+ /** Says what a plugin refuses in `prepared`; true when something does. */
2056
+ const refused = (context, { contributions }) => {
2057
+ const blocked = Object.values(contributions).find((entry) => entry.blocked)?.blocked;
2058
+ if (blocked) fail(context, blocked.title, blocked.detail, blocked.commands);
2059
+ return Boolean(blocked);
2060
+ };
1967
2061
  /**
1968
2062
  * Versions what `prepared` covers on one branch from main, opens its PR, and goes back to main.
1969
2063
  * Null, with what to do, when it must not run.
@@ -1971,11 +2065,7 @@ const printSummary = (context, prepared) => {
1971
2065
  const openReleasePr = async (context, prepared, replaces = []) => {
1972
2066
  const { output, services, clock } = context;
1973
2067
  printSummary(context, prepared);
1974
- const blocked = Object.values(prepared.contributions).find((entry) => entry.blocked)?.blocked;
1975
- if (blocked) {
1976
- fail(context, blocked.title, blocked.detail, blocked.commands);
1977
- return null;
1978
- }
2068
+ if (refused(context, prepared)) return null;
1979
2069
  const source = releaseSource("build", "preview", await services.sourceControl.position());
1980
2070
  if (!source.allowed) {
1981
2071
  fail(context, source.why === "not-main" ? "Not from main" : "main is behind origin", "a release versions what is merged.", [
@@ -2003,17 +2093,20 @@ const openReleasePr = async (context, prepared, replaces = []) => {
2003
2093
  output.line(paint("dim", " Steps"));
2004
2094
  planned.forEach((step, index) => output.line(` ${index + 1}. ${step}`));
2005
2095
  output.line();
2006
- if (!await confirm(context, `Release these ${environmentLabel(context, prepared.bumps.map(({ app }) => app), "preview") === "live" ? "live" : "to preview"}?`, true)) {
2096
+ const chosen = await chooseVersion(context, prepared, whereTo(context, prepared));
2097
+ if (!chosen) {
2007
2098
  output.line(paint("dim", "Nothing ran."));
2008
2099
  return null;
2009
2100
  }
2101
+ if (refused(context, chosen)) return null;
2102
+ const opening = prGroupsOf(context, chosen);
2010
2103
  const now = clock.now();
2011
2104
  const prs = [];
2012
- for (const group of groups) {
2105
+ for (const group of opening) {
2013
2106
  const apps = new Set(group.map(({ app }) => app));
2014
- const scoped = groups.length > 1 ? await prepareRelease(context, apps, prepared.contributions) : prepared;
2107
+ const scoped = opening.length > 1 ? await prepareRelease(context, apps, chosen.contributions) : chosen;
2015
2108
  const [first] = group;
2016
- const pr = await openOne(context, scoped, kindOf, `${releaseBranchName(now)}${groups.length > 1 && first ? `-${first.app}` : ""}`, replaces);
2109
+ const pr = await openOne(context, scoped, kindOf, `${releaseBranchName(now)}${opening.length > 1 && first ? `-${first.app}` : ""}`, replaces);
2017
2110
  if (!pr) {
2018
2111
  if (prs.length > 0) output.line(paint("dim", ` ${listed(prs.map(({ number }) => `#${number}`))} stay open: merge them, then run shiplane for the rest.`));
2019
2112
  return null;
@@ -2045,7 +2138,7 @@ const openOne = async (context, prepared, kindOf, branch, replaces) => {
2045
2138
  branchStep(context, branch),
2046
2139
  {
2047
2140
  label: "versions and changelogs",
2048
- run: () => services.versioning.apply(prepared.added, prepared.split.waits)
2141
+ run: () => services.versioning.apply(prepared.added, prepared.split.waits, prepared.forced?.level)
2049
2142
  },
2050
2143
  ...Object.values(prepared.contributions).flatMap(({ writes }) => writes),
2051
2144
  {
@@ -2058,7 +2151,7 @@ const openOne = async (context, prepared, kindOf, branch, replaces) => {
2058
2151
  base: "main",
2059
2152
  head: branch,
2060
2153
  title,
2061
- body: replacedLine(replaces) + releasePrBody(prepared.bumps, shipsOnMerge(context, prepared)),
2154
+ body: replacedLine(replaces) + releasePrBody(prepared.bumps, shipsOnMerge(context, prepared), whereTo(context, prepared)),
2062
2155
  label: "type: chore"
2063
2156
  });
2064
2157
  return created.pr;
@@ -2072,16 +2165,12 @@ const openOne = async (context, prepared, kindOf, branch, replaces) => {
2072
2165
  //#endregion
2073
2166
  //#region src/domain/scope.ts
2074
2167
  const plural$1 = (count, word) => `${count} ${word}${count === 1 ? "" : "s"}`;
2075
- const previewChoice = ({ version, changesets, commits, tagged, versioned, firstRelease, onChannel, decidedBy, releaseOnly }) => {
2168
+ const previewChoice = ({ version, changesets, tagged, versioned, firstRelease, onChannel, decidedBy, releaseOnly, noEnvironment }) => {
2076
2169
  const later = decidedBy ? ` · ${decidedBy.platform} decides ${decidedBy.choice} once picked` : "";
2077
2170
  if (changesets > 0) return {
2078
2171
  pending: true,
2079
2172
  hint: `${plural$1(changesets, "changeset")}${later}`
2080
2173
  };
2081
- if (commits > 0) return {
2082
- pending: true,
2083
- hint: `${plural$1(commits, "commit")} since ${version}, changelog from its commits${later}`
2084
- };
2085
2174
  if (!tagged) {
2086
2175
  if (versioned) return {
2087
2176
  pending: true,
@@ -2103,12 +2192,13 @@ const previewChoice = ({ version, changesets, commits, tagged, versioned, firstR
2103
2192
  pending: false,
2104
2193
  hint: `${version} released, nothing new (${decidedBy.check} shows its builds)`
2105
2194
  };
2195
+ const where = noEnvironment ? "live" : "on preview";
2106
2196
  return onChannel ? {
2107
2197
  pending: false,
2108
- hint: `${version} is on preview, nothing new`
2198
+ hint: `${version} is ${where}, nothing new`
2109
2199
  } : {
2110
2200
  pending: true,
2111
- hint: `${version} released, not on preview yet`
2201
+ hint: `${version} released, not ${where} yet`
2112
2202
  };
2113
2203
  };
2114
2204
  const productionChoice = ({ version, tagged, onChannel, onPreview, decidedBy, releaseOnly }) => {
@@ -2151,14 +2241,16 @@ const defaultScope = (info, environment) => new Set(scopeChoices(info, environme
2151
2241
  */
2152
2242
  const pickScope = async (context, environment) => {
2153
2243
  const { output, prompter, options, progress } = context;
2154
- const info = await progress.during("Reading what changed: changesets, commits, tags and GitHub deployments", "thinking", () => readScope(context, environment));
2244
+ const info = await progress.during("Reading what changed: changesets, tags and GitHub deployments", "thinking", () => readScope(context, environment));
2155
2245
  const choices = scopeChoices(info, environment);
2246
+ const where = destination(context, info.map(({ app }) => app), environment);
2156
2247
  if (!choices.some(({ pending }) => pending)) {
2157
2248
  output.line();
2158
2249
  choices.forEach(({ app, hint }) => output.line(` ${paint("dim", `${app.padEnd(15)}${hint}`)}`));
2159
2250
  output.line();
2160
- progress.say("resting", `${paint("bold", `Nothing to release to ${environment}.`)} ${paint("dim", environment === "preview" ? "Queue a change first:" : "Release to preview first:")}`);
2161
- output.line(` ${paint("cyan", environment === "preview" ? "pnpm changeset" : "shiplane")}`);
2251
+ const queue = environment === "preview" || info.every(({ releaseOnly }) => releaseOnly);
2252
+ progress.say("resting", `${paint("bold", `Nothing to release ${where}.`)} ${paint("dim", queue ? "Queue a change first:" : "Release to preview first:")}`);
2253
+ output.line(` ${paint("cyan", queue ? context.services.versioning.nextChange : "shiplane")}`);
2162
2254
  output.line();
2163
2255
  return null;
2164
2256
  }
@@ -2166,7 +2258,7 @@ const pickScope = async (context, environment) => {
2166
2258
  scope: defaultScope(info, environment),
2167
2259
  info
2168
2260
  };
2169
- const picked = await prompter.multiselect(`What do you want to release to ${environment}? Greyed units have nothing to release.`, choices.map(({ app, pending, hint }) => ({
2261
+ const picked = await prompter.multiselect(`What do you want to release ${where}? Greyed units have nothing to release.`, choices.map(({ app, pending, hint }) => ({
2170
2262
  value: app,
2171
2263
  label: app,
2172
2264
  hint,
@@ -2220,7 +2312,7 @@ const planShips = async (context, environment) => {
2220
2312
  const { release, services, output } = context;
2221
2313
  const { head } = await services.sourceControl.position();
2222
2314
  output.line();
2223
- output.line(` ${paint("bold", "Plan")} ${paint("dim", "·")} ${environment} ${paint("dim", "· nothing runs")}`);
2315
+ output.line(` ${paint("bold", "Plan")} ${paint("dim", "·")} ${environmentLabel(context, [], environment)} ${paint("dim", "· nothing runs")}`);
2224
2316
  output.line(` ${paint("bold", "Order")} ${releaseOrder(release.units)}`);
2225
2317
  const shipped = [];
2226
2318
  for (const unit of release.units) {
@@ -2510,7 +2602,8 @@ const decideAll = async (context, environment, scope) => {
2510
2602
  decision: module.decide ? await module.decide(decideContext(context), input) : webDecision(context, module, input, recorded)
2511
2603
  };
2512
2604
  };
2513
- let { input, decision } = await context.progress.during(`Checking what ${tag} needs on ${environment}`, "thinking", decide);
2605
+ const checked = module.kind === "published-package" ? module.provider : environment;
2606
+ let { input, decision } = await context.progress.during(module.releaseOnly ? `Checking what ${tag} needs` : `Checking what ${tag} needs on ${checked}`, "thinking", decide);
2514
2607
  while (decision.action === "pull-request") {
2515
2608
  const merged = await pullRequestFirst(context, decision);
2516
2609
  if (merged === "failed") return null;
@@ -2655,7 +2748,7 @@ const shipTo = async (context, environment, { scope, via }) => {
2655
2748
  const ready = await decideAll(context, environment, scope);
2656
2749
  if (!ready) return false;
2657
2750
  if (ready.length === 0) {
2658
- context.progress.say("resting", paint("dim", `Nothing to ship to ${environment}.`));
2751
+ context.progress.say("resting", paint("dim", `Nothing to ship ${destination(context, scope ?? [], environment)}.`));
2659
2752
  return true;
2660
2753
  }
2661
2754
  const forced = options.ci ? "local" : via;
@@ -2724,8 +2817,9 @@ const shipTo = async (context, environment, { scope, via }) => {
2724
2817
  }
2725
2818
  }
2726
2819
  const names = going.map(({ input }) => input.tag).join(", ");
2820
+ const where = destination(context, going.map(({ unit }) => unit.name), environment);
2727
2821
  output.line();
2728
- context.progress.say("happy", `${paint(["bold", "green"], "✓ Triggered.")} ${paint("dim", `${names}, shipping to ${environment} on their own.`)}`);
2822
+ context.progress.say("happy", `${paint(["bold", "green"], "✓ Triggered.")} ${paint("dim", `${names}, shipping ${where} on their own.`)}`);
2729
2823
  await runFollowUps(context, going.map(({ unit, input }) => ({
2730
2824
  unit,
2731
2825
  tag: input.tag,
@@ -2935,8 +3029,7 @@ const releaseToPreview = async (context) => {
2935
3029
  const step = nextStep({
2936
3030
  pending: covered.reduce((sum, { changesets }) => sum + changesets, 0),
2937
3031
  releasePrs,
2938
- untagged: missing.length,
2939
- unreleased: covered.filter(({ changesets, commits }) => changesets === 0 && commits > 0).length
3032
+ untagged: missing.length
2940
3033
  });
2941
3034
  let prs = [];
2942
3035
  let current = context;
@@ -2963,7 +3056,7 @@ const releaseToPreview = async (context) => {
2963
3056
  prs = fresh;
2964
3057
  } else if (missing.length > 0) {
2965
3058
  progress.say("thinking", `↻ Picking up a merged release`);
2966
- output.line(paint("dim", ` Left to do: tag ${plural(missing.length, "version")} → ship to preview`));
3059
+ output.line(paint("dim", ` Left to do: tag ${plural(missing.length, "version")} → ship ${destination(context, missing.map(({ app }) => app), "preview")}`));
2967
3060
  }
2968
3061
  if (prs.length > 0) stage("Merge");
2969
3062
  for (const pr of prs) {
@@ -3260,6 +3353,7 @@ const rehearse = async (context) => {
3260
3353
  //#region src/application/setup.ts
3261
3354
  const ok = paint("green", "✓");
3262
3355
  const unsure = paint("yellow", "?");
3356
+ const CHANGESETS_CONFIG_FILE = ".changeset/config.json";
3263
3357
  /** What a flow port is called, and what proves the ready-made adapter fits. */
3264
3358
  const FLOW_LABEL = {
3265
3359
  sourceControl: {
@@ -3337,7 +3431,7 @@ const flowEvidence = async (context) => {
3337
3431
  sourceControl: files.exists(".git") ? ".git" : null,
3338
3432
  codeHost: github ? `remote github.com/${github}` : null,
3339
3433
  ciPipeline: workflows[0] ? `.github/workflows/${workflows[0]}` : null,
3340
- versioning: files.exists(".changeset/config.json") ? ".changeset/config.json" : null
3434
+ versioning: files.exists(CHANGESETS_CONFIG_FILE) ? CHANGESETS_CONFIG_FILE : null
3341
3435
  };
3342
3436
  };
3343
3437
  /** A name for a custom adapter: asked, checked, unused. Null when cancelled. */
@@ -3367,6 +3461,63 @@ const customWrites = (port, name, pkg) => [{
3367
3461
  text: renderCustomTest(port, name, pkg),
3368
3462
  created: true
3369
3463
  }];
3464
+ /** What both ways of versioning need: the changesets config, and its CLI when it is missing. */
3465
+ const changesetsWrites = ({ files }) => {
3466
+ const manifest = files.read("package.json");
3467
+ const parsed = JSON.parse(manifest ?? "{}");
3468
+ const present = {
3469
+ ...parsed.dependencies,
3470
+ ...parsed.devDependencies
3471
+ }[CHANGESETS_CLI.name];
3472
+ return [{
3473
+ file: CHANGESETS_CONFIG_FILE,
3474
+ text: CHANGESETS_CONFIG,
3475
+ created: true
3476
+ }, ...manifest === null || present ? [] : [{
3477
+ file: "package.json",
3478
+ text: `${JSON.stringify({
3479
+ ...parsed,
3480
+ devDependencies: {
3481
+ ...parsed.devDependencies,
3482
+ [CHANGESETS_CLI.name]: CHANGESETS_CLI.version
3483
+ }
3484
+ }, null, 2)}\n`,
3485
+ created: false
3486
+ }]];
3487
+ };
3488
+ /** How a repository with no changesets config releases: asked once, commits unless told. */
3489
+ const chooseVersioning = async (context, yes, writes, pkg) => {
3490
+ const { prompter } = context;
3491
+ const picked = yes || !prompter.interactive ? "commits" : await prompter.select("How do you want to release?", [
3492
+ {
3493
+ value: "commits",
3494
+ label: "From commits",
3495
+ hint: "feat, fix and ! set the version, nothing to write"
3496
+ },
3497
+ {
3498
+ value: "changesets",
3499
+ label: "From changesets",
3500
+ hint: "you write what ships, and when"
3501
+ },
3502
+ {
3503
+ value: "custom",
3504
+ label: "Custom",
3505
+ hint: "a no-op in memory you implement"
3506
+ }
3507
+ ], "commits");
3508
+ if (picked === null) return null;
3509
+ if (picked === "custom") {
3510
+ const name = await askName(context, "versioning", suggestedName("versioning"));
3511
+ if (name === null) return null;
3512
+ writes.push(...customWrites("versioning", name, pkg));
3513
+ return {
3514
+ factory: name,
3515
+ from: customFiles(name).from
3516
+ };
3517
+ }
3518
+ writes.push(...changesetsWrites(context));
3519
+ return picked === "commits" ? COMMITS_VERSIONING : DEFAULT_FLOW.versioning;
3520
+ };
3370
3521
  /** The flow, from what the repository proves; asked part by part when unsure or when asked to. */
3371
3522
  const chooseFlow = async (context, yes, needsPerson, writes, pkg) => {
3372
3523
  const { output, prompter } = context;
@@ -3378,12 +3529,19 @@ const chooseFlow = async (context, yes, needsPerson, writes, pkg) => {
3378
3529
  output.line(proof ? ` ${ok} ${ready.padEnd(16)}${paint("dim", proof)}` : ` ${unsure} ${label.padEnd(16)}${paint("dim", "not sure: nothing here proves one")}`);
3379
3530
  });
3380
3531
  if (FLOW_PORTS.every((port) => evidence[port] !== null)) return DEFAULT_FLOW;
3381
- if (yes) {
3382
- needsPerson.push(...FLOW_PORTS.filter((port) => !evidence[port]).map((port) => `the ${FLOW_LABEL[port].label.toLowerCase()} (nothing proves one)`));
3532
+ const missing = FLOW_PORTS.filter((port) => !evidence[port] && port !== "versioning");
3533
+ if (yes && missing.length > 0) {
3534
+ needsPerson.push(...missing.map((port) => `the ${FLOW_LABEL[port].label.toLowerCase()} (nothing proves one)`));
3383
3535
  return null;
3384
3536
  }
3385
3537
  const flow = { ...DEFAULT_FLOW };
3386
- for (const port of FLOW_PORTS) {
3538
+ for (const port of missing.length > 0 ? FLOW_PORTS : ["versioning"]) {
3539
+ if (port === "versioning" && !evidence.versioning) {
3540
+ const choice = await chooseVersioning(context, yes, writes, pkg);
3541
+ if (choice === null) return null;
3542
+ flow.versioning = choice;
3543
+ continue;
3544
+ }
3387
3545
  const { label, ready } = FLOW_LABEL[port];
3388
3546
  const picked = await prompter.select(`${label}?`, [{
3389
3547
  value: "ready",
@@ -3633,8 +3791,12 @@ const setup = async (context, { yes }) => {
3633
3791
  output.line(` ${paint("dim", "Custom adapters start in memory: fill them in until their contract test passes.")}`);
3634
3792
  output.line(` ${paint("dim", "Works? Share it as shiplane-<name>, or open a pull request at github.com/arnaud-zg/packages.")}`);
3635
3793
  }
3794
+ const fromCommits = flow ? flow.versioning.factory === COMMITS_VERSIONING.factory : existing?.flow.versioning.name === "commits";
3795
+ const next = fromCommits ? "erge a commit" : "dd a changeset, merge";
3796
+ const install = writes.some(({ file }) => file === "package.json");
3797
+ const start = fromCommits ? "m" : "a";
3636
3798
  output.line();
3637
- output.line(` ${ok} ${paint("bold", "Ready.")} Add a changeset, merge, and run ${paint("cyan", "shiplane")}`);
3799
+ output.line(` ${ok} ${paint("bold", "Ready.")} ${install ? `Run ${runner(context)} install, then ${start}` : start.toUpperCase()}${next}, and run ${paint("cyan", "shiplane")}`);
3638
3800
  return true;
3639
3801
  };
3640
3802
  const cancelled = (context) => {
@@ -3776,7 +3938,6 @@ const readStatus = async (context, environment) => {
3776
3938
  tag: tagName(entry.app, entry.version, context.release.tagFormat),
3777
3939
  tagged: entry.tagged,
3778
3940
  changesets: entry.changesets,
3779
- commits: entry.commits,
3780
3941
  pending: choice?.pending ?? false,
3781
3942
  hint: choice?.hint ?? "",
3782
3943
  ...await live(entry.app)
@@ -3787,12 +3948,11 @@ const readStatus = async (context, environment) => {
3787
3948
  next: nextStep({
3788
3949
  pending: info.reduce((sum, { changesets }) => sum + changesets, 0),
3789
3950
  releasePrs,
3790
- untagged: untagged.length,
3791
- unreleased: info.filter(({ changesets, commits }) => changesets === 0 && commits > 0).length
3951
+ untagged: untagged.length
3792
3952
  })
3793
3953
  };
3794
3954
  };
3795
3955
  //#endregion
3796
- export { refreshEditorSchema as C, nodeFiles as D, keysAt as E, CONFIG_FILE as S, ENVIRONMENTS as T, loadRelease as _, releaseToPreview as a, initRelease as b, promote as c, pickScope as d, openReleasePr as f, findConfig as g, docsFor as h, setup as i, shipTo as l, newAdapter as m, systemShell as n, missingTags as o, prepareRelease as p, liveLine as r, tagRelease as s, readStatus as t, planShips as u, addUnit as v, optionsFor as w, doctor as x, removeUnit as y };
3956
+ export { refreshEditorSchema as C, keysAt as D, ENVIRONMENTS as E, nodeFiles as O, CONFIG_FILE as S, optionsFor as T, loadRelease as _, releaseToPreview as a, initRelease as b, promote as c, pickScope as d, openReleasePr as f, findConfig as g, docsFor as h, setup as i, shipTo as l, newAdapter as m, systemShell as n, missingTags as o, prepareRelease as p, liveLine as r, tagRelease as s, readStatus as t, planShips as u, addUnit as v, environmentLabel as w, doctor as x, removeUnit as y };
3797
3957
 
3798
- //# sourceMappingURL=readStatus-Bo7hpUT3.js.map
3958
+ //# sourceMappingURL=readStatus-Dd_pBt-6.js.map