@openpkg-ts/spec 0.27.1 → 0.31.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.
- package/README.md +24 -3
- package/dist/index.d.ts +11 -2
- package/dist/index.js +15 -13
- package/package.json +5 -6
package/README.md
CHANGED
|
@@ -66,8 +66,8 @@ const diff = diffSpec(baseSpec, headSpec);
|
|
|
66
66
|
|
|
67
67
|
console.log(`Added: ${diff.added.length}`);
|
|
68
68
|
console.log(`Removed: ${diff.removed.length}`);
|
|
69
|
-
console.log(`Modified: ${diff.modified.length}`);
|
|
70
69
|
console.log(`Breaking: ${diff.breaking.length}`);
|
|
70
|
+
console.log(`Docs only: ${diff.docsOnly.length}`);
|
|
71
71
|
|
|
72
72
|
// Get semver recommendation
|
|
73
73
|
const recommendation = recommendSemverBump(diff);
|
|
@@ -79,6 +79,21 @@ const next = calculateNextVersion('1.2.3', recommendation.bump);
|
|
|
79
79
|
console.log(`Next version: ${next}`); // '2.0.0'
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
+
### DiffOptions
|
|
83
|
+
|
|
84
|
+
Filter diff results by criteria.
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { diffSpec, type DiffOptions } from '@openpkg-ts/spec';
|
|
88
|
+
|
|
89
|
+
const options: DiffOptions = {
|
|
90
|
+
includeDocsOnly: false, // exclude documentation-only changes
|
|
91
|
+
kinds: ['function', 'class'], // filter by export kind
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const diff = diffSpec(oldSpec, newSpec, options);
|
|
95
|
+
```
|
|
96
|
+
|
|
82
97
|
## Dereferencing
|
|
83
98
|
|
|
84
99
|
Resolve `$ref` pointers in the spec.
|
|
@@ -101,6 +116,10 @@ import type {
|
|
|
101
116
|
SpecClass,
|
|
102
117
|
SpecInterface,
|
|
103
118
|
SpecMeta,
|
|
119
|
+
SpecDiff,
|
|
120
|
+
DiffOptions,
|
|
121
|
+
SemverBump,
|
|
122
|
+
SemverRecommendation,
|
|
104
123
|
} from '@openpkg-ts/spec';
|
|
105
124
|
```
|
|
106
125
|
|
|
@@ -117,10 +136,10 @@ import type {
|
|
|
117
136
|
- `dereference(spec)` - Resolve $ref pointers
|
|
118
137
|
|
|
119
138
|
### Diffing
|
|
120
|
-
- `diffSpec(base, head)` - Compare specs
|
|
139
|
+
- `diffSpec(base, head, options?)` - Compare specs (supports `DiffOptions`)
|
|
121
140
|
- `recommendSemverBump(diff)` - Suggest version bump
|
|
122
141
|
- `calculateNextVersion(version, bump)` - Calculate next version
|
|
123
|
-
- `categorizeBreakingChanges(
|
|
142
|
+
- `categorizeBreakingChanges(breaking, old, new)` - Group by severity
|
|
124
143
|
|
|
125
144
|
### Types
|
|
126
145
|
- `OpenPkg` - Root spec type
|
|
@@ -128,6 +147,8 @@ import type {
|
|
|
128
147
|
- `SpecType` - Type definition
|
|
129
148
|
- `SpecFunction`, `SpecClass`, `SpecInterface` - Export kinds
|
|
130
149
|
- `SpecDiff` - Diff result type
|
|
150
|
+
- `DiffOptions` - Diff filtering options
|
|
151
|
+
- `SemverBump`, `SemverRecommendation` - Semver types
|
|
131
152
|
|
|
132
153
|
## License
|
|
133
154
|
|
package/dist/index.d.ts
CHANGED
|
@@ -424,9 +424,18 @@ type SpecDiff = {
|
|
|
424
424
|
docsOnly: string[];
|
|
425
425
|
};
|
|
426
426
|
/**
|
|
427
|
+
* Options for diffSpec filtering.
|
|
428
|
+
*/
|
|
429
|
+
interface DiffOptions {
|
|
430
|
+
/** Include documentation-only changes (default: true) */
|
|
431
|
+
includeDocsOnly?: boolean;
|
|
432
|
+
/** Filter by kinds */
|
|
433
|
+
kinds?: SpecExportKind[];
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
427
436
|
* Compare two OpenPkg specs and compute differences.
|
|
428
437
|
*/
|
|
429
|
-
declare function diffSpec(oldSpec: OpenPkg, newSpec: OpenPkg): SpecDiff;
|
|
438
|
+
declare function diffSpec(oldSpec: OpenPkg, newSpec: OpenPkg, options?: DiffOptions): SpecDiff;
|
|
430
439
|
/**
|
|
431
440
|
* Categorize breaking changes by severity
|
|
432
441
|
*/
|
|
@@ -529,4 +538,4 @@ declare function assertSpec(spec: unknown, version?: SchemaVersion): asserts spe
|
|
|
529
538
|
* @returns Array of validation errors (empty if valid)
|
|
530
539
|
*/
|
|
531
540
|
declare function getValidationErrors(spec: unknown, version?: SchemaVersion): SpecError[];
|
|
532
|
-
export { validateSpec, recommendSemverBump, normalize, getValidationErrors, getAvailableVersions, diffSpec, dereference, categorizeBreakingChanges, calculateNextVersion, assertSpec, SpecVisibility, SpecTypePredicate, SpecTypeParameter, SpecTypeKind, SpecTypeAliasKind, SpecType, SpecThrows, SpecTagParam, SpecTag, SpecSource, SpecSignatureReturn, SpecSignatureParameter, SpecSignature, SpecSchemaRef, SpecSchemaPrimitive, SpecSchemaGeneric, SpecSchemaFallback, SpecSchemaComposite, SpecSchemaCombinator, SpecSchema, SpecPresentationMeta, SpecMember, SpecMappedType, SpecInheritedMember, SpecGenerationMeta, SpecGenerationInfo, SpecExtractionMode, SpecExtractionLimitation, SpecExtensions, SpecExtension, SpecExportKind, SpecExport, SpecExampleLanguage, SpecExample, SpecDiff, SpecDecorator, SpecConditionalType, SemverRecommendation, SemverBump, SCHEMA_VERSION, SCHEMA_URL, OpenPkgVersion, OpenPkgMeta, OpenPkg, MemberChangeInfo, JSON_SCHEMA_DRAFT, JSONSchemaExtensions, GenerationIssueSeverity, GenerationIssue, EntryPointDetectionMethod, CategorizedBreaking, BreakingSeverity };
|
|
541
|
+
export { validateSpec, recommendSemverBump, normalize, getValidationErrors, getAvailableVersions, diffSpec, dereference, categorizeBreakingChanges, calculateNextVersion, assertSpec, SpecVisibility, SpecTypePredicate, SpecTypeParameter, SpecTypeKind, SpecTypeAliasKind, SpecType, SpecThrows, SpecTagParam, SpecTag, SpecSource, SpecSignatureReturn, SpecSignatureParameter, SpecSignature, SpecSchemaRef, SpecSchemaPrimitive, SpecSchemaGeneric, SpecSchemaFallback, SpecSchemaComposite, SpecSchemaCombinator, SpecSchema, SpecPresentationMeta, SpecMember, SpecMappedType, SpecInheritedMember, SpecGenerationMeta, SpecGenerationInfo, SpecExtractionMode, SpecExtractionLimitation, SpecExtensions, SpecExtension, SpecExportKind, SpecExport, SpecExampleLanguage, SpecExample, SpecDiff, SpecDecorator, SpecConditionalType, SemverRecommendation, SemverBump, SCHEMA_VERSION, SCHEMA_URL, OpenPkgVersion, OpenPkgMeta, OpenPkg, MemberChangeInfo, JSON_SCHEMA_DRAFT, JSONSchemaExtensions, GenerationIssueSeverity, GenerationIssue, EntryPointDetectionMethod, DiffOptions, CategorizedBreaking, BreakingSeverity };
|
package/dist/index.js
CHANGED
|
@@ -68,24 +68,26 @@ function resolveTypeRef(id, lookup, seen) {
|
|
|
68
68
|
return JSON.parse(JSON.stringify(target));
|
|
69
69
|
}
|
|
70
70
|
// src/diff.ts
|
|
71
|
-
function diffSpec(oldSpec, newSpec) {
|
|
71
|
+
function diffSpec(oldSpec, newSpec, options) {
|
|
72
|
+
const { includeDocsOnly = true, kinds } = options ?? {};
|
|
73
|
+
let oldExports = oldSpec.exports;
|
|
74
|
+
let newExports = newSpec.exports;
|
|
75
|
+
if (kinds && kinds.length > 0) {
|
|
76
|
+
const kindSet = new Set(kinds);
|
|
77
|
+
oldExports = oldExports.filter((e) => kindSet.has(e.kind));
|
|
78
|
+
newExports = newExports.filter((e) => kindSet.has(e.kind));
|
|
79
|
+
}
|
|
72
80
|
const result = {
|
|
73
81
|
breaking: [],
|
|
74
82
|
nonBreaking: [],
|
|
75
83
|
docsOnly: []
|
|
76
84
|
};
|
|
77
|
-
diffCollections(result,
|
|
85
|
+
diffCollections(result, oldExports, newExports);
|
|
78
86
|
diffCollections(result, oldSpec.types ?? [], newSpec.types ?? []);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
function toExportMap(exports) {
|
|
82
|
-
const map = new Map;
|
|
83
|
-
for (const exp of exports) {
|
|
84
|
-
if (exp && typeof exp.id === "string") {
|
|
85
|
-
map.set(exp.id, exp);
|
|
86
|
-
}
|
|
87
|
+
if (!includeDocsOnly) {
|
|
88
|
+
result.docsOnly = [];
|
|
87
89
|
}
|
|
88
|
-
return
|
|
90
|
+
return result;
|
|
89
91
|
}
|
|
90
92
|
function diffCollections(result, oldItems, newItems) {
|
|
91
93
|
const oldMap = toMap(oldItems);
|
|
@@ -168,8 +170,8 @@ function sortKeys(value) {
|
|
|
168
170
|
return result;
|
|
169
171
|
}
|
|
170
172
|
function categorizeBreakingChanges(breaking, oldSpec, newSpec, memberChanges) {
|
|
171
|
-
const oldExportMap =
|
|
172
|
-
const newExportMap =
|
|
173
|
+
const oldExportMap = toMap(oldSpec.exports);
|
|
174
|
+
const newExportMap = toMap(newSpec.exports);
|
|
173
175
|
const categorized = [];
|
|
174
176
|
for (const id of breaking) {
|
|
175
177
|
const oldExport = oldExportMap.get(id);
|
package/package.json
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpkg-ts/spec",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0",
|
|
4
4
|
"description": "Shared schema, validation, and diff utilities for OpenPkg specs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"openpkg",
|
|
7
|
-
"doccov",
|
|
8
7
|
"json-schema",
|
|
9
8
|
"validation",
|
|
10
9
|
"typescript",
|
|
11
10
|
"spec"
|
|
12
11
|
],
|
|
13
|
-
"homepage": "https://github.com/
|
|
12
|
+
"homepage": "https://github.com/ryanwaits/openpkg-ts#readme",
|
|
14
13
|
"repository": {
|
|
15
14
|
"type": "git",
|
|
16
|
-
"url": "git+https://github.com/
|
|
15
|
+
"url": "git+https://github.com/ryanwaits/openpkg-ts.git",
|
|
17
16
|
"directory": "packages/spec"
|
|
18
17
|
},
|
|
19
18
|
"license": "MIT",
|
|
@@ -23,8 +22,8 @@
|
|
|
23
22
|
"types": "./dist/index.d.ts",
|
|
24
23
|
"exports": {
|
|
25
24
|
".": {
|
|
26
|
-
"import": "./
|
|
27
|
-
"types": "./
|
|
25
|
+
"import": "./src/index.ts",
|
|
26
|
+
"types": "./src/index.ts"
|
|
28
27
|
}
|
|
29
28
|
},
|
|
30
29
|
"files": [
|