@mark1russell7/conventions 0.52.3 → 0.52.5

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.
@@ -3265,7 +3265,7 @@ const securityGate = {
3265
3265
  * GitHub fails at times with a 504, and a bare `curl` then fails the job.
3266
3266
  */
3267
3267
  /** The files of a composite action. */
3268
- const ACTION$4 = /^\.github\/actions\/.+\/action\.ya?ml$/;
3268
+ const ACTION$5 = /^\.github\/actions\/.+\/action\.ya?ml$/;
3269
3269
  /** The action of the template itself. It is the one place with the download. */
3270
3270
  const SHARED_ACTION$1 = ".github/actions/setup-cue/action.yml";
3271
3271
  /** A hand-written install of the cue CLI: a download of a release asset, or a build with `go install`. */
@@ -3312,7 +3312,7 @@ const setupCue = {
3312
3312
  const files = context.gitFiles();
3313
3313
  if (files === void 0) return { skipped: "the root is not in a git repository" };
3314
3314
  const breaks = [];
3315
- for (const file of files.filter((path) => (WORKFLOW$1.test(path) || ACTION$4.test(path)) && path !== SHARED_ACTION$1).sort(byCode)) {
3315
+ for (const file of files.filter((path) => (WORKFLOW$1.test(path) || ACTION$5.test(path)) && path !== SHARED_ACTION$1).sort(byCode)) {
3316
3316
  let text;
3317
3317
  try {
3318
3318
  text = readFileSync(join(context.root, file), "utf8");
@@ -3380,7 +3380,7 @@ const SHARED_ACTIONS = [
3380
3380
  /** The `uses` value of a job that calls the shared CI, with no pin. */
3381
3381
  const SHARED_CI = "mark1russell7/template/.github/workflows/reusable-ci.yml";
3382
3382
  /** The action folder of a path: `.github/actions/<name>/action.yml` gives `<name>`. */
3383
- const ACTION$3 = /^\.github\/actions\/([^/]+)\//;
3383
+ const ACTION$4 = /^\.github\/actions\/([^/]+)\//;
3384
3384
  /** The file name of a path. */
3385
3385
  const baseName = (path) => path.slice(path.lastIndexOf("/") + 1);
3386
3386
  /** This function tells if a job of a workflow text uses the shared CI of the template. */
@@ -3444,7 +3444,7 @@ const sharedCi = {
3444
3444
  });
3445
3445
  const actions = /* @__PURE__ */ new Set();
3446
3446
  for (const file of files) {
3447
- const folder = ACTION$3.exec(file)?.[1];
3447
+ const folder = ACTION$4.exec(file)?.[1];
3448
3448
  if (folder !== void 0 && SHARED_ACTIONS.includes(folder) && !actions.has(folder)) {
3449
3449
  actions.add(folder);
3450
3450
  breaks.push({
@@ -3607,7 +3607,7 @@ function importsService(text) {
3607
3607
  /** A call of `run(` on a value, but not on `this`. */
3608
3608
  const RUN_CALL = /(?<!\bthis)\.run\s*\(/;
3609
3609
  /** The source files that the rule reads. */
3610
- const SOURCE = /\.(c|m)?tsx?$/;
3610
+ const SOURCE$1 = /\.(c|m)?tsx?$/;
3611
3611
  /**
3612
3612
  * This function gives the lines (from 1) of the calls of `run(` in a source text that imports the service package. A
3613
3613
  * text that imports only the tool entries (`/channel`, `/clock`, `/heartbeat`, `/backoff`, `/limiter`, `/rules`) has
@@ -3671,7 +3671,7 @@ const serviceRunMain = {
3671
3671
  if (!dependsOnService(info.manifest) || !hasFile(info.dir, main)) continue;
3672
3672
  const prefix = info.folder === "" ? "" : `${info.folder}/`;
3673
3673
  const entry = inFolder(info.folder, main);
3674
- const own = tracked.filter((path) => path.startsWith(`${prefix}src/`) && SOURCE.test(path) && !/\.d\.(c|m)?ts$/.test(path) && path !== entry && !isTestFile(path.slice(prefix.length)));
3674
+ const own = tracked.filter((path) => path.startsWith(`${prefix}src/`) && SOURCE$1.test(path) && !/\.d\.(c|m)?ts$/.test(path) && path !== entry && !isTestFile(path.slice(prefix.length)));
3675
3675
  for (const file of own.sort(byCode)) {
3676
3676
  let text;
3677
3677
  try {
@@ -4862,7 +4862,7 @@ const HOMES = [
4862
4862
  {
4863
4863
  area: "plain-text",
4864
4864
  title: "Plain text helpers",
4865
- covers: "escaping for HTML, attributes, regular expressions and Markdown, case conversion, padding and truncation, templates, English word forms (plurals, lists), the text of a thrown value (it never throws), the redaction of known secrets in a text (the raw form, the URL form and the Basic form). Escaping comes first",
4865
+ covers: "escaping for HTML, attributes, regular expressions and Markdown, case conversion, padding and truncation, templates, English word forms (plurals, lists), the text of a thrown value (it never throws), the redaction of known secrets in a text (the raw form, the URL form and the Basic form), a printer of lines and tables to injected streams (entry /print: the output of a CLI for a person; a diagnostic goes to a log record of otel-ts). Escaping comes first",
4866
4866
  packages: ["@mark1russell7/text"],
4867
4867
  repo: "mark1russell7/text",
4868
4868
  state: "published",
@@ -4883,7 +4883,11 @@ const HOMES = [
4883
4883
  "secret",
4884
4884
  "mask",
4885
4885
  "error message",
4886
- "thrown value"
4886
+ "thrown value",
4887
+ "printer",
4888
+ "cli output",
4889
+ "status line",
4890
+ "console"
4887
4891
  ],
4888
4892
  signatures: [
4889
4893
  "escapeHtml",
@@ -4896,7 +4900,8 @@ const HOMES = [
4896
4900
  "snakeCase",
4897
4901
  "pluralize",
4898
4902
  "redactSecrets",
4899
- "errorMessage"
4903
+ "errorMessage",
4904
+ "createPrinter"
4900
4905
  ]
4901
4906
  },
4902
4907
  {
@@ -17015,7 +17020,7 @@ function unpublishedNote(home) {
17015
17020
  return home.state === "unpublished" ? ` (not on npm: use workspace:* inside ${home.repo}; elsewhere a github: specifier pinned to a commit works only if ${home.repo} keeps its built files in git, else wait for the first npm publish)` : "";
17016
17021
  }
17017
17022
  /** This function gives the message of a break: the home, and if the home already exports the name. */
17018
- function messageOf(file, name, home) {
17023
+ function messageOf$1(file, name, home) {
17019
17024
  const exporter = home.packages.find((pkg) => HOME_EXPORTS[pkg]?.names.includes(name) === true);
17020
17025
  const where = home.packages.length === 0 ? home.repo : home.packages.map((pkg) => `\`${pkg}\``).join(", ");
17021
17026
  const use = unpublishedNote(home);
@@ -17071,7 +17076,7 @@ const homePackage = {
17071
17076
  if (signature !== void 0) breaks.push({
17072
17077
  file,
17073
17078
  line: index + 1,
17074
- message: messageOf(file, name, signature.home)
17079
+ message: messageOf$1(file, name, signature.home)
17075
17080
  });
17076
17081
  });
17077
17082
  }
@@ -17091,7 +17096,7 @@ const homePackage = {
17091
17096
  */
17092
17097
  const STATIC = /^[ \t]*(?:import|export)[ \t]+(type[ \t]+)?(?:(?:(?!\b(?:import|export)\b)[^;=()"'`])*?\bfrom[ \t]*)?(["'])([^"'\r\n]+)\2/gm;
17093
17098
  /** A call that loads a module: `import("x")`, `require("x")` or `process.getBuiltinModule("x")`. */
17094
- const CALL = /\b(import|require|getBuiltinModule)[ \t]*\([ \t]*(["'`])([^"'`\r\n]+)\2[ \t]*\)/g;
17099
+ const CALL$1 = /\b(import|require|getBuiltinModule)[ \t]*\([ \t]*(["'`])([^"'`\r\n]+)\2[ \t]*\)/g;
17095
17100
  /** The text after `import("x")` that makes it a type: a member that is not a method of a promise. */
17096
17101
  const TYPE_MEMBER = /^[ \t]*\.[ \t]*(?!then\b|catch\b|finally\b)[A-Za-z_$]/;
17097
17102
  /** This function gives the line (from 1) of each index of `text`, by the starts of the lines. */
@@ -17129,7 +17134,7 @@ function moduleUses(text) {
17129
17134
  }
17130
17135
  });
17131
17136
  }
17132
- for (const match of text.matchAll(CALL)) {
17137
+ for (const match of text.matchAll(CALL$1)) {
17133
17138
  const start = text.lastIndexOf("\n", match.index) + 1;
17134
17139
  const before = text.slice(start, match.index);
17135
17140
  if (before.includes("//") || /^[ \t]*(?:\*|\/\*)/.test(before)) continue;
@@ -17716,7 +17721,7 @@ function movedTo(repo, moves) {
17716
17721
  * Each run of the workflow then fails before it starts ("workflow file issue"), and no job shows why.
17717
17722
  */
17718
17723
  /** The files of a composite action. */
17719
- const ACTION$2 = /^\.github\/actions\/.+\/action\.ya?ml$/;
17724
+ const ACTION$3 = /^\.github\/actions\/.+\/action\.ya?ml$/;
17720
17725
  /** The value of `uses:` that names another repository: `owner/name`, then a path or nothing, then `@` and the ref. */
17721
17726
  const REMOTE = /^([\w.-]+)\/([\w.-]+)(\/[^@\s]*)?@\S+$/;
17722
17727
  /** This function gives each `uses:` of a workflow or an action that names another repository. A local path (`./`) and a Docker image (`docker://`) are not calls of a repository. */
@@ -17772,7 +17777,7 @@ const movedRepoCalls = {
17772
17777
  if (bad !== void 0) return { skipped: `the option moves has "${bad.text}", which is not in the form owner/name=owner/name` };
17773
17778
  const moves = [...MOVES, ...extra.map((each) => each.move)];
17774
17779
  const breaks = [];
17775
- for (const file of files.filter((path) => WORKFLOW$1.test(path) || ACTION$2.test(path)).sort(byCode)) {
17780
+ for (const file of files.filter((path) => WORKFLOW$1.test(path) || ACTION$3.test(path)).sort(byCode)) {
17776
17781
  let text;
17777
17782
  try {
17778
17783
  text = readFileSync(join(context.root, file), "utf8");
@@ -17875,7 +17880,7 @@ const MANIFEST = /(^|\/)package\.json$/;
17875
17880
  const MARKDOWN = /\.mdx?$/i;
17876
17881
  const CHANGELOG = /(^|\/)CHANGELOG\.md$/i;
17877
17882
  /** A file of a composite action. */
17878
- const ACTION$1 = /^\.github\/actions\/.+\/action\.ya?ml$/;
17883
+ const ACTION$2 = /^\.github\/actions\/.+\/action\.ya?ml$/;
17879
17884
  /** The kinds of place of the core, in the order of a report. */
17880
17885
  const PLACE_KINDS = [
17881
17886
  {
@@ -17893,7 +17898,7 @@ const PLACE_KINDS = [
17893
17898
  {
17894
17899
  id: "workflow-names",
17895
17900
  title: "The addresses and each key repository of a workflow or a composite action, except uses: (the rule moved-repo-calls).",
17896
- reads: (file) => WORKFLOW$1.test(file) || ACTION$1.test(file),
17901
+ reads: (file) => WORKFLOW$1.test(file) || ACTION$2.test(file),
17897
17902
  find: (text) => {
17898
17903
  const skip = (line) => line.trimStart().startsWith("#") || keyValue(line, "uses") !== void 0;
17899
17904
  const keys = [];
@@ -18082,6 +18087,126 @@ const noBuildOutput = {
18082
18087
  }));
18083
18088
  }
18084
18089
  };
18090
+ // src/rules/no-console.ts
18091
+ /**
18092
+ * The rule `no-console`: no source file calls `console`. Each call is one of two kinds, and the break names the kind.
18093
+ *
18094
+ * - Output for a person: the text, the tables and the status lines of a command-line tool. It goes to the printer of
18095
+ * `@mark1russell7/text/print` (`createPrinter`), with the streams as parameters.
18096
+ * - A diagnostic of a library or a service: a warning, a debug line, a caught error. It goes to a log record through the
18097
+ * logger of `@mark1russell7/otel-ts` (`getLogger`), with its trace context, and not to a printer.
18098
+ *
18099
+ * A call in a CLI file is output, except `console.debug` and `console.trace`. A CLI file starts with `#!`, has the name
18100
+ * `cli`, `main` or a folder `bin` or `commands` in its path, or reads `process.argv`. Each other call is a diagnostic,
18101
+ * except `console.table`, which is output. Until a repository sets the option `fail`, a break is a warning. A repository
18102
+ * sets the option when its count is 0, so the count cannot grow again.
18103
+ */
18104
+ /** The files that the rule reads: the sources of JavaScript and TypeScript, and the pages and components that hold scripts. */
18105
+ const SOURCE = /\.(?:[cm]?[jt]s|[jt]sx|svelte|vue|html)$/;
18106
+ /** The files that are not sources: tests, fixtures, scripts, benches and examples. The census of 2026-11-25 uses the same split. */
18107
+ const NOT_SOURCE = [
18108
+ "**/*.d.ts",
18109
+ "**/*.test.*",
18110
+ "**/*.spec.*",
18111
+ "**/*.e2e.*",
18112
+ "**/*.probe.ts",
18113
+ "**/test/**",
18114
+ "**/tests/**",
18115
+ "**/__tests__/**",
18116
+ "**/e2e/**",
18117
+ "**/fixture/**",
18118
+ "**/fixtures/**",
18119
+ "**/script/**",
18120
+ "**/scripts/**",
18121
+ "**/bin/**",
18122
+ "**/tools/**",
18123
+ "**/bench/**",
18124
+ "**/benches/**",
18125
+ "**/benchmark/**",
18126
+ "**/benchmarks/**",
18127
+ "**/example/**",
18128
+ "**/examples/**",
18129
+ "**/demo/**"
18130
+ ];
18131
+ /** A call of a method of `console`. The group `method` is the name of the method. */
18132
+ const CALL = /\bconsole\s*\.\s*(?<method>[A-Za-z]+)\s*\(/g;
18133
+ /** A line that is a comment: it starts with `//`, `/*` or `*`. */
18134
+ const COMMENT = /^\s*(?:\/\/|\/\*|\*)/;
18135
+ /** The path of a CLI file: a folder `cli`, `bin` or `commands`, or a file `cli.*` or `main.*`. */
18136
+ const CLI_PATH = /(?:^|\/)(?:cli|bin|commands?)(?:\/|\.)|(?:^|[/._-])(?:cli|main)\.[a-z]+$/;
18137
+ /** This function tells if a source file is a CLI file: it starts with `#!`, its path names a CLI, or it reads `process.argv`. */
18138
+ function isCliFile(file, text) {
18139
+ return text.startsWith("#!") || CLI_PATH.test(file) || /\bprocess\.argv\b/.test(text);
18140
+ }
18141
+ /** This function gives the kind of a call of `console.<method>` in a file. */
18142
+ function consoleKind(cli, method) {
18143
+ if (method === "table") return "output";
18144
+ return cli && method !== "debug" && method !== "trace" ? "output" : "diagnostic";
18145
+ }
18146
+ /** This function gives the message of a break: the call, its kind and where it goes. */
18147
+ function messageOf(file, method, kind) {
18148
+ return kind === "output" ? `${file} calls console.${method} for output to a person. Write it with createPrinter of @mark1russell7/text/print.` : `${file} calls console.${method} for a diagnostic. Emit a log record with the logger of @mark1russell7/otel-ts (getLogger), with its trace context.`;
18149
+ }
18150
+ /** This function gives a break for each call of `console` in the text of one source file. */
18151
+ function consoleBreaks(file, text) {
18152
+ const cli = isCliFile(file, text);
18153
+ const breaks = [];
18154
+ text.split(/\r?\n/).forEach((line, index) => {
18155
+ if (COMMENT.test(line)) return;
18156
+ for (const match of line.matchAll(CALL)) {
18157
+ const method = match.groups?.["method"] ?? "";
18158
+ breaks.push({
18159
+ file,
18160
+ line: index + 1,
18161
+ message: messageOf(file, method, consoleKind(cli, method))
18162
+ });
18163
+ }
18164
+ });
18165
+ return breaks;
18166
+ }
18167
+ const noConsole = {
18168
+ id: "no-console",
18169
+ title: "No source file calls `console`: output for a person goes to the printer of `@mark1russell7/text/print`, and a diagnostic goes to a log record of `@mark1russell7/otel-ts`.",
18170
+ reason: "A console line has no trace id, no level that a collector reads and no redaction of secrets. A diagnostic then does not join the trace of its request, and the output of a CLI cannot go to a buffer in a test. A census of 2026-11-25 found 1549 console calls in the sources of 36 repositories.",
18171
+ fix: "Write the output of a CLI with createPrinter({ out: process.stdout, err: process.stderr }) of @mark1russell7/text/print. Emit each diagnostic of a library or a service with the logger of @mark1russell7/otel-ts. When the count is 0, set the option fail: true.",
18172
+ sources: [{
18173
+ repo: "private",
18174
+ rule: "no-console",
18175
+ doc: "a decision of 2026-11-25: no raw console, one printer for output and one logger for diagnostics"
18176
+ }],
18177
+ options: {
18178
+ fail: {
18179
+ type: "boolean",
18180
+ default: false,
18181
+ description: "A break fails the check. Until a repository sets it, a break is a warning. Set it when the count is 0."
18182
+ },
18183
+ skip: {
18184
+ type: "strings",
18185
+ default: NOT_SOURCE,
18186
+ description: "The globs of the files that are not sources: tests, fixtures, scripts, benches and examples."
18187
+ }
18188
+ },
18189
+ failsFrom: "2026-12-09",
18190
+ check(context, options) {
18191
+ const files = context.gitFiles();
18192
+ if (files === void 0) return { skipped: "the root is not in a git repository" };
18193
+ const skip = options["skip"];
18194
+ const breaks = [];
18195
+ for (const file of files.filter((path) => SOURCE.test(path) && !matchesAny(path, skip)).sort(byCode)) {
18196
+ let text;
18197
+ try {
18198
+ text = readFileSync(join(context.root, file), "utf8");
18199
+ } catch {
18200
+ continue;
18201
+ }
18202
+ if (text.includes("console")) breaks.push(...consoleBreaks(file, text));
18203
+ }
18204
+ return breaks;
18205
+ },
18206
+ warnOnly(options) {
18207
+ return options["fail"] === true ? void 0 : "The rule fails in a repository that sets the option fail: true, when its count is 0.";
18208
+ }
18209
+ };
18085
18210
  // src/private-names.ts
18086
18211
  /**
18087
18212
  * The private name list: a JSON file outside of the public repositories, with the names of private projects. The file
@@ -20971,7 +21096,7 @@ const jobFails = {
20971
21096
  * more try. A bare `playwright install --with-deps` waits for the package mirror with no limit.
20972
21097
  */
20973
21098
  /** The files of a composite action. */
20974
- const ACTION = /^\.github\/actions\/.+\/action\.ya?ml$/;
21099
+ const ACTION$1 = /^\.github\/actions\/.+\/action\.ya?ml$/;
20975
21100
  /** The folder of the action of the template itself. It is the one place with the install. */
20976
21101
  const SHARED_ACTION = ".github/actions/setup-playwright/";
20977
21102
  /**
@@ -21048,7 +21173,7 @@ const playwrightInstall = {
21048
21173
  return;
21049
21174
  }
21050
21175
  };
21051
- for (const file of files.filter((path) => (WORKFLOW$1.test(path) || ACTION.test(path)) && !path.startsWith(SHARED_ACTION)).sort(byCode)) {
21176
+ for (const file of files.filter((path) => (WORKFLOW$1.test(path) || ACTION$1.test(path)) && !path.startsWith(SHARED_ACTION)).sort(byCode)) {
21052
21177
  const text = read(file);
21053
21178
  if (text === void 0) continue;
21054
21179
  for (const install of playwrightInstalls(text)) breaks.push({
@@ -24021,6 +24146,7 @@ const RULES = [
24021
24146
  requiredScripts,
24022
24147
  noBuildOutput,
24023
24148
  noLocalPaths,
24149
+ noConsole,
24024
24150
  apiReportScript,
24025
24151
  releaseFiles,
24026
24152
  unreleasedChange,
@@ -24548,6 +24674,114 @@ function installHook(options, io) {
24548
24674
  io.stdout(`conventions hook install: ${before === void 0 ? "wrote" : "updated"} ${shown}.\n`);
24549
24675
  return 0;
24550
24676
  }
24677
+ // src/move-plan.ts
24678
+ /**
24679
+ * The plan of a move of a repository to another owner. It has each place of a repository that names the old name, and each
24680
+ * step that no file holds. The rules `moved-repo-names` and `moved-repo-calls` read the same places, so the plan and the gate
24681
+ * agree. A step is data: its id, what to do, and the function that tells if the places of the plan need it.
24682
+ *
24683
+ * This file reads no file and starts no program. The command `conventions move plan` gives it the files of git.
24684
+ */
24685
+ /** The files of a composite action. */
24686
+ const ACTION = /^\.github\/actions\/.+\/action\.ya?ml$/;
24687
+ /** The steps of a move that no file holds, in the order of the work. */
24688
+ const MOVE_STEPS = [
24689
+ {
24690
+ id: "npm-trust",
24691
+ title: "For each package that this repository publishes, add a trusted publisher on npm for the new repository, before the next release: npm provenance compares the field repository with the repository of the run.",
24692
+ needed: (places) => places.some((place) => place.kind === "package-fields" && place.file.endsWith("package.json"))
24693
+ },
24694
+ {
24695
+ id: "pages-address",
24696
+ title: "The GitHub Pages address changes to the new owner. Make sure that each link from outside the repository (a profile, a package page, another site) uses the new address: the old address gives 404.",
24697
+ needed: (places) => places.some((place) => place.form === "pages")
24698
+ },
24699
+ {
24700
+ id: "workflow-calls",
24701
+ title: "Each repository that calls a workflow or an action of the moved repository needs the new name in its uses: line: GitHub does not follow the move for uses:. Run this plan in each such repository.",
24702
+ needed: () => true
24703
+ },
24704
+ {
24705
+ id: "clone-remotes",
24706
+ title: "In each clone, write the new address of the remote: git remote set-url origin https://github.com/<new owner>/<name>.git.",
24707
+ needed: () => true
24708
+ }
24709
+ ];
24710
+ /** This function gives the plan of the moves over the files of a repository, in the order of the files and the lines. */
24711
+ function movePlan(files, moves) {
24712
+ const places = [];
24713
+ for (const file of files) {
24714
+ if (PLACE_KINDS.some((kind) => kind.reads(file.path))) for (const place of stalePlaces(file.path, file.text, moves)) places.push(toPlace(place));
24715
+ if (WORKFLOW$1.test(file.path) || ACTION.test(file.path)) for (const call of remoteCalls(file.text)) {
24716
+ const to = movedTo(call.repo, moves);
24717
+ if (to !== void 0) places.push({
24718
+ file: file.path,
24719
+ line: call.line,
24720
+ kind: "workflow-calls",
24721
+ text: call.repo,
24722
+ replacement: to,
24723
+ form: "repo"
24724
+ });
24725
+ }
24726
+ }
24727
+ places.sort((a, b) => a.file < b.file ? -1 : a.file > b.file ? 1 : a.line - b.line);
24728
+ return {
24729
+ moves,
24730
+ places,
24731
+ steps: MOVE_STEPS.filter((step) => step.needed(places))
24732
+ };
24733
+ }
24734
+ function toPlace(place) {
24735
+ return {
24736
+ file: place.file,
24737
+ line: place.line,
24738
+ kind: place.kind,
24739
+ text: place.text,
24740
+ replacement: place.replacement,
24741
+ form: place.form
24742
+ };
24743
+ }
24744
+ /**
24745
+ * This function gives each file that the moves change, with its new text. It writes each place of a kind of `places.ts`.
24746
+ * It also writes each `uses:` line that names a moved repository. A file with no place is not in the result.
24747
+ */
24748
+ function applyMoves(files, moves) {
24749
+ const changed = [];
24750
+ for (const file of files) {
24751
+ let text = file.text;
24752
+ if (PLACE_KINDS.some((kind) => kind.reads(file.path))) text = replacePlaces(text, stalePlaces(file.path, text, moves));
24753
+ if (WORKFLOW$1.test(file.path) || ACTION.test(file.path)) {
24754
+ const calls = remoteCalls(text);
24755
+ if (calls.length > 0) {
24756
+ const eol = text.includes("\r\n") ? "\r\n" : "\n";
24757
+ const lines = text.split(/\r?\n/);
24758
+ for (const call of calls) {
24759
+ const to = movedTo(call.repo, moves);
24760
+ const line = lines[call.line - 1];
24761
+ if (to !== void 0 && line !== void 0) lines[call.line - 1] = movedLine(line, call.repo, to);
24762
+ }
24763
+ text = lines.join(eol);
24764
+ }
24765
+ }
24766
+ if (text !== file.text) changed.push({
24767
+ path: file.path,
24768
+ text
24769
+ });
24770
+ }
24771
+ return changed;
24772
+ }
24773
+ /** This function gives the plan as text: one line for each place, then the steps. */
24774
+ function movePlanText(plan) {
24775
+ const lines = [`The plan of ${plan.moves.map((move) => `${move.from} to ${move.to}`).join(", ")}:`];
24776
+ if (plan.places.length === 0) lines.push("", "No file names an old name.");
24777
+ else {
24778
+ lines.push("", `${plan.places.length} places. \`conventions move apply\` with the same moves writes each one:`);
24779
+ for (const place of plan.places) lines.push(` ${place.file}:${place.line} ${place.kind} ${place.text} -> ${place.replacement}`);
24780
+ }
24781
+ lines.push("", "The steps that no file holds:");
24782
+ plan.steps.forEach((step, index) => lines.push(` ${index + 1}. ${step.title}`));
24783
+ return `${lines.join("\n")}\n`;
24784
+ }
24551
24785
  // src/run.ts
24552
24786
  /**
24553
24787
  * The commands `check`, `fix` and `--list` of the bin `conventions`, as functions. `runChecks` starts the
@@ -24685,8 +24919,14 @@ function runChecks(options) {
24685
24919
  message: `The entry \`${glob}\` of \`${field}\` matches no break of this rule. Remove it from the field \`conventions\`.`
24686
24920
  });
24687
24921
  }
24688
- const warns = breaks.length > 0 && rule.failsFrom !== void 0 && today < rule.failsFrom;
24689
- const reason = warns ? [ruleConfig.reason, `The rule fails from ${rule.failsFrom ?? ""}.`].filter((text) => text !== void 0).join(" ") : ruleConfig.reason;
24922
+ const beforeDay = rule.failsFrom !== void 0 && today < rule.failsFrom;
24923
+ const optIn = breaks.length > 0 ? rule.warnOnly?.(ruleConfig.options) : void 0;
24924
+ const warns = breaks.length > 0 && (beforeDay || optIn !== void 0);
24925
+ const reason = warns ? [
24926
+ ruleConfig.reason,
24927
+ beforeDay ? `The rule fails from ${rule.failsFrom ?? ""}.` : void 0,
24928
+ optIn
24929
+ ].filter((text) => text !== void 0).join(" ") : ruleConfig.reason;
24690
24930
  const note = reason === void 0 ? {} : { note: reason };
24691
24931
  let noRead;
24692
24932
  try {
@@ -24855,6 +25095,7 @@ const USAGE = `Usage: conventions check [options]
24855
25095
  conventions pre-push <remote> [<url>]
24856
25096
  conventions pre-push --base <ref> [--head <ref>]
24857
25097
  conventions hook install
25098
+ conventions move plan|apply <owner/name=owner/name>... [--known] [--root <folder>] [--json]
24858
25099
 
24859
25100
  check Start each rule. Exit code 1 when a rule has a break.
24860
25101
  fix Write the fixes of the breaks that have one, and check again. Exit code 1 when a break stays.
@@ -24871,6 +25112,11 @@ const USAGE = `Usage: conventions check [options]
24871
25112
  request of the run. It reads no standard input.
24872
25113
  hook install Write the hook pre-push into the hooks folder of git. It keeps a hook that it did not write.
24873
25114
  In CI, or outside a git repository, it does nothing.
25115
+ move plan Show each place of the repository that names a moved repository by its old name (package
25116
+ fields, Markdown links, workflow keys and uses: lines, config values), and the steps of the
25117
+ move that no file holds (npm trust, the Pages address, the callers, the remotes). --known adds
25118
+ the moves that the package knows.
25119
+ move apply Write the new name in each place of the plan, and show the plan that stays.
24874
25120
 
24875
25121
  --root <folder> The root of the repository. The default is the current folder.
24876
25122
  --rule <id> Only this rule. Use it again for more rules.
@@ -24931,6 +25177,7 @@ function runCli(args, io) {
24931
25177
  if (args[0] === "map") return runMap(args.slice(1), io);
24932
25178
  if (args[0] === "pre-push") return runPrePush(args.slice(1), io);
24933
25179
  if (args[0] === "hook") return runHook(args.slice(1), io);
25180
+ if (args[0] === "move") return runMove(args.slice(1), io);
24934
25181
  let check = false;
24935
25182
  let fix = false;
24936
25183
  let list = false;
@@ -25014,6 +25261,77 @@ function runCli(args, io) {
25014
25261
  return result.failed ? 1 : 0;
25015
25262
  }
25016
25263
  /** The command `map`: the home of each area, or of the areas that match the words. */
25264
+ /** This function starts `conventions move plan` or `conventions move apply`. */
25265
+ function runMove(args, io) {
25266
+ const [action, ...rest] = args;
25267
+ const moves = [];
25268
+ let root = io.cwd;
25269
+ let json = false;
25270
+ let known = false;
25271
+ const usage = (message) => {
25272
+ io.stderr(`conventions: ${message}
25273
+
25274
+ ${USAGE}`);
25275
+ return 2;
25276
+ };
25277
+ if (action !== "plan" && action !== "apply") return usage("Give the command move plan or move apply.");
25278
+ for (let index = 0; index < rest.length; index++) {
25279
+ const arg = rest[index] ?? "";
25280
+ if (arg === "--json") json = true;
25281
+ else if (arg === "--known") known = true;
25282
+ else if (arg === "--root") {
25283
+ const next = rest[++index];
25284
+ if (next === void 0 || next.startsWith("-")) return usage("The option --root needs a value.");
25285
+ root = resolve(io.cwd, next);
25286
+ } else if (arg.startsWith("-")) return usage(`An unknown argument: ${arg}`);
25287
+ else {
25288
+ const move = parseMove(arg);
25289
+ if (move === void 0) return usage(`The move "${arg}" is not in the form owner/name=owner/name.`);
25290
+ moves.push(move);
25291
+ }
25292
+ }
25293
+ if (known) moves.push(...MOVES);
25294
+ if (moves.length === 0) return usage("Give one move or more, or --known.");
25295
+ const listed = runGit(root, [
25296
+ "ls-files",
25297
+ "-z",
25298
+ "--cached"
25299
+ ]);
25300
+ if (listed === void 0) {
25301
+ io.stderr(`conventions: ${root} is not in a git repository.
25302
+ `);
25303
+ return 1;
25304
+ }
25305
+ const read = () => listed.split("\0").filter((path) => path !== "").flatMap((path) => {
25306
+ try {
25307
+ return [{
25308
+ path,
25309
+ text: readFileSync(join(root, path), "utf8")
25310
+ }];
25311
+ } catch {
25312
+ return [];
25313
+ }
25314
+ });
25315
+ if (action === "apply") {
25316
+ const changed = applyMoves(read(), moves);
25317
+ for (const file of changed) writeFileSync(join(root, file.path), file.text);
25318
+ if (!json) io.stdout(`Wrote ${changed.length} files.
25319
+
25320
+ `);
25321
+ }
25322
+ const plan = movePlan(read(), moves);
25323
+ if (json) io.stdout(`${JSON.stringify({
25324
+ moves: plan.moves,
25325
+ places: plan.places,
25326
+ steps: plan.steps.map(({ id, title }) => ({
25327
+ id,
25328
+ title
25329
+ }))
25330
+ }, null, 2)}
25331
+ `);
25332
+ else io.stdout(movePlanText(plan));
25333
+ return 0;
25334
+ }
25017
25335
  function runMap(args, io) {
25018
25336
  let format = "text";
25019
25337
  let homes = HOMES;
@@ -25069,6 +25387,6 @@ function runHook(args, io) {
25069
25387
  git: (gitArgs) => runGit(io.cwd, gitArgs)
25070
25388
  }, io);
25071
25389
  }
25072
- export { requiredScripts as $, LICENSE_TEXTS as $n, noBuildOutput as $t, scriptsOf as A, SHARED_ACTIONS as An, parseJsonc as Ar, packNoBuildinfo as At, TEMPLATE_CALLED as B, SUMMARY_GATES as Bn, parseRuleConfig as Br, privatePatterns as Bt, setVersions as C, npmNames as Cn, codePackages as Cr, pagesAfterRelease as Ct, trustPolicy as D, serviceRunMain as Dn, lineOf as Dr, pagesSite as Dt, TRAIN_SCOPES as E, runCalls as En, keyLine as Er, pagesCalls as Et, sourceMain as F, setupCue as Fn, runGitShow as Fr, PRIVATE_PATTERNS_VARIABLE as Ft, runnerPeak as G, SECURITY_SCAN_COMMIT as Gn, isAllowedHit as Gt, calledJobs as H, hasSummaryJob as Hn, PRIVATE_NAME_LIST as Ht, HOME_TIMEOUT_MS as I, SECURITY_FILE as In, showFiles as Ir, invalidPatternBreaks as It, evaluateExpression as J, securityCallers as Jn, lineNameHits as Jt, runsAtOnce as K, SECURITY_SCAN_INPUTS as Kn, isCommonUse as Kt, blockHash as L, isSecurityGate as Ln, specifiersOf as Lr, noLocalPaths as Lt, testsRequired as M, SHARED_WORKFLOWS as Mn, replaceLine as Mr, HOME_PATTERNS as Mt, isSourcePath as N, callsSharedCi as Nn, repositoryOfRemote as Nr, PRIVATE_NAMES_FILE_CONFIG as Nt, typedScripts as O, hasTests as On, matchesAny as Or, exportsRequire as Ot, pathsOf as P, sharedCi as Pn, runGit as Pr, PRIVATE_NAMES_FILE_VARIABLE as Pt, roadmapParses as Q, scheduleMinute as Qn, pathNameHit as Qt, githubFetch as R, securityGate as Rn, defaultOptions as Rr, privateNamesFile as Rt, namedVersions as S, npmDrift as Sn, cleanPath as Sr, siteCheckInCi as St, IGNORE_AFTER as T, SERVICE_PACKAGE as Tn, inFolder as Tr, PAGES_WORKFLOWS as Tt, eventClass as U, startsOnPullRequest as Un, PrivateNameListError as Ut, UNKNOWN_MATRIX_JOBS as V, addSummaryJob as Vn, privateTextBreaks as Vt, matrixPeak as W, summaryJobRule as Wn, firstNameMatch as Wt, mayRun as X, withOneJob as Xn, nameMatches as Xt, groupParts as Y, securityOneJob as Yn, mergePrivateNames as Yt, roadmapOfLine as Z, runnerBudget as Zn, parsePrivateNames as Zt, runPrePushArgs as _, MAP_RULE as _n, yamlFaults as _r, swallowsTests as _t, listRules as a, homeModule as an, ACTIONS_COMMIT as ar, reachOf as at, GITHUB_YAML as b, mapText as bn, DEPENDENCY_FIELDS as br, isPinned as bt, runCli as c, modulesOf as cn, prPathFilters as cr, UNSHIPPED_FILES as ct, HOOK_MARKER as d, messageOf as dn, summaryName as dr, unreleasedChangeRule as dt, REAL_COMPARE as en, authorOf as er, releaseFiles as et, NO_READ_LINE as f, repoOf as fn, gateAfterCancel as fr, playwrightInstall as ft, prePush as g, HOMES as gn, readWorkflow as gr, startsTests as gt, parsePrePushArgs as h, HOME_EXPORTS as hn, readAction as hr, parseAdvisory as ht, formatResult as i, apiReportScript as in, repositoryIsPublic as ir, publishedMinorRule as it, typedFiles as j, SHARED_CI as jn, readJsonc as jr, DEFAULT_ALLOWED as jt, configsOfScript as k, tsconfigTest as kn, parseCatFileBatch as kr, publishTextSafe as kt, runFix as l, declaredName as ln, skippableJobs as lr, npmLookup as lt, installHook as m, signaturesOf as mn, parseWorkflow as mr, jobFails as mt, annotations as n, mainCheck as nn, licenseFileOf as nr, minorOf as nt, readConfig as o, moduleMessage as on, convertGate as or, NPM_REGISTRY as ot, PRE_PUSH_HOOK as p, reposOf as pn, MATRIX_EXPAND_MAX as pr, hiddenFailures as pt, workflowPeaks as q, SECURITY_TIMEOUT_MINUTES as qn, lineNameHit as qt, createContext as r, coverageProvider as rn, mitText as rr, publishedMinor as rt, runChecks as s, moduleUses as sn, gateTrigger as sr, SHIPPED_FIELDS as st, USAGE as t, hasImportMetaMain as tn, licenseFile as tr, lockedVersions as tt, summaryMarkdown as u, homePackage as un, summaryJob as ur, unreleasedChange as ut, RULES as v, findHomes as vn, STRICT_OPTIONS as vr, pipeFails as vt, versionTitle as w, readOverlay as wn, hasFile as wr, pushMainOnly as wt, workflowParses as x, mergeHomes as xn, RULE_WARN_DAYS as xr, pinnedGitDeps as xt, workspaceProtocol as y, mapMarkdown as yn, cuePreset as yr, isGitSpecifier as yt, sharedDocsRule as z, securityWorkflow as zn, parseConfig as zr, privateNamesFiles as zt };
25390
+ export { requiredScripts as $, securityCallers as $n, NOT_SOURCE as $t, scriptsOf as A, SERVICE_PACKAGE as An, inFolder as Ar, packNoBuildinfo as At, TEMPLATE_CALLED as B, setupCue as Bn, runGitShow as Br, privatePatterns as Bt, setVersions as C, findHomes as Cn, STRICT_OPTIONS as Cr, pagesAfterRelease as Ct, trustPolicy as D, npmDrift as Dn, cleanPath as Dr, pagesSite as Dt, TRAIN_SCOPES as E, mergeHomes as En, RULE_WARN_DAYS as Er, pagesCalls as Et, sourceMain as F, SHARED_ACTIONS as Fn, parseJsonc as Fr, PRIVATE_PATTERNS_VARIABLE as Ft, runnerPeak as G, SUMMARY_GATES as Gn, parseRuleConfig as Gr, isAllowedHit as Gt, calledJobs as H, isSecurityGate as Hn, specifiersOf as Hr, PRIVATE_NAME_LIST as Ht, HOME_TIMEOUT_MS as I, SHARED_CI as In, readJsonc as Ir, invalidPatternBreaks as It, evaluateExpression as J, startsOnPullRequest as Jn, lineNameHits as Jt, runsAtOnce as K, addSummaryJob as Kn, isCommonUse as Kt, blockHash as L, SHARED_WORKFLOWS as Ln, replaceLine as Lr, noLocalPaths as Lt, testsRequired as M, serviceRunMain as Mn, lineOf as Mr, HOME_PATTERNS as Mt, isSourcePath as N, hasTests as Nn, matchesAny as Nr, PRIVATE_NAMES_FILE_CONFIG as Nt, typedScripts as O, npmNames as On, codePackages as Or, exportsRequire as Ot, pathsOf as P, tsconfigTest as Pn, parseCatFileBatch as Pr, PRIVATE_NAMES_FILE_VARIABLE as Pt, roadmapParses as Q, SECURITY_TIMEOUT_MINUTES as Qn, pathNameHit as Qt, githubFetch as R, callsSharedCi as Rn, repositoryOfRemote as Rr, privateNamesFile as Rt, namedVersions as S, MAP_RULE as Sn, yamlFaults as Sr, siteCheckInCi as St, IGNORE_AFTER as T, mapText as Tn, DEPENDENCY_FIELDS as Tr, PAGES_WORKFLOWS as Tt, eventClass as U, securityGate as Un, defaultOptions as Ur, PrivateNameListError as Ut, UNKNOWN_MATRIX_JOBS as V, SECURITY_FILE as Vn, showFiles as Vr, privateTextBreaks as Vt, matrixPeak as W, securityWorkflow as Wn, parseConfig as Wr, firstNameMatch as Wt, mayRun as X, SECURITY_SCAN_COMMIT as Xn, nameMatches as Xt, groupParts as Y, summaryJobRule as Yn, mergePrivateNames as Yt, roadmapOfLine as Z, SECURITY_SCAN_INPUTS as Zn, parsePrivateNames as Zt, runPrePushArgs as _, repoOf as _n, gateAfterCancel as _r, swallowsTests as _t, listRules as a, REAL_COMPARE as an, authorOf as ar, reachOf as at, GITHUB_YAML as b, HOME_EXPORTS as bn, readAction as br, isPinned as bt, runCli as c, coverageProvider as cn, mitText as cr, UNSHIPPED_FILES as ct, HOOK_MARKER as d, moduleMessage as dn, convertGate as dr, unreleasedChangeRule as dt, consoleBreaks as en, securityOneJob as er, releaseFiles as et, NO_READ_LINE as f, moduleUses as fn, gateTrigger as fr, playwrightInstall as ft, prePush as g, messageOf$1 as gn, summaryName as gr, startsTests as gt, parsePrePushArgs as h, homePackage as hn, summaryJob as hr, parseAdvisory as ht, formatResult as i, noBuildOutput as in, LICENSE_TEXTS as ir, publishedMinorRule as it, typedFiles as j, runCalls as jn, keyLine as jr, DEFAULT_ALLOWED as jt, configsOfScript as k, readOverlay as kn, hasFile as kr, publishTextSafe as kt, runFix as l, apiReportScript as ln, repositoryIsPublic as lr, npmLookup as lt, installHook as m, declaredName as mn, skippableJobs as mr, jobFails as mt, annotations as n, isCliFile as nn, runnerBudget as nr, minorOf as nt, readConfig as o, hasImportMetaMain as on, licenseFile as or, NPM_REGISTRY as ot, PRE_PUSH_HOOK as p, modulesOf as pn, prPathFilters as pr, hiddenFailures as pt, workflowPeaks as q, hasSummaryJob as qn, lineNameHit as qt, createContext as r, noConsole as rn, scheduleMinute as rr, publishedMinor as rt, runChecks as s, mainCheck as sn, licenseFileOf as sr, SHIPPED_FIELDS as st, USAGE as t, consoleKind as tn, withOneJob as tr, lockedVersions as tt, summaryMarkdown as u, homeModule as un, ACTIONS_COMMIT as ur, unreleasedChange as ut, RULES as v, reposOf as vn, MATRIX_EXPAND_MAX as vr, pipeFails as vt, versionTitle as w, mapMarkdown as wn, cuePreset as wr, pushMainOnly as wt, workflowParses as x, HOMES as xn, readWorkflow as xr, pinnedGitDeps as xt, workspaceProtocol as y, signaturesOf as yn, parseWorkflow as yr, isGitSpecifier as yt, sharedDocsRule as z, sharedCi as zn, runGit as zr, privateNamesFiles as zt };
25073
25391
 
25074
- //# sourceMappingURL=run-Ck7ahUNV.js.map
25392
+ //# sourceMappingURL=run-Bh2ogCYi.js.map