@wirecat/cli-base 0.131.0 → 1.0.0-rc.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 (103) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/README.md +7 -1
  3. package/dist/batch.d.ts +1 -0
  4. package/dist/batch.js +1 -0
  5. package/dist/codegen/graphql-fake.d.ts +1 -1
  6. package/dist/codegen/graphql-fake.js +1 -1
  7. package/dist/codegen/graphql.d.ts +1 -12
  8. package/dist/codegen/graphql.js +0 -44
  9. package/dist/codegen/index.d.ts +4 -3
  10. package/dist/codegen/index.js +2 -1
  11. package/dist/codegen/model.d.ts +4 -1
  12. package/dist/codegen/pipeline.d.ts +5 -5
  13. package/dist/codegen/runtime.d.ts +9 -2
  14. package/dist/codegen/runtime.js +7 -1
  15. package/dist/codegen/selection.d.ts +13 -0
  16. package/dist/codegen/selection.js +44 -0
  17. package/dist/codegen/wp-json.d.ts +2 -2
  18. package/dist/commands/document.d.ts +3 -0
  19. package/dist/commands/document.js +3 -0
  20. package/dist/commands/page.d.ts +14 -2
  21. package/dist/commands/page.js +3 -0
  22. package/dist/completion/index.d.ts +5 -1
  23. package/dist/completion/index.js +5 -1
  24. package/dist/credentials.d.ts +2 -0
  25. package/dist/credentials.js +2 -0
  26. package/dist/dev/api-report.d.ts +24 -0
  27. package/dist/dev/api-report.js +345 -0
  28. package/dist/dev/main.js +9 -19
  29. package/dist/dev/next-version.d.ts +5 -1
  30. package/dist/dev/next-version.js +30 -2
  31. package/dist/dev/result-shape.d.ts +4 -0
  32. package/dist/dev/result-shape.js +4 -4
  33. package/dist/dev/wcat-lint.d.ts +4 -1
  34. package/dist/dev/wcat-lint.js +9 -2
  35. package/dist/executable.d.ts +2 -0
  36. package/dist/executable.js +2 -0
  37. package/dist/http/fetch.d.ts +1 -0
  38. package/dist/http/fetch.js +1 -0
  39. package/dist/http/hosts.d.ts +11 -2
  40. package/dist/http/hosts.js +11 -2
  41. package/dist/http/index.d.ts +10 -2
  42. package/dist/http/index.js +10 -2
  43. package/dist/index.d.ts +2 -2
  44. package/dist/index.js +2 -2
  45. package/dist/logging.d.ts +3 -0
  46. package/dist/logging.js +3 -0
  47. package/dist/mcp/index.d.ts +17 -3
  48. package/dist/mcp/index.js +12 -2
  49. package/dist/output-buffer.d.ts +3 -0
  50. package/dist/output-buffer.js +1 -0
  51. package/dist/query/dates.d.ts +6 -1
  52. package/dist/query/dates.js +6 -1
  53. package/dist/query/help.d.ts +1 -0
  54. package/dist/query/help.js +1 -0
  55. package/dist/query/registry.d.ts +6 -1
  56. package/dist/query/registry.js +6 -1
  57. package/dist/query/types.d.ts +1 -0
  58. package/dist/query/types.js +1 -0
  59. package/dist/release/fold.d.ts +5 -0
  60. package/dist/release/fold.js +10 -1
  61. package/dist/release/fragments.d.ts +5 -2
  62. package/dist/release/fragments.js +18 -15
  63. package/dist/release/level.js +17 -11
  64. package/dist/skill/index.d.ts +34 -5
  65. package/dist/skill/index.js +21 -3
  66. package/dist/standards/audit.d.ts +15 -1
  67. package/dist/standards/audit.js +12 -1
  68. package/dist/standards/effects.d.ts +2 -0
  69. package/dist/standards/effects.js +1 -0
  70. package/dist/standards/errors.d.ts +2 -0
  71. package/dist/standards/errors.js +2 -0
  72. package/dist/standards/fields.d.ts +3 -0
  73. package/dist/standards/fields.js +2 -0
  74. package/dist/standards/flags-what.js +1 -3
  75. package/dist/standards/flags-work.d.ts +3 -0
  76. package/dist/standards/flags-work.js +25 -0
  77. package/dist/standards/identifiers.d.ts +7 -1
  78. package/dist/standards/identifiers.js +6 -1
  79. package/dist/standards/lint.d.ts +48 -8
  80. package/dist/standards/lint.js +45 -8
  81. package/dist/standards/log.d.ts +15 -3
  82. package/dist/standards/log.js +15 -3
  83. package/dist/standards/monthly.d.ts +2 -0
  84. package/dist/standards/monthly.js +2 -0
  85. package/dist/standards/output.d.ts +8 -1
  86. package/dist/standards/output.js +7 -1
  87. package/dist/standards/registry.d.ts +6 -1
  88. package/dist/standards/registry.js +6 -1
  89. package/dist/standards/steps.d.ts +5 -1
  90. package/dist/standards/steps.js +5 -1
  91. package/dist/standards/vocabulary.d.ts +5 -1
  92. package/dist/standards/vocabulary.js +8 -2
  93. package/dist/testing/index.d.ts +1 -2
  94. package/dist/testing/index.js +1 -2
  95. package/dist/update/index.d.ts +25 -4
  96. package/dist/update/index.js +24 -4
  97. package/dist/wcat/manifest.d.ts +11 -1
  98. package/dist/wcat/manifest.js +10 -1
  99. package/docs/standards/commands.md +5 -4
  100. package/docs/standards/docs.md +5 -2
  101. package/docs/standards/releases.md +37 -9
  102. package/docs/standards/toolchain.md +1 -1
  103. package/package.json +23 -5
@@ -0,0 +1,345 @@
1
+ /**
2
+ * The stable API of a package, as text a pull request diffs: `package.json`'s `wirecat.stable` names the stable entry
3
+ * points, and inside them a declaration whose TSDoc says `@experimental` is left out. Read from the emitted `.d.ts`
4
+ * with a small scanner, because TypeScript 7 ships no compiler API to walk them with.
5
+ */
6
+ import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
7
+ import { dirname, join } from "node:path";
8
+ import { parseArgs } from "node:util";
9
+ import spawn from "cross-spawn";
10
+ import { declarationOf, RELATIVE_MODULE, STRINGS_AND_COMMENTS, typesIn } from "./result-shape.js";
11
+ export const API_REPORT_USAGE = ` api-report [--check] [--skip-build]
12
+ builds the package, then writes api/<entry>.api.txt for each
13
+ entry point package.json lists in "wirecat.stable", without
14
+ the names whose TSDoc says @experimental; --check fails when a
15
+ committed report differs. Does nothing without that list`;
16
+ export const API_DIR = "api";
17
+ export const API_SUFFIX = ".api.txt";
18
+ const skipLiteral = (source, at) => {
19
+ const char = source[at];
20
+ if (char === "/" && source[at + 1] === "*") {
21
+ const end = source.indexOf("*/", at + 2);
22
+ return end < 0 ? source.length : end + 2;
23
+ }
24
+ if (char === "/" && source[at + 1] === "/") {
25
+ const end = source.indexOf("\n", at);
26
+ return end < 0 ? source.length : end;
27
+ }
28
+ if (char === '"' || char === "'" || char === "`") {
29
+ let end = at + 1;
30
+ while (end < source.length && source[end] !== char)
31
+ end += source[end] === "\\" ? 2 : 1;
32
+ return end + 1;
33
+ }
34
+ return at;
35
+ };
36
+ const BLOCK = /^(?:export\s+)?(?:declare\s+)?(?:default\s+)?(?:abstract\s+)?(?:interface|class|enum|const\s+enum|namespace|module|global)\b/;
37
+ /** Top-level statements with the `/** … *\/` comment right before each. */
38
+ export const statementsOf = (source) => {
39
+ const found = [];
40
+ let doc = "";
41
+ let at = 0;
42
+ while (at < source.length) {
43
+ if (/\s/.test(source[at])) {
44
+ at += 1;
45
+ continue;
46
+ }
47
+ const skipped = skipLiteral(source, at);
48
+ if (skipped > at && source[at] === "/") {
49
+ if (source.startsWith("/**", at))
50
+ doc = source.slice(at, skipped);
51
+ at = skipped;
52
+ continue;
53
+ }
54
+ const start = at;
55
+ const block = BLOCK.test(source.slice(start, start + 200));
56
+ let depth = 0;
57
+ for (; at < source.length; at += 1) {
58
+ const past = skipLiteral(source, at);
59
+ if (past > at) {
60
+ at = past - 1;
61
+ continue;
62
+ }
63
+ const char = source[at];
64
+ if ("{([".includes(char))
65
+ depth += 1;
66
+ else if ("})]".includes(char)) {
67
+ depth -= 1;
68
+ // A body closes at the end of its line; a `}` inside generics (`<T extends { a: 1 }>`) does not.
69
+ if (depth === 0 && char === "}" && block && /^[ \t]*(?:\n|$)/.test(source.slice(at + 1, at + 80))) {
70
+ at += 1;
71
+ break;
72
+ }
73
+ }
74
+ else if (char === ";" && depth === 0) {
75
+ at += 1;
76
+ break;
77
+ }
78
+ }
79
+ found.push({ text: source.slice(start, at), doc });
80
+ doc = "";
81
+ }
82
+ return found;
83
+ };
84
+ const linesOf = (text) => text
85
+ .replace(STRINGS_AND_COMMENTS, (match) => (match.startsWith("/") ? "" : match))
86
+ .split("\n")
87
+ .map((line) => line.trim().replace(/\s+/g, " "))
88
+ .filter((line) => line !== "" && !/^(?:private\b|#private\b)/.test(line));
89
+ const EXPERIMENTAL = /@experimental\b/;
90
+ const DECLARATION = /^(export\s+)?(?:declare\s+)?(?:abstract\s+)?(const\s+enum|const|let|var|function|class|interface|type|enum|namespace)\s+([\w$]+)/;
91
+ const STAR = /^export\s+(?:type\s+)?\*\s+(?:as\s+([\w$]+)\s+)?from\s*["']([^"']+)["']/;
92
+ const LIST = /^export\s+(?:type\s+)?\{([^}]*)\}(?:\s*from\s*["']([^"']+)["'])?/;
93
+ const IMPORT_LIST = /^import\s+(?:type\s+)?\{([^}]*)\}\s*from\s*["']([^"']+)["']/;
94
+ const IMPORT_ALL = /^import\s+(?:type\s+)?\*\s+as\s+([\w$]+)\s+from\s*["']([^"']+)["']/;
95
+ /** `declare module "x" { … }` changes another package's types for every caller, so it is API too. */
96
+ const AMBIENT = /^declare\s+(module\s+["'][^"']+["']|global)/;
97
+ const merge = (into, add) => into === undefined
98
+ ? { kinds: [...add.kinds], lines: [...add.lines], experimental: add.experimental }
99
+ : {
100
+ kinds: [...new Set([...into.kinds, ...add.kinds])].sort(),
101
+ lines: [...into.lines, ...add.lines],
102
+ experimental: into.experimental || add.experimental,
103
+ };
104
+ const byName = ([a], [b]) => (a < b ? -1 : a > b ? 1 : 0);
105
+ const namespaceOf = (exports) => ({
106
+ kinds: ["namespace"],
107
+ lines: [...exports]
108
+ .filter(([, name]) => !name.experimental)
109
+ .sort(byName)
110
+ .flatMap(([member, { kinds, lines }]) => lines.map((line) => `${member} · ${kinds.join("+")} · ${line}`)),
111
+ experimental: false,
112
+ });
113
+ const itemsOf = (list) => list
114
+ .split(",")
115
+ .map((item) => item.trim().replace(/^type\s+/, ""))
116
+ .filter(Boolean)
117
+ .map((item) => {
118
+ const [original = "", alias = original] = item.split(/\s+as\s+/);
119
+ return { original, alias };
120
+ });
121
+ /** The exports of one `.d.ts` file; a non-exported local a declaration names is reported with it. */
122
+ const moduleOf = (file, cache, problems) => {
123
+ const cached = cache.get(file);
124
+ if (cached)
125
+ return cached;
126
+ const text = readFileSync(file, "utf8");
127
+ const reaches = [...text.matchAll(RELATIVE_MODULE)].flatMap(([, from]) => declarationOf(dirname(file), from) ?? []);
128
+ const module = { exports: new Map(), ambient: new Map(), reaches: [...new Set(reaches)].sort() };
129
+ cache.set(file, module);
130
+ const locals = new Map();
131
+ const exported = new Set();
132
+ const imports = new Map();
133
+ const lists = [];
134
+ for (const statement of statementsOf(text)) {
135
+ const lines = linesOf(statement.text);
136
+ const flat = lines.join(" ");
137
+ const experimental = EXPERIMENTAL.test(statement.doc);
138
+ if (flat === "" || /^export\s*\{\s*\}\s*;?$/.test(flat))
139
+ continue;
140
+ const declared = DECLARATION.exec(flat);
141
+ const imported = IMPORT_LIST.exec(flat);
142
+ const all = IMPORT_ALL.exec(flat);
143
+ const ambient = AMBIENT.exec(flat);
144
+ if (declared) {
145
+ const [, isExported, kind = "", name = ""] = declared;
146
+ locals.set(name, merge(locals.get(name), { kinds: [kind.replace(/\s+/g, " ")], lines, experimental }));
147
+ if (isExported)
148
+ exported.add(name);
149
+ }
150
+ else if (imported)
151
+ for (const { original, alias } of itemsOf(imported[1] ?? ""))
152
+ imports.set(alias, { from: imported[2] ?? "", original });
153
+ else if (all)
154
+ imports.set(all[1] ?? "", { from: all[2] ?? "", original: "*" });
155
+ else if (ambient) {
156
+ const key = ambient[1] ?? "";
157
+ module.ambient.set(key, merge(module.ambient.get(key), { kinds: ["augmentation"], lines, experimental }));
158
+ }
159
+ else if (/^export\s+default\b/.test(flat))
160
+ module.exports.set("default", { kinds: ["default"], lines, experimental });
161
+ else if (STAR.test(flat) || LIST.test(flat))
162
+ lists.push({ marked: experimental, flat });
163
+ else if (!/^import\b/.test(flat))
164
+ problems.push(`${file}: cli-dev api-report cannot read "${flat.slice(0, 80)}"`);
165
+ }
166
+ const withLocals = (name) => {
167
+ const own = locals.get(name);
168
+ const lines = [...own.lines];
169
+ const seen = new Set([name]);
170
+ for (let at = 0; at < lines.length; at += 1)
171
+ for (const [word] of lines[at].matchAll(/[\w$]+/g)) {
172
+ const local = locals.get(word);
173
+ if (local === undefined || seen.has(word) || exported.has(word))
174
+ continue;
175
+ seen.add(word);
176
+ for (const line of local.lines)
177
+ lines.push(line);
178
+ }
179
+ return { ...own, lines };
180
+ };
181
+ /** Another package's name is reported by where it comes from: its types are that package's API. */
182
+ const resolve = (from, original) => {
183
+ const outside = { kinds: ["re-export"], lines: [`${original} from "${from}"`], experimental: false };
184
+ if (!from.startsWith("."))
185
+ return outside;
186
+ const target = declarationOf(dirname(file), from);
187
+ if (target === undefined) {
188
+ problems.push(`${file}: no declaration file for "${from}"`);
189
+ return undefined;
190
+ }
191
+ const exports = moduleOf(target, cache, problems).exports;
192
+ const found = original === "*" ? namespaceOf(exports) : exports.get(original);
193
+ if (found === undefined)
194
+ problems.push(`${file}: exports "${original}", which ${from} does not declare`);
195
+ return found;
196
+ };
197
+ for (const name of exported)
198
+ module.exports.set(name, withLocals(name));
199
+ for (const { marked, flat } of lists) {
200
+ const add = (alias, found) => {
201
+ if (found)
202
+ module.exports.set(alias, { ...found, experimental: found.experimental || marked });
203
+ };
204
+ const star = STAR.exec(flat);
205
+ if (star) {
206
+ const [, namespace, from = ""] = star;
207
+ if (namespace)
208
+ add(namespace, resolve(from, "*"));
209
+ else if (!from.startsWith("."))
210
+ problems.push(`${file}: cli-dev api-report cannot follow "export * from ${from}"`);
211
+ else {
212
+ const target = declarationOf(dirname(file), from);
213
+ if (target === undefined)
214
+ problems.push(`${file}: no declaration file for "${from}"`);
215
+ else
216
+ for (const [name, found] of moduleOf(target, cache, problems).exports)
217
+ add(name, found);
218
+ }
219
+ continue;
220
+ }
221
+ const [, list = "", from] = LIST.exec(flat) ?? [];
222
+ for (const { original, alias } of itemsOf(list)) {
223
+ const via = imports.get(original);
224
+ if (from !== undefined)
225
+ add(alias, resolve(from, original));
226
+ else if (locals.has(original))
227
+ add(alias, withLocals(original));
228
+ else if (via)
229
+ add(alias, resolve(via.from, via.original));
230
+ else
231
+ problems.push(`${file}: exports "${original}", which the file does not declare`);
232
+ }
233
+ }
234
+ return module;
235
+ };
236
+ /** The augmentations of every declaration file the entry point loads, in file order. */
237
+ const ambientFrom = (entry, cache, problems) => {
238
+ const found = new Map();
239
+ const seen = new Set([entry]);
240
+ const queue = [entry];
241
+ for (let file = queue.shift(); file !== undefined; file = queue.shift()) {
242
+ const { ambient, reaches } = moduleOf(file, cache, problems);
243
+ for (const [key, name] of ambient)
244
+ found.set(key, merge(found.get(key), name));
245
+ for (const next of reaches.filter((one) => !seen.has(one))) {
246
+ seen.add(next);
247
+ queue.push(next);
248
+ }
249
+ }
250
+ return found;
251
+ };
252
+ export const reportFileOf = (entry) => `${API_DIR}/${entry === "." ? "index" : entry.replace(/^\.\//, "").replaceAll("/", "-")}${API_SUFFIX}`;
253
+ /** The stable entry points `package.json` lists, or undefined when it lists none (the package opted out). */
254
+ export const stableEntries = (pkg) => pkg.wirecat?.stable;
255
+ /**
256
+ * One report per stable entry point, keyed by its path under `api/`: `<name> · <kind> · <line>` for each line of each
257
+ * stable declaration, sorted by name, so a pull request that removes or changes a stable name shows a removed line.
258
+ */
259
+ export const apiReports = (cwd) => {
260
+ const pkg = JSON.parse(readFileSync(join(cwd, "package.json"), "utf8"));
261
+ const stable = stableEntries(pkg);
262
+ const files = new Map();
263
+ const problems = [];
264
+ if (!Array.isArray(stable) || !stable.every((entry) => typeof entry === "string"))
265
+ return {
266
+ files,
267
+ problems: ['package.json: "wirecat.stable" must be a list of "exports" keys, such as [".", "./http"]'],
268
+ };
269
+ const exports = (typeof pkg.exports === "object" && pkg.exports !== null ? pkg.exports : {});
270
+ const cache = new Map();
271
+ for (const entry of stable) {
272
+ if (!(entry in exports)) {
273
+ problems.push(`package.json: "wirecat.stable" lists "${entry}", which is not an "exports" key`);
274
+ continue;
275
+ }
276
+ const [types] = typesIn(exports[entry], typeof exports[entry] === "string" ? "types" : undefined).filter((path) => path.endsWith(".d.ts"));
277
+ if (types === undefined) {
278
+ problems.push(`package.json: stable entry "${entry}" has no "types" file to report on`);
279
+ continue;
280
+ }
281
+ const file = join(cwd, types);
282
+ if (!existsSync(file)) {
283
+ problems.push(`${types} is not built: build the package before cli-dev api-report`);
284
+ continue;
285
+ }
286
+ const names = [...moduleOf(file, cache, problems).exports, ...ambientFrom(file, cache, problems)]
287
+ .filter(([, name]) => !name.experimental)
288
+ .sort(byName);
289
+ const lines = names.flatMap(([name, { kinds, lines }]) => lines.map((line) => `${name} · ${kinds.join("+")} · ${line}`));
290
+ const header = `# ${String(pkg.name)} "${entry}": the stable API, written by cli-dev api-report. Do not edit.`;
291
+ files.set(reportFileOf(entry), `${[header, ...lines].join("\n")}\n`);
292
+ }
293
+ return { files, problems };
294
+ };
295
+ const report = (io, problems, ok) => {
296
+ for (const problem of problems)
297
+ io.err(problem);
298
+ if (problems.length > 0)
299
+ return 1;
300
+ io.out(ok);
301
+ return 0;
302
+ };
303
+ /** The stable API report under api/: written, or with `--check` compared with the committed one. */
304
+ export const apiReportCommand = (args, io) => {
305
+ const { values } = parseArgs({
306
+ args,
307
+ options: { check: { type: "boolean", default: false }, "skip-build": { type: "boolean", default: false } },
308
+ });
309
+ const pkg = JSON.parse(readFileSync(join(io.cwd, "package.json"), "utf8"));
310
+ if (stableEntries(pkg) === undefined) {
311
+ io.out('package.json lists no "wirecat.stable" entry points: no API report');
312
+ return 0;
313
+ }
314
+ if (!values["skip-build"]) {
315
+ const manager = String(pkg.packageManager ?? "npm").split("@")[0] || "npm";
316
+ const built = spawn.sync(manager, ["run", "build"], { cwd: io.cwd, stdio: ["ignore", "inherit", "inherit"] });
317
+ if (built.status !== 0) {
318
+ io.err(`${manager} run build failed: the API report reads the built .d.ts files`);
319
+ return 1;
320
+ }
321
+ }
322
+ const { files, problems } = apiReports(io.cwd);
323
+ if (problems.length > 0)
324
+ return report(io, problems, "");
325
+ const dir = join(io.cwd, API_DIR);
326
+ const committed = existsSync(dir) ? readdirSync(dir).filter((name) => name.endsWith(API_SUFFIX)) : [];
327
+ const stale = committed.map((name) => `${API_DIR}/${name}`).filter((path) => !files.has(path));
328
+ if (values.check) {
329
+ const differ = [...files].filter(([path, text]) => {
330
+ const file = join(io.cwd, path);
331
+ return !existsSync(file) || readFileSync(file, "utf8") !== text;
332
+ });
333
+ return report(io, [
334
+ ...differ.map(([path]) => `${path} differs from the build: run cli-dev api-report and commit it`),
335
+ ...stale.map((path) => `${path} reports no stable entry point any more: run cli-dev api-report`),
336
+ ], `${API_DIR}/: ${files.size} API reports match the build`);
337
+ }
338
+ mkdirSync(dir, { recursive: true });
339
+ for (const [path, text] of files)
340
+ writeFileSync(join(io.cwd, path), text);
341
+ for (const path of stale)
342
+ rmSync(join(io.cwd, path));
343
+ io.out(`${API_DIR}/: wrote ${files.size} API reports${stale.length > 0 ? `, removed ${stale.join(", ")}` : ""}`);
344
+ return 0;
345
+ };
package/dist/dev/main.js CHANGED
@@ -13,7 +13,7 @@ import * as v from "valibot";
13
13
  import { parseCommandsDocument } from "../commands/document.js";
14
14
  import { describeProgram } from "../commands/registry.js";
15
15
  import { taggedSection } from "../release/fold.js";
16
- import { CHANGELOG_HEADINGS, changelogProblems, collectFragments, docsProblems, fragmentProblems, JOURNAL_IDS, levelledVersion, markdownFiles, packageVersion, readFragments, structureProblems, versionLevelProblem, versionScript, } from "../release/index.js";
16
+ import { CHANGELOG_HEADINGS, changelogProblems, collectFragments, docsProblems, fragmentProblems, JOURNAL_IDS, markdownFiles, packageVersion, readFragments, structureProblems, versionScript, } from "../release/index.js";
17
17
  import { AUDIT_BLOCKS, defineParityGroups, PARITY_GROUPS, REQUIRED_ROOTS } from "../standards/audit.js";
18
18
  import { defineReasons } from "../standards/errors.js";
19
19
  import { baselineProblems, baselineSchema, LINT_RULES, OVERRIDE_BUDGET, OVERRIDE_RULE_REVIEW, overdue, overrideSchema, overridesDueSoon, overridesProblems, rulesForReview, } from "../standards/lint.js";
@@ -21,6 +21,7 @@ import { issuesOf, RegistryError } from "../standards/registry.js";
21
21
  import { VOCABULARY } from "../standards/vocabulary.js";
22
22
  import { buildManifest, MANIFEST_FILE, ManifestError, manifestText } from "../wcat/manifest.js";
23
23
  import { adopt } from "./adopt.js";
24
+ import { API_REPORT_USAGE, apiReportCommand } from "./api-report.js";
24
25
  import { auditClis, scorecardTable, sharedDifferences, sharedReviews, snakeKeys } from "./audit.js";
25
26
  import { readCapabilities } from "./capabilities.js";
26
27
  import { CONFORMANCE_USAGE, conformanceCommand } from "./conformance.js";
@@ -28,7 +29,7 @@ import { familyPackages, installFamily } from "./family.js";
28
29
  import { changelogChange, landChange, landFold, newestTag, processShell, restoreChange } from "./land.js";
29
30
  import { baselineOf, judge, lintCommands, misfiled, RUN_LOG_COMMANDS, walk } from "./lint.js";
30
31
  import { readSources } from "./network.js";
31
- import { nextVersion } from "./next-version.js";
32
+ import { levelCommand, nextVersion } from "./next-version.js";
32
33
  import { READY_USAGE, ready } from "./ready.js";
33
34
  import { readDeclarations } from "./result-shape.js";
34
35
  import { slowTests } from "./slow-tests.js";
@@ -109,7 +110,8 @@ const USAGE = `usage: cli-dev <command> [options]
109
110
  __dirname was read and found harmless. Fails when a bundled
110
111
  module would look for a file or package in the wrong place
111
112
  ${CONFORMANCE_USAGE}
112
- ${READY_USAGE}`;
113
+ ${READY_USAGE}
114
+ ${API_REPORT_USAGE}`;
113
115
  const load = async (cwd, path) => (await import(pathToFileURL(isAbsolute(path) ? path : join(cwd, path)).href));
114
116
  const report = (io, problems, ok) => {
115
117
  for (const problem of problems)
@@ -136,7 +138,7 @@ const docsCheck = async (args, io) => {
136
138
  else {
137
139
  const ids = [...JOURNAL_IDS, ...(values.ids?.split(",").filter(Boolean) ?? [])];
138
140
  changelog = {
139
- headings: ["Added", "Changed — may break callers", "Fixed", "Security", "Removed"],
141
+ headings: CHANGELOG_HEADINGS,
140
142
  unreleased: "Unreleased",
141
143
  ids,
142
144
  };
@@ -173,26 +175,12 @@ const fragments = (args, io) => {
173
175
  io.out(`collected ${found.length} changelog fragments into ${values.collect}`);
174
176
  return 0;
175
177
  };
176
- /** The top section's version level: with `--next <x.y.z>`, the version it needs; without, whether it has it. */
177
- const level = (args, io) => {
178
- const { values } = parseArgs({
179
- args,
180
- options: { next: { type: "string" }, file: { type: "string", default: "CHANGELOG.md" } },
181
- });
182
- const text = readFileSync(isAbsolute(values.file) ? values.file : join(io.cwd, values.file), "utf8");
183
- if (values.next) {
184
- io.out(levelledVersion(text, values.next));
185
- return 0;
186
- }
187
- const problem = versionLevelProblem(text);
188
- return report(io, problem ? [problem] : [], `${values.file}: the top section's version fits its headings`);
189
- };
190
178
  const changelog = (args, io) => {
191
179
  const [action, ...rest] = args;
192
180
  if (action === "fragments")
193
181
  return fragments(rest, io);
194
182
  if (action === "level")
195
- return level(rest, io);
183
+ return levelCommand(rest, io);
196
184
  if (action !== "fold" && action !== "restore") {
197
185
  io.err(`cli-dev changelog: no action "${action ?? ""}" — the ones there are: fold, restore, fragments, level`);
198
186
  return 2;
@@ -957,6 +945,8 @@ export const main = async (argv, io) => {
957
945
  }
958
946
  case "changelog":
959
947
  return changelog(args, io);
948
+ case "api-report":
949
+ return apiReportCommand(args, io);
960
950
  case "docs-check":
961
951
  return docsCheck(args, io);
962
952
  case "test-matrix":
@@ -1,6 +1,8 @@
1
+ import type { DevIo } from "./main.js";
1
2
  /**
2
3
  * The version `bin/release` publishes: the one in package.json when npm has not taken it and it is
3
- * above npm's latest, else the next free one at the same bump level (x.y.0 → minor, x.y.z → patch).
4
+ * above npm's latest, else the next free one at the same bump level (x.0.0 → major from 1.0.0 on, x.y.0 → minor,
5
+ * x.y.z → patch).
4
6
  * npm's answers are arguments, not calls, so CI and a test can hand it any registry state.
5
7
  */
6
8
  export declare const nextVersion: (wanted: string, latest: string, versionsJson: string) => {
@@ -8,3 +10,5 @@ export declare const nextVersion: (wanted: string, latest: string, versionsJson:
8
10
  } | {
9
11
  error: string;
10
12
  };
13
+ /** The top section's version level: with `--next <x.y.z>`, the version it needs; without, whether it has it. */
14
+ export declare const levelCommand: (args: string[], io: DevIo) => number;
@@ -1,6 +1,11 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { isAbsolute, join } from "node:path";
3
+ import { parseArgs } from "node:util";
4
+ import { levelledVersion, versionLevelProblem } from "../release/level.js";
1
5
  /**
2
6
  * The version `bin/release` publishes: the one in package.json when npm has not taken it and it is
3
- * above npm's latest, else the next free one at the same bump level (x.y.0 → minor, x.y.z → patch).
7
+ * above npm's latest, else the next free one at the same bump level (x.0.0 → major from 1.0.0 on, x.y.0 → minor,
8
+ * x.y.z → patch).
4
9
  * npm's answers are arguments, not calls, so CI and a test can hand it any registry state.
5
10
  */
6
11
  export const nextVersion = (wanted, latest, versionsJson) => {
@@ -24,9 +29,32 @@ export const nextVersion = (wanted, latest, versionsJson) => {
24
29
  }
25
30
  if (!taken.has(wanted) && compare(want, top) > 0)
26
31
  return { version: wanted };
27
- const step = ([major = 0, minor = 0, patch = 0]) => want[2] === 0 ? [major, minor + 1, 0] : [major, minor, patch + 1];
32
+ // A taken x.0.0 stays a major: 2.0.0 taken goes to 3.0.0, never to 2.1.0.
33
+ const step = ([major = 0, minor = 0, patch = 0]) => want[1] === 0 && want[2] === 0 && (want[0] ?? 0) >= 1
34
+ ? [major + 1, 0, 0]
35
+ : want[2] === 0
36
+ ? [major, minor + 1, 0]
37
+ : [major, minor, patch + 1];
28
38
  let next = step(top);
29
39
  while (taken.has(next.join(".")))
30
40
  next = step(next);
31
41
  return { version: next.join(".") };
32
42
  };
43
+ /** The top section's version level: with `--next <x.y.z>`, the version it needs; without, whether it has it. */
44
+ export const levelCommand = (args, io) => {
45
+ const { values } = parseArgs({
46
+ args,
47
+ options: { next: { type: "string" }, file: { type: "string", default: "CHANGELOG.md" } },
48
+ });
49
+ const text = readFileSync(isAbsolute(values.file) ? values.file : join(io.cwd, values.file), "utf8");
50
+ if (values.next) {
51
+ io.out(levelledVersion(text, values.next));
52
+ return 0;
53
+ }
54
+ const problem = versionLevelProblem(text);
55
+ if (problem)
56
+ io.err(problem);
57
+ else
58
+ io.out(`${values.file}: the top section's version fits its headings`);
59
+ return problem ? 1 : 0;
60
+ };
@@ -4,8 +4,12 @@ export interface Declarations {
4
4
  files: readonly SourceFile[];
5
5
  missing: readonly string[];
6
6
  }
7
+ export declare const typesIn: (value: unknown, key?: string) => string[];
8
+ export declare const RELATIVE_MODULE: RegExp;
9
+ export declare const declarationOf: (dir: string, specifier: string) => string | undefined;
7
10
  /** Every declaration file reachable from the package's `types` entries, by their relative imports. */
8
11
  export declare const readDeclarations: (cwd: string) => Declarations;
12
+ export declare const STRINGS_AND_COMMENTS: RegExp;
9
13
  export interface ShapeFinding {
10
14
  target: string;
11
15
  message: string;
@@ -1,6 +1,6 @@
1
1
  import { existsSync, readFileSync } from "node:fs";
2
2
  import { dirname, join, relative } from "node:path";
3
- const typesIn = (value, key) => {
3
+ export const typesIn = (value, key) => {
4
4
  if (typeof value === "string")
5
5
  return key === "types" || key === "typings" ? [value] : [];
6
6
  if (Array.isArray(value))
@@ -9,8 +9,8 @@ const typesIn = (value, key) => {
9
9
  return Object.entries(value).flatMap(([at, one]) => typesIn(one, at));
10
10
  return [];
11
11
  };
12
- const RELATIVE_MODULE = /(?:\bfrom\s*|\bimport\s*\(\s*)["'](\.{1,2}\/[^"']+)["']/g;
13
- const declarationOf = (dir, specifier) => {
12
+ export const RELATIVE_MODULE = /(?:\bfrom\s*|\bimport\s*\(\s*)["'](\.{1,2}\/[^"']+)["']/g;
13
+ export const declarationOf = (dir, specifier) => {
14
14
  const base = join(dir, specifier);
15
15
  const candidates = /\.[cm]?js$/.test(base)
16
16
  ? [base.replace(/\.(c|m)?js$/, ".d.$1ts")]
@@ -45,7 +45,7 @@ export const readDeclarations = (cwd) => {
45
45
  .sort((a, b) => (a.path < b.path ? -1 : 1));
46
46
  return { files, missing };
47
47
  };
48
- const STRINGS_AND_COMMENTS = /\/\/[^\n]*|\/\*[\s\S]*?\*\/|"(?:[^"\\\n]|\\.)*"|'(?:[^'\\\n]|\\.)*'|`(?:[^`\\]|\\.)*`/g;
48
+ export const STRINGS_AND_COMMENTS = /\/\/[^\n]*|\/\*[\s\S]*?\*\/|"(?:[^"\\\n]|\\.)*"|'(?:[^'\\\n]|\\.)*'|`(?:[^`\\]|\\.)*`/g;
49
49
  const OPEN = "([{<";
50
50
  const CLOSE = ")]}>";
51
51
  /** Brackets of every kind count, and the `>` of `=>` closes nothing. */
@@ -10,7 +10,10 @@ export declare const binNames: (pkg: {
10
10
  name?: unknown;
11
11
  bin?: unknown;
12
12
  }) => string[];
13
- /** Each command is `wcat-<name>`, and a package outside `@wirecat/` takes no reserved name. */
13
+ /**
14
+ * Each command is `wcat-<name>`, and a package outside `@wirecat/` takes no reserved name. A short name is fine beside
15
+ * a `wcat-<name>` that runs the same file: the template installs both while users move to the long one.
16
+ */
14
17
  export declare const binNameWarnings: (pkg: {
15
18
  name?: unknown;
16
19
  bin?: unknown;
@@ -15,10 +15,16 @@ export const binNames = (pkg) => {
15
15
  return typeof pkg.name === "string" ? [pkg.name.replace(/^@[^/]+\//, "")] : [];
16
16
  return typeof pkg.bin === "object" && pkg.bin !== null ? Object.keys(pkg.bin) : [];
17
17
  };
18
- /** Each command is `wcat-<name>`, and a package outside `@wirecat/` takes no reserved name. */
18
+ /**
19
+ * Each command is `wcat-<name>`, and a package outside `@wirecat/` takes no reserved name. A short name is fine beside
20
+ * a `wcat-<name>` that runs the same file: the template installs both while users move to the long one.
21
+ */
19
22
  export const binNameWarnings = (pkg) => binNames(pkg).flatMap((command) => {
20
23
  const target = `package.json "bin" ${command}`;
21
- if (!command.startsWith(PROGRAM_PREFIX))
24
+ if (!command.startsWith(PROGRAM_PREFIX)) {
25
+ const bins = typeof pkg.bin === "object" && pkg.bin !== null ? pkg.bin : {};
26
+ if (bins[command] !== undefined && bins[`${PROGRAM_PREFIX}${command}`] === bins[command])
27
+ return [];
22
28
  return [
23
29
  {
24
30
  rule: "wcat-bin-name",
@@ -26,6 +32,7 @@ export const binNameWarnings = (pkg) => binNames(pkg).flatMap((command) => {
26
32
  message: `install the command as ${PROGRAM_PREFIX}${command}, so no other program on PATH has its name`,
27
33
  },
28
34
  ];
35
+ }
29
36
  const name = command.slice(PROGRAM_PREFIX.length);
30
37
  if (!TOOL_NAME.test(name))
31
38
  return [{ rule: "wcat-bin-name", target, message: "the name after wcat- is lower-case letters, digits and -" }];
@@ -1,2 +1,4 @@
1
+ /** @experimental */
1
2
  export declare const executableOnPath: (command: string, env: NodeJS.ProcessEnv, platform?: NodeJS.Platform, exists?: (path: string) => boolean) => string;
3
+ /** @experimental */
2
4
  export declare const executableEnvironment: (env: NodeJS.ProcessEnv, platform?: NodeJS.Platform) => NodeJS.ProcessEnv;
@@ -1,6 +1,7 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { win32 } from "node:path";
3
3
  const variable = (env, name) => Object.entries(env).find(([key]) => key.toUpperCase() === name)?.[1];
4
+ /** @experimental */
4
5
  export const executableOnPath = (command, env, platform = process.platform, exists = existsSync) => {
5
6
  if (platform !== "win32" || win32.isAbsolute(command))
6
7
  return command;
@@ -19,6 +20,7 @@ export const executableOnPath = (command, env, platform = process.platform, exis
19
20
  }
20
21
  return command;
21
22
  };
23
+ /** @experimental */
22
24
  export const executableEnvironment = (env, platform = process.platform) => {
23
25
  if (platform !== "win32")
24
26
  return env;
@@ -12,6 +12,7 @@ export interface HostFetchOptions {
12
12
  */
13
13
  credentialScope?: string;
14
14
  }
15
+ /** @experimental */
15
16
  export declare const HOST_FETCH_TIMEOUT_MS = 30000;
16
17
  /** `fetch` that reaches only the declared hosts, checks every redirect hop, and gives up after `timeoutMs`. */
17
18
  export declare const hostFetch: (options: HostFetchOptions) => FetchLike;
@@ -1,5 +1,6 @@
1
1
  import { CliError, isCliError } from "../errors.js";
2
2
  import { hostCovered, hostProblems } from "./hosts.js";
3
+ /** @experimental */
3
4
  export const HOST_FETCH_TIMEOUT_MS = 30_000;
4
5
  const REDIRECTS = 5;
5
6
  const REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);
@@ -1,5 +1,14 @@
1
- /** A lower-case hostname, or `*.` and at least two labels: `api.acme.example`, `*.cdn.acme.example`, never `*.com`. */
1
+ /**
2
+ * A lower-case hostname, or `*.` and at least two labels: `api.acme.example`, `*.cdn.acme.example`, never `*.com`.
3
+ *
4
+ * @experimental
5
+ */
2
6
  export declare const HOST_PATTERN: RegExp;
7
+ /** @experimental */
3
8
  export declare const hostProblems: (hosts: readonly string[]) => string[];
4
- /** `*.x` covers every name under `x`, but not `x` itself. */
9
+ /**
10
+ * `*.x` covers every name under `x`, but not `x` itself.
11
+ *
12
+ * @experimental
13
+ */
5
14
  export declare const hostCovered: (hostname: string, hosts: readonly string[]) => boolean;
@@ -1,13 +1,22 @@
1
1
  const LABEL = "[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?";
2
- /** A lower-case hostname, or `*.` and at least two labels: `api.acme.example`, `*.cdn.acme.example`, never `*.com`. */
2
+ /**
3
+ * A lower-case hostname, or `*.` and at least two labels: `api.acme.example`, `*.cdn.acme.example`, never `*.com`.
4
+ *
5
+ * @experimental
6
+ */
3
7
  export const HOST_PATTERN = new RegExp(`^(?:${LABEL}(?:\\.${LABEL})*|\\*\\.${LABEL}(?:\\.${LABEL})+)$`);
8
+ /** @experimental */
4
9
  export const hostProblems = (hosts) => [
5
10
  ...hosts
6
11
  .filter((host) => !HOST_PATTERN.test(host) || host.length > 253)
7
12
  .map((host) => `${JSON.stringify(host)} is not a host: a lower-case hostname with no scheme, port or path, or one leading *. before two labels or more`),
8
13
  ...hosts.filter((host, at) => hosts.indexOf(host) !== at).map((host) => `${JSON.stringify(host)} is listed twice`),
9
14
  ];
10
- /** `*.x` covers every name under `x`, but not `x` itself. */
15
+ /**
16
+ * `*.x` covers every name under `x`, but not `x` itself.
17
+ *
18
+ * @experimental
19
+ */
11
20
  export const hostCovered = (hostname, hosts) => {
12
21
  const name = hostname.toLowerCase().replace(/\.$/, "");
13
22
  return hosts.some((host) => (host.startsWith("*.") ? name.endsWith(host.slice(1)) : name === host));