@plexus-ms/cli 0.6.0 → 0.8.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 (2) hide show
  1. package/dist/plx.js +42 -12
  2. package/package.json +2 -2
package/dist/plx.js CHANGED
@@ -7731,7 +7731,7 @@ async function exists(ctx, path3) {
7731
7731
 
7732
7732
  // ../lib/dist/changeset.js
7733
7733
  var import_yaml2 = __toESM(require_dist(), 1);
7734
- import { join as join3 } from "node:path";
7734
+ import { dirname, join as join3 } from "node:path";
7735
7735
 
7736
7736
  // ../lib/dist/io.js
7737
7737
  import { spawn } from "node:child_process";
@@ -7824,6 +7824,7 @@ function body(step) {
7824
7824
  // ../lib/dist/changeset.js
7825
7825
  var CHANGESET_DIR = ".changeset";
7826
7826
  var FIELDS = ["dependencies", "optionalDependencies", "peerDependencies"];
7827
+ var TEST_FILE = /\.test\.[cm]?[jt]sx?$|\/testing\//;
7827
7828
  function changesetPath(branch) {
7828
7829
  const slug = branch.replace(/^(renovate|dependabot)\//, "").replace(/[^a-z0-9]+/gi, "-").replace(/^-|-$/g, "").toLowerCase();
7829
7830
  return `${CHANGESET_DIR}/bot-${slug || "branch"}.md`;
@@ -7831,11 +7832,19 @@ function changesetPath(branch) {
7831
7832
  function planChangeset(input) {
7832
7833
  const path3 = changesetPath(input.branch);
7833
7834
  const changes = [];
7835
+ const sources = [];
7834
7836
  const releases = {};
7835
7837
  for (const diff of input.packages) {
7836
7838
  const { before, after } = diff;
7837
7839
  if (!before || !after?.name || after.private || input.ignore.includes(after.name))
7838
7840
  continue;
7841
+ const src = `${dirname(diff.path)}/src/`;
7842
+ for (const file of input.files ?? []) {
7843
+ if (!file.startsWith(src) || TEST_FILE.test(file))
7844
+ continue;
7845
+ sources.push({ package: after.name, file });
7846
+ releases[after.name] ??= "patch";
7847
+ }
7839
7848
  for (const field of FIELDS) {
7840
7849
  const names = /* @__PURE__ */ new Set([...Object.keys(before[field] ?? {}), ...Object.keys(after[field] ?? {})]);
7841
7850
  for (const dependency of [...names].sort()) {
@@ -7851,19 +7860,23 @@ function planChangeset(input) {
7851
7860
  }
7852
7861
  }
7853
7862
  const root = input.root;
7854
- if (changes.length === 0) {
7863
+ if (changes.length === 0 && sources.length === 0) {
7855
7864
  const remove = run("rm", ["-f", path3], root ? { cwd: root } : {});
7856
- return { path: path3, releases, changes, plan: input.exists ? [remove] : [] };
7865
+ return { path: path3, releases, changes, sources, plan: input.exists ? [remove] : [] };
7857
7866
  }
7858
7867
  const header = Object.entries(releases).sort(([a], [b]) => a.localeCompare(b)).map(([name, bump]) => `'${name}': ${bump}`);
7859
- const lines = [...new Set(changes.map(describeChange))].sort((a, b) => a.localeCompare(b));
7868
+ const described = [
7869
+ ...changes.map(describeChange),
7870
+ ...sources.map((s) => `Update the version pinned in \`${s.file}\``)
7871
+ ];
7872
+ const lines = [...new Set(described)].sort((a, b) => a.localeCompare(b));
7860
7873
  const content = `---
7861
7874
  ${header.join("\n")}
7862
7875
  ---
7863
7876
 
7864
7877
  ${lines.join("\n")}
7865
7878
  `;
7866
- return { path: path3, releases, changes, content, plan: [write(root ? join3(root, path3) : path3, content)] };
7879
+ return { path: path3, releases, changes, sources, content, plan: [write(root ? join3(root, path3) : path3, content)] };
7867
7880
  }
7868
7881
  function describeChange(c) {
7869
7882
  const peer = c.field === "peerDependencies" ? " (peer)" : "";
@@ -7936,6 +7949,7 @@ async function readChangeset(ctx, dir, base, branch) {
7936
7949
  catalogsBefore: parseCatalogs(await show("pnpm-workspace.yaml")),
7937
7950
  catalogsAfter: parseCatalogs(workspaceAfter),
7938
7951
  ignore,
7952
+ files: (await git2(["diff", "--name-only", mergeBase, "HEAD"])).split("\n").filter(Boolean),
7939
7953
  exists: entries.some((e) => !e.directory && `${CHANGESET_DIR}/${e.name}` === path3),
7940
7954
  root: dir
7941
7955
  });
@@ -8126,6 +8140,8 @@ function indent(text) {
8126
8140
  var import_yaml3 = __toESM(require_dist(), 1);
8127
8141
  var ANSWERS_FILE = ".copier-answers.yml";
8128
8142
  var TEMPLATE_FILES = ["copier.yml", "copier.yaml"];
8143
+ var COPIER_VERSION = "9.19.1";
8144
+ var copierVia = (args) => ["exec", `copier@${COPIER_VERSION}`, "--", "copier", ...args];
8129
8145
  function parseAnswers(text) {
8130
8146
  const data = (0, import_yaml3.parse)(text);
8131
8147
  if (data === null || typeof data !== "object" || Array.isArray(data))
@@ -8682,13 +8698,11 @@ async function updateSite(ctx, consumer, site, localPreset, summary, cloneOf, pr
8682
8698
  const answers = await ctx.readFile(join8(site.path, ANSWERS_FILE));
8683
8699
  await ctx.stage(write(join8(target, ANSWERS_FILE), answers.replace(/^_src_path: .*$/m, `_src_path: ${localPreset}`)));
8684
8700
  await previewCommit(repo, `plx preview: ${site.rel} reads ${localPreset} from the local checkout`);
8685
- await ctx.stage(run("copier", ["update", "--skip-answered", "--trust", "--defaults", "--skip-tasks", "--vcs-ref", "main"], {
8686
- cwd: target
8687
- }));
8701
+ await ctx.stage(run("mise", copierVia(["update", "--skip-answered", "--trust", "--defaults", "--skip-tasks", "--vcs-ref", "main"]), { cwd: target }));
8688
8702
  } else {
8689
8703
  ctx.say(`\u2192 ${site.rel}: copier update`);
8690
8704
  const args = ["update", "--skip-answered", "--trust", ...ctx.yes ? ["--defaults"] : []];
8691
- await ctx.apply([run("copier", args, { cwd: target, interactive: true })]);
8705
+ await ctx.apply([run("mise", copierVia(args), { cwd: target, interactive: true })]);
8692
8706
  }
8693
8707
  } catch (error) {
8694
8708
  ctx.say(` \u2717 FAILED \u2014 copier update exited nonzero${detail(error)}`);
@@ -8935,11 +8949,25 @@ async function checkCompendium(ctx, compendium) {
8935
8949
  };
8936
8950
  }
8937
8951
 
8952
+ // ../lib/dist/self.js
8953
+ var SELF_PACKAGE = "@plexus-ms/cli";
8954
+ async function preflightSelf(ctx, running) {
8955
+ const latest = (await ctx.read("npm", ["view", SELF_PACKAGE, "version"]).catch(() => "")).trim();
8956
+ if (!latest) {
8957
+ ctx.say(`\u26A0 could not ask the registry for the newest ${SELF_PACKAGE}; going on with plx ${running}`);
8958
+ return;
8959
+ }
8960
+ if (compareTrains(running, latest) < 0)
8961
+ throw new Error(`plx ${running} is behind ${latest}, the newest release; update it first: mise up npm:${SELF_PACKAGE}`);
8962
+ }
8963
+
8938
8964
  // ../lib/dist/ship.js
8939
8965
  import { join as join10 } from "node:path";
8940
8966
  async function ship(ctx, options) {
8941
8967
  const upstream = join10(options.workspace, UPSTREAM);
8942
8968
  const propagateOnly = options.propagateOnly ?? false;
8969
+ if (options.plx)
8970
+ await preflightSelf(ctx, options.plx);
8943
8971
  const train = await readTrain(ctx, upstream);
8944
8972
  if (!propagateOnly)
8945
8973
  await preflightRelease(ctx, train);
@@ -13901,7 +13929,9 @@ function register(program2) {
13901
13929
  // src/commands/changeset.ts
13902
13930
  import { resolve as resolve2 } from "node:path";
13903
13931
  function register2(program2) {
13904
- program2.command("changeset").description("write the changeset a dependency bump owes: a patch per package whose runtime dependencies moved").argument("[dir]", "a checkout of the package repo, on the bump branch", ".").option("--base <ref>", "the trunk the branch is diffed against, at the merge base", "origin/main").option("--branch <name>", "the branch name that names the file (default: the checked-out branch)").action(async (dir, opts, command) => {
13932
+ program2.command("changeset").description(
13933
+ "write the changeset a dependency bump owes: a patch per package whose runtime dependencies or shipped source moved"
13934
+ ).argument("[dir]", "a checkout of the package repo, on the bump branch", ".").option("--base <ref>", "the trunk the branch is diffed against, at the merge base", "origin/main").option("--branch <name>", "the branch name that names the file (default: the checked-out branch)").action(async (dir, opts, command) => {
13905
13935
  const ctx = contextOf2(command);
13906
13936
  const changeset = await readChangeset(ctx, resolve2(dir), opts.base, opts.branch);
13907
13937
  await ctx.apply(changeset.plan);
@@ -14057,7 +14087,7 @@ import { resolve as resolve7 } from "node:path";
14057
14087
  function register7(program2) {
14058
14088
  program2.command("ship").description("release the train: tag every train repo identically, then copier-update every consumer").argument("[dir]", "the workspace: plexus-ms/ and the consumers sit under it", ".").option("--train <version>", "the train version, plain semver (default: minor+1 over the latest train)").action(async (dir, opts, command) => {
14059
14089
  const ctx = contextOf2(command);
14060
- const result = await ship(ctx, { workspace: resolve7(dir), train: opts.train });
14090
+ const result = await ship(ctx, { workspace: resolve7(dir), train: opts.train, plx: version });
14061
14091
  ctx.result(result, (r) => renderSummary(r, `plx -y ship --train ${r.train} ${dir}`));
14062
14092
  if (!isClean(result)) process.exitCode = 1;
14063
14093
  });
@@ -14083,7 +14113,7 @@ function renderSummary(s, realCommand) {
14083
14113
  function register8(program2) {
14084
14114
  program2.command("propagate").description("copier-update every consumer of the presets to the current train, and pin their ci-cd workflow refs").argument("[dir]", "the workspace: plexus-ms/ and the consumers sit under it", ".").option("--train <version>", "the train to propagate (default: the current one)").action(async (dir, opts, command) => {
14085
14115
  const ctx = contextOf2(command);
14086
- const result = await ship(ctx, { workspace: resolve8(dir), train: opts.train, propagateOnly: true });
14116
+ const result = await ship(ctx, { workspace: resolve8(dir), train: opts.train, propagateOnly: true, plx: version });
14087
14117
  ctx.result(result, (r) => renderSummary(r, `plx -y propagate --train ${r.train} ${dir}`));
14088
14118
  if (!isClean(result)) process.exitCode = 1;
14089
14119
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plexus-ms/cli",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "description": "plx, the Plexus command-line tool: a single-script adapter over @plexus-ms/lib",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "type": "module",
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@inquirer/prompts": "^8.7.4",
27
- "@plexus-ms/lib": "0.6.0",
27
+ "@plexus-ms/lib": "0.8.0",
28
28
  "commander": "^15.0.0"
29
29
  },
30
30
  "devDependencies": {