@openpkg-ts/sdk 0.32.1 → 0.33.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/dist/index.d.ts +183 -140
- package/dist/index.js +319 -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,7 +1896,7 @@ 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);
|
|
1866
1902
|
}
|
|
@@ -1886,8 +1922,8 @@ function createProgram({
|
|
|
1886
1922
|
return moduleNames.map((moduleName) => {
|
|
1887
1923
|
const srcDir = workspaceMap.packages.get(moduleName);
|
|
1888
1924
|
if (srcDir) {
|
|
1889
|
-
const indexFile =
|
|
1890
|
-
if (
|
|
1925
|
+
const indexFile = path2.join(srcDir, "index.ts");
|
|
1926
|
+
if (fs3.existsSync(indexFile)) {
|
|
1891
1927
|
return { resolvedFileName: indexFile, isExternalLibraryImport: false };
|
|
1892
1928
|
}
|
|
1893
1929
|
}
|
|
@@ -4779,7 +4815,7 @@ function serializeDeclaration(declaration, _exportSymbol, _targetSymbol, exportN
|
|
|
4779
4815
|
return result;
|
|
4780
4816
|
}
|
|
4781
4817
|
// src/primitives/list.ts
|
|
4782
|
-
import * as
|
|
4818
|
+
import * as path3 from "node:path";
|
|
4783
4819
|
import ts12 from "typescript";
|
|
4784
4820
|
async function listExports(options) {
|
|
4785
4821
|
const { entryFile, baseDir, content } = options;
|
|
@@ -4827,7 +4863,7 @@ function extractExportItem(symbol, checker, entryFile, entrySourceFile) {
|
|
|
4827
4863
|
return {
|
|
4828
4864
|
name,
|
|
4829
4865
|
kind: "namespace",
|
|
4830
|
-
file:
|
|
4866
|
+
file: path3.relative(path3.dirname(entryFile), declaration.fileName),
|
|
4831
4867
|
line: 1,
|
|
4832
4868
|
reexport: true
|
|
4833
4869
|
};
|
|
@@ -4841,7 +4877,7 @@ function extractExportItem(symbol, checker, entryFile, entrySourceFile) {
|
|
|
4841
4877
|
return {
|
|
4842
4878
|
name,
|
|
4843
4879
|
kind,
|
|
4844
|
-
file:
|
|
4880
|
+
file: path3.relative(path3.dirname(entryFile), sourceFile.fileName),
|
|
4845
4881
|
line: line + 1,
|
|
4846
4882
|
...description ? { description } : {},
|
|
4847
4883
|
...deprecated ? { deprecated: true } : {},
|
|
@@ -4893,10 +4929,10 @@ function getDescriptionPreview(symbol, checker) {
|
|
|
4893
4929
|
return `${firstLine.slice(0, 77)}...`;
|
|
4894
4930
|
}
|
|
4895
4931
|
// src/builder/spec-builder.ts
|
|
4896
|
-
import * as
|
|
4897
|
-
import * as
|
|
4932
|
+
import * as fs6 from "node:fs";
|
|
4933
|
+
import * as path6 from "node:path";
|
|
4898
4934
|
import { SCHEMA_URL, SCHEMA_VERSION } from "@openpkg-ts/spec";
|
|
4899
|
-
import
|
|
4935
|
+
import ts15 from "typescript";
|
|
4900
4936
|
|
|
4901
4937
|
// src/ast/resolve.ts
|
|
4902
4938
|
import ts13 from "typescript";
|
|
@@ -4930,9 +4966,9 @@ function resolveExportTarget2(symbol, checker) {
|
|
|
4930
4966
|
|
|
4931
4967
|
// src/schema/standard-schema.ts
|
|
4932
4968
|
import { spawn, spawnSync } from "node:child_process";
|
|
4933
|
-
import * as
|
|
4969
|
+
import * as fs4 from "node:fs";
|
|
4934
4970
|
import * as os from "node:os";
|
|
4935
|
-
import * as
|
|
4971
|
+
import * as path4 from "node:path";
|
|
4936
4972
|
function isStandardJSONSchema(obj) {
|
|
4937
4973
|
if (typeof obj !== "object" || obj === null)
|
|
4938
4974
|
return false;
|
|
@@ -5178,21 +5214,21 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
|
|
|
5178
5214
|
result.errors.push("No TypeScript runtime available. Install bun, tsx, or ts-node, or use Node 22+.");
|
|
5179
5215
|
return result;
|
|
5180
5216
|
}
|
|
5181
|
-
if (!
|
|
5217
|
+
if (!fs4.existsSync(tsFilePath)) {
|
|
5182
5218
|
result.errors.push(`TypeScript file not found: ${tsFilePath}`);
|
|
5183
5219
|
return result;
|
|
5184
5220
|
}
|
|
5185
5221
|
const tempDir = os.tmpdir();
|
|
5186
|
-
const workerPath =
|
|
5222
|
+
const workerPath = path4.join(tempDir, `openpkg-extract-worker-${Date.now()}.ts`);
|
|
5187
5223
|
try {
|
|
5188
|
-
|
|
5224
|
+
fs4.writeFileSync(workerPath, TS_WORKER_SCRIPT);
|
|
5189
5225
|
const optionsJson = JSON.stringify({ target, libraryOptions });
|
|
5190
5226
|
const args = [...runtime.args, workerPath, tsFilePath, optionsJson];
|
|
5191
5227
|
return await new Promise((resolve2) => {
|
|
5192
5228
|
const child = spawn(runtime.cmd, args, {
|
|
5193
5229
|
timeout,
|
|
5194
5230
|
stdio: ["ignore", "pipe", "pipe"],
|
|
5195
|
-
cwd:
|
|
5231
|
+
cwd: path4.dirname(tsFilePath)
|
|
5196
5232
|
});
|
|
5197
5233
|
let stdout = "";
|
|
5198
5234
|
let stderr = "";
|
|
@@ -5204,7 +5240,7 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
|
|
|
5204
5240
|
});
|
|
5205
5241
|
child.on("close", (code) => {
|
|
5206
5242
|
try {
|
|
5207
|
-
|
|
5243
|
+
fs4.unlinkSync(workerPath);
|
|
5208
5244
|
} catch {}
|
|
5209
5245
|
if (code !== 0) {
|
|
5210
5246
|
result.errors.push(`Extraction failed (${runtime.name}): ${stderr || `exit code ${code}`}`);
|
|
@@ -5233,7 +5269,7 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
|
|
|
5233
5269
|
});
|
|
5234
5270
|
child.on("error", (err) => {
|
|
5235
5271
|
try {
|
|
5236
|
-
|
|
5272
|
+
fs4.unlinkSync(workerPath);
|
|
5237
5273
|
} catch {}
|
|
5238
5274
|
result.errors.push(`Subprocess error: ${err.message}`);
|
|
5239
5275
|
resolve2(result);
|
|
@@ -5241,19 +5277,19 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
|
|
|
5241
5277
|
});
|
|
5242
5278
|
} catch (e) {
|
|
5243
5279
|
try {
|
|
5244
|
-
|
|
5280
|
+
fs4.unlinkSync(workerPath);
|
|
5245
5281
|
} catch {}
|
|
5246
5282
|
result.errors.push(`Failed to create worker script: ${e}`);
|
|
5247
5283
|
return result;
|
|
5248
5284
|
}
|
|
5249
5285
|
}
|
|
5250
5286
|
function readTsconfigOutDir(baseDir) {
|
|
5251
|
-
const tsconfigPath =
|
|
5287
|
+
const tsconfigPath = path4.join(baseDir, "tsconfig.json");
|
|
5252
5288
|
try {
|
|
5253
|
-
if (!
|
|
5289
|
+
if (!fs4.existsSync(tsconfigPath)) {
|
|
5254
5290
|
return null;
|
|
5255
5291
|
}
|
|
5256
|
-
const content =
|
|
5292
|
+
const content = fs4.readFileSync(tsconfigPath, "utf-8");
|
|
5257
5293
|
const stripped = content.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*$/gm, "");
|
|
5258
5294
|
const tsconfig = JSON.parse(stripped);
|
|
5259
5295
|
if (tsconfig.compilerOptions?.outDir) {
|
|
@@ -5263,7 +5299,7 @@ function readTsconfigOutDir(baseDir) {
|
|
|
5263
5299
|
return null;
|
|
5264
5300
|
}
|
|
5265
5301
|
function resolveCompiledPath(tsPath, baseDir) {
|
|
5266
|
-
const relativePath =
|
|
5302
|
+
const relativePath = path4.relative(baseDir, tsPath);
|
|
5267
5303
|
const withoutExt = relativePath.replace(/\.tsx?$/, "");
|
|
5268
5304
|
const srcPrefix = withoutExt.replace(/^src\//, "");
|
|
5269
5305
|
const tsconfigOutDir = readTsconfigOutDir(baseDir);
|
|
@@ -5271,7 +5307,7 @@ function resolveCompiledPath(tsPath, baseDir) {
|
|
|
5271
5307
|
const candidates = [];
|
|
5272
5308
|
if (tsconfigOutDir) {
|
|
5273
5309
|
for (const ext of extensions) {
|
|
5274
|
-
candidates.push(
|
|
5310
|
+
candidates.push(path4.join(baseDir, tsconfigOutDir, `${srcPrefix}${ext}`));
|
|
5275
5311
|
}
|
|
5276
5312
|
}
|
|
5277
5313
|
const commonOutDirs = ["dist", "build", "lib", "out"];
|
|
@@ -5279,21 +5315,21 @@ function resolveCompiledPath(tsPath, baseDir) {
|
|
|
5279
5315
|
if (outDir === tsconfigOutDir)
|
|
5280
5316
|
continue;
|
|
5281
5317
|
for (const ext of extensions) {
|
|
5282
|
-
candidates.push(
|
|
5318
|
+
candidates.push(path4.join(baseDir, outDir, `${srcPrefix}${ext}`));
|
|
5283
5319
|
}
|
|
5284
5320
|
}
|
|
5285
5321
|
for (const ext of extensions) {
|
|
5286
|
-
candidates.push(
|
|
5322
|
+
candidates.push(path4.join(baseDir, `${withoutExt}${ext}`));
|
|
5287
5323
|
}
|
|
5288
5324
|
const workspaceMatch = baseDir.match(/^(.+\/packages\/[^/]+)$/);
|
|
5289
5325
|
if (workspaceMatch) {
|
|
5290
5326
|
const pkgRoot = workspaceMatch[1];
|
|
5291
5327
|
for (const ext of extensions) {
|
|
5292
|
-
candidates.push(
|
|
5328
|
+
candidates.push(path4.join(pkgRoot, "dist", `${srcPrefix}${ext}`));
|
|
5293
5329
|
}
|
|
5294
5330
|
}
|
|
5295
5331
|
for (const candidate of candidates) {
|
|
5296
|
-
if (
|
|
5332
|
+
if (fs4.existsSync(candidate)) {
|
|
5297
5333
|
return candidate;
|
|
5298
5334
|
}
|
|
5299
5335
|
}
|
|
@@ -5305,7 +5341,7 @@ async function extractStandardSchemas(compiledJsPath, options = {}) {
|
|
|
5305
5341
|
schemas: new Map,
|
|
5306
5342
|
errors: []
|
|
5307
5343
|
};
|
|
5308
|
-
if (!
|
|
5344
|
+
if (!fs4.existsSync(compiledJsPath)) {
|
|
5309
5345
|
result.errors.push(`Compiled JS not found: ${compiledJsPath}`);
|
|
5310
5346
|
return result;
|
|
5311
5347
|
}
|
|
@@ -5386,6 +5422,173 @@ async function extractStandardSchemasFromProject(entryFile, baseDir, options = {
|
|
|
5386
5422
|
};
|
|
5387
5423
|
}
|
|
5388
5424
|
|
|
5425
|
+
// src/builder/external-resolver.ts
|
|
5426
|
+
import * as fs5 from "node:fs";
|
|
5427
|
+
import * as path5 from "node:path";
|
|
5428
|
+
import picomatch from "picomatch";
|
|
5429
|
+
import ts14 from "typescript";
|
|
5430
|
+
function matchesExternalPattern(packageName, include, exclude) {
|
|
5431
|
+
if (!include?.length)
|
|
5432
|
+
return false;
|
|
5433
|
+
const matchOptions = { bash: true };
|
|
5434
|
+
const isIncluded = include.some((p) => picomatch.isMatch(packageName, p, matchOptions));
|
|
5435
|
+
if (!isIncluded)
|
|
5436
|
+
return false;
|
|
5437
|
+
if (exclude?.length) {
|
|
5438
|
+
const isExcluded = exclude.some((p) => picomatch.isMatch(packageName, p, matchOptions));
|
|
5439
|
+
if (isExcluded)
|
|
5440
|
+
return false;
|
|
5441
|
+
}
|
|
5442
|
+
return true;
|
|
5443
|
+
}
|
|
5444
|
+
function resolveExternalModule(moduleSpecifier, containingFile, compilerOptions) {
|
|
5445
|
+
const resolved = ts14.resolveModuleName(moduleSpecifier, containingFile, compilerOptions, ts14.sys);
|
|
5446
|
+
if (!resolved.resolvedModule) {
|
|
5447
|
+
return null;
|
|
5448
|
+
}
|
|
5449
|
+
const resolvedPath = resolved.resolvedModule.resolvedFileName;
|
|
5450
|
+
const packageJson = findPackageJson(resolvedPath, moduleSpecifier);
|
|
5451
|
+
return {
|
|
5452
|
+
resolvedPath,
|
|
5453
|
+
packageName: moduleSpecifier,
|
|
5454
|
+
packageVersion: packageJson?.version
|
|
5455
|
+
};
|
|
5456
|
+
}
|
|
5457
|
+
function findPackageJson(resolvedPath, packageName) {
|
|
5458
|
+
const isScoped = packageName.startsWith("@");
|
|
5459
|
+
const packageParts = isScoped ? packageName.split("/").slice(0, 2) : [packageName.split("/")[0]];
|
|
5460
|
+
const packageDir = packageParts.join("/");
|
|
5461
|
+
let dir = path5.dirname(resolvedPath);
|
|
5462
|
+
const maxDepth = 10;
|
|
5463
|
+
for (let i = 0;i < maxDepth; i++) {
|
|
5464
|
+
if (dir.endsWith(`node_modules/${packageDir}`)) {
|
|
5465
|
+
const pkgPath = path5.join(dir, "package.json");
|
|
5466
|
+
if (fs5.existsSync(pkgPath)) {
|
|
5467
|
+
try {
|
|
5468
|
+
return JSON.parse(fs5.readFileSync(pkgPath, "utf-8"));
|
|
5469
|
+
} catch {
|
|
5470
|
+
return;
|
|
5471
|
+
}
|
|
5472
|
+
}
|
|
5473
|
+
}
|
|
5474
|
+
const parent = path5.dirname(dir);
|
|
5475
|
+
if (parent === dir)
|
|
5476
|
+
break;
|
|
5477
|
+
dir = parent;
|
|
5478
|
+
}
|
|
5479
|
+
return;
|
|
5480
|
+
}
|
|
5481
|
+
function determineExportKind(symbol, checker) {
|
|
5482
|
+
const declarations = symbol.declarations ?? [];
|
|
5483
|
+
const decl = declarations[0];
|
|
5484
|
+
if (!decl)
|
|
5485
|
+
return "variable";
|
|
5486
|
+
if (ts14.isFunctionDeclaration(decl) || ts14.isFunctionExpression(decl))
|
|
5487
|
+
return "function";
|
|
5488
|
+
if (ts14.isClassDeclaration(decl))
|
|
5489
|
+
return "class";
|
|
5490
|
+
if (ts14.isInterfaceDeclaration(decl))
|
|
5491
|
+
return "interface";
|
|
5492
|
+
if (ts14.isTypeAliasDeclaration(decl))
|
|
5493
|
+
return "type";
|
|
5494
|
+
if (ts14.isEnumDeclaration(decl))
|
|
5495
|
+
return "enum";
|
|
5496
|
+
if (ts14.isModuleDeclaration(decl))
|
|
5497
|
+
return "namespace";
|
|
5498
|
+
if (ts14.isVariableDeclaration(decl)) {
|
|
5499
|
+
const type = checker.getTypeAtLocation(decl);
|
|
5500
|
+
if (type.getCallSignatures().length > 0)
|
|
5501
|
+
return "function";
|
|
5502
|
+
}
|
|
5503
|
+
return "variable";
|
|
5504
|
+
}
|
|
5505
|
+
function extractExternalExport(exportName, resolvedModule, program, ctx, visited) {
|
|
5506
|
+
const key = `${resolvedModule.resolvedPath}:${exportName}`;
|
|
5507
|
+
if (visited.has(key)) {
|
|
5508
|
+
return {
|
|
5509
|
+
id: exportName,
|
|
5510
|
+
name: exportName,
|
|
5511
|
+
kind: "external",
|
|
5512
|
+
source: {
|
|
5513
|
+
package: resolvedModule.packageName,
|
|
5514
|
+
version: resolvedModule.packageVersion
|
|
5515
|
+
}
|
|
5516
|
+
};
|
|
5517
|
+
}
|
|
5518
|
+
visited.add(key);
|
|
5519
|
+
const checker = program.getTypeChecker();
|
|
5520
|
+
const sourceFile = program.getSourceFile(resolvedModule.resolvedPath);
|
|
5521
|
+
if (!sourceFile) {
|
|
5522
|
+
return null;
|
|
5523
|
+
}
|
|
5524
|
+
const moduleSymbol = checker.getSymbolAtLocation(sourceFile);
|
|
5525
|
+
if (!moduleSymbol) {
|
|
5526
|
+
return null;
|
|
5527
|
+
}
|
|
5528
|
+
const exports = checker.getExportsOfModule(moduleSymbol);
|
|
5529
|
+
const targetExport = exports.find((e) => e.getName() === exportName);
|
|
5530
|
+
if (!targetExport) {
|
|
5531
|
+
return null;
|
|
5532
|
+
}
|
|
5533
|
+
let resolvedSymbol = targetExport;
|
|
5534
|
+
if (targetExport.flags & ts14.SymbolFlags.Alias) {
|
|
5535
|
+
const aliased = checker.getAliasedSymbol(targetExport);
|
|
5536
|
+
if (aliased && aliased !== targetExport) {
|
|
5537
|
+
resolvedSymbol = aliased;
|
|
5538
|
+
}
|
|
5539
|
+
}
|
|
5540
|
+
const kind = determineExportKind(resolvedSymbol, checker);
|
|
5541
|
+
const docComment = resolvedSymbol.getDocumentationComment(checker);
|
|
5542
|
+
const description = docComment.length > 0 ? docComment.map((c) => c.text).join(`
|
|
5543
|
+
`) : undefined;
|
|
5544
|
+
const specExport = {
|
|
5545
|
+
id: exportName,
|
|
5546
|
+
name: exportName,
|
|
5547
|
+
kind,
|
|
5548
|
+
...description && { description },
|
|
5549
|
+
source: {
|
|
5550
|
+
package: resolvedModule.packageName,
|
|
5551
|
+
version: resolvedModule.packageVersion,
|
|
5552
|
+
file: resolvedModule.resolvedPath
|
|
5553
|
+
}
|
|
5554
|
+
};
|
|
5555
|
+
if (kind === "function") {
|
|
5556
|
+
const type = checker.getTypeOfSymbol(resolvedSymbol);
|
|
5557
|
+
const callSignatures = type.getCallSignatures();
|
|
5558
|
+
if (callSignatures.length > 0) {
|
|
5559
|
+
const signatures = callSignatures.map((sig, index) => {
|
|
5560
|
+
const params = extractParameters(sig, ctx);
|
|
5561
|
+
const returnType = checker.getReturnTypeOfSignature(sig);
|
|
5562
|
+
registerReferencedTypes(returnType, ctx);
|
|
5563
|
+
const returnSchema = buildSchema(returnType, checker, ctx);
|
|
5564
|
+
const sigDoc = getJSDocForSignature(sig, checker);
|
|
5565
|
+
const sigTypeParams = extractTypeParametersFromSignature(sig, checker);
|
|
5566
|
+
return {
|
|
5567
|
+
parameters: params,
|
|
5568
|
+
returns: { schema: returnSchema },
|
|
5569
|
+
...sigDoc.description && { description: sigDoc.description },
|
|
5570
|
+
...sigDoc.tags.length > 0 && { tags: sigDoc.tags },
|
|
5571
|
+
...sigDoc.examples.length > 0 && { examples: sigDoc.examples },
|
|
5572
|
+
...sigTypeParams && { typeParameters: sigTypeParams },
|
|
5573
|
+
...callSignatures.length > 1 && { overloadIndex: index }
|
|
5574
|
+
};
|
|
5575
|
+
});
|
|
5576
|
+
specExport.signatures = signatures;
|
|
5577
|
+
}
|
|
5578
|
+
} else if (kind === "interface" || kind === "type" || kind === "class") {
|
|
5579
|
+
const type = checker.getTypeOfSymbol(resolvedSymbol);
|
|
5580
|
+
registerReferencedTypes(type, ctx);
|
|
5581
|
+
const schema = buildSchema(type, checker, ctx);
|
|
5582
|
+
specExport.schema = schema;
|
|
5583
|
+
} else if (kind === "variable") {
|
|
5584
|
+
const type = checker.getTypeOfSymbol(resolvedSymbol);
|
|
5585
|
+
registerReferencedTypes(type, ctx);
|
|
5586
|
+
const schema = buildSchema(type, checker, ctx);
|
|
5587
|
+
specExport.schema = schema;
|
|
5588
|
+
}
|
|
5589
|
+
return specExport;
|
|
5590
|
+
}
|
|
5591
|
+
|
|
5389
5592
|
// src/builder/schema-merger.ts
|
|
5390
5593
|
function mergeRuntimeSchemas(staticExports, runtimeSchemas) {
|
|
5391
5594
|
let merged = 0;
|
|
@@ -5647,9 +5850,9 @@ async function extract(options) {
|
|
|
5647
5850
|
break;
|
|
5648
5851
|
}
|
|
5649
5852
|
}
|
|
5650
|
-
if (
|
|
5853
|
+
if (ts15.isExportSpecifier(decl)) {
|
|
5651
5854
|
const exportDecl = decl.parent?.parent;
|
|
5652
|
-
if (exportDecl &&
|
|
5855
|
+
if (exportDecl && ts15.isExportDeclaration(exportDecl) && exportDecl.moduleSpecifier) {
|
|
5653
5856
|
const moduleText = exportDecl.moduleSpecifier.getText().slice(1, -1);
|
|
5654
5857
|
if (!moduleText.startsWith(".") && !moduleText.startsWith("/")) {
|
|
5655
5858
|
externalPackage = moduleText;
|
|
@@ -5659,6 +5862,20 @@ async function extract(options) {
|
|
|
5659
5862
|
}
|
|
5660
5863
|
}
|
|
5661
5864
|
if (externalPackage) {
|
|
5865
|
+
const shouldResolve = matchesExternalPattern(externalPackage, options.externals?.include, options.externals?.exclude);
|
|
5866
|
+
if (shouldResolve) {
|
|
5867
|
+
const resolvedModule = resolveExternalModule(externalPackage, sourceFile.fileName, program.getCompilerOptions());
|
|
5868
|
+
if (resolvedModule) {
|
|
5869
|
+
const visitedExternals = new Set;
|
|
5870
|
+
const extractedExport = extractExternalExport(exportName, resolvedModule, program, ctx, visitedExternals);
|
|
5871
|
+
if (extractedExport) {
|
|
5872
|
+
exports.push(extractedExport);
|
|
5873
|
+
tracker.status = "success";
|
|
5874
|
+
tracker.kind = extractedExport.kind;
|
|
5875
|
+
continue;
|
|
5876
|
+
}
|
|
5877
|
+
}
|
|
5878
|
+
}
|
|
5662
5879
|
const externalExport = {
|
|
5663
5880
|
id: exportName,
|
|
5664
5881
|
name: exportName,
|
|
@@ -5699,7 +5916,7 @@ async function extract(options) {
|
|
|
5699
5916
|
const verification = buildVerificationSummary(exportedSymbols.length, exports.length, exportTracker);
|
|
5700
5917
|
const meta = await getPackageMeta(entryFile, baseDir);
|
|
5701
5918
|
const types = ctx.typeRegistry.getAll();
|
|
5702
|
-
const projectBaseDir = baseDir ??
|
|
5919
|
+
const projectBaseDir = baseDir ?? path6.dirname(entryFile);
|
|
5703
5920
|
const definedTypes = new Set(types.map((t) => t.id));
|
|
5704
5921
|
const forgottenExports = collectForgottenExports(exports, types, program, sourceFile, exportedIds, projectBaseDir, definedTypes);
|
|
5705
5922
|
for (const forgotten of forgottenExports) {
|
|
@@ -5732,7 +5949,7 @@ async function extract(options) {
|
|
|
5732
5949
|
}
|
|
5733
5950
|
let runtimeMetadata;
|
|
5734
5951
|
if (options.schemaExtraction === "hybrid") {
|
|
5735
|
-
const projectBaseDir2 = baseDir ||
|
|
5952
|
+
const projectBaseDir2 = baseDir || path6.dirname(entryFile);
|
|
5736
5953
|
const runtimeResult = await extractStandardSchemasFromProject(entryFile, projectBaseDir2, {
|
|
5737
5954
|
target: options.schemaTarget || "draft-2020-12",
|
|
5738
5955
|
timeout: 15000
|
|
@@ -5772,6 +5989,9 @@ async function extract(options) {
|
|
|
5772
5989
|
...options.schemaExtraction === "hybrid" ? { schemaExtraction: "hybrid" } : {},
|
|
5773
5990
|
...isDtsSource && {
|
|
5774
5991
|
limitations: ["No JSDoc descriptions", "No @example tags", "No @param descriptions"]
|
|
5992
|
+
},
|
|
5993
|
+
...verification.details.skipped.length > 0 && {
|
|
5994
|
+
skipped: verification.details.skipped
|
|
5775
5995
|
}
|
|
5776
5996
|
}
|
|
5777
5997
|
};
|
|
@@ -5845,11 +6065,11 @@ function findTypeDefinition(typeName, program, sourceFile) {
|
|
|
5845
6065
|
}
|
|
5846
6066
|
const checker = program.getTypeChecker();
|
|
5847
6067
|
const findInNode = (node) => {
|
|
5848
|
-
if ((
|
|
6068
|
+
if ((ts15.isInterfaceDeclaration(node) || ts15.isTypeAliasDeclaration(node) || ts15.isClassDeclaration(node) || ts15.isEnumDeclaration(node)) && node.name?.text === typeName) {
|
|
5849
6069
|
const sf = node.getSourceFile();
|
|
5850
6070
|
return sf.fileName;
|
|
5851
6071
|
}
|
|
5852
|
-
return
|
|
6072
|
+
return ts15.forEachChild(node, findInNode);
|
|
5853
6073
|
};
|
|
5854
6074
|
const entryResult = findInNode(sourceFile);
|
|
5855
6075
|
if (entryResult) {
|
|
@@ -5865,7 +6085,7 @@ function findTypeDefinition(typeName, program, sourceFile) {
|
|
|
5865
6085
|
}
|
|
5866
6086
|
}
|
|
5867
6087
|
}
|
|
5868
|
-
const symbol = checker.resolveName(typeName, sourceFile,
|
|
6088
|
+
const symbol = checker.resolveName(typeName, sourceFile, ts15.SymbolFlags.Type, false);
|
|
5869
6089
|
if (symbol?.declarations?.[0]) {
|
|
5870
6090
|
const result = symbol.declarations[0].getSourceFile().fileName;
|
|
5871
6091
|
cache.set(typeName, result);
|
|
@@ -5879,8 +6099,8 @@ function isExternalType2(definedIn, baseDir) {
|
|
|
5879
6099
|
return true;
|
|
5880
6100
|
if (definedIn.includes("node_modules"))
|
|
5881
6101
|
return true;
|
|
5882
|
-
const normalizedDefined =
|
|
5883
|
-
const normalizedBase =
|
|
6102
|
+
const normalizedDefined = path6.resolve(definedIn);
|
|
6103
|
+
const normalizedBase = path6.resolve(baseDir);
|
|
5884
6104
|
return !normalizedDefined.startsWith(normalizedBase);
|
|
5885
6105
|
}
|
|
5886
6106
|
function hasInternalTag(typeName, program, sourceFile) {
|
|
@@ -5890,7 +6110,7 @@ function hasInternalTag(typeName, program, sourceFile) {
|
|
|
5890
6110
|
return cached;
|
|
5891
6111
|
}
|
|
5892
6112
|
const checker = program.getTypeChecker();
|
|
5893
|
-
const symbol = checker.resolveName(typeName, sourceFile,
|
|
6113
|
+
const symbol = checker.resolveName(typeName, sourceFile, ts15.SymbolFlags.Type, false);
|
|
5894
6114
|
if (!symbol) {
|
|
5895
6115
|
cache.set(typeName, false);
|
|
5896
6116
|
return false;
|
|
@@ -5942,27 +6162,27 @@ function collectForgottenExports(exports, types, program, sourceFile, exportedId
|
|
|
5942
6162
|
}
|
|
5943
6163
|
function serializeDeclaration2(declaration, exportSymbol, _targetSymbol, exportName, ctx, isTypeOnly = false) {
|
|
5944
6164
|
let result = null;
|
|
5945
|
-
if (
|
|
6165
|
+
if (ts15.isFunctionDeclaration(declaration)) {
|
|
5946
6166
|
result = serializeFunctionExport(declaration, ctx);
|
|
5947
|
-
} else if (
|
|
6167
|
+
} else if (ts15.isClassDeclaration(declaration)) {
|
|
5948
6168
|
result = serializeClass(declaration, ctx);
|
|
5949
|
-
} else if (
|
|
6169
|
+
} else if (ts15.isInterfaceDeclaration(declaration)) {
|
|
5950
6170
|
result = serializeInterface(declaration, ctx);
|
|
5951
|
-
} else if (
|
|
6171
|
+
} else if (ts15.isTypeAliasDeclaration(declaration)) {
|
|
5952
6172
|
result = serializeTypeAlias(declaration, ctx);
|
|
5953
|
-
} else if (
|
|
6173
|
+
} else if (ts15.isEnumDeclaration(declaration)) {
|
|
5954
6174
|
result = serializeEnum(declaration, ctx);
|
|
5955
|
-
} else if (
|
|
6175
|
+
} else if (ts15.isVariableDeclaration(declaration)) {
|
|
5956
6176
|
const varStatement = declaration.parent?.parent;
|
|
5957
|
-
if (varStatement &&
|
|
5958
|
-
if (declaration.initializer &&
|
|
5959
|
-
const varName =
|
|
6177
|
+
if (varStatement && ts15.isVariableStatement(varStatement)) {
|
|
6178
|
+
if (declaration.initializer && ts15.isArrowFunction(declaration.initializer)) {
|
|
6179
|
+
const varName = ts15.isIdentifier(declaration.name) ? declaration.name.text : declaration.name.getText();
|
|
5960
6180
|
result = serializeFunctionExport(declaration.initializer, ctx, varName);
|
|
5961
6181
|
} else {
|
|
5962
6182
|
result = serializeVariable(declaration, varStatement, ctx);
|
|
5963
6183
|
}
|
|
5964
6184
|
}
|
|
5965
|
-
} else if (
|
|
6185
|
+
} else if (ts15.isNamespaceExport(declaration) || ts15.isModuleDeclaration(declaration)) {
|
|
5966
6186
|
try {
|
|
5967
6187
|
result = serializeNamespaceExport(exportSymbol, exportName, ctx);
|
|
5968
6188
|
} catch {
|
|
@@ -5975,7 +6195,7 @@ function serializeDeclaration2(declaration, exportSymbol, _targetSymbol, exportN
|
|
|
5975
6195
|
examples: []
|
|
5976
6196
|
};
|
|
5977
6197
|
}
|
|
5978
|
-
} else if (
|
|
6198
|
+
} else if (ts15.isNamespaceImport(declaration)) {
|
|
5979
6199
|
try {
|
|
5980
6200
|
result = serializeNamespaceExport(exportSymbol, exportName, ctx);
|
|
5981
6201
|
} catch {
|
|
@@ -5988,7 +6208,7 @@ function serializeDeclaration2(declaration, exportSymbol, _targetSymbol, exportN
|
|
|
5988
6208
|
examples: []
|
|
5989
6209
|
};
|
|
5990
6210
|
}
|
|
5991
|
-
} else if (
|
|
6211
|
+
} else if (ts15.isSourceFile(declaration)) {
|
|
5992
6212
|
try {
|
|
5993
6213
|
result = serializeNamespaceExport(exportSymbol, exportName, ctx);
|
|
5994
6214
|
} catch {
|
|
@@ -6018,7 +6238,7 @@ function serializeNamespaceExport(symbol, exportName, ctx) {
|
|
|
6018
6238
|
const members = [];
|
|
6019
6239
|
const checker = ctx.program.getTypeChecker();
|
|
6020
6240
|
let targetSymbol = symbol;
|
|
6021
|
-
if (symbol.flags &
|
|
6241
|
+
if (symbol.flags & ts15.SymbolFlags.Alias) {
|
|
6022
6242
|
const aliased = checker.getAliasedSymbol(symbol);
|
|
6023
6243
|
if (aliased && aliased !== symbol) {
|
|
6024
6244
|
targetSymbol = aliased;
|
|
@@ -6045,31 +6265,31 @@ function serializeNamespaceExport(symbol, exportName, ctx) {
|
|
|
6045
6265
|
function serializeNamespaceMember(symbol, memberName, ctx) {
|
|
6046
6266
|
const checker = ctx.program.getTypeChecker();
|
|
6047
6267
|
let targetSymbol = symbol;
|
|
6048
|
-
if (symbol.flags &
|
|
6268
|
+
if (symbol.flags & ts15.SymbolFlags.Alias) {
|
|
6049
6269
|
const aliased = checker.getAliasedSymbol(symbol);
|
|
6050
6270
|
if (aliased && aliased !== symbol) {
|
|
6051
6271
|
targetSymbol = aliased;
|
|
6052
6272
|
}
|
|
6053
6273
|
}
|
|
6054
6274
|
const declarations = targetSymbol.declarations ?? [];
|
|
6055
|
-
const declaration = targetSymbol.valueDeclaration || declarations.find((d) => d.kind !==
|
|
6275
|
+
const declaration = targetSymbol.valueDeclaration || declarations.find((d) => d.kind !== ts15.SyntaxKind.ExportSpecifier) || declarations[0];
|
|
6056
6276
|
if (!declaration)
|
|
6057
6277
|
return null;
|
|
6058
6278
|
const type = checker.getTypeAtLocation(declaration);
|
|
6059
6279
|
const callSignatures = type.getCallSignatures();
|
|
6060
6280
|
const deprecated = isSymbolDeprecated(targetSymbol);
|
|
6061
6281
|
let kind = "variable";
|
|
6062
|
-
if (
|
|
6282
|
+
if (ts15.isFunctionDeclaration(declaration) || ts15.isFunctionExpression(declaration)) {
|
|
6063
6283
|
kind = "function";
|
|
6064
|
-
} else if (
|
|
6284
|
+
} else if (ts15.isClassDeclaration(declaration)) {
|
|
6065
6285
|
kind = "class";
|
|
6066
|
-
} else if (
|
|
6286
|
+
} else if (ts15.isInterfaceDeclaration(declaration)) {
|
|
6067
6287
|
kind = "interface";
|
|
6068
|
-
} else if (
|
|
6288
|
+
} else if (ts15.isTypeAliasDeclaration(declaration)) {
|
|
6069
6289
|
kind = "type";
|
|
6070
|
-
} else if (
|
|
6290
|
+
} else if (ts15.isEnumDeclaration(declaration)) {
|
|
6071
6291
|
kind = "enum";
|
|
6072
|
-
} else if (
|
|
6292
|
+
} else if (ts15.isVariableDeclaration(declaration)) {
|
|
6073
6293
|
if (callSignatures.length > 0) {
|
|
6074
6294
|
kind = "function";
|
|
6075
6295
|
}
|
|
@@ -6116,11 +6336,11 @@ function getJSDocFromExportSymbol(symbol) {
|
|
|
6116
6336
|
const examples = [];
|
|
6117
6337
|
const decl = symbol.declarations?.[0];
|
|
6118
6338
|
if (decl) {
|
|
6119
|
-
const exportDecl =
|
|
6120
|
-
if (exportDecl &&
|
|
6121
|
-
const jsDocs =
|
|
6339
|
+
const exportDecl = ts15.isNamespaceExport(decl) ? decl.parent : decl;
|
|
6340
|
+
if (exportDecl && ts15.isExportDeclaration(exportDecl)) {
|
|
6341
|
+
const jsDocs = ts15.getJSDocCommentsAndTags(exportDecl);
|
|
6122
6342
|
for (const doc of jsDocs) {
|
|
6123
|
-
if (
|
|
6343
|
+
if (ts15.isJSDoc(doc) && doc.comment) {
|
|
6124
6344
|
const commentText = typeof doc.comment === "string" ? doc.comment : doc.comment.map((c) => ("text" in c) ? c.text : "").join("");
|
|
6125
6345
|
if (commentText) {
|
|
6126
6346
|
return {
|
|
@@ -6175,14 +6395,14 @@ function withExportName(entry, exportName) {
|
|
|
6175
6395
|
return {
|
|
6176
6396
|
...entry,
|
|
6177
6397
|
id: exportName,
|
|
6178
|
-
name:
|
|
6398
|
+
name: exportName
|
|
6179
6399
|
};
|
|
6180
6400
|
}
|
|
6181
6401
|
function createEmptySpec(entryFile, includeSchema, isDtsSource) {
|
|
6182
6402
|
return {
|
|
6183
6403
|
...includeSchema ? { $schema: SCHEMA_URL } : {},
|
|
6184
6404
|
openpkg: SCHEMA_VERSION,
|
|
6185
|
-
meta: { name:
|
|
6405
|
+
meta: { name: path6.basename(entryFile, path6.extname(entryFile)) },
|
|
6186
6406
|
exports: [],
|
|
6187
6407
|
generation: {
|
|
6188
6408
|
generator: "@openpkg-ts/sdk",
|
|
@@ -6195,19 +6415,19 @@ function createEmptySpec(entryFile, includeSchema, isDtsSource) {
|
|
|
6195
6415
|
};
|
|
6196
6416
|
}
|
|
6197
6417
|
async function getPackageMeta(entryFile, baseDir) {
|
|
6198
|
-
const searchDir = baseDir ??
|
|
6199
|
-
const pkgPath =
|
|
6418
|
+
const searchDir = baseDir ?? path6.dirname(entryFile);
|
|
6419
|
+
const pkgPath = path6.join(searchDir, "package.json");
|
|
6200
6420
|
try {
|
|
6201
|
-
if (
|
|
6202
|
-
const pkg = JSON.parse(
|
|
6421
|
+
if (fs6.existsSync(pkgPath)) {
|
|
6422
|
+
const pkg = JSON.parse(fs6.readFileSync(pkgPath, "utf-8"));
|
|
6203
6423
|
return {
|
|
6204
|
-
name: pkg.name ??
|
|
6424
|
+
name: pkg.name ?? path6.basename(searchDir),
|
|
6205
6425
|
version: pkg.version,
|
|
6206
6426
|
description: pkg.description
|
|
6207
6427
|
};
|
|
6208
6428
|
}
|
|
6209
6429
|
} catch {}
|
|
6210
|
-
return { name:
|
|
6430
|
+
return { name: path6.basename(searchDir) };
|
|
6211
6431
|
}
|
|
6212
6432
|
|
|
6213
6433
|
// src/primitives/spec.ts
|
|
@@ -6261,7 +6481,9 @@ export {
|
|
|
6261
6481
|
normalizeSchema,
|
|
6262
6482
|
normalizeMembers,
|
|
6263
6483
|
normalizeExport,
|
|
6484
|
+
mergeConfig,
|
|
6264
6485
|
loadSpec,
|
|
6486
|
+
loadConfig,
|
|
6265
6487
|
listExports,
|
|
6266
6488
|
isTypeReference,
|
|
6267
6489
|
isTypeOnlyExport,
|
|
@@ -6323,6 +6545,7 @@ export {
|
|
|
6323
6545
|
arktypeAdapter,
|
|
6324
6546
|
analyzeSpec,
|
|
6325
6547
|
TypeRegistry,
|
|
6548
|
+
CONFIG_FILENAME,
|
|
6326
6549
|
BUILTIN_TYPE_SCHEMAS,
|
|
6327
6550
|
ARRAY_PROTOTYPE_METHODS
|
|
6328
6551
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpkg-ts/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.33.0",
|
|
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": {
|