contractdiff 1.0.0 → 1.1.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.
- package/README.md +7 -7
- package/dist/cli.d.ts +20 -0
- package/dist/cli.js +33 -1
- package/dist/command-diff.js +37 -6
- package/dist/command-migrate.js +6 -2
- package/dist/command-plugin.js +3 -1
- package/dist/command-props.js +2 -1
- package/dist/diff-decisions.js +8 -8
- package/dist/extract-standard.js +14 -2
- package/dist/inputs.js +1 -2
- package/dist/migrate-openapi-fetch.js +3 -2
- package/dist/migrate-openapi-typescript.js +12 -4
- package/dist/migrate-orval.js +7 -6
- package/dist/migrate-shared.js +7 -0
- package/dist/plugin-extract-standard-schema.js +9 -4
- package/dist/plugin-validator-code.js +6 -0
- package/dist/plugin-validator.js +7 -2
- package/dist/props-mutate.js +4 -3
- package/dist/run-command.js +13 -4
- package/dist/run-text.js +40 -0
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
</p>
|
|
27
27
|
|
|
28
28
|
<p align="center">
|
|
29
|
-
Docs: <a href="https://
|
|
29
|
+
Docs: <a href="https://contractdiff.interlace.tools">https://contractdiff.interlace.tools</a><br />
|
|
30
30
|
Migrating from: <a href="https://github.com/ofri-peretz/burgee/tree/main/packages/contractdiff#migrating">openapi-typescript</a>
|
|
31
31
|
</p>
|
|
32
32
|
|
|
@@ -216,13 +216,13 @@ keeps both true.
|
|
|
216
216
|
| [bellpull](https://bellpull.interlace.tools/docs) | Subprocesses, and which executable actually ran | cross-spawn and which |
|
|
217
217
|
| [controlroom](https://controlroom.interlace.tools/docs) | Keyboard-driven terminal screens, inline or full-screen | ink |
|
|
218
218
|
| [oxmutate](https://oxmutate.interlace.tools/docs) | Mutation testing on the oxc engine, inside your own Vitest | Stryker |
|
|
219
|
-
| [truepass](https://
|
|
219
|
+
| [truepass](https://truepass.interlace.tools/docs) | Lint rules and a pre-push check that keep a test suite honest | @vitest/eslint-plugin |
|
|
220
220
|
| **contractdiff** (this package) | API contracts: breaking-change diff, lint, and code from the spec | openapi-typescript |
|
|
221
|
-
| [truefit](https://
|
|
222
|
-
| [provedone](https://
|
|
223
|
-
| [replz](https://
|
|
224
|
-
| [hookset](https://
|
|
225
|
-
| [triggerlist](https://
|
|
221
|
+
| [truefit](https://truefit.interlace.tools/docs) | Validation whose schemas are data, with no eval | zod |
|
|
222
|
+
| [provedone](https://provedone.interlace.tools/docs) | A receipt for how every change was verified, and a gate that reads it | @commitlint/cli |
|
|
223
|
+
| [replz](https://replz.interlace.tools/docs) | Recall of a reviewer and its checks, replayed on bugs that shipped | promptfoo |
|
|
224
|
+
| [hookset](https://hookset.interlace.tools/docs) | The same git and Claude Code hooks in every repository, pinned by tag | husky |
|
|
225
|
+
| [triggerlist](https://triggerlist.interlace.tools/docs) | The review checklist a diff selects, read from the base branch | danger |
|
|
226
226
|
|
|
227
227
|
Every migration guide, and the family-wide [compatibility](https://burgee.interlace.tools/docs/compatibility)
|
|
228
228
|
and [benchmarks](https://burgee.interlace.tools/docs/benchmarks) pages, are on
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
1
|
/** The published version, read from the manifest beside dist/ so `--version` cannot drift from npm. */
|
|
2
2
|
export declare const VERSION: string;
|
|
3
|
+
/**
|
|
4
|
+
* A refusal at exit 1 with its fix: burgee reads the code off the class, as it does a `defineError`
|
|
5
|
+
* class's, and then the instance's `fix`. A plain `Error` is exit 1 too, but burgee reads no `fix` off it.
|
|
6
|
+
*/
|
|
7
|
+
export declare class Refusal extends Error {
|
|
8
|
+
readonly fix: string;
|
|
9
|
+
constructor(message: string, fix: string, cause: unknown);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A refusal whose message ends in its one `fix:` line, as burgee's own error and fix: the message
|
|
13
|
+
* before it, and the fix beside it, which burgee prints as its own `fix:` line (and `error.fix`
|
|
14
|
+
* under `--json`). Without one burgee finds no fix and teaches with the command's usage block, so a
|
|
15
|
+
* refusal that already said what to do printed the whole options table after it. A message with
|
|
16
|
+
* several fixes (a config's problems, one per line) is left whole.
|
|
17
|
+
*/
|
|
18
|
+
export declare const carryFix: (error: unknown) => unknown;
|
|
19
|
+
/** The command, its refusals carrying their fix (`carryFix`). */
|
|
20
|
+
export declare const carryingFix: <C extends {
|
|
21
|
+
readonly run?: ((context: never) => unknown) | undefined;
|
|
22
|
+
}>(command: C) => C;
|
|
3
23
|
export declare const program: import("burgee").Manifest;
|
package/dist/cli.js
CHANGED
|
@@ -11,6 +11,38 @@ const planned = (name, description, phase, effects = 'read_only') => defineComma
|
|
|
11
11
|
throw new Error(`\`contractdiff ${name}\` is not implemented yet. fix: it lands in ${phase} (.sdlc/intents/contractdiff/roadmap.md)`);
|
|
12
12
|
},
|
|
13
13
|
});
|
|
14
|
+
const ONE_FIX = /^(?<what>[\s\S]+?)\. fix: (?<fix>[\s\S]+)$/u;
|
|
15
|
+
const NAMED = new Set(['USAGE', 'CONFIG', 'CANCELLED', 'AUTH', 'TIMEOUT']);
|
|
16
|
+
export class Refusal extends Error {
|
|
17
|
+
fix;
|
|
18
|
+
constructor(message, fix, cause) {
|
|
19
|
+
super(message, { cause });
|
|
20
|
+
this.name = 'Refusal';
|
|
21
|
+
this.fix = fix;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
Object.defineProperty(Refusal, Symbol.for('burgee.exitCode'), { value: 1 });
|
|
25
|
+
export const carryFix = (error) => {
|
|
26
|
+
if (!(error instanceof Error) || 'fix' in error || error.message.split(' fix: ').length !== 2)
|
|
27
|
+
return error;
|
|
28
|
+
const groups = ONE_FIX.exec(error.message)?.groups;
|
|
29
|
+
if (groups === undefined)
|
|
30
|
+
return error;
|
|
31
|
+
const { what, fix } = groups;
|
|
32
|
+
if (!NAMED.has(String(error.code)))
|
|
33
|
+
return new Refusal(what, fix, error);
|
|
34
|
+
error.message = what;
|
|
35
|
+
return Object.assign(error, { fix });
|
|
36
|
+
};
|
|
37
|
+
export const carryingFix = (command) => {
|
|
38
|
+
const { run } = command;
|
|
39
|
+
if (run === undefined)
|
|
40
|
+
return command;
|
|
41
|
+
const wrapped = async (context) => Promise.resolve()
|
|
42
|
+
.then(() => run(context))
|
|
43
|
+
.catch(async (error) => Promise.reject(carryFix(error)));
|
|
44
|
+
return { ...command, run: wrapped };
|
|
45
|
+
};
|
|
14
46
|
export const program = defineProgram({
|
|
15
47
|
name: 'contractdiff',
|
|
16
48
|
version: VERSION,
|
|
@@ -20,5 +52,5 @@ export const program = defineProgram({
|
|
|
20
52
|
extractCommand,
|
|
21
53
|
...commands,
|
|
22
54
|
planned('check', 'Call sites in the code that disagree with the contract, found statically', 'Phase 7'),
|
|
23
|
-
],
|
|
55
|
+
].map(carryingFix),
|
|
24
56
|
});
|
package/dist/command-diff.js
CHANGED
|
@@ -2,6 +2,7 @@ import { createHash } from 'node:crypto';
|
|
|
2
2
|
import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { isAbsolute, join, resolve } from 'node:path';
|
|
4
4
|
import { pathToFileURL } from 'node:url';
|
|
5
|
+
import { ambientRuntime, run as spawn } from 'bellpull';
|
|
5
6
|
import { defineCommand, ExitCode } from 'burgee';
|
|
6
7
|
import { parse as parseYaml } from 'seniority/yaml';
|
|
7
8
|
import { MODES, SIDES } from './diff-classify.js';
|
|
@@ -13,15 +14,45 @@ import { breakingIn, bufIn, builtImages, LEVELS, refFix } from './input-buf.js';
|
|
|
13
14
|
import { builtinAdapters } from './inputs.js';
|
|
14
15
|
import { DECISION_SETTINGS, decisionSettingOf, UsageError } from './run-config.js';
|
|
15
16
|
const TEXT = Symbol.for('burgee.text');
|
|
17
|
+
const GIT = /^git:(?<ref>[^:]+):(?<path>.+)$/;
|
|
18
|
+
const CONFIG = 'contractdiff.config.json';
|
|
16
19
|
export const noGit = (ref, path) => {
|
|
17
|
-
throw new Error(`cannot read \`git:${ref}:${path}\`:
|
|
20
|
+
throw new Error(`cannot read \`git:${ref}:${path}\`: it was not read through git first. fix: \`git show ${ref}:${path} > old.yaml\` and diff that file`);
|
|
21
|
+
};
|
|
22
|
+
export const gitReader = async (specs, cwd, { config = false, runtime: ambient = ambientRuntime() } = {}) => {
|
|
23
|
+
const wanted = specs.flatMap((spec) => {
|
|
24
|
+
const groups = GIT.exec(String(spec))?.groups;
|
|
25
|
+
return groups === undefined ? [] : [groups];
|
|
26
|
+
});
|
|
27
|
+
if (wanted.length === 0)
|
|
28
|
+
return noGit;
|
|
29
|
+
const runtime = { ...ambient, env: Object.fromEntries(Object.entries(ambient.env).filter(([key]) => !key.startsWith('GIT_'))) };
|
|
30
|
+
const base = config ? GIT.exec(String(specs[0]))?.groups : undefined;
|
|
31
|
+
const asked = base === undefined ? wanted : [...wanted, { ref: base.ref, path: CONFIG }];
|
|
32
|
+
const answers = new Map(await Promise.all(asked.map(async ({ ref, path }) => {
|
|
33
|
+
const answer = await spawn('git', ['show', `${ref}:./${path}`], { cwd: resolve(cwd), runtime }).then((result) => (result.ok ? { text: result.stdout } : { error: result.stderr.trim() }), (error) => ({ error: error.message }));
|
|
34
|
+
return [`${ref}:${path}`, answer];
|
|
35
|
+
})));
|
|
36
|
+
return (ref, path) => {
|
|
37
|
+
const answer = answers.get(`${ref}:${path}`);
|
|
38
|
+
if (answer === undefined)
|
|
39
|
+
return noGit(ref, path, cwd);
|
|
40
|
+
if ('text' in answer)
|
|
41
|
+
return answer.text;
|
|
42
|
+
throw new UsageError(`cannot read \`git:${ref}:${path}\`: ${answer.error}. fix: name a ref and a path, relative to this folder, that \`git show ${ref}:./${path}\` prints`);
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
const fileText = (spec, cwd) => {
|
|
46
|
+
const path = resolve(cwd, spec);
|
|
47
|
+
if (!existsSync(path))
|
|
48
|
+
throw new UsageError(`there is no file ${spec}. fix: pass the path of a contract file, or git:<ref>:<path> for one at a ref`);
|
|
49
|
+
return readFileSync(path, 'utf8');
|
|
18
50
|
};
|
|
19
|
-
const GIT = /^git:(?<ref>[^:]+):(?<path>.+)$/;
|
|
20
51
|
export const readContract = (spec, cwd, git, built = new Map()) => {
|
|
21
52
|
const match = GIT.exec(spec);
|
|
22
53
|
const { ref, path } = (match?.groups ?? {});
|
|
23
54
|
const file = path ?? spec;
|
|
24
|
-
const text = built.get(spec) ?? (ref === undefined ?
|
|
55
|
+
const text = built.get(spec) ?? (ref === undefined ? fileText(spec, cwd) : git(ref, file, cwd));
|
|
25
56
|
let document;
|
|
26
57
|
try {
|
|
27
58
|
document = parseYaml(text);
|
|
@@ -155,14 +186,13 @@ const writeChangeset = (cwd, pkg, comparison, labels) => {
|
|
|
155
186
|
return undefined;
|
|
156
187
|
const body = comparison.findings.filter((finding) => finding.verdict !== 'non-breaking').map((finding) => `- ${finding.verdict}: \`${finding.id}\` in ${finding.operation} ${where(finding)}`);
|
|
157
188
|
const text = [`---`, `'${pkg}': ${BUMP[comparison.verdict]}`, `---`, '', `Contract changes from ${old} to ${nu}: ${comparison.verdict}.`, ...(body.length > 0 ? ['', ...body] : []), ''].join('\n');
|
|
158
|
-
const file = `.changeset/
|
|
189
|
+
const file = `.changeset/contractdiff-${createHash('sha256').update(text).digest('hex').slice(0, HASH_DIGITS)}.md`;
|
|
159
190
|
if (existsSync(resolve(cwd, file)))
|
|
160
191
|
return { file, changed: false };
|
|
161
192
|
mkdirSync(resolve(cwd, '.changeset'), { recursive: true });
|
|
162
193
|
writeFileSync(resolve(cwd, file), text);
|
|
163
194
|
return { file, changed: true };
|
|
164
195
|
};
|
|
165
|
-
const CONFIG = 'contractdiff.config.json';
|
|
166
196
|
const DATE_LENGTH = 10;
|
|
167
197
|
const settingAt = (ref, cwd, git) => {
|
|
168
198
|
try {
|
|
@@ -275,7 +305,7 @@ export const command = defineCommand({
|
|
|
275
305
|
mode: { type: 'string', choices: MODES, description: 'backward: old peers keep working; forward: the side may move first; full: both (default backward)' },
|
|
276
306
|
side: { type: 'string', choices: SIDES, description: 'whose code the question is about (default caller)' },
|
|
277
307
|
sarif: { type: 'boolean', description: 'print SARIF 2.1.0 for code scanning instead of text' },
|
|
278
|
-
changeset: { type: 'string', description: 'write .changeset
|
|
308
|
+
changeset: { type: 'string', description: 'write .changeset/contractdiff-<hash>.md bumping this package by the verdict', placeholder: 'package' },
|
|
279
309
|
decisions: {
|
|
280
310
|
type: 'string',
|
|
281
311
|
choices: DECISION_SETTINGS,
|
|
@@ -290,6 +320,7 @@ export const command = defineCommand({
|
|
|
290
320
|
run: async ({ args, options }) => {
|
|
291
321
|
const sides = {
|
|
292
322
|
built: await builtImages([args.old, args.new, ...args.more], HERE, bufIn()),
|
|
323
|
+
git: await gitReader([args.old, args.new, ...args.more], HERE, { config: true }),
|
|
293
324
|
cwd: HERE,
|
|
294
325
|
old: args.old,
|
|
295
326
|
new: args.new,
|
package/dist/command-migrate.js
CHANGED
|
@@ -6,6 +6,7 @@ import { migrate as openapiFetch } from './migrate-openapi-fetch.js';
|
|
|
6
6
|
import { migrate as openapiTypescript } from './migrate-openapi-typescript.js';
|
|
7
7
|
import { migrate as orval } from './migrate-orval.js';
|
|
8
8
|
import { configText } from './migrate-shared.js';
|
|
9
|
+
import { migrateText, withText } from './run-text.js';
|
|
9
10
|
import { writeFiles } from './scaffold-write.js';
|
|
10
11
|
export const SOURCES = {
|
|
11
12
|
'openapi-typescript': { migrate: openapiTypescript, configs: ['redocly.yaml', '.redocly.yaml'] },
|
|
@@ -57,14 +58,17 @@ export const command = defineCommand({
|
|
|
57
58
|
const dryRun = options.dryRun === true;
|
|
58
59
|
const report = dryRun ? { written: [], unchanged: [], kept: [] } : await writeFiles(root, written);
|
|
59
60
|
await Promise.all((dryRun ? [] : result.edits).map(async (edit) => writeFile(join(root, edit.path), edit.after)));
|
|
60
|
-
|
|
61
|
+
const read = [...(config === undefined ? [] : [config.name]), ...('package.json' in files ? ['package.json'] : [])];
|
|
62
|
+
const data = {
|
|
61
63
|
changed: !dryRun && (report.written.length > 0 || result.edits.length > 0),
|
|
62
|
-
read
|
|
64
|
+
read,
|
|
63
65
|
config: result.config ?? null,
|
|
64
66
|
...report,
|
|
65
67
|
edited: result.edits.map((edit) => edit.path),
|
|
66
68
|
findings: result.findings,
|
|
67
69
|
uninstall: result.uninstall,
|
|
68
70
|
};
|
|
71
|
+
const would = { ...data, written: dryRun ? written.map((file) => file.path) : data.written, edited: data.edited, dryRun };
|
|
72
|
+
return withText(data, () => migrateText(would));
|
|
69
73
|
},
|
|
70
74
|
});
|
package/dist/command-plugin.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { resolve } from 'node:path';
|
|
2
2
|
import { defineCommand } from 'burgee';
|
|
3
3
|
import { UsageError } from './run-config.js';
|
|
4
|
+
import { scaffoldText, withText } from './run-text.js';
|
|
4
5
|
import { seedOf } from './scaffold-seed.js';
|
|
5
6
|
import { writeFiles } from './scaffold-write.js';
|
|
6
7
|
import { KINDS, scaffold } from './scaffold.js';
|
|
@@ -27,6 +28,7 @@ export const command = defineCommand({
|
|
|
27
28
|
throw new UsageError(`--from seeds a rule, and --kind is ${options.kind}. fix: pass --kind rules with --from`);
|
|
28
29
|
const files = scaffold(args.name, options.kind, options.from === undefined ? undefined : seedOf(options.from, '.'));
|
|
29
30
|
const written = await writeFiles(resolve(options.out ?? ''), files);
|
|
30
|
-
|
|
31
|
+
const next = `node --test plugin-${args.name}.test.ts`;
|
|
32
|
+
return withText({ changed: written.written.length > 0, ...written, next }, () => scaffoldText(written, next));
|
|
31
33
|
},
|
|
32
34
|
});
|
package/dist/command-props.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { dirname, resolve } from 'node:path';
|
|
3
3
|
import { defineCommand, ExitCode } from 'burgee';
|
|
4
|
-
import { noGit, readContract, uriOf } from './command-diff.js';
|
|
4
|
+
import { gitReader, noGit, readContract, uriOf } from './command-diff.js';
|
|
5
5
|
import { MODES, SIDES } from './diff-classify.js';
|
|
6
6
|
import { bufIn, builtImages } from './input-buf.js';
|
|
7
7
|
import { emitArbitraries } from './props-emit.js';
|
|
@@ -103,6 +103,7 @@ export const command = defineCommand({
|
|
|
103
103
|
},
|
|
104
104
|
run: async ({ args, options }) => props({
|
|
105
105
|
built: await builtImages([args.contract, options.against], HERE, bufIn()),
|
|
106
|
+
git: await gitReader([args.contract, options.against], HERE),
|
|
106
107
|
cwd: HERE,
|
|
107
108
|
contract: args.contract,
|
|
108
109
|
against: options.against,
|
package/dist/diff-decisions.js
CHANGED
|
@@ -109,7 +109,7 @@ const record = (scan, at, pointer, holder) => {
|
|
|
109
109
|
scan.problems.push(decisionFinding(scan.level, 'invalid', place(at, pointer), {
|
|
110
110
|
before: value,
|
|
111
111
|
after: undefined,
|
|
112
|
-
fix: `${wordsFor(at.operation.id, at.payload, pointer)} has a bad \`${marker}
|
|
112
|
+
fix: `${wordsFor(at.operation.id, at.payload, pointer)} has a bad \`${marker}\`; ${fix}`,
|
|
113
113
|
}));
|
|
114
114
|
});
|
|
115
115
|
if (Object.keys(fields).length === 0)
|
|
@@ -245,14 +245,14 @@ const audit = (scan, holders, node, pointer) => {
|
|
|
245
245
|
scan.problems.push(decisionFinding(scan.level, 'misspelled', where(), {
|
|
246
246
|
before: key,
|
|
247
247
|
after: right,
|
|
248
|
-
fix: `\`${key}\` at ${here} is not a marker
|
|
248
|
+
fix: `\`${key}\` at ${here} is not a marker: rename it \`${right}\``,
|
|
249
249
|
}));
|
|
250
250
|
}
|
|
251
251
|
else if (!allowed && MARKERS.includes(key)) {
|
|
252
252
|
scan.problems.push(decisionFinding(scan.level, 'misplaced', where(), {
|
|
253
253
|
before: key,
|
|
254
254
|
after: node[key],
|
|
255
|
-
fix: `\`${key}\` at ${here} is not on a schema member, an operation or a parameter
|
|
255
|
+
fix: `\`${key}\` at ${here} is not on a schema member, an operation or a parameter: move it onto the member it describes, or remove it`,
|
|
256
256
|
}));
|
|
257
257
|
}
|
|
258
258
|
}
|
|
@@ -359,7 +359,7 @@ const holdBreaking = (sides, comparison) => {
|
|
|
359
359
|
held.findings.push(decisionFinding(sides.options.level, 'missing', placeOf(finding), {
|
|
360
360
|
before: finding.before,
|
|
361
361
|
after: finding.after,
|
|
362
|
-
fix: `breaking change (\`${finding.id}\`) at ${where} with no decision
|
|
362
|
+
fix: `breaking change (\`${finding.id}\`) at ${where} with no decision: add \`x-change: <the decision>\` to ${where}, or an ancestor or its operation, naming who decided it; or revert the change`,
|
|
363
363
|
}));
|
|
364
364
|
}
|
|
365
365
|
return held;
|
|
@@ -377,14 +377,14 @@ const holdStale = (sides, comparison) => [...sides.nu.decisions.values()]
|
|
|
377
377
|
.map((decision) => decisionFinding(sides.options.level, 'stale', placeOfDecision(sides, decision), {
|
|
378
378
|
before: undefined,
|
|
379
379
|
after: decision.change,
|
|
380
|
-
fix: `\`x-change: ${decision.change}\` at ${wordsOfDecision(decision)} records a change that is not in this diff
|
|
380
|
+
fix: `\`x-change: ${decision.change}\` at ${wordsOfDecision(decision)} records a change that is not in this diff: remove the marker, or make the change it records`,
|
|
381
381
|
}));
|
|
382
382
|
const holdOverdue = (sides) => [...sides.nu.decisions.values()]
|
|
383
383
|
.filter((decision) => decision.sunset !== undefined && decision.sunset < sides.options.today)
|
|
384
384
|
.map((decision) => decisionFinding(sides.options.level, 'overdue', placeOfDecision(sides, decision), {
|
|
385
385
|
before: decision.sunset,
|
|
386
386
|
after: sides.options.today,
|
|
387
|
-
fix: `${wordsOfDecision(decision)} was to go after ${decision.sunset} and is still here
|
|
387
|
+
fix: `${wordsOfDecision(decision)} was to go after ${decision.sunset} and is still here: remove it as decided, or move \`x-sunset\` to a date that still holds`,
|
|
388
388
|
}));
|
|
389
389
|
export const replacementKey = (decision) => {
|
|
390
390
|
const value = decision.replacedBy;
|
|
@@ -401,7 +401,7 @@ const holdReplacements = (sides) => [...sides.nu.decisions.values()]
|
|
|
401
401
|
.map((decision) => decisionFinding(sides.options.level, 'replacement-missing', placeOfDecision(sides, decision), {
|
|
402
402
|
before: decision.replacedBy,
|
|
403
403
|
after: undefined,
|
|
404
|
-
fix: `${wordsOfDecision(decision)} is replaced by \`${decision.replacedBy}\`, which is not in the new contract
|
|
404
|
+
fix: `${wordsOfDecision(decision)} is replaced by \`${decision.replacedBy}\`, which is not in the new contract: add that member, or point \`x-replaced-by\` at one that exists`,
|
|
405
405
|
}));
|
|
406
406
|
export const segmentOf = (operation) => {
|
|
407
407
|
const { major } = (/^#\/(?:paths|webhooks)\/[^/]*?~1v(?<major>\d+)(?=~1|\/|$)/.exec(operation.source)?.groups ?? {});
|
|
@@ -424,7 +424,7 @@ const holdVersions = (sides, decidedBy) => [...decidedBy.values()]
|
|
|
424
424
|
.map((decision) => decisionFinding(sides.options.level, 'unversioned', placeOfDecision(sides, decision), {
|
|
425
425
|
before: infoVersion(sides.oldContract),
|
|
426
426
|
after: infoVersion(sides.newContract),
|
|
427
|
-
fix: `\`x-change: ${decision.change}\` at ${wordsOfDecision(decision)} decides a breaking change, and the major version did not move
|
|
427
|
+
fix: `\`x-change: ${decision.change}\` at ${wordsOfDecision(decision)} decides a breaking change, and the major version did not move: move the path to a new major segment (/v3/ to /v4/), raise the major of \`info.version\`, or pass \`--changeset\` to write a major bump`,
|
|
428
428
|
}));
|
|
429
429
|
export const checkDecisions = (old, nu, comparison, options) => {
|
|
430
430
|
const oldOf = new Map(pair(old.operations, nu.operations).map(([before, after]) => [(after ?? before).id, (before ?? after)]));
|
package/dist/extract-standard.js
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
3
|
import { pathToFileURL } from 'node:url';
|
|
4
|
+
import { standardJson } from 'truefit/json-schema';
|
|
5
|
+
import { VENDOR } from 'truefit/standard';
|
|
4
6
|
import { stable } from './extract-normalise.js';
|
|
5
7
|
export const TARGET = 'draft-2020-12';
|
|
6
8
|
export const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
7
9
|
export const isStandard = (value) => (isRecord(value) || typeof value === 'function') && isRecord(value['~standard']);
|
|
10
|
+
const isTruefit = (value) => isRecord(value) && typeof value.kind === 'string' && typeof value.check === 'function';
|
|
11
|
+
export const asStandard = (value) => {
|
|
12
|
+
if (!isTruefit(value))
|
|
13
|
+
return value;
|
|
14
|
+
if (!isStandard(value))
|
|
15
|
+
return standardJson(value);
|
|
16
|
+
const props = value['~standard'];
|
|
17
|
+
return props.vendor !== VENDOR || isRecord(props.jsonSchema) ? value : standardJson(value);
|
|
18
|
+
};
|
|
8
19
|
export const escape = (step) => step.replaceAll('~', '~0').replaceAll('/', '~1');
|
|
9
20
|
export const finding = (code, pointer, message, fix) => ({ code, pointer, message, fix });
|
|
10
21
|
export const loadModule = async (module) => {
|
|
@@ -24,9 +35,10 @@ export const sideOf = (value) => {
|
|
|
24
35
|
return 'output';
|
|
25
36
|
throw new TypeError(`the \`side\` option is ${JSON.stringify(value)}. fix: write "input" or "output"`);
|
|
26
37
|
};
|
|
27
|
-
export const toJsonSchema = (
|
|
38
|
+
export const toJsonSchema = (given, side, pointer) => {
|
|
39
|
+
const value = asStandard(given);
|
|
28
40
|
if (!isStandard(value)) {
|
|
29
|
-
return { finding: finding('not-a-standard-schema', pointer, `${pointer} is not a Standard Schema: it has no \`~standard\``, 'export a schema of a Standard Schema library (Zod 4, Valibot, ArkType,
|
|
41
|
+
return { finding: finding('not-a-standard-schema', pointer, `${pointer} is not a Standard Schema: it has no \`~standard\``, 'export a schema of a Standard Schema library (Zod 4, Valibot, ArkType, truefit), or leave it out of the extract') };
|
|
30
42
|
}
|
|
31
43
|
const props = value['~standard'];
|
|
32
44
|
const vendor = typeof props.vendor === 'string' ? props.vendor : 'an unnamed library';
|
package/dist/inputs.js
CHANGED
|
@@ -4,5 +4,4 @@ import { adapter as mcp } from './input-mcp.js';
|
|
|
4
4
|
import { adapter as protobuf } from './input-protobuf.js';
|
|
5
5
|
import { adapter as swagger2 } from './input-swagger2.js';
|
|
6
6
|
import { openapi } from './openapi.js';
|
|
7
|
-
const
|
|
8
|
-
export const builtinAdapters = Object.fromEntries(Object.entries(planned).filter((entry) => entry[1] !== undefined));
|
|
7
|
+
export const builtinAdapters = { openapi, swagger2, asyncapi, mcp, protobuf, jsonschema };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { posix } from 'node:path';
|
|
2
2
|
import { migrate as migrateTypes } from './migrate-openapi-typescript.js';
|
|
3
3
|
import { finding } from './migrate-shared.js';
|
|
4
|
+
import { CLIENT_FILE } from './plugin-fetch.js';
|
|
4
5
|
const SOURCE = /\.(?:[cm]?[jt]s|[jt]sx)$/u;
|
|
5
6
|
const DEFAULT_IMPORT = /import\s+([$A-Z_a-z][\w$]*)\s+from\s+(["'])openapi-fetch\2/gu;
|
|
6
7
|
const ANY_IMPORT = /from\s+["']openapi-fetch["']|import\(\s*["']openapi-fetch["']\s*\)|require\(\s*["']openapi-fetch["']\s*\)/gu;
|
|
@@ -48,8 +49,8 @@ export const migrate = (configText, files) => {
|
|
|
48
49
|
if (types.config === undefined)
|
|
49
50
|
return { ...types, uninstall };
|
|
50
51
|
const { out } = types.config.targets.types;
|
|
51
|
-
const client = posix.join(
|
|
52
|
-
const config = { ...types.config, targets: { ...types.config.targets, fetch: { generator: 'fetch', out
|
|
52
|
+
const client = posix.join(out, CLIENT_FILE);
|
|
53
|
+
const config = { ...types.config, targets: { ...types.config.targets, fetch: { generator: 'fetch', out } } };
|
|
53
54
|
const sources = Object.entries(files)
|
|
54
55
|
.filter(([path, text]) => SOURCE.test(path) && text.includes('openapi-fetch'))
|
|
55
56
|
.map(([path, text]) => rewrite(path, text, client));
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { posix } from 'node:path';
|
|
1
2
|
import { parse as parseYaml } from 'seniority/yaml';
|
|
2
|
-
import { camel, commandParts, editScripts, finding, scripts } from './migrate-shared.js';
|
|
3
|
+
import { camel, commandParts, editScripts, finding, placeOf, scripts } from './migrate-shared.js';
|
|
4
|
+
import { TYPES_FILE } from './plugin-types.js';
|
|
5
|
+
import { under } from './run-commit.js';
|
|
3
6
|
const CARRIED = new Set([
|
|
4
7
|
'additional-properties',
|
|
5
8
|
'alphabetize',
|
|
@@ -27,7 +30,7 @@ const ALIASES = new Map([
|
|
|
27
30
|
['-t', '--export-type'],
|
|
28
31
|
]);
|
|
29
32
|
const RUNNERS = new Set(['npx', 'bunx', 'pnpx', 'pnpm', 'yarn', 'npm', 'exec', 'dlx']);
|
|
30
|
-
export const STDOUT_OUT = '
|
|
33
|
+
export const STDOUT_OUT = '.';
|
|
31
34
|
const words = (command) => [...command.matchAll(/"([^"]*)"|'([^']*)'|(\S+)/gu)].map((match) => match[1] ?? match[2] ?? match[3]);
|
|
32
35
|
const flagValue = (value) => {
|
|
33
36
|
if (value === undefined || value === 'true')
|
|
@@ -142,11 +145,16 @@ const assemble = (runs) => {
|
|
|
142
145
|
findings.push(finding('second-input', run.pointer, `${run.input} is a second input, and one contractdiff.config.json reads one`, 'write a second contractdiff.config.json for it in its own folder'));
|
|
143
146
|
continue;
|
|
144
147
|
}
|
|
148
|
+
const { out, file } = run.out === undefined ? { out: STDOUT_OUT, file: undefined } : placeOf(run.out);
|
|
149
|
+
const written = under(out, TYPES_FILE);
|
|
145
150
|
if (run.out === undefined) {
|
|
146
|
-
findings.push(finding('stdout-output', run.pointer, 'openapi-typescript printed to stdout, and contractdiff writes a file', `the target writes ${
|
|
151
|
+
findings.push(finding('stdout-output', run.pointer, 'openapi-typescript printed to stdout, and contractdiff writes a file', `the target writes ${written}: change \`out\` to the folder the types belong in`));
|
|
152
|
+
}
|
|
153
|
+
else if (file !== undefined && posix.basename(file) !== TYPES_FILE) {
|
|
154
|
+
findings.push(finding('output-renamed', run.pointer, `openapi-typescript wrote ${file}, and the types target writes ${written}: \`out\` names a folder`, `after \`contractdiff gen\`, point imports of ${file} at ${written}, and delete ${file}`));
|
|
147
155
|
}
|
|
148
156
|
const name = targets.size === 0 ? 'types' : `types-${String(targets.size + 1)}`;
|
|
149
|
-
targets.set(name, { generator: 'types', out
|
|
157
|
+
targets.set(name, { generator: 'types', out, options: { compat: 'openapi-typescript', ...run.options } });
|
|
150
158
|
}
|
|
151
159
|
return { config: { input, targets: Object.fromEntries(targets) }, findings };
|
|
152
160
|
};
|
package/dist/migrate-orval.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isUnreadable, readExport } from './migrate-literal.js';
|
|
2
|
-
import { commandParts, editScripts, finding, scripts } from './migrate-shared.js';
|
|
2
|
+
import { commandParts, editScripts, finding, placeOf, scripts } from './migrate-shared.js';
|
|
3
3
|
const CLIENTS = new Map([
|
|
4
4
|
['fetch', ['fetch']],
|
|
5
5
|
['axios', ['fetch']],
|
|
@@ -33,7 +33,8 @@ const targetOf = (value, pointer, findings, read) => {
|
|
|
33
33
|
findings.push(dropped(pointer, key));
|
|
34
34
|
return targetOf(value.target, `${pointer}/target`, findings, read);
|
|
35
35
|
};
|
|
36
|
-
const targetsOf = (settings,
|
|
36
|
+
const targetsOf = (settings, target, pointer, findings) => {
|
|
37
|
+
const { out } = placeOf(target);
|
|
37
38
|
const targets = new Map([['types', { generator: 'types', out: typeof settings.schemas === 'string' ? settings.schemas : out }]]);
|
|
38
39
|
const client = settings.client ?? DEFAULT_CLIENT;
|
|
39
40
|
const generators = CLIENTS.get(client) ?? [];
|
|
@@ -50,7 +51,7 @@ const targetsOf = (settings, out, pointer, findings) => {
|
|
|
50
51
|
targets.set('msw', { generator: 'msw', out });
|
|
51
52
|
else if (settings.mock !== undefined && settings.mock !== false)
|
|
52
53
|
findings.push(finding('option-dropped', `${pointer}/output/mock`, 'mock options other than `true` have no counterpart in contractdiff', 'set `mock: true` and run the migration again, or carry the options over by hand'));
|
|
53
|
-
findings.push(finding('imports-change', `${pointer}/output`, `the files
|
|
54
|
+
findings.push(finding('imports-change', `${pointer}/output`, `orval wrote ${target}, and the targets write their files into ${out} with contractdiff's module names, not orval's`, `after \`contractdiff gen\`, point imports of ${target} at the targets' files in ${out}`));
|
|
54
55
|
return Object.fromEntries(targets);
|
|
55
56
|
};
|
|
56
57
|
const project = (name, value, findings) => {
|
|
@@ -63,14 +64,14 @@ const project = (name, value, findings) => {
|
|
|
63
64
|
for (const key of Object.keys(rest))
|
|
64
65
|
findings.push(dropped(pointer, key));
|
|
65
66
|
const path = targetOf(input, `${pointer}/input`, findings, new Set(['target']));
|
|
66
|
-
const
|
|
67
|
-
if (path === undefined ||
|
|
67
|
+
const target = targetOf(output, `${pointer}/output`, findings, READ);
|
|
68
|
+
if (path === undefined || target === undefined) {
|
|
68
69
|
findings.push(finding('nothing-to-migrate', pointer, `the \`${name}\` project names no input or no output`, 'set `input` and `output` and run the migration again'));
|
|
69
70
|
return undefined;
|
|
70
71
|
}
|
|
71
72
|
if (/^https?:\/\//u.test(path))
|
|
72
73
|
findings.push(finding('remote-input', 'contractdiff.config.json#/input', `${path} is fetched over the network, and contractdiff reads local files`, 'download the document into the project and point `input` at it'));
|
|
73
|
-
return { input: path, targets: targetsOf(isDict(output) ? output : {},
|
|
74
|
+
return { input: path, targets: targetsOf(isDict(output) ? output : {}, target, pointer, findings) };
|
|
74
75
|
};
|
|
75
76
|
const BINARY = /^(\s*)(?:npx\s+)?orval((?:\s.*)?)$/u;
|
|
76
77
|
const fromFlags = (args) => {
|
package/dist/migrate-shared.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { posix } from 'node:path';
|
|
1
2
|
export const finding = (code, pointer, message, fix) => ({ code, pointer, message, fix });
|
|
2
3
|
export const scripts = (files) => {
|
|
3
4
|
try {
|
|
@@ -29,3 +30,9 @@ export const editScripts = (files, replaced) => {
|
|
|
29
30
|
export const commandParts = (command) => command.split(/(\s*(?:&&|\|\||;|\|)\s*)/u);
|
|
30
31
|
export const camel = (name) => name.replaceAll(/-([a-z])/gu, (_match, letter) => letter.toUpperCase());
|
|
31
32
|
export const configText = (config) => `${JSON.stringify(config, undefined, 2)}\n`;
|
|
33
|
+
const FILE_NAME = /\.[^./]+$/u;
|
|
34
|
+
export const placeOf = (path) => {
|
|
35
|
+
if (!FILE_NAME.test(posix.basename(path)))
|
|
36
|
+
return { out: path, file: undefined };
|
|
37
|
+
return { out: posix.dirname(path), file: path };
|
|
38
|
+
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { optional, number, object, string } from 'truefit';
|
|
2
2
|
import { standardJson } from 'truefit/json-schema';
|
|
3
|
-
import { definitions, escape, isStandard, loadModule, placeAt, relocate, sideOf, toJsonSchema } from './extract-standard.js';
|
|
3
|
+
import { asStandard, definitions, escape, finding, isStandard, loadModule, placeAt, relocate, sideOf, toJsonSchema } from './extract-standard.js';
|
|
4
4
|
export const DIALECT = 'https://json-schema.org/draft/2020-12/schema';
|
|
5
5
|
export const exportsOf = (namespace, wanted) => {
|
|
6
6
|
if (wanted === undefined || wanted === '*')
|
|
7
|
-
return Object.keys(namespace).filter((name) => isStandard(namespace[name])).toSorted();
|
|
7
|
+
return Object.keys(namespace).filter((name) => isStandard(asStandard(namespace[name]))).toSorted();
|
|
8
8
|
if (!Object.keys(namespace).includes(wanted)) {
|
|
9
9
|
throw new TypeError(`the module has no export ${JSON.stringify(wanted)}. fix: name one of ${Object.keys(namespace).toSorted().join(', ') || 'its exports'}, or write "*"`);
|
|
10
10
|
}
|
|
@@ -13,7 +13,12 @@ export const exportsOf = (namespace, wanted) => {
|
|
|
13
13
|
export const extractSchemas = (namespace, options) => {
|
|
14
14
|
const side = sideOf(options.side);
|
|
15
15
|
const place = placeAt('#/$defs/');
|
|
16
|
-
|
|
16
|
+
const names = exportsOf(namespace, options.export);
|
|
17
|
+
if (names.length === 0) {
|
|
18
|
+
const exported = Object.keys(namespace).toSorted();
|
|
19
|
+
place.findings.push(finding('no-schemas', '', `the module exports no schema this extractor reads${exported.length === 0 ? '' : ` (its exports: ${exported.join(', ')})`}`, 'export schemas of a Standard Schema library (Zod 4, Valibot, ArkType) or truefit, or name the export to read with `"export"`'));
|
|
20
|
+
}
|
|
21
|
+
for (const name of names) {
|
|
17
22
|
const result = toJsonSchema(namespace[name], side, `/${escape(name)}`);
|
|
18
23
|
if ('finding' in result)
|
|
19
24
|
place.findings.push(result.finding);
|
|
@@ -24,7 +29,7 @@ export const extractSchemas = (namespace, options) => {
|
|
|
24
29
|
};
|
|
25
30
|
const Pet = standardJson(object({ id: number(), name: optional(string()) }));
|
|
26
31
|
const extractor = {
|
|
27
|
-
description: 'Every Standard JSON Schema export of a module (Zod 4, Valibot, ArkType,
|
|
32
|
+
description: 'Every Standard JSON Schema export of a module (Zod 4, Valibot, ArkType, truefit) as one JSON Schema document',
|
|
28
33
|
options: {
|
|
29
34
|
module: { type: 'string', description: 'the module to import, relative to the working folder; its code runs' },
|
|
30
35
|
export: { type: 'string', description: 'the export to read, or "*" for every schema it exports (default)' },
|
|
@@ -35,6 +35,12 @@ export const validatorCode = (name, document, where) => {
|
|
|
35
35
|
].join('\n');
|
|
36
36
|
return { text, findings, door: true, typed };
|
|
37
37
|
};
|
|
38
|
+
export const nothingCode = (name, where) => ({
|
|
39
|
+
text: `export type ${name} = undefined;\n${comment([...where.doc, '', 'Nothing is sent: the only value is `undefined`.'])}\nexport const ${name}: ${guard(name)} = (value): value is ${name} => value === undefined;`,
|
|
40
|
+
findings: [],
|
|
41
|
+
door: false,
|
|
42
|
+
typed: true,
|
|
43
|
+
});
|
|
38
44
|
export const moduleOf = (codes, after = []) => {
|
|
39
45
|
const head = [...(codes.some((code) => !code.typed) ? [UNTYPED] : []), ...(codes.some((code) => code.door) ? [DOOR_IMPORTS] : [])];
|
|
40
46
|
return `${[...(head.length > 0 ? [head.join('\n')] : []), ...codes.map((code) => code.text), ...after].join('\n\n')}\n`;
|
package/dist/plugin-validator.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { build, sourceOf } from './plugin-json-schema-build.js';
|
|
2
|
-
import { comment, moduleOf, validatorCode } from './plugin-validator-code.js';
|
|
2
|
+
import { comment, moduleOf, nothingCode, validatorCode } from './plugin-validator-code.js';
|
|
3
3
|
import { namedPayloads } from './plugin-validator-names.js';
|
|
4
4
|
export const VALIDATORS_FILE = 'validators.ts';
|
|
5
5
|
export const INPUTS = ['openapi', 'swagger2', 'asyncapi', 'mcp', 'protobuf', 'jsonschema'];
|
|
@@ -10,8 +10,13 @@ export const generateValidators = (contract) => {
|
|
|
10
10
|
const named = namedPayloads(contract);
|
|
11
11
|
for (const { name, operation, payload } of named) {
|
|
12
12
|
const where = { label: name, at: operation.source };
|
|
13
|
+
const doc = [`\`${operation.id}\` ${payload.name} (${payload.direction}${payload.required ? '' : ', optional'}).`];
|
|
14
|
+
if (payload.schema === false) {
|
|
15
|
+
codes.push(nothingCode(name, { ...where, doc }));
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
13
18
|
const built = build(contract.document, payload.schema, { draft: '2020-12', refs: 'keep', source, ...where });
|
|
14
|
-
const code = validatorCode(name, built.schema, { ...where, typed: true, doc
|
|
19
|
+
const code = validatorCode(name, built.schema, { ...where, typed: true, doc });
|
|
15
20
|
findings.push(...built.findings, ...code.findings);
|
|
16
21
|
codes.push(code);
|
|
17
22
|
}
|
package/dist/props-mutate.js
CHANGED
|
@@ -41,14 +41,15 @@ const listBreaks = (schema, tokens) => {
|
|
|
41
41
|
}
|
|
42
42
|
return out;
|
|
43
43
|
};
|
|
44
|
-
const
|
|
44
|
+
const beyond = (bound, step) => bound + step * Math.max(1, Math.abs(bound) * Number.EPSILON);
|
|
45
|
+
const outside = (bound, excluded, step) => (excluded ? bound : beyond(bound, step));
|
|
45
46
|
const numberBreaks = (draw, schema, value, tokens) => {
|
|
46
47
|
const out = [];
|
|
47
48
|
const range = rangeOf(schema, draw.draft);
|
|
48
49
|
const whole = !typesOf(schema, draw.draft).includes('number');
|
|
49
50
|
const [low, high] = wholeIn(range);
|
|
50
|
-
const below = whole ? low -
|
|
51
|
-
const above = whole ? high
|
|
51
|
+
const below = whole ? beyond(low, -1) : outside(range.low, range.lowOut, -1);
|
|
52
|
+
const above = whole ? beyond(high, 1) : outside(range.high, range.highOut, 1);
|
|
52
53
|
const lowKey = range.lowOut && has(schema, 'exclusiveMinimum') ? 'exclusiveMinimum' : 'minimum';
|
|
53
54
|
const highKey = range.highOut && has(schema, 'exclusiveMaximum') ? 'exclusiveMaximum' : 'maximum';
|
|
54
55
|
if (has(schema, lowKey))
|
package/dist/run-command.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { defineCommand } from 'burgee';
|
|
2
|
+
import { builtins } from './plugins.js';
|
|
2
3
|
import { extract } from './run-extract.js';
|
|
3
4
|
import { gen } from './run-gen.js';
|
|
5
|
+
import { reportText, withText } from './run-text.js';
|
|
6
|
+
export const BUILTIN_EXTRACTORS = builtins.flatMap((plugin) => Object.keys(plugin.extractors ?? {}));
|
|
4
7
|
const writing = {
|
|
5
8
|
check: { type: 'boolean', description: 'write nothing; exit 1 and list the files that are stale' },
|
|
6
9
|
dryRun: { type: 'boolean', description: 'write nothing; print the diff a run would write' },
|
|
@@ -16,16 +19,22 @@ export const genCommand = defineCommand({
|
|
|
16
19
|
...writing,
|
|
17
20
|
target: { type: 'string', multiple: true, description: 'run only this target (repeatable)', placeholder: 'name' },
|
|
18
21
|
},
|
|
19
|
-
run: async ({ options }) =>
|
|
22
|
+
run: async ({ options }) => {
|
|
23
|
+
const report = await gen({ cwd: HERE, config: options.config, targets: options.target, check: options.check, dryRun: options.dryRun, force: options.force });
|
|
24
|
+
return withText(report, () => reportText(report));
|
|
25
|
+
},
|
|
20
26
|
});
|
|
21
27
|
export const extractCommand = defineCommand({
|
|
22
28
|
name: 'extract',
|
|
23
|
-
description: 'A spec from your code, one plugin per source:
|
|
29
|
+
description: 'A spec from your code, one plugin per source: Standard Schema exports (Zod 4, Valibot, ArkType, truefit), ts-rest contracts, routes declared with schemas',
|
|
24
30
|
effects: 'idempotent',
|
|
25
31
|
options: {
|
|
26
32
|
...writing,
|
|
27
|
-
from: { type: 'string', description:
|
|
33
|
+
from: { type: 'string', description: `the extractor to run: ${BUILTIN_EXTRACTORS.join(', ')}, or a plugin's (default: \`extract.from\` in the config)`, placeholder: 'extractor' },
|
|
28
34
|
out: { type: 'string', description: 'the spec file to write (default: spec.json)', placeholder: 'file' },
|
|
29
35
|
},
|
|
30
|
-
run: async ({ options }) =>
|
|
36
|
+
run: async ({ options }) => {
|
|
37
|
+
const report = await extract({ cwd: HERE, config: options.config, from: options.from, out: options.out, check: options.check, dryRun: options.dryRun, force: options.force });
|
|
38
|
+
return withText(report, () => reportText(report));
|
|
39
|
+
},
|
|
31
40
|
});
|
package/dist/run-text.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export const TEXT = Symbol.for('burgee.text');
|
|
2
|
+
export const withText = (data, text) => Object.assign({ ...data }, { [TEXT]: text });
|
|
3
|
+
const findingLines = (findings) => findings.length === 0
|
|
4
|
+
? []
|
|
5
|
+
: [
|
|
6
|
+
'',
|
|
7
|
+
`findings: ${String(findings.length)}`,
|
|
8
|
+
...findings.flatMap((finding) => [
|
|
9
|
+
` ${[finding.target, finding.code, finding.pointer].filter((part) => part !== undefined && part !== '').join(' ')}: ${finding.message}`,
|
|
10
|
+
` fix: ${finding.fix}`,
|
|
11
|
+
]),
|
|
12
|
+
];
|
|
13
|
+
export const reportText = (report) => {
|
|
14
|
+
if (report.stale !== undefined) {
|
|
15
|
+
const head = report.stale.length === 0 ? [`up to date: ${String(report.unchanged)} file(s)`] : [`stale: ${String(report.stale.length)} file(s)`, ...report.stale.map((path) => ` ${path}`), `fix: ${report.fix}`];
|
|
16
|
+
return [...head, ...findingLines(report.findings)].join('\n');
|
|
17
|
+
}
|
|
18
|
+
const verb = report.diff === undefined ? '' : 'would ';
|
|
19
|
+
const done = report.files.filter((file) => file.action !== 'unchanged').map((file) => `${verb}${file.action} ${file.path}`);
|
|
20
|
+
const lines = done.length === 0 ? [`nothing to write: ${String(report.unchanged)} file(s) up to date`] : done;
|
|
21
|
+
return [...lines, ...findingLines(report.findings), ...(report.diff === undefined || report.diff === '' ? [] : ['', report.diff.trimEnd()])].join('\n');
|
|
22
|
+
};
|
|
23
|
+
export const migrateText = (report) => {
|
|
24
|
+
const verb = report.dryRun ? 'would ' : '';
|
|
25
|
+
const lines = [
|
|
26
|
+
`read: ${report.read.length === 0 ? 'nothing (no config file and no package.json)' : report.read.join(', ')}`,
|
|
27
|
+
...report.written.map((path) => `${verb}write ${path}`),
|
|
28
|
+
...report.edited.map((path) => `${verb}edit ${path}`),
|
|
29
|
+
...report.kept.map((path) => `kept ${path}: it is already there, and yours`),
|
|
30
|
+
...report.unchanged.map((path) => `unchanged ${path}`),
|
|
31
|
+
];
|
|
32
|
+
return [...lines, ...findingLines(report.findings), '', `then remove it: ${report.uninstall}`].join('\n');
|
|
33
|
+
};
|
|
34
|
+
export const scaffoldText = (written, next) => [
|
|
35
|
+
...written.written.map((path) => `write ${path}`),
|
|
36
|
+
...written.unchanged.map((path) => `unchanged ${path}`),
|
|
37
|
+
...written.kept.map((path) => `kept ${path}: it is already there, and yours`),
|
|
38
|
+
'',
|
|
39
|
+
`next: ${next}`,
|
|
40
|
+
].join('\n');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "contractdiff",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Breaking-change diff, lint and code generation for API contracts (OpenAPI, JSON Schema, AsyncAPI, MCP), and the spec back from the code. No dependency outside the burgee family. An openapi-typescript migration path.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"bugs": {
|
|
14
14
|
"url": "https://github.com/ofri-peretz/burgee/issues"
|
|
15
15
|
},
|
|
16
|
-
"homepage": "https://
|
|
16
|
+
"homepage": "https://contractdiff.interlace.tools",
|
|
17
17
|
"type": "module",
|
|
18
18
|
"sideEffects": [
|
|
19
19
|
"./dist/bin.js"
|
|
@@ -79,11 +79,11 @@
|
|
|
79
79
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
80
80
|
"test": "vitest run",
|
|
81
81
|
"coverage": "vitest run --coverage.enabled",
|
|
82
|
-
"lint": "eslint src"
|
|
82
|
+
"lint": "cd ../.. && eslint packages/contractdiff/src --max-warnings 0"
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
85
|
"bellpull": "^2.0.3",
|
|
86
|
-
"burgee": "^2.2.
|
|
86
|
+
"burgee": "^2.2.2",
|
|
87
87
|
"seniority": "^2.0.0",
|
|
88
88
|
"truefit": "^1.0.0"
|
|
89
89
|
},
|