@openpkg-ts/sdk 0.32.1 → 0.33.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/dist/index.d.ts +183 -140
- package/dist/index.js +321 -96
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,159 @@
|
|
|
1
1
|
import { BreakingSeverity, CategorizedBreaking, calculateNextVersion, categorizeBreakingChanges, diffSpec, diffSpec as diffSpec2, MemberChangeInfo, recommendSemverBump, SemverBump, SemverRecommendation, SpecDiff } from "@openpkg-ts/spec";
|
|
2
|
-
import { OpenPkg
|
|
2
|
+
import { OpenPkg } from "@openpkg-ts/spec";
|
|
3
|
+
/** Configuration for resolving external package re-exports */
|
|
4
|
+
interface ExternalsConfig {
|
|
5
|
+
/** Package patterns to resolve (globs supported, e.g., "@myorg/*") */
|
|
6
|
+
include?: string[];
|
|
7
|
+
/** Package patterns to never resolve */
|
|
8
|
+
exclude?: string[];
|
|
9
|
+
/** Max transitive depth for resolution (default: 1) */
|
|
10
|
+
depth?: number;
|
|
11
|
+
}
|
|
12
|
+
interface ExtractOptions {
|
|
13
|
+
entryFile: string;
|
|
14
|
+
baseDir?: string;
|
|
15
|
+
content?: string;
|
|
16
|
+
maxTypeDepth?: number;
|
|
17
|
+
maxExternalTypeDepth?: number;
|
|
18
|
+
resolveExternalTypes?: boolean;
|
|
19
|
+
schemaExtraction?: "static" | "hybrid";
|
|
20
|
+
/** Target JSON Schema dialect for runtime schema extraction */
|
|
21
|
+
schemaTarget?: "draft-2020-12" | "draft-07" | "openapi-3.0";
|
|
22
|
+
/** Include $schema URL in output */
|
|
23
|
+
includeSchema?: boolean;
|
|
24
|
+
/** Only extract these exports (supports * wildcards) */
|
|
25
|
+
only?: string[];
|
|
26
|
+
/** Ignore these exports (supports * wildcards) */
|
|
27
|
+
ignore?: string[];
|
|
28
|
+
/** Progress callback for tracking extraction progress */
|
|
29
|
+
onProgress?: (current: number, total: number, item: string) => void;
|
|
30
|
+
/** Whether source is a .d.ts file (degraded mode - TSDoc may be missing) */
|
|
31
|
+
isDtsSource?: boolean;
|
|
32
|
+
/** Include private/protected class members (default: false) */
|
|
33
|
+
includePrivate?: boolean;
|
|
34
|
+
/** Configuration for resolving external package re-exports */
|
|
35
|
+
externals?: ExternalsConfig;
|
|
36
|
+
}
|
|
37
|
+
interface ExtractResult {
|
|
38
|
+
spec: OpenPkg;
|
|
39
|
+
diagnostics: Diagnostic[];
|
|
40
|
+
forgottenExports?: ForgottenExport[];
|
|
41
|
+
/** Metadata about runtime schema extraction (when schemaExtraction: 'hybrid') */
|
|
42
|
+
runtimeSchemas?: {
|
|
43
|
+
/** Number of schema exports found */
|
|
44
|
+
extracted: number;
|
|
45
|
+
/** Number of schemas successfully merged with static types */
|
|
46
|
+
merged: number;
|
|
47
|
+
/** Schema vendors detected (e.g., 'zod', 'arktype', 'valibot', 'typebox') */
|
|
48
|
+
vendors: string[];
|
|
49
|
+
/** Any errors encountered during runtime extraction */
|
|
50
|
+
errors: string[];
|
|
51
|
+
/** Extraction method used: 'compiled' or 'direct-ts (runtime)' */
|
|
52
|
+
method?: string;
|
|
53
|
+
};
|
|
54
|
+
/** Degraded mode info when extracting from .d.ts files */
|
|
55
|
+
degradedMode?: {
|
|
56
|
+
reason: "dts-source";
|
|
57
|
+
stats: {
|
|
58
|
+
exportsWithoutDescription: number;
|
|
59
|
+
paramsWithoutDocs: number;
|
|
60
|
+
missingExamples: number;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
/** Export verification comparing discovered vs extracted */
|
|
64
|
+
verification?: ExportVerification;
|
|
65
|
+
}
|
|
66
|
+
interface Diagnostic {
|
|
67
|
+
message: string;
|
|
68
|
+
severity: "error" | "warning" | "info";
|
|
69
|
+
code?: string;
|
|
70
|
+
suggestion?: string;
|
|
71
|
+
location?: {
|
|
72
|
+
file?: string;
|
|
73
|
+
line?: number;
|
|
74
|
+
column?: number;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/** Context tracking for type references in public API */
|
|
78
|
+
interface TypeReference2 {
|
|
79
|
+
typeName: string;
|
|
80
|
+
exportName: string;
|
|
81
|
+
location: "return" | "parameter" | "property" | "extends" | "type-parameter";
|
|
82
|
+
path?: string;
|
|
83
|
+
}
|
|
84
|
+
/** Structured data for forgotten exports */
|
|
85
|
+
interface ForgottenExport {
|
|
86
|
+
name: string;
|
|
87
|
+
definedIn?: string;
|
|
88
|
+
referencedBy: TypeReference2[];
|
|
89
|
+
isExternal: boolean;
|
|
90
|
+
fix?: string;
|
|
91
|
+
}
|
|
92
|
+
/** Tracks status of each discovered through serialization pipeline */
|
|
93
|
+
interface ExportTracker {
|
|
94
|
+
name: string;
|
|
95
|
+
discovered: boolean;
|
|
96
|
+
status: "pending" | "success" | "skipped" | "failed";
|
|
97
|
+
skipReason?: "filtered" | "no-declaration" | "internal" | "external-unresolved";
|
|
98
|
+
/** Package name for external-unresolved skips */
|
|
99
|
+
externalPackage?: string;
|
|
100
|
+
error?: string;
|
|
101
|
+
kind?: string;
|
|
102
|
+
}
|
|
103
|
+
/** Detail for a skipped */
|
|
104
|
+
interface SkippedExportDetail {
|
|
105
|
+
name: string;
|
|
106
|
+
reason: "filtered" | "no-declaration" | "internal" | "external-unresolved";
|
|
107
|
+
/** Package name when reason is external-unresolved */
|
|
108
|
+
package?: string;
|
|
109
|
+
}
|
|
110
|
+
/** Verification result comparing discovered vs extracted exports */
|
|
111
|
+
interface ExportVerification {
|
|
112
|
+
/** Total exports discovered by TypeScript */
|
|
113
|
+
discovered: number;
|
|
114
|
+
/** Exports successfully extracted */
|
|
115
|
+
extracted: number;
|
|
116
|
+
/** Exports skipped (filtered, no-declaration, internal, external-unresolved) */
|
|
117
|
+
skipped: number;
|
|
118
|
+
/** Exports that failed during serialization */
|
|
119
|
+
failed: number;
|
|
120
|
+
/** Delta: discovered - extracted */
|
|
121
|
+
delta: number;
|
|
122
|
+
details: {
|
|
123
|
+
skipped: SkippedExportDetail[];
|
|
124
|
+
failed: Array<{
|
|
125
|
+
name: string;
|
|
126
|
+
error: string;
|
|
127
|
+
}>;
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/** openpkg configuration from config file or package.json */
|
|
131
|
+
interface OpenpkgConfig {
|
|
132
|
+
/** Configuration for resolving external package re-exports */
|
|
133
|
+
externals?: ExternalsConfig;
|
|
134
|
+
}
|
|
135
|
+
/** Default config filename */
|
|
136
|
+
declare const CONFIG_FILENAME = "openpkg.config.json";
|
|
137
|
+
/**
|
|
138
|
+
* Load openpkg configuration from the project directory
|
|
139
|
+
*
|
|
140
|
+
* Looks for config in order of precedence:
|
|
141
|
+
* 1. openpkg.config.json
|
|
142
|
+
* 2. package.json "openpkg" field
|
|
143
|
+
*
|
|
144
|
+
* @param cwd - Directory to search for config
|
|
145
|
+
* @returns Loaded config or null if not found
|
|
146
|
+
*/
|
|
147
|
+
declare function loadConfig(cwd: string): OpenpkgConfig | null;
|
|
148
|
+
/**
|
|
149
|
+
* Merge file config with CLI options (CLI takes precedence)
|
|
150
|
+
*
|
|
151
|
+
* @param fileConfig - Config loaded from file (or null)
|
|
152
|
+
* @param cliOptions - Options provided via CLI flags
|
|
153
|
+
* @returns Merged config
|
|
154
|
+
*/
|
|
155
|
+
declare function mergeConfig(fileConfig: OpenpkgConfig | null, cliOptions: Partial<OpenpkgConfig>): OpenpkgConfig;
|
|
156
|
+
import { OpenPkg as OpenPkg2, SpecExport } from "@openpkg-ts/spec";
|
|
3
157
|
interface DiagnosticItem {
|
|
4
158
|
exportId: string;
|
|
5
159
|
exportName: string;
|
|
@@ -33,7 +187,7 @@ declare function findMissingParamDocs(exp: SpecExport): string[];
|
|
|
33
187
|
/**
|
|
34
188
|
* Analyze a spec for quality issues.
|
|
35
189
|
*/
|
|
36
|
-
declare function analyzeSpec(spec:
|
|
190
|
+
declare function analyzeSpec(spec: OpenPkg2): SpecDiagnostics;
|
|
37
191
|
import { SpecMember } from "@openpkg-ts/spec";
|
|
38
192
|
/**
|
|
39
193
|
* Extract badge strings from a member's visibility and flags.
|
|
@@ -44,8 +198,8 @@ declare function getMemberBadges(member: SpecMember): string[];
|
|
|
44
198
|
* Format badges array into a display string (space-separated).
|
|
45
199
|
*/
|
|
46
200
|
declare function formatBadges(badges: string[]): string;
|
|
47
|
-
import { OpenPkg as
|
|
48
|
-
import { OpenPkg as
|
|
201
|
+
import { OpenPkg as OpenPkg8, SpecExport as SpecExport3, SpecExportKind as SpecExportKind4, SpecType } from "@openpkg-ts/spec";
|
|
202
|
+
import { OpenPkg as OpenPkg3 } from "@openpkg-ts/spec";
|
|
49
203
|
interface HTMLOptions {
|
|
50
204
|
/** Page title override */
|
|
51
205
|
title?: string;
|
|
@@ -83,8 +237,8 @@ interface HTMLOptions {
|
|
|
83
237
|
* const fragment = docs.toHTML({ export: 'greet', fullDocument: false })
|
|
84
238
|
* ```
|
|
85
239
|
*/
|
|
86
|
-
declare function toHTML2(spec:
|
|
87
|
-
import { OpenPkg as
|
|
240
|
+
declare function toHTML2(spec: OpenPkg3, options?: HTMLOptions): string;
|
|
241
|
+
import { OpenPkg as OpenPkg4, SpecExportKind } from "@openpkg-ts/spec";
|
|
88
242
|
interface JSONOptions {
|
|
89
243
|
/** Include raw spec data alongside simplified data */
|
|
90
244
|
includeRaw?: boolean;
|
|
@@ -178,7 +332,7 @@ interface SimplifiedSpec {
|
|
|
178
332
|
* // { id, name, kind, signature, parameters, returns, ... }
|
|
179
333
|
* ```
|
|
180
334
|
*/
|
|
181
|
-
declare function toJSON2(spec:
|
|
335
|
+
declare function toJSON2(spec: OpenPkg4, options?: JSONOptions): SimplifiedSpec | SimplifiedExport;
|
|
182
336
|
/**
|
|
183
337
|
* Serialize to JSON string with formatting.
|
|
184
338
|
*
|
|
@@ -186,10 +340,10 @@ declare function toJSON2(spec: OpenPkg3, options?: JSONOptions): SimplifiedSpec
|
|
|
186
340
|
* @param options - JSON options plus pretty formatting option
|
|
187
341
|
* @returns JSON string
|
|
188
342
|
*/
|
|
189
|
-
declare function toJSONString(spec:
|
|
343
|
+
declare function toJSONString(spec: OpenPkg4, options?: JSONOptions & {
|
|
190
344
|
pretty?: boolean;
|
|
191
345
|
}): string;
|
|
192
|
-
import { OpenPkg as
|
|
346
|
+
import { OpenPkg as OpenPkg5, SpecExport as SpecExport2 } from "@openpkg-ts/spec";
|
|
193
347
|
interface MarkdownOptions {
|
|
194
348
|
/** Include frontmatter in output */
|
|
195
349
|
frontmatter?: boolean;
|
|
@@ -255,8 +409,8 @@ declare function exportToMarkdown(exp: SpecExport2, options?: MarkdownOptions):
|
|
|
255
409
|
* // Single * const fnMdx = docs.toMarkdown({ export: 'greet' })
|
|
256
410
|
* ```
|
|
257
411
|
*/
|
|
258
|
-
declare function toMarkdown2(spec:
|
|
259
|
-
import { OpenPkg as
|
|
412
|
+
declare function toMarkdown2(spec: OpenPkg5, options?: ExportMarkdownOptions): string;
|
|
413
|
+
import { OpenPkg as OpenPkg6, SpecExportKind as SpecExportKind2 } from "@openpkg-ts/spec";
|
|
260
414
|
type NavFormat = "fumadocs" | "docusaurus" | "generic";
|
|
261
415
|
type GroupBy = "kind" | "module" | "tag" | "none";
|
|
262
416
|
interface NavOptions {
|
|
@@ -331,7 +485,7 @@ type DocusaurusSidebar = DocusaurusSidebarItem[];
|
|
|
331
485
|
* const sidebar = docs.toNavigation({ format: 'docusaurus' })
|
|
332
486
|
* ```
|
|
333
487
|
*/
|
|
334
|
-
declare function toNavigation2(spec:
|
|
488
|
+
declare function toNavigation2(spec: OpenPkg6, options?: NavOptions): GenericNav | FumadocsMeta | DocusaurusSidebar;
|
|
335
489
|
/**
|
|
336
490
|
* Generate Fumadocs meta.json file content.
|
|
337
491
|
*
|
|
@@ -345,7 +499,7 @@ declare function toNavigation2(spec: OpenPkg5, options?: NavOptions): GenericNav
|
|
|
345
499
|
* fs.writeFileSync('docs/api/meta.json', meta)
|
|
346
500
|
* ```
|
|
347
501
|
*/
|
|
348
|
-
declare function toFumadocsMetaJSON(spec:
|
|
502
|
+
declare function toFumadocsMetaJSON(spec: OpenPkg6, options?: Omit<NavOptions, "format">): string;
|
|
349
503
|
/**
|
|
350
504
|
* Generate Docusaurus sidebar config.
|
|
351
505
|
*
|
|
@@ -359,8 +513,8 @@ declare function toFumadocsMetaJSON(spec: OpenPkg5, options?: Omit<NavOptions, "
|
|
|
359
513
|
* fs.writeFileSync('sidebars.js', sidebar)
|
|
360
514
|
* ```
|
|
361
515
|
*/
|
|
362
|
-
declare function toDocusaurusSidebarJS(spec:
|
|
363
|
-
import { OpenPkg as
|
|
516
|
+
declare function toDocusaurusSidebarJS(spec: OpenPkg6, options?: Omit<NavOptions, "format">): string;
|
|
517
|
+
import { OpenPkg as OpenPkg7, SpecExportKind as SpecExportKind3 } from "@openpkg-ts/spec";
|
|
364
518
|
interface SearchOptions {
|
|
365
519
|
/** Base URL for search result links */
|
|
366
520
|
baseUrl?: string;
|
|
@@ -453,7 +607,7 @@ interface SearchIndex {
|
|
|
453
607
|
* // { records: [...], version: '1.0.0', packageName: 'my-lib' }
|
|
454
608
|
* ```
|
|
455
609
|
*/
|
|
456
|
-
declare function toSearchIndex2(spec:
|
|
610
|
+
declare function toSearchIndex2(spec: OpenPkg7, options?: SearchOptions): SearchIndex;
|
|
457
611
|
/**
|
|
458
612
|
* Generate Pagefind-compatible records.
|
|
459
613
|
*
|
|
@@ -469,7 +623,7 @@ declare function toSearchIndex2(spec: OpenPkg6, options?: SearchOptions): Search
|
|
|
469
623
|
* })
|
|
470
624
|
* ```
|
|
471
625
|
*/
|
|
472
|
-
declare function toPagefindRecords2(spec:
|
|
626
|
+
declare function toPagefindRecords2(spec: OpenPkg7, options?: SearchOptions): PagefindRecord[];
|
|
473
627
|
/**
|
|
474
628
|
* Generate Algolia-compatible records.
|
|
475
629
|
*
|
|
@@ -483,7 +637,7 @@ declare function toPagefindRecords2(spec: OpenPkg6, options?: SearchOptions): Pa
|
|
|
483
637
|
* // Upload to Algolia index
|
|
484
638
|
* ```
|
|
485
639
|
*/
|
|
486
|
-
declare function toAlgoliaRecords2(spec:
|
|
640
|
+
declare function toAlgoliaRecords2(spec: OpenPkg7, options?: SearchOptions): AlgoliaRecord[];
|
|
487
641
|
/**
|
|
488
642
|
* Serialize search index to JSON string.
|
|
489
643
|
*
|
|
@@ -497,16 +651,16 @@ declare function toAlgoliaRecords2(spec: OpenPkg6, options?: SearchOptions): Alg
|
|
|
497
651
|
* fs.writeFileSync('search-index.json', json)
|
|
498
652
|
* ```
|
|
499
653
|
*/
|
|
500
|
-
declare function toSearchIndexJSON(spec:
|
|
654
|
+
declare function toSearchIndexJSON(spec: OpenPkg7, options?: SearchOptions & {
|
|
501
655
|
pretty?: boolean;
|
|
502
656
|
}): string;
|
|
503
657
|
interface LoadOptions {
|
|
504
658
|
/** Path to openpkg.json file or the spec object directly */
|
|
505
|
-
input: string |
|
|
659
|
+
input: string | OpenPkg8;
|
|
506
660
|
}
|
|
507
661
|
interface DocsInstance {
|
|
508
662
|
/** The parsed OpenPkg spec */
|
|
509
|
-
spec:
|
|
663
|
+
spec: OpenPkg8;
|
|
510
664
|
/** Get an by its ID */
|
|
511
665
|
getExport(id: string): SpecExport3 | undefined;
|
|
512
666
|
/** Get a type definition by its ID */
|
|
@@ -554,7 +708,7 @@ interface DocsInstance {
|
|
|
554
708
|
* const docs = loadSpec(spec)
|
|
555
709
|
* ```
|
|
556
710
|
*/
|
|
557
|
-
declare function loadSpec(spec:
|
|
711
|
+
declare function loadSpec(spec: OpenPkg8): DocsInstance;
|
|
558
712
|
/**
|
|
559
713
|
* Creates a docs instance for querying and rendering API documentation.
|
|
560
714
|
*
|
|
@@ -576,8 +730,8 @@ declare function loadSpec(spec: OpenPkg7): DocsInstance;
|
|
|
576
730
|
* docs.search('hook')
|
|
577
731
|
* ```
|
|
578
732
|
*/
|
|
579
|
-
declare function createDocs(input: string |
|
|
580
|
-
import { OpenPkg as
|
|
733
|
+
declare function createDocs(input: string | OpenPkg8): DocsInstance;
|
|
734
|
+
import { OpenPkg as OpenPkg9, SpecExport as SpecExport4, SpecMember as SpecMember2, SpecSchema, SpecSignature, SpecType as SpecType2, SpecTypeParameter } from "@openpkg-ts/spec";
|
|
581
735
|
interface FormatSchemaOptions {
|
|
582
736
|
/** Include package attribution for external types */
|
|
583
737
|
includePackage?: boolean;
|
|
@@ -672,7 +826,7 @@ declare function buildSignatureString(exp: SpecExport4, sigIndex?: number): stri
|
|
|
672
826
|
* // { id: 'User', name: 'User', kind: 'interface', ... }
|
|
673
827
|
* ```
|
|
674
828
|
*/
|
|
675
|
-
declare function resolveTypeRef(ref: string, spec:
|
|
829
|
+
declare function resolveTypeRef(ref: string, spec: OpenPkg9): SpecType2 | undefined;
|
|
676
830
|
/**
|
|
677
831
|
* Check if a member is a method (has signatures).
|
|
678
832
|
*
|
|
@@ -787,7 +941,7 @@ declare function formatConditionalType(condType: SpecConditionalType): string;
|
|
|
787
941
|
* ```
|
|
788
942
|
*/
|
|
789
943
|
declare function formatMappedType(mappedType: SpecMappedType): string;
|
|
790
|
-
import { OpenPkg as
|
|
944
|
+
import { OpenPkg as OpenPkg10, SpecExportKind as SpecExportKind5 } from "@openpkg-ts/spec";
|
|
791
945
|
type FilterCriteria = {
|
|
792
946
|
/** Filter by kinds */
|
|
793
947
|
kinds?: SpecExportKind5[];
|
|
@@ -812,7 +966,7 @@ type FilterCriteria = {
|
|
|
812
966
|
};
|
|
813
967
|
type FilterResult = {
|
|
814
968
|
/** New spec with only matched exports (immutable) */
|
|
815
|
-
spec:
|
|
969
|
+
spec: OpenPkg10;
|
|
816
970
|
/** Number of exports that matched */
|
|
817
971
|
matched: number;
|
|
818
972
|
/** Total number of exports in original spec */
|
|
@@ -828,7 +982,7 @@ type FilterResult = {
|
|
|
828
982
|
* @param criteria - Filter criteria (empty criteria matches all)
|
|
829
983
|
* @returns FilterResult with new spec, matched count, total count
|
|
830
984
|
*/
|
|
831
|
-
declare function filterSpec(spec:
|
|
985
|
+
declare function filterSpec(spec: OpenPkg10, criteria: FilterCriteria): FilterResult;
|
|
832
986
|
import { SpecExport as SpecExport5, SpecType as SpecType3 } from "@openpkg-ts/spec";
|
|
833
987
|
interface GetExportOptions {
|
|
834
988
|
/** Entry point file path */
|
|
@@ -885,117 +1039,6 @@ interface ListExportsResult {
|
|
|
885
1039
|
* List all exports from a TypeScript entry point
|
|
886
1040
|
*/
|
|
887
1041
|
declare function listExports(options: ListExportsOptions): Promise<ListExportsResult>;
|
|
888
|
-
import { OpenPkg as OpenPkg10 } from "@openpkg-ts/spec";
|
|
889
|
-
interface ExtractOptions {
|
|
890
|
-
entryFile: string;
|
|
891
|
-
baseDir?: string;
|
|
892
|
-
content?: string;
|
|
893
|
-
maxTypeDepth?: number;
|
|
894
|
-
maxExternalTypeDepth?: number;
|
|
895
|
-
resolveExternalTypes?: boolean;
|
|
896
|
-
schemaExtraction?: "static" | "hybrid";
|
|
897
|
-
/** Target JSON Schema dialect for runtime schema extraction */
|
|
898
|
-
schemaTarget?: "draft-2020-12" | "draft-07" | "openapi-3.0";
|
|
899
|
-
/** Include $schema URL in output */
|
|
900
|
-
includeSchema?: boolean;
|
|
901
|
-
/** Only extract these exports (supports * wildcards) */
|
|
902
|
-
only?: string[];
|
|
903
|
-
/** Ignore these exports (supports * wildcards) */
|
|
904
|
-
ignore?: string[];
|
|
905
|
-
/** Progress callback for tracking extraction progress */
|
|
906
|
-
onProgress?: (current: number, total: number, item: string) => void;
|
|
907
|
-
/** Whether source is a .d.ts file (degraded mode - TSDoc may be missing) */
|
|
908
|
-
isDtsSource?: boolean;
|
|
909
|
-
/** Include private/protected class members (default: false) */
|
|
910
|
-
includePrivate?: boolean;
|
|
911
|
-
}
|
|
912
|
-
interface ExtractResult {
|
|
913
|
-
spec: OpenPkg10;
|
|
914
|
-
diagnostics: Diagnostic[];
|
|
915
|
-
forgottenExports?: ForgottenExport[];
|
|
916
|
-
/** Metadata about runtime schema extraction (when schemaExtraction: 'hybrid') */
|
|
917
|
-
runtimeSchemas?: {
|
|
918
|
-
/** Number of schema exports found */
|
|
919
|
-
extracted: number;
|
|
920
|
-
/** Number of schemas successfully merged with static types */
|
|
921
|
-
merged: number;
|
|
922
|
-
/** Schema vendors detected (e.g., 'zod', 'arktype', 'valibot', 'typebox') */
|
|
923
|
-
vendors: string[];
|
|
924
|
-
/** Any errors encountered during runtime extraction */
|
|
925
|
-
errors: string[];
|
|
926
|
-
/** Extraction method used: 'compiled' or 'direct-ts (runtime)' */
|
|
927
|
-
method?: string;
|
|
928
|
-
};
|
|
929
|
-
/** Degraded mode info when extracting from .d.ts files */
|
|
930
|
-
degradedMode?: {
|
|
931
|
-
reason: "dts-source";
|
|
932
|
-
stats: {
|
|
933
|
-
exportsWithoutDescription: number;
|
|
934
|
-
paramsWithoutDocs: number;
|
|
935
|
-
missingExamples: number;
|
|
936
|
-
};
|
|
937
|
-
};
|
|
938
|
-
/** Export verification comparing discovered vs extracted */
|
|
939
|
-
verification?: ExportVerification;
|
|
940
|
-
}
|
|
941
|
-
interface Diagnostic {
|
|
942
|
-
message: string;
|
|
943
|
-
severity: "error" | "warning" | "info";
|
|
944
|
-
code?: string;
|
|
945
|
-
suggestion?: string;
|
|
946
|
-
location?: {
|
|
947
|
-
file?: string;
|
|
948
|
-
line?: number;
|
|
949
|
-
column?: number;
|
|
950
|
-
};
|
|
951
|
-
}
|
|
952
|
-
/** Context tracking for type references in public API */
|
|
953
|
-
interface TypeReference2 {
|
|
954
|
-
typeName: string;
|
|
955
|
-
exportName: string;
|
|
956
|
-
location: "return" | "parameter" | "property" | "extends" | "type-parameter";
|
|
957
|
-
path?: string;
|
|
958
|
-
}
|
|
959
|
-
/** Structured data for forgotten exports */
|
|
960
|
-
interface ForgottenExport {
|
|
961
|
-
name: string;
|
|
962
|
-
definedIn?: string;
|
|
963
|
-
referencedBy: TypeReference2[];
|
|
964
|
-
isExternal: boolean;
|
|
965
|
-
fix?: string;
|
|
966
|
-
}
|
|
967
|
-
/** Tracks status of each discovered through serialization pipeline */
|
|
968
|
-
interface ExportTracker {
|
|
969
|
-
name: string;
|
|
970
|
-
discovered: boolean;
|
|
971
|
-
status: "pending" | "success" | "skipped" | "failed";
|
|
972
|
-
skipReason?: "filtered" | "no-declaration" | "internal";
|
|
973
|
-
error?: string;
|
|
974
|
-
kind?: string;
|
|
975
|
-
}
|
|
976
|
-
/** Verification result comparing discovered vs extracted exports */
|
|
977
|
-
interface ExportVerification {
|
|
978
|
-
/** Total exports discovered by TypeScript */
|
|
979
|
-
discovered: number;
|
|
980
|
-
/** Exports successfully extracted */
|
|
981
|
-
extracted: number;
|
|
982
|
-
/** Exports skipped (filtered, no-declaration, internal) */
|
|
983
|
-
skipped: number;
|
|
984
|
-
/** Exports that failed during serialization */
|
|
985
|
-
failed: number;
|
|
986
|
-
/** Delta: discovered - extracted */
|
|
987
|
-
delta: number;
|
|
988
|
-
details: {
|
|
989
|
-
skipped: Array<{
|
|
990
|
-
name: string;
|
|
991
|
-
reason: "filtered" | "no-declaration" | "internal";
|
|
992
|
-
}>;
|
|
993
|
-
failed: Array<{
|
|
994
|
-
name: string;
|
|
995
|
-
error: string;
|
|
996
|
-
}>;
|
|
997
|
-
};
|
|
998
|
-
}
|
|
999
1042
|
/**
|
|
1000
1043
|
* Extract full OpenPkg spec from a TypeScript entry point
|
|
1001
1044
|
*
|
|
@@ -1481,4 +1524,4 @@ declare function normalizeMembers(members: SpecMember3[], options?: NormalizeOpt
|
|
|
1481
1524
|
import ts14 from "typescript";
|
|
1482
1525
|
declare function isExported(node: ts14.Node): boolean;
|
|
1483
1526
|
declare function getNodeName(node: ts14.Node): string | undefined;
|
|
1484
|
-
export { zodAdapter, withDescription, valibotAdapter, typeboxAdapter, toSearchIndexJSON, toSearchIndex2 as toSearchIndex, toPagefindRecords2 as toPagefindRecords, toNavigation2 as toNavigation, toMarkdown2 as toMarkdown, toJSONString, toJSON2 as toJSON, toHTML2 as toHTML, toFumadocsMetaJSON, toDocusaurusSidebarJS, toAlgoliaRecords2 as toAlgoliaRecords, sortByName, serializeVariable, serializeTypeAlias, serializeInterface, serializeFunctionExport, serializeEnum, serializeClass, schemasAreEqual, schemaIsAny, resolveTypeRef, resolveExportTarget, resolveCompiledPath, registerReferencedTypes, registerAdapter, recommendSemverBump, normalizeType, normalizeSchema, normalizeMembers, normalizeExport, loadSpec, listExports, isTypeReference, isTypeOnlyExport, isSymbolDeprecated, isStandardJSONSchema, isSchemaType, isPureRefSchema, isProperty, isPrimitiveName, isMethod, isExported, isBuiltinGeneric, isAnonymous, hasDeprecatedTag, groupByVisibility, getTypeOrigin, getSourceLocation, getProperties, getParamDescription, getNonNullableType, getNodeName, getMethods, getMemberBadges, getJSDocComment, getExport2 as getExport, getDeprecationMessage, toMarkdown2 as generateDocs, formatTypeParameters, formatSchema, formatReturnType, formatParameters, formatMappedType, formatConditionalType, formatBadges, findMissingParamDocs, findDiscriminatorProperty, findAdapter, filterSpec, extractTypeParameters, extractStandardSchemasFromTs, extractStandardSchemasFromProject, extractStandardSchemas, extractSpec, extractSchemaType, extractParameters, extract, exportToMarkdown, ensureNonEmptySchema, diffSpec2 as diffSpecs, diffSpec, detectTsRuntime, deduplicateSchemas, createProgram, createDocs, categorizeBreakingChanges, calculateNextVersion, buildSignatureString, buildSchema, arktypeAdapter, analyzeSpec, TypeRegistry, TypeReference2 as TypeReference, TsRuntime, StandardSchemaExtractionResult, StandardSchemaExtractionOutput, StandardJSONSchemaV1, StandardJSONSchemaTarget, StandardJSONSchemaOptions, SpecMappedType, SpecDiff, SpecDiagnostics, SpecConditionalType, SimplifiedSpec, SimplifiedSignature, SimplifiedReturn, SimplifiedParameter, SimplifiedMember, SimplifiedExport, SimplifiedExample, SerializerContext, SemverRecommendation, SemverBump, SearchRecord, SearchOptions, SearchIndex, SchemaExtractionResult, SchemaAdapter, ProjectExtractionOutput, ProjectExtractionInfo, ProgramResult, ProgramOptions, PagefindRecord, NormalizeOptions, NavOptions, NavItem, NavGroup, NavFormat, MemberChangeInfo, MarkdownOptions, LoadOptions, ListExportsResult, ListExportsOptions, JSONSchema, JSONOptions, HTMLOptions, GroupBy, GetExportResult, GetExportOptions, GenericNav, FumadocsMetaItem, FumadocsMeta, FormatSchemaOptions, ForgottenExport, FilterResult, FilterCriteria, ExtractStandardSchemasOptions, ExtractResult, ExtractOptions, ExtractFromProjectOptions, ExportVerification, ExportTracker, ExportMarkdownOptions, ExportItem, DocusaurusSidebarItem, DocusaurusSidebar, DocsInstance, DiagnosticItem, Diagnostic, CategorizedBreaking, BreakingSeverity, BUILTIN_TYPE_SCHEMAS, AlgoliaRecord, ARRAY_PROTOTYPE_METHODS };
|
|
1527
|
+
export { zodAdapter, withDescription, valibotAdapter, typeboxAdapter, toSearchIndexJSON, toSearchIndex2 as toSearchIndex, toPagefindRecords2 as toPagefindRecords, toNavigation2 as toNavigation, toMarkdown2 as toMarkdown, toJSONString, toJSON2 as toJSON, toHTML2 as toHTML, toFumadocsMetaJSON, toDocusaurusSidebarJS, toAlgoliaRecords2 as toAlgoliaRecords, sortByName, serializeVariable, serializeTypeAlias, serializeInterface, serializeFunctionExport, serializeEnum, serializeClass, schemasAreEqual, schemaIsAny, resolveTypeRef, resolveExportTarget, resolveCompiledPath, registerReferencedTypes, registerAdapter, recommendSemverBump, normalizeType, normalizeSchema, normalizeMembers, normalizeExport, mergeConfig, loadSpec, loadConfig, listExports, isTypeReference, isTypeOnlyExport, isSymbolDeprecated, isStandardJSONSchema, isSchemaType, isPureRefSchema, isProperty, isPrimitiveName, isMethod, isExported, isBuiltinGeneric, isAnonymous, hasDeprecatedTag, groupByVisibility, getTypeOrigin, getSourceLocation, getProperties, getParamDescription, getNonNullableType, getNodeName, getMethods, getMemberBadges, getJSDocComment, getExport2 as getExport, getDeprecationMessage, toMarkdown2 as generateDocs, formatTypeParameters, formatSchema, formatReturnType, formatParameters, formatMappedType, formatConditionalType, formatBadges, findMissingParamDocs, findDiscriminatorProperty, findAdapter, filterSpec, extractTypeParameters, extractStandardSchemasFromTs, extractStandardSchemasFromProject, extractStandardSchemas, extractSpec, extractSchemaType, extractParameters, extract, exportToMarkdown, ensureNonEmptySchema, diffSpec2 as diffSpecs, diffSpec, detectTsRuntime, deduplicateSchemas, createProgram, createDocs, categorizeBreakingChanges, calculateNextVersion, buildSignatureString, buildSchema, arktypeAdapter, analyzeSpec, TypeRegistry, TypeReference2 as TypeReference, TsRuntime, StandardSchemaExtractionResult, StandardSchemaExtractionOutput, StandardJSONSchemaV1, StandardJSONSchemaTarget, StandardJSONSchemaOptions, SpecMappedType, SpecDiff, SpecDiagnostics, SpecConditionalType, SkippedExportDetail, SimplifiedSpec, SimplifiedSignature, SimplifiedReturn, SimplifiedParameter, SimplifiedMember, SimplifiedExport, SimplifiedExample, SerializerContext, SemverRecommendation, SemverBump, SearchRecord, SearchOptions, SearchIndex, SchemaExtractionResult, SchemaAdapter, ProjectExtractionOutput, ProjectExtractionInfo, ProgramResult, ProgramOptions, PagefindRecord, OpenpkgConfig, NormalizeOptions, NavOptions, NavItem, NavGroup, NavFormat, MemberChangeInfo, MarkdownOptions, LoadOptions, ListExportsResult, ListExportsOptions, JSONSchema, JSONOptions, HTMLOptions, GroupBy, GetExportResult, GetExportOptions, GenericNav, FumadocsMetaItem, FumadocsMeta, FormatSchemaOptions, ForgottenExport, FilterResult, FilterCriteria, ExtractStandardSchemasOptions, ExtractResult, ExtractOptions, ExtractFromProjectOptions, ExternalsConfig, ExportVerification, ExportTracker, ExportMarkdownOptions, ExportItem, DocusaurusSidebarItem, DocusaurusSidebar, DocsInstance, DiagnosticItem, Diagnostic, CategorizedBreaking, CONFIG_FILENAME, BreakingSeverity, BUILTIN_TYPE_SCHEMAS, AlgoliaRecord, ARRAY_PROTOTYPE_METHODS };
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,42 @@ import {
|
|
|
6
6
|
diffSpec as diffSpec2,
|
|
7
7
|
recommendSemverBump
|
|
8
8
|
} from "@openpkg-ts/spec";
|
|
9
|
+
// src/core/config.ts
|
|
10
|
+
import * as fs from "node:fs";
|
|
11
|
+
import * as path from "node:path";
|
|
12
|
+
var CONFIG_FILENAME = "openpkg.config.json";
|
|
13
|
+
function loadConfig(cwd) {
|
|
14
|
+
const configPath = path.join(cwd, CONFIG_FILENAME);
|
|
15
|
+
if (fs.existsSync(configPath)) {
|
|
16
|
+
try {
|
|
17
|
+
const content = fs.readFileSync(configPath, "utf-8");
|
|
18
|
+
return JSON.parse(content);
|
|
19
|
+
} catch {}
|
|
20
|
+
}
|
|
21
|
+
const pkgPath = path.join(cwd, "package.json");
|
|
22
|
+
if (fs.existsSync(pkgPath)) {
|
|
23
|
+
try {
|
|
24
|
+
const content = fs.readFileSync(pkgPath, "utf-8");
|
|
25
|
+
const pkg = JSON.parse(content);
|
|
26
|
+
if (pkg.openpkg) {
|
|
27
|
+
return pkg.openpkg;
|
|
28
|
+
}
|
|
29
|
+
} catch {}
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
function mergeConfig(fileConfig, cliOptions) {
|
|
34
|
+
if (!fileConfig) {
|
|
35
|
+
return cliOptions;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
externals: {
|
|
39
|
+
include: cliOptions.externals?.include ?? fileConfig.externals?.include,
|
|
40
|
+
exclude: cliOptions.externals?.exclude ?? fileConfig.externals?.exclude,
|
|
41
|
+
depth: cliOptions.externals?.depth ?? fileConfig.externals?.depth
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
9
45
|
// src/core/diagnostics.ts
|
|
10
46
|
function hasDeprecatedTag(exp) {
|
|
11
47
|
if (exp.deprecated === true)
|
|
@@ -104,7 +140,7 @@ function formatBadges(badges) {
|
|
|
104
140
|
return badges.join(" ");
|
|
105
141
|
}
|
|
106
142
|
// src/core/loader.ts
|
|
107
|
-
import * as
|
|
143
|
+
import * as fs2 from "node:fs";
|
|
108
144
|
|
|
109
145
|
// src/core/query.ts
|
|
110
146
|
function formatFunctionSchema(schema) {
|
|
@@ -1502,7 +1538,7 @@ function loadSpec(spec) {
|
|
|
1502
1538
|
return createDocsInstance(spec);
|
|
1503
1539
|
}
|
|
1504
1540
|
function createDocs(input) {
|
|
1505
|
-
const spec = typeof input === "string" ? JSON.parse(
|
|
1541
|
+
const spec = typeof input === "string" ? JSON.parse(fs2.readFileSync(input, "utf-8")) : input;
|
|
1506
1542
|
return createDocsInstance(spec);
|
|
1507
1543
|
}
|
|
1508
1544
|
function createDocsInstance(spec) {
|
|
@@ -1725,8 +1761,8 @@ function filterSpec(spec, criteria) {
|
|
|
1725
1761
|
import ts11 from "typescript";
|
|
1726
1762
|
|
|
1727
1763
|
// src/compiler/program.ts
|
|
1728
|
-
import * as
|
|
1729
|
-
import * as
|
|
1764
|
+
import * as fs3 from "node:fs";
|
|
1765
|
+
import * as path2 from "node:path";
|
|
1730
1766
|
import ts from "typescript";
|
|
1731
1767
|
function isJsFile(file) {
|
|
1732
1768
|
return /\.(js|mjs|cjs|jsx)$/.test(file);
|
|
@@ -1752,16 +1788,16 @@ function resolveProjectReferences(configPath, parsedConfig) {
|
|
|
1752
1788
|
if (!parsedConfig.projectReferences?.length) {
|
|
1753
1789
|
return additionalFiles;
|
|
1754
1790
|
}
|
|
1755
|
-
const configDir =
|
|
1791
|
+
const configDir = path2.dirname(configPath);
|
|
1756
1792
|
for (const ref of parsedConfig.projectReferences) {
|
|
1757
|
-
const refPath =
|
|
1758
|
-
const refConfigPath =
|
|
1759
|
-
if (!
|
|
1793
|
+
const refPath = path2.resolve(configDir, ref.path);
|
|
1794
|
+
const refConfigPath = fs3.existsSync(path2.join(refPath, "tsconfig.json")) ? path2.join(refPath, "tsconfig.json") : refPath;
|
|
1795
|
+
if (!fs3.existsSync(refConfigPath))
|
|
1760
1796
|
continue;
|
|
1761
1797
|
const refConfigFile = ts.readConfigFile(refConfigPath, ts.sys.readFile);
|
|
1762
1798
|
if (refConfigFile.error)
|
|
1763
1799
|
continue;
|
|
1764
|
-
const refParsed = ts.parseJsonConfigFileContent(refConfigFile.config, ts.sys,
|
|
1800
|
+
const refParsed = ts.parseJsonConfigFileContent(refConfigFile.config, ts.sys, path2.dirname(refConfigPath));
|
|
1765
1801
|
additionalFiles.push(...refParsed.fileNames);
|
|
1766
1802
|
}
|
|
1767
1803
|
return additionalFiles;
|
|
@@ -1794,10 +1830,10 @@ function buildWorkspaceMap(baseDir) {
|
|
|
1794
1830
|
let rootDir;
|
|
1795
1831
|
let workspaceGlobs = [];
|
|
1796
1832
|
for (let i = 0;i < 10; i++) {
|
|
1797
|
-
const pnpmPath =
|
|
1798
|
-
if (
|
|
1833
|
+
const pnpmPath = path2.join(currentDir, "pnpm-workspace.yaml");
|
|
1834
|
+
if (fs3.existsSync(pnpmPath)) {
|
|
1799
1835
|
try {
|
|
1800
|
-
const yamlContent =
|
|
1836
|
+
const yamlContent = fs3.readFileSync(pnpmPath, "utf-8");
|
|
1801
1837
|
workspaceGlobs = parsePnpmWorkspace(yamlContent);
|
|
1802
1838
|
if (workspaceGlobs.length > 0) {
|
|
1803
1839
|
rootDir = currentDir;
|
|
@@ -1805,10 +1841,10 @@ function buildWorkspaceMap(baseDir) {
|
|
|
1805
1841
|
}
|
|
1806
1842
|
} catch {}
|
|
1807
1843
|
}
|
|
1808
|
-
const pkgPath =
|
|
1809
|
-
if (
|
|
1844
|
+
const pkgPath = path2.join(currentDir, "package.json");
|
|
1845
|
+
if (fs3.existsSync(pkgPath)) {
|
|
1810
1846
|
try {
|
|
1811
|
-
const pkg = JSON.parse(
|
|
1847
|
+
const pkg = JSON.parse(fs3.readFileSync(pkgPath, "utf-8"));
|
|
1812
1848
|
if (pkg.workspaces) {
|
|
1813
1849
|
rootDir = currentDir;
|
|
1814
1850
|
workspaceGlobs = Array.isArray(pkg.workspaces) ? pkg.workspaces : pkg.workspaces?.packages || [];
|
|
@@ -1816,7 +1852,7 @@ function buildWorkspaceMap(baseDir) {
|
|
|
1816
1852
|
}
|
|
1817
1853
|
} catch {}
|
|
1818
1854
|
}
|
|
1819
|
-
const parent =
|
|
1855
|
+
const parent = path2.dirname(currentDir);
|
|
1820
1856
|
if (parent === currentDir)
|
|
1821
1857
|
break;
|
|
1822
1858
|
currentDir = parent;
|
|
@@ -1825,21 +1861,21 @@ function buildWorkspaceMap(baseDir) {
|
|
|
1825
1861
|
return;
|
|
1826
1862
|
const packages = new Map;
|
|
1827
1863
|
for (const glob of workspaceGlobs) {
|
|
1828
|
-
const globDir =
|
|
1829
|
-
if (!
|
|
1864
|
+
const globDir = path2.join(rootDir, glob.replace(/\/\*$/, ""));
|
|
1865
|
+
if (!fs3.existsSync(globDir) || !fs3.statSync(globDir).isDirectory())
|
|
1830
1866
|
continue;
|
|
1831
|
-
const entries =
|
|
1867
|
+
const entries = fs3.readdirSync(globDir, { withFileTypes: true });
|
|
1832
1868
|
for (const entry of entries) {
|
|
1833
1869
|
if (!entry.isDirectory())
|
|
1834
1870
|
continue;
|
|
1835
|
-
const pkgDir =
|
|
1836
|
-
const pkgJsonPath =
|
|
1837
|
-
if (!
|
|
1871
|
+
const pkgDir = path2.join(globDir, entry.name);
|
|
1872
|
+
const pkgJsonPath = path2.join(pkgDir, "package.json");
|
|
1873
|
+
if (!fs3.existsSync(pkgJsonPath))
|
|
1838
1874
|
continue;
|
|
1839
1875
|
try {
|
|
1840
|
-
const pkg = JSON.parse(
|
|
1876
|
+
const pkg = JSON.parse(fs3.readFileSync(pkgJsonPath, "utf-8"));
|
|
1841
1877
|
if (pkg.name) {
|
|
1842
|
-
const srcDir =
|
|
1878
|
+
const srcDir = fs3.existsSync(path2.join(pkgDir, "src")) ? path2.join(pkgDir, "src") : pkgDir;
|
|
1843
1879
|
packages.set(pkg.name, srcDir);
|
|
1844
1880
|
}
|
|
1845
1881
|
} catch {}
|
|
@@ -1849,7 +1885,7 @@ function buildWorkspaceMap(baseDir) {
|
|
|
1849
1885
|
}
|
|
1850
1886
|
function createProgram({
|
|
1851
1887
|
entryFile,
|
|
1852
|
-
baseDir =
|
|
1888
|
+
baseDir = path2.dirname(entryFile),
|
|
1853
1889
|
content
|
|
1854
1890
|
}) {
|
|
1855
1891
|
let configPath = ts.findConfigFile(baseDir, ts.sys.fileExists, "tsconfig.json");
|
|
@@ -1860,9 +1896,11 @@ function createProgram({
|
|
|
1860
1896
|
let additionalRootFiles = [];
|
|
1861
1897
|
if (configPath) {
|
|
1862
1898
|
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
1863
|
-
const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys,
|
|
1899
|
+
const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path2.dirname(configPath));
|
|
1864
1900
|
compilerOptions = { ...compilerOptions, ...parsedConfig.options };
|
|
1865
1901
|
additionalRootFiles = resolveProjectReferences(configPath, parsedConfig);
|
|
1902
|
+
const sourceFiles = parsedConfig.fileNames.filter((f) => !f.includes(".test.") && !f.includes(".spec.") && !f.includes("/dist/") && !f.includes("/node_modules/"));
|
|
1903
|
+
additionalRootFiles.push(...sourceFiles);
|
|
1866
1904
|
}
|
|
1867
1905
|
if (isJsFile(entryFile)) {
|
|
1868
1906
|
compilerOptions = {
|
|
@@ -1886,8 +1924,8 @@ function createProgram({
|
|
|
1886
1924
|
return moduleNames.map((moduleName) => {
|
|
1887
1925
|
const srcDir = workspaceMap.packages.get(moduleName);
|
|
1888
1926
|
if (srcDir) {
|
|
1889
|
-
const indexFile =
|
|
1890
|
-
if (
|
|
1927
|
+
const indexFile = path2.join(srcDir, "index.ts");
|
|
1928
|
+
if (fs3.existsSync(indexFile)) {
|
|
1891
1929
|
return { resolvedFileName: indexFile, isExternalLibraryImport: false };
|
|
1892
1930
|
}
|
|
1893
1931
|
}
|
|
@@ -4779,7 +4817,7 @@ function serializeDeclaration(declaration, _exportSymbol, _targetSymbol, exportN
|
|
|
4779
4817
|
return result;
|
|
4780
4818
|
}
|
|
4781
4819
|
// src/primitives/list.ts
|
|
4782
|
-
import * as
|
|
4820
|
+
import * as path3 from "node:path";
|
|
4783
4821
|
import ts12 from "typescript";
|
|
4784
4822
|
async function listExports(options) {
|
|
4785
4823
|
const { entryFile, baseDir, content } = options;
|
|
@@ -4827,7 +4865,7 @@ function extractExportItem(symbol, checker, entryFile, entrySourceFile) {
|
|
|
4827
4865
|
return {
|
|
4828
4866
|
name,
|
|
4829
4867
|
kind: "namespace",
|
|
4830
|
-
file:
|
|
4868
|
+
file: path3.relative(path3.dirname(entryFile), declaration.fileName),
|
|
4831
4869
|
line: 1,
|
|
4832
4870
|
reexport: true
|
|
4833
4871
|
};
|
|
@@ -4841,7 +4879,7 @@ function extractExportItem(symbol, checker, entryFile, entrySourceFile) {
|
|
|
4841
4879
|
return {
|
|
4842
4880
|
name,
|
|
4843
4881
|
kind,
|
|
4844
|
-
file:
|
|
4882
|
+
file: path3.relative(path3.dirname(entryFile), sourceFile.fileName),
|
|
4845
4883
|
line: line + 1,
|
|
4846
4884
|
...description ? { description } : {},
|
|
4847
4885
|
...deprecated ? { deprecated: true } : {},
|
|
@@ -4893,10 +4931,10 @@ function getDescriptionPreview(symbol, checker) {
|
|
|
4893
4931
|
return `${firstLine.slice(0, 77)}...`;
|
|
4894
4932
|
}
|
|
4895
4933
|
// src/builder/spec-builder.ts
|
|
4896
|
-
import * as
|
|
4897
|
-
import * as
|
|
4934
|
+
import * as fs6 from "node:fs";
|
|
4935
|
+
import * as path6 from "node:path";
|
|
4898
4936
|
import { SCHEMA_URL, SCHEMA_VERSION } from "@openpkg-ts/spec";
|
|
4899
|
-
import
|
|
4937
|
+
import ts15 from "typescript";
|
|
4900
4938
|
|
|
4901
4939
|
// src/ast/resolve.ts
|
|
4902
4940
|
import ts13 from "typescript";
|
|
@@ -4930,9 +4968,9 @@ function resolveExportTarget2(symbol, checker) {
|
|
|
4930
4968
|
|
|
4931
4969
|
// src/schema/standard-schema.ts
|
|
4932
4970
|
import { spawn, spawnSync } from "node:child_process";
|
|
4933
|
-
import * as
|
|
4971
|
+
import * as fs4 from "node:fs";
|
|
4934
4972
|
import * as os from "node:os";
|
|
4935
|
-
import * as
|
|
4973
|
+
import * as path4 from "node:path";
|
|
4936
4974
|
function isStandardJSONSchema(obj) {
|
|
4937
4975
|
if (typeof obj !== "object" || obj === null)
|
|
4938
4976
|
return false;
|
|
@@ -5178,21 +5216,21 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
|
|
|
5178
5216
|
result.errors.push("No TypeScript runtime available. Install bun, tsx, or ts-node, or use Node 22+.");
|
|
5179
5217
|
return result;
|
|
5180
5218
|
}
|
|
5181
|
-
if (!
|
|
5219
|
+
if (!fs4.existsSync(tsFilePath)) {
|
|
5182
5220
|
result.errors.push(`TypeScript file not found: ${tsFilePath}`);
|
|
5183
5221
|
return result;
|
|
5184
5222
|
}
|
|
5185
5223
|
const tempDir = os.tmpdir();
|
|
5186
|
-
const workerPath =
|
|
5224
|
+
const workerPath = path4.join(tempDir, `openpkg-extract-worker-${Date.now()}.ts`);
|
|
5187
5225
|
try {
|
|
5188
|
-
|
|
5226
|
+
fs4.writeFileSync(workerPath, TS_WORKER_SCRIPT);
|
|
5189
5227
|
const optionsJson = JSON.stringify({ target, libraryOptions });
|
|
5190
5228
|
const args = [...runtime.args, workerPath, tsFilePath, optionsJson];
|
|
5191
5229
|
return await new Promise((resolve2) => {
|
|
5192
5230
|
const child = spawn(runtime.cmd, args, {
|
|
5193
5231
|
timeout,
|
|
5194
5232
|
stdio: ["ignore", "pipe", "pipe"],
|
|
5195
|
-
cwd:
|
|
5233
|
+
cwd: path4.dirname(tsFilePath)
|
|
5196
5234
|
});
|
|
5197
5235
|
let stdout = "";
|
|
5198
5236
|
let stderr = "";
|
|
@@ -5204,7 +5242,7 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
|
|
|
5204
5242
|
});
|
|
5205
5243
|
child.on("close", (code) => {
|
|
5206
5244
|
try {
|
|
5207
|
-
|
|
5245
|
+
fs4.unlinkSync(workerPath);
|
|
5208
5246
|
} catch {}
|
|
5209
5247
|
if (code !== 0) {
|
|
5210
5248
|
result.errors.push(`Extraction failed (${runtime.name}): ${stderr || `exit code ${code}`}`);
|
|
@@ -5233,7 +5271,7 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
|
|
|
5233
5271
|
});
|
|
5234
5272
|
child.on("error", (err) => {
|
|
5235
5273
|
try {
|
|
5236
|
-
|
|
5274
|
+
fs4.unlinkSync(workerPath);
|
|
5237
5275
|
} catch {}
|
|
5238
5276
|
result.errors.push(`Subprocess error: ${err.message}`);
|
|
5239
5277
|
resolve2(result);
|
|
@@ -5241,19 +5279,19 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
|
|
|
5241
5279
|
});
|
|
5242
5280
|
} catch (e) {
|
|
5243
5281
|
try {
|
|
5244
|
-
|
|
5282
|
+
fs4.unlinkSync(workerPath);
|
|
5245
5283
|
} catch {}
|
|
5246
5284
|
result.errors.push(`Failed to create worker script: ${e}`);
|
|
5247
5285
|
return result;
|
|
5248
5286
|
}
|
|
5249
5287
|
}
|
|
5250
5288
|
function readTsconfigOutDir(baseDir) {
|
|
5251
|
-
const tsconfigPath =
|
|
5289
|
+
const tsconfigPath = path4.join(baseDir, "tsconfig.json");
|
|
5252
5290
|
try {
|
|
5253
|
-
if (!
|
|
5291
|
+
if (!fs4.existsSync(tsconfigPath)) {
|
|
5254
5292
|
return null;
|
|
5255
5293
|
}
|
|
5256
|
-
const content =
|
|
5294
|
+
const content = fs4.readFileSync(tsconfigPath, "utf-8");
|
|
5257
5295
|
const stripped = content.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*$/gm, "");
|
|
5258
5296
|
const tsconfig = JSON.parse(stripped);
|
|
5259
5297
|
if (tsconfig.compilerOptions?.outDir) {
|
|
@@ -5263,7 +5301,7 @@ function readTsconfigOutDir(baseDir) {
|
|
|
5263
5301
|
return null;
|
|
5264
5302
|
}
|
|
5265
5303
|
function resolveCompiledPath(tsPath, baseDir) {
|
|
5266
|
-
const relativePath =
|
|
5304
|
+
const relativePath = path4.relative(baseDir, tsPath);
|
|
5267
5305
|
const withoutExt = relativePath.replace(/\.tsx?$/, "");
|
|
5268
5306
|
const srcPrefix = withoutExt.replace(/^src\//, "");
|
|
5269
5307
|
const tsconfigOutDir = readTsconfigOutDir(baseDir);
|
|
@@ -5271,7 +5309,7 @@ function resolveCompiledPath(tsPath, baseDir) {
|
|
|
5271
5309
|
const candidates = [];
|
|
5272
5310
|
if (tsconfigOutDir) {
|
|
5273
5311
|
for (const ext of extensions) {
|
|
5274
|
-
candidates.push(
|
|
5312
|
+
candidates.push(path4.join(baseDir, tsconfigOutDir, `${srcPrefix}${ext}`));
|
|
5275
5313
|
}
|
|
5276
5314
|
}
|
|
5277
5315
|
const commonOutDirs = ["dist", "build", "lib", "out"];
|
|
@@ -5279,21 +5317,21 @@ function resolveCompiledPath(tsPath, baseDir) {
|
|
|
5279
5317
|
if (outDir === tsconfigOutDir)
|
|
5280
5318
|
continue;
|
|
5281
5319
|
for (const ext of extensions) {
|
|
5282
|
-
candidates.push(
|
|
5320
|
+
candidates.push(path4.join(baseDir, outDir, `${srcPrefix}${ext}`));
|
|
5283
5321
|
}
|
|
5284
5322
|
}
|
|
5285
5323
|
for (const ext of extensions) {
|
|
5286
|
-
candidates.push(
|
|
5324
|
+
candidates.push(path4.join(baseDir, `${withoutExt}${ext}`));
|
|
5287
5325
|
}
|
|
5288
5326
|
const workspaceMatch = baseDir.match(/^(.+\/packages\/[^/]+)$/);
|
|
5289
5327
|
if (workspaceMatch) {
|
|
5290
5328
|
const pkgRoot = workspaceMatch[1];
|
|
5291
5329
|
for (const ext of extensions) {
|
|
5292
|
-
candidates.push(
|
|
5330
|
+
candidates.push(path4.join(pkgRoot, "dist", `${srcPrefix}${ext}`));
|
|
5293
5331
|
}
|
|
5294
5332
|
}
|
|
5295
5333
|
for (const candidate of candidates) {
|
|
5296
|
-
if (
|
|
5334
|
+
if (fs4.existsSync(candidate)) {
|
|
5297
5335
|
return candidate;
|
|
5298
5336
|
}
|
|
5299
5337
|
}
|
|
@@ -5305,7 +5343,7 @@ async function extractStandardSchemas(compiledJsPath, options = {}) {
|
|
|
5305
5343
|
schemas: new Map,
|
|
5306
5344
|
errors: []
|
|
5307
5345
|
};
|
|
5308
|
-
if (!
|
|
5346
|
+
if (!fs4.existsSync(compiledJsPath)) {
|
|
5309
5347
|
result.errors.push(`Compiled JS not found: ${compiledJsPath}`);
|
|
5310
5348
|
return result;
|
|
5311
5349
|
}
|
|
@@ -5386,6 +5424,173 @@ async function extractStandardSchemasFromProject(entryFile, baseDir, options = {
|
|
|
5386
5424
|
};
|
|
5387
5425
|
}
|
|
5388
5426
|
|
|
5427
|
+
// src/builder/external-resolver.ts
|
|
5428
|
+
import * as fs5 from "node:fs";
|
|
5429
|
+
import * as path5 from "node:path";
|
|
5430
|
+
import picomatch from "picomatch";
|
|
5431
|
+
import ts14 from "typescript";
|
|
5432
|
+
function matchesExternalPattern(packageName, include, exclude) {
|
|
5433
|
+
if (!include?.length)
|
|
5434
|
+
return false;
|
|
5435
|
+
const matchOptions = { bash: true };
|
|
5436
|
+
const isIncluded = include.some((p) => picomatch.isMatch(packageName, p, matchOptions));
|
|
5437
|
+
if (!isIncluded)
|
|
5438
|
+
return false;
|
|
5439
|
+
if (exclude?.length) {
|
|
5440
|
+
const isExcluded = exclude.some((p) => picomatch.isMatch(packageName, p, matchOptions));
|
|
5441
|
+
if (isExcluded)
|
|
5442
|
+
return false;
|
|
5443
|
+
}
|
|
5444
|
+
return true;
|
|
5445
|
+
}
|
|
5446
|
+
function resolveExternalModule(moduleSpecifier, containingFile, compilerOptions) {
|
|
5447
|
+
const resolved = ts14.resolveModuleName(moduleSpecifier, containingFile, compilerOptions, ts14.sys);
|
|
5448
|
+
if (!resolved.resolvedModule) {
|
|
5449
|
+
return null;
|
|
5450
|
+
}
|
|
5451
|
+
const resolvedPath = resolved.resolvedModule.resolvedFileName;
|
|
5452
|
+
const packageJson = findPackageJson(resolvedPath, moduleSpecifier);
|
|
5453
|
+
return {
|
|
5454
|
+
resolvedPath,
|
|
5455
|
+
packageName: moduleSpecifier,
|
|
5456
|
+
packageVersion: packageJson?.version
|
|
5457
|
+
};
|
|
5458
|
+
}
|
|
5459
|
+
function findPackageJson(resolvedPath, packageName) {
|
|
5460
|
+
const isScoped = packageName.startsWith("@");
|
|
5461
|
+
const packageParts = isScoped ? packageName.split("/").slice(0, 2) : [packageName.split("/")[0]];
|
|
5462
|
+
const packageDir = packageParts.join("/");
|
|
5463
|
+
let dir = path5.dirname(resolvedPath);
|
|
5464
|
+
const maxDepth = 10;
|
|
5465
|
+
for (let i = 0;i < maxDepth; i++) {
|
|
5466
|
+
if (dir.endsWith(`node_modules/${packageDir}`)) {
|
|
5467
|
+
const pkgPath = path5.join(dir, "package.json");
|
|
5468
|
+
if (fs5.existsSync(pkgPath)) {
|
|
5469
|
+
try {
|
|
5470
|
+
return JSON.parse(fs5.readFileSync(pkgPath, "utf-8"));
|
|
5471
|
+
} catch {
|
|
5472
|
+
return;
|
|
5473
|
+
}
|
|
5474
|
+
}
|
|
5475
|
+
}
|
|
5476
|
+
const parent = path5.dirname(dir);
|
|
5477
|
+
if (parent === dir)
|
|
5478
|
+
break;
|
|
5479
|
+
dir = parent;
|
|
5480
|
+
}
|
|
5481
|
+
return;
|
|
5482
|
+
}
|
|
5483
|
+
function determineExportKind(symbol, checker) {
|
|
5484
|
+
const declarations = symbol.declarations ?? [];
|
|
5485
|
+
const decl = declarations[0];
|
|
5486
|
+
if (!decl)
|
|
5487
|
+
return "variable";
|
|
5488
|
+
if (ts14.isFunctionDeclaration(decl) || ts14.isFunctionExpression(decl))
|
|
5489
|
+
return "function";
|
|
5490
|
+
if (ts14.isClassDeclaration(decl))
|
|
5491
|
+
return "class";
|
|
5492
|
+
if (ts14.isInterfaceDeclaration(decl))
|
|
5493
|
+
return "interface";
|
|
5494
|
+
if (ts14.isTypeAliasDeclaration(decl))
|
|
5495
|
+
return "type";
|
|
5496
|
+
if (ts14.isEnumDeclaration(decl))
|
|
5497
|
+
return "enum";
|
|
5498
|
+
if (ts14.isModuleDeclaration(decl))
|
|
5499
|
+
return "namespace";
|
|
5500
|
+
if (ts14.isVariableDeclaration(decl)) {
|
|
5501
|
+
const type = checker.getTypeAtLocation(decl);
|
|
5502
|
+
if (type.getCallSignatures().length > 0)
|
|
5503
|
+
return "function";
|
|
5504
|
+
}
|
|
5505
|
+
return "variable";
|
|
5506
|
+
}
|
|
5507
|
+
function extractExternalExport(exportName, resolvedModule, program, ctx, visited) {
|
|
5508
|
+
const key = `${resolvedModule.resolvedPath}:${exportName}`;
|
|
5509
|
+
if (visited.has(key)) {
|
|
5510
|
+
return {
|
|
5511
|
+
id: exportName,
|
|
5512
|
+
name: exportName,
|
|
5513
|
+
kind: "external",
|
|
5514
|
+
source: {
|
|
5515
|
+
package: resolvedModule.packageName,
|
|
5516
|
+
version: resolvedModule.packageVersion
|
|
5517
|
+
}
|
|
5518
|
+
};
|
|
5519
|
+
}
|
|
5520
|
+
visited.add(key);
|
|
5521
|
+
const checker = program.getTypeChecker();
|
|
5522
|
+
const sourceFile = program.getSourceFile(resolvedModule.resolvedPath);
|
|
5523
|
+
if (!sourceFile) {
|
|
5524
|
+
return null;
|
|
5525
|
+
}
|
|
5526
|
+
const moduleSymbol = checker.getSymbolAtLocation(sourceFile);
|
|
5527
|
+
if (!moduleSymbol) {
|
|
5528
|
+
return null;
|
|
5529
|
+
}
|
|
5530
|
+
const exports = checker.getExportsOfModule(moduleSymbol);
|
|
5531
|
+
const targetExport = exports.find((e) => e.getName() === exportName);
|
|
5532
|
+
if (!targetExport) {
|
|
5533
|
+
return null;
|
|
5534
|
+
}
|
|
5535
|
+
let resolvedSymbol = targetExport;
|
|
5536
|
+
if (targetExport.flags & ts14.SymbolFlags.Alias) {
|
|
5537
|
+
const aliased = checker.getAliasedSymbol(targetExport);
|
|
5538
|
+
if (aliased && aliased !== targetExport) {
|
|
5539
|
+
resolvedSymbol = aliased;
|
|
5540
|
+
}
|
|
5541
|
+
}
|
|
5542
|
+
const kind = determineExportKind(resolvedSymbol, checker);
|
|
5543
|
+
const docComment = resolvedSymbol.getDocumentationComment(checker);
|
|
5544
|
+
const description = docComment.length > 0 ? docComment.map((c) => c.text).join(`
|
|
5545
|
+
`) : undefined;
|
|
5546
|
+
const specExport = {
|
|
5547
|
+
id: exportName,
|
|
5548
|
+
name: exportName,
|
|
5549
|
+
kind,
|
|
5550
|
+
...description && { description },
|
|
5551
|
+
source: {
|
|
5552
|
+
package: resolvedModule.packageName,
|
|
5553
|
+
version: resolvedModule.packageVersion,
|
|
5554
|
+
file: resolvedModule.resolvedPath
|
|
5555
|
+
}
|
|
5556
|
+
};
|
|
5557
|
+
if (kind === "function") {
|
|
5558
|
+
const type = checker.getTypeOfSymbol(resolvedSymbol);
|
|
5559
|
+
const callSignatures = type.getCallSignatures();
|
|
5560
|
+
if (callSignatures.length > 0) {
|
|
5561
|
+
const signatures = callSignatures.map((sig, index) => {
|
|
5562
|
+
const params = extractParameters(sig, ctx);
|
|
5563
|
+
const returnType = checker.getReturnTypeOfSignature(sig);
|
|
5564
|
+
registerReferencedTypes(returnType, ctx);
|
|
5565
|
+
const returnSchema = buildSchema(returnType, checker, ctx);
|
|
5566
|
+
const sigDoc = getJSDocForSignature(sig, checker);
|
|
5567
|
+
const sigTypeParams = extractTypeParametersFromSignature(sig, checker);
|
|
5568
|
+
return {
|
|
5569
|
+
parameters: params,
|
|
5570
|
+
returns: { schema: returnSchema },
|
|
5571
|
+
...sigDoc.description && { description: sigDoc.description },
|
|
5572
|
+
...sigDoc.tags.length > 0 && { tags: sigDoc.tags },
|
|
5573
|
+
...sigDoc.examples.length > 0 && { examples: sigDoc.examples },
|
|
5574
|
+
...sigTypeParams && { typeParameters: sigTypeParams },
|
|
5575
|
+
...callSignatures.length > 1 && { overloadIndex: index }
|
|
5576
|
+
};
|
|
5577
|
+
});
|
|
5578
|
+
specExport.signatures = signatures;
|
|
5579
|
+
}
|
|
5580
|
+
} else if (kind === "interface" || kind === "type" || kind === "class") {
|
|
5581
|
+
const type = checker.getTypeOfSymbol(resolvedSymbol);
|
|
5582
|
+
registerReferencedTypes(type, ctx);
|
|
5583
|
+
const schema = buildSchema(type, checker, ctx);
|
|
5584
|
+
specExport.schema = schema;
|
|
5585
|
+
} else if (kind === "variable") {
|
|
5586
|
+
const type = checker.getTypeOfSymbol(resolvedSymbol);
|
|
5587
|
+
registerReferencedTypes(type, ctx);
|
|
5588
|
+
const schema = buildSchema(type, checker, ctx);
|
|
5589
|
+
specExport.schema = schema;
|
|
5590
|
+
}
|
|
5591
|
+
return specExport;
|
|
5592
|
+
}
|
|
5593
|
+
|
|
5389
5594
|
// src/builder/schema-merger.ts
|
|
5390
5595
|
function mergeRuntimeSchemas(staticExports, runtimeSchemas) {
|
|
5391
5596
|
let merged = 0;
|
|
@@ -5647,9 +5852,9 @@ async function extract(options) {
|
|
|
5647
5852
|
break;
|
|
5648
5853
|
}
|
|
5649
5854
|
}
|
|
5650
|
-
if (
|
|
5855
|
+
if (ts15.isExportSpecifier(decl)) {
|
|
5651
5856
|
const exportDecl = decl.parent?.parent;
|
|
5652
|
-
if (exportDecl &&
|
|
5857
|
+
if (exportDecl && ts15.isExportDeclaration(exportDecl) && exportDecl.moduleSpecifier) {
|
|
5653
5858
|
const moduleText = exportDecl.moduleSpecifier.getText().slice(1, -1);
|
|
5654
5859
|
if (!moduleText.startsWith(".") && !moduleText.startsWith("/")) {
|
|
5655
5860
|
externalPackage = moduleText;
|
|
@@ -5659,6 +5864,20 @@ async function extract(options) {
|
|
|
5659
5864
|
}
|
|
5660
5865
|
}
|
|
5661
5866
|
if (externalPackage) {
|
|
5867
|
+
const shouldResolve = matchesExternalPattern(externalPackage, options.externals?.include, options.externals?.exclude);
|
|
5868
|
+
if (shouldResolve) {
|
|
5869
|
+
const resolvedModule = resolveExternalModule(externalPackage, sourceFile.fileName, program.getCompilerOptions());
|
|
5870
|
+
if (resolvedModule) {
|
|
5871
|
+
const visitedExternals = new Set;
|
|
5872
|
+
const extractedExport = extractExternalExport(exportName, resolvedModule, program, ctx, visitedExternals);
|
|
5873
|
+
if (extractedExport) {
|
|
5874
|
+
exports.push(extractedExport);
|
|
5875
|
+
tracker.status = "success";
|
|
5876
|
+
tracker.kind = extractedExport.kind;
|
|
5877
|
+
continue;
|
|
5878
|
+
}
|
|
5879
|
+
}
|
|
5880
|
+
}
|
|
5662
5881
|
const externalExport = {
|
|
5663
5882
|
id: exportName,
|
|
5664
5883
|
name: exportName,
|
|
@@ -5699,7 +5918,7 @@ async function extract(options) {
|
|
|
5699
5918
|
const verification = buildVerificationSummary(exportedSymbols.length, exports.length, exportTracker);
|
|
5700
5919
|
const meta = await getPackageMeta(entryFile, baseDir);
|
|
5701
5920
|
const types = ctx.typeRegistry.getAll();
|
|
5702
|
-
const projectBaseDir = baseDir ??
|
|
5921
|
+
const projectBaseDir = baseDir ?? path6.dirname(entryFile);
|
|
5703
5922
|
const definedTypes = new Set(types.map((t) => t.id));
|
|
5704
5923
|
const forgottenExports = collectForgottenExports(exports, types, program, sourceFile, exportedIds, projectBaseDir, definedTypes);
|
|
5705
5924
|
for (const forgotten of forgottenExports) {
|
|
@@ -5732,7 +5951,7 @@ async function extract(options) {
|
|
|
5732
5951
|
}
|
|
5733
5952
|
let runtimeMetadata;
|
|
5734
5953
|
if (options.schemaExtraction === "hybrid") {
|
|
5735
|
-
const projectBaseDir2 = baseDir ||
|
|
5954
|
+
const projectBaseDir2 = baseDir || path6.dirname(entryFile);
|
|
5736
5955
|
const runtimeResult = await extractStandardSchemasFromProject(entryFile, projectBaseDir2, {
|
|
5737
5956
|
target: options.schemaTarget || "draft-2020-12",
|
|
5738
5957
|
timeout: 15000
|
|
@@ -5772,6 +5991,9 @@ async function extract(options) {
|
|
|
5772
5991
|
...options.schemaExtraction === "hybrid" ? { schemaExtraction: "hybrid" } : {},
|
|
5773
5992
|
...isDtsSource && {
|
|
5774
5993
|
limitations: ["No JSDoc descriptions", "No @example tags", "No @param descriptions"]
|
|
5994
|
+
},
|
|
5995
|
+
...verification.details.skipped.length > 0 && {
|
|
5996
|
+
skipped: verification.details.skipped
|
|
5775
5997
|
}
|
|
5776
5998
|
}
|
|
5777
5999
|
};
|
|
@@ -5845,11 +6067,11 @@ function findTypeDefinition(typeName, program, sourceFile) {
|
|
|
5845
6067
|
}
|
|
5846
6068
|
const checker = program.getTypeChecker();
|
|
5847
6069
|
const findInNode = (node) => {
|
|
5848
|
-
if ((
|
|
6070
|
+
if ((ts15.isInterfaceDeclaration(node) || ts15.isTypeAliasDeclaration(node) || ts15.isClassDeclaration(node) || ts15.isEnumDeclaration(node)) && node.name?.text === typeName) {
|
|
5849
6071
|
const sf = node.getSourceFile();
|
|
5850
6072
|
return sf.fileName;
|
|
5851
6073
|
}
|
|
5852
|
-
return
|
|
6074
|
+
return ts15.forEachChild(node, findInNode);
|
|
5853
6075
|
};
|
|
5854
6076
|
const entryResult = findInNode(sourceFile);
|
|
5855
6077
|
if (entryResult) {
|
|
@@ -5865,7 +6087,7 @@ function findTypeDefinition(typeName, program, sourceFile) {
|
|
|
5865
6087
|
}
|
|
5866
6088
|
}
|
|
5867
6089
|
}
|
|
5868
|
-
const symbol = checker.resolveName(typeName, sourceFile,
|
|
6090
|
+
const symbol = checker.resolveName(typeName, sourceFile, ts15.SymbolFlags.Type, false);
|
|
5869
6091
|
if (symbol?.declarations?.[0]) {
|
|
5870
6092
|
const result = symbol.declarations[0].getSourceFile().fileName;
|
|
5871
6093
|
cache.set(typeName, result);
|
|
@@ -5879,8 +6101,8 @@ function isExternalType2(definedIn, baseDir) {
|
|
|
5879
6101
|
return true;
|
|
5880
6102
|
if (definedIn.includes("node_modules"))
|
|
5881
6103
|
return true;
|
|
5882
|
-
const normalizedDefined =
|
|
5883
|
-
const normalizedBase =
|
|
6104
|
+
const normalizedDefined = path6.resolve(definedIn);
|
|
6105
|
+
const normalizedBase = path6.resolve(baseDir);
|
|
5884
6106
|
return !normalizedDefined.startsWith(normalizedBase);
|
|
5885
6107
|
}
|
|
5886
6108
|
function hasInternalTag(typeName, program, sourceFile) {
|
|
@@ -5890,7 +6112,7 @@ function hasInternalTag(typeName, program, sourceFile) {
|
|
|
5890
6112
|
return cached;
|
|
5891
6113
|
}
|
|
5892
6114
|
const checker = program.getTypeChecker();
|
|
5893
|
-
const symbol = checker.resolveName(typeName, sourceFile,
|
|
6115
|
+
const symbol = checker.resolveName(typeName, sourceFile, ts15.SymbolFlags.Type, false);
|
|
5894
6116
|
if (!symbol) {
|
|
5895
6117
|
cache.set(typeName, false);
|
|
5896
6118
|
return false;
|
|
@@ -5942,27 +6164,27 @@ function collectForgottenExports(exports, types, program, sourceFile, exportedId
|
|
|
5942
6164
|
}
|
|
5943
6165
|
function serializeDeclaration2(declaration, exportSymbol, _targetSymbol, exportName, ctx, isTypeOnly = false) {
|
|
5944
6166
|
let result = null;
|
|
5945
|
-
if (
|
|
6167
|
+
if (ts15.isFunctionDeclaration(declaration)) {
|
|
5946
6168
|
result = serializeFunctionExport(declaration, ctx);
|
|
5947
|
-
} else if (
|
|
6169
|
+
} else if (ts15.isClassDeclaration(declaration)) {
|
|
5948
6170
|
result = serializeClass(declaration, ctx);
|
|
5949
|
-
} else if (
|
|
6171
|
+
} else if (ts15.isInterfaceDeclaration(declaration)) {
|
|
5950
6172
|
result = serializeInterface(declaration, ctx);
|
|
5951
|
-
} else if (
|
|
6173
|
+
} else if (ts15.isTypeAliasDeclaration(declaration)) {
|
|
5952
6174
|
result = serializeTypeAlias(declaration, ctx);
|
|
5953
|
-
} else if (
|
|
6175
|
+
} else if (ts15.isEnumDeclaration(declaration)) {
|
|
5954
6176
|
result = serializeEnum(declaration, ctx);
|
|
5955
|
-
} else if (
|
|
6177
|
+
} else if (ts15.isVariableDeclaration(declaration)) {
|
|
5956
6178
|
const varStatement = declaration.parent?.parent;
|
|
5957
|
-
if (varStatement &&
|
|
5958
|
-
if (declaration.initializer &&
|
|
5959
|
-
const varName =
|
|
6179
|
+
if (varStatement && ts15.isVariableStatement(varStatement)) {
|
|
6180
|
+
if (declaration.initializer && ts15.isArrowFunction(declaration.initializer)) {
|
|
6181
|
+
const varName = ts15.isIdentifier(declaration.name) ? declaration.name.text : declaration.name.getText();
|
|
5960
6182
|
result = serializeFunctionExport(declaration.initializer, ctx, varName);
|
|
5961
6183
|
} else {
|
|
5962
6184
|
result = serializeVariable(declaration, varStatement, ctx);
|
|
5963
6185
|
}
|
|
5964
6186
|
}
|
|
5965
|
-
} else if (
|
|
6187
|
+
} else if (ts15.isNamespaceExport(declaration) || ts15.isModuleDeclaration(declaration)) {
|
|
5966
6188
|
try {
|
|
5967
6189
|
result = serializeNamespaceExport(exportSymbol, exportName, ctx);
|
|
5968
6190
|
} catch {
|
|
@@ -5975,7 +6197,7 @@ function serializeDeclaration2(declaration, exportSymbol, _targetSymbol, exportN
|
|
|
5975
6197
|
examples: []
|
|
5976
6198
|
};
|
|
5977
6199
|
}
|
|
5978
|
-
} else if (
|
|
6200
|
+
} else if (ts15.isNamespaceImport(declaration)) {
|
|
5979
6201
|
try {
|
|
5980
6202
|
result = serializeNamespaceExport(exportSymbol, exportName, ctx);
|
|
5981
6203
|
} catch {
|
|
@@ -5988,7 +6210,7 @@ function serializeDeclaration2(declaration, exportSymbol, _targetSymbol, exportN
|
|
|
5988
6210
|
examples: []
|
|
5989
6211
|
};
|
|
5990
6212
|
}
|
|
5991
|
-
} else if (
|
|
6213
|
+
} else if (ts15.isSourceFile(declaration)) {
|
|
5992
6214
|
try {
|
|
5993
6215
|
result = serializeNamespaceExport(exportSymbol, exportName, ctx);
|
|
5994
6216
|
} catch {
|
|
@@ -6018,7 +6240,7 @@ function serializeNamespaceExport(symbol, exportName, ctx) {
|
|
|
6018
6240
|
const members = [];
|
|
6019
6241
|
const checker = ctx.program.getTypeChecker();
|
|
6020
6242
|
let targetSymbol = symbol;
|
|
6021
|
-
if (symbol.flags &
|
|
6243
|
+
if (symbol.flags & ts15.SymbolFlags.Alias) {
|
|
6022
6244
|
const aliased = checker.getAliasedSymbol(symbol);
|
|
6023
6245
|
if (aliased && aliased !== symbol) {
|
|
6024
6246
|
targetSymbol = aliased;
|
|
@@ -6045,31 +6267,31 @@ function serializeNamespaceExport(symbol, exportName, ctx) {
|
|
|
6045
6267
|
function serializeNamespaceMember(symbol, memberName, ctx) {
|
|
6046
6268
|
const checker = ctx.program.getTypeChecker();
|
|
6047
6269
|
let targetSymbol = symbol;
|
|
6048
|
-
if (symbol.flags &
|
|
6270
|
+
if (symbol.flags & ts15.SymbolFlags.Alias) {
|
|
6049
6271
|
const aliased = checker.getAliasedSymbol(symbol);
|
|
6050
6272
|
if (aliased && aliased !== symbol) {
|
|
6051
6273
|
targetSymbol = aliased;
|
|
6052
6274
|
}
|
|
6053
6275
|
}
|
|
6054
6276
|
const declarations = targetSymbol.declarations ?? [];
|
|
6055
|
-
const declaration = targetSymbol.valueDeclaration || declarations.find((d) => d.kind !==
|
|
6277
|
+
const declaration = targetSymbol.valueDeclaration || declarations.find((d) => d.kind !== ts15.SyntaxKind.ExportSpecifier) || declarations[0];
|
|
6056
6278
|
if (!declaration)
|
|
6057
6279
|
return null;
|
|
6058
6280
|
const type = checker.getTypeAtLocation(declaration);
|
|
6059
6281
|
const callSignatures = type.getCallSignatures();
|
|
6060
6282
|
const deprecated = isSymbolDeprecated(targetSymbol);
|
|
6061
6283
|
let kind = "variable";
|
|
6062
|
-
if (
|
|
6284
|
+
if (ts15.isFunctionDeclaration(declaration) || ts15.isFunctionExpression(declaration)) {
|
|
6063
6285
|
kind = "function";
|
|
6064
|
-
} else if (
|
|
6286
|
+
} else if (ts15.isClassDeclaration(declaration)) {
|
|
6065
6287
|
kind = "class";
|
|
6066
|
-
} else if (
|
|
6288
|
+
} else if (ts15.isInterfaceDeclaration(declaration)) {
|
|
6067
6289
|
kind = "interface";
|
|
6068
|
-
} else if (
|
|
6290
|
+
} else if (ts15.isTypeAliasDeclaration(declaration)) {
|
|
6069
6291
|
kind = "type";
|
|
6070
|
-
} else if (
|
|
6292
|
+
} else if (ts15.isEnumDeclaration(declaration)) {
|
|
6071
6293
|
kind = "enum";
|
|
6072
|
-
} else if (
|
|
6294
|
+
} else if (ts15.isVariableDeclaration(declaration)) {
|
|
6073
6295
|
if (callSignatures.length > 0) {
|
|
6074
6296
|
kind = "function";
|
|
6075
6297
|
}
|
|
@@ -6116,11 +6338,11 @@ function getJSDocFromExportSymbol(symbol) {
|
|
|
6116
6338
|
const examples = [];
|
|
6117
6339
|
const decl = symbol.declarations?.[0];
|
|
6118
6340
|
if (decl) {
|
|
6119
|
-
const exportDecl =
|
|
6120
|
-
if (exportDecl &&
|
|
6121
|
-
const jsDocs =
|
|
6341
|
+
const exportDecl = ts15.isNamespaceExport(decl) ? decl.parent : decl;
|
|
6342
|
+
if (exportDecl && ts15.isExportDeclaration(exportDecl)) {
|
|
6343
|
+
const jsDocs = ts15.getJSDocCommentsAndTags(exportDecl);
|
|
6122
6344
|
for (const doc of jsDocs) {
|
|
6123
|
-
if (
|
|
6345
|
+
if (ts15.isJSDoc(doc) && doc.comment) {
|
|
6124
6346
|
const commentText = typeof doc.comment === "string" ? doc.comment : doc.comment.map((c) => ("text" in c) ? c.text : "").join("");
|
|
6125
6347
|
if (commentText) {
|
|
6126
6348
|
return {
|
|
@@ -6175,14 +6397,14 @@ function withExportName(entry, exportName) {
|
|
|
6175
6397
|
return {
|
|
6176
6398
|
...entry,
|
|
6177
6399
|
id: exportName,
|
|
6178
|
-
name:
|
|
6400
|
+
name: exportName
|
|
6179
6401
|
};
|
|
6180
6402
|
}
|
|
6181
6403
|
function createEmptySpec(entryFile, includeSchema, isDtsSource) {
|
|
6182
6404
|
return {
|
|
6183
6405
|
...includeSchema ? { $schema: SCHEMA_URL } : {},
|
|
6184
6406
|
openpkg: SCHEMA_VERSION,
|
|
6185
|
-
meta: { name:
|
|
6407
|
+
meta: { name: path6.basename(entryFile, path6.extname(entryFile)) },
|
|
6186
6408
|
exports: [],
|
|
6187
6409
|
generation: {
|
|
6188
6410
|
generator: "@openpkg-ts/sdk",
|
|
@@ -6195,19 +6417,19 @@ function createEmptySpec(entryFile, includeSchema, isDtsSource) {
|
|
|
6195
6417
|
};
|
|
6196
6418
|
}
|
|
6197
6419
|
async function getPackageMeta(entryFile, baseDir) {
|
|
6198
|
-
const searchDir = baseDir ??
|
|
6199
|
-
const pkgPath =
|
|
6420
|
+
const searchDir = baseDir ?? path6.dirname(entryFile);
|
|
6421
|
+
const pkgPath = path6.join(searchDir, "package.json");
|
|
6200
6422
|
try {
|
|
6201
|
-
if (
|
|
6202
|
-
const pkg = JSON.parse(
|
|
6423
|
+
if (fs6.existsSync(pkgPath)) {
|
|
6424
|
+
const pkg = JSON.parse(fs6.readFileSync(pkgPath, "utf-8"));
|
|
6203
6425
|
return {
|
|
6204
|
-
name: pkg.name ??
|
|
6426
|
+
name: pkg.name ?? path6.basename(searchDir),
|
|
6205
6427
|
version: pkg.version,
|
|
6206
6428
|
description: pkg.description
|
|
6207
6429
|
};
|
|
6208
6430
|
}
|
|
6209
6431
|
} catch {}
|
|
6210
|
-
return { name:
|
|
6432
|
+
return { name: path6.basename(searchDir) };
|
|
6211
6433
|
}
|
|
6212
6434
|
|
|
6213
6435
|
// src/primitives/spec.ts
|
|
@@ -6261,7 +6483,9 @@ export {
|
|
|
6261
6483
|
normalizeSchema,
|
|
6262
6484
|
normalizeMembers,
|
|
6263
6485
|
normalizeExport,
|
|
6486
|
+
mergeConfig,
|
|
6264
6487
|
loadSpec,
|
|
6488
|
+
loadConfig,
|
|
6265
6489
|
listExports,
|
|
6266
6490
|
isTypeReference,
|
|
6267
6491
|
isTypeOnlyExport,
|
|
@@ -6323,6 +6547,7 @@ export {
|
|
|
6323
6547
|
arktypeAdapter,
|
|
6324
6548
|
analyzeSpec,
|
|
6325
6549
|
TypeRegistry,
|
|
6550
|
+
CONFIG_FILENAME,
|
|
6326
6551
|
BUILTIN_TYPE_SCHEMAS,
|
|
6327
6552
|
ARRAY_PROTOTYPE_METHODS
|
|
6328
6553
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpkg-ts/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.33.1",
|
|
4
4
|
"description": "TypeScript API extraction SDK - programmatic primitives for OpenPkg specs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"openpkg",
|
|
@@ -38,7 +38,8 @@
|
|
|
38
38
|
"test": "bun test"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@openpkg-ts/spec": "^0.
|
|
41
|
+
"@openpkg-ts/spec": "^0.33.0",
|
|
42
|
+
"picomatch": "4.0.3",
|
|
42
43
|
"typescript": "^5.0.0"
|
|
43
44
|
},
|
|
44
45
|
"peerDependencies": {
|