@openpkg-ts/sdk 0.37.1 → 0.38.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/LICENSE +21 -0
- package/dist/index.d.ts +7 -31
- package/dist/index.js +72 -289
- package/package.json +7 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Ryan Waits
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
CHANGED
|
@@ -733,8 +733,7 @@ declare function loadSpec(spec: OpenPkg8): DocsInstance;
|
|
|
733
733
|
* Creates a docs instance for querying and rendering API documentation.
|
|
734
734
|
*
|
|
735
735
|
* Render methods (toMarkdown, toHTML, toJSON, toNavigation) return strings or
|
|
736
|
-
* plain data objects — not React components.
|
|
737
|
-
* `@openpkg-ts/registry` package.
|
|
736
|
+
* plain data objects — not React components. Bring your own UI components.
|
|
738
737
|
*
|
|
739
738
|
* @example
|
|
740
739
|
* ```ts
|
|
@@ -1038,30 +1037,7 @@ declare class QueryBuilder {
|
|
|
1038
1037
|
* Create a query builder for the given spec
|
|
1039
1038
|
*/
|
|
1040
1039
|
declare function query(spec: OpenPkg10): QueryBuilder;
|
|
1041
|
-
import { OpenPkg as OpenPkg11 } from "@openpkg-ts/spec";
|
|
1042
|
-
interface ReactLayoutOptions {
|
|
1043
|
-
/** Output directory for generated files */
|
|
1044
|
-
outDir: string;
|
|
1045
|
-
/** Layout variant: 'full' (single page) or 'index' (index with links) */
|
|
1046
|
-
variant?: "full" | "index";
|
|
1047
|
-
/** Components path alias (default: @/components/api) */
|
|
1048
|
-
componentsPath?: string;
|
|
1049
|
-
}
|
|
1050
|
-
/**
|
|
1051
|
-
* Generate React layout from an OpenPkg spec.
|
|
1052
|
-
*
|
|
1053
|
-
* Unlike the old per-approach, this generates a single layout file.
|
|
1054
|
-
* Components are installed separately via the registry.
|
|
1055
|
-
*/
|
|
1056
|
-
declare function toReact(spec: OpenPkg11, options: ReactLayoutOptions): Promise<void>;
|
|
1057
|
-
/**
|
|
1058
|
-
* Generate layout code as a string (for preview).
|
|
1059
|
-
*/
|
|
1060
|
-
declare function toReactString(spec: OpenPkg11, options?: {
|
|
1061
|
-
variant?: "full" | "index";
|
|
1062
|
-
componentsPath?: string;
|
|
1063
|
-
}): string;
|
|
1064
|
-
import { OpenPkg as OpenPkg12, SpecExportKind as SpecExportKind7 } from "@openpkg-ts/spec";
|
|
1040
|
+
import { OpenPkg as OpenPkg11, SpecExportKind as SpecExportKind7 } from "@openpkg-ts/spec";
|
|
1065
1041
|
type FilterCriteria = {
|
|
1066
1042
|
/** Filter by kinds */
|
|
1067
1043
|
kinds?: SpecExportKind7[];
|
|
@@ -1086,7 +1062,7 @@ type FilterCriteria = {
|
|
|
1086
1062
|
};
|
|
1087
1063
|
type FilterResult = {
|
|
1088
1064
|
/** New spec with only matched exports (immutable) */
|
|
1089
|
-
spec:
|
|
1065
|
+
spec: OpenPkg11;
|
|
1090
1066
|
/** Number of exports that matched */
|
|
1091
1067
|
matched: number;
|
|
1092
1068
|
/** Total number of exports in original spec */
|
|
@@ -1102,7 +1078,7 @@ type FilterResult = {
|
|
|
1102
1078
|
* @param criteria - Filter criteria (empty criteria matches all)
|
|
1103
1079
|
* @returns FilterResult with new spec, matched count, total count
|
|
1104
1080
|
*/
|
|
1105
|
-
declare function filterSpec(spec:
|
|
1081
|
+
declare function filterSpec(spec: OpenPkg11, criteria: FilterCriteria): FilterResult;
|
|
1106
1082
|
import { SpecExport as SpecExport6, SpecType as SpecType3 } from "@openpkg-ts/spec";
|
|
1107
1083
|
interface GetExportOptions {
|
|
1108
1084
|
/** Entry point file path */
|
|
@@ -1259,7 +1235,7 @@ declare function getSourceLocation(node: ts4.Node, sourceFile: ts4.SourceFile):
|
|
|
1259
1235
|
* - @param {type} paramName - type annotation format
|
|
1260
1236
|
*/
|
|
1261
1237
|
declare function getParamDescription(propertyName: string, jsdocTags: readonly ts4.JSDocTag[], inferredAlias?: string): string | undefined;
|
|
1262
|
-
type DeclarationWithTypeParams = ts4.FunctionDeclaration | ts4.ClassDeclaration | ts4.InterfaceDeclaration | ts4.TypeAliasDeclaration | ts4.MethodDeclaration | ts4.ArrowFunction;
|
|
1238
|
+
type DeclarationWithTypeParams = ts4.FunctionDeclaration | ts4.ClassDeclaration | ts4.InterfaceDeclaration | ts4.TypeAliasDeclaration | ts4.MethodDeclaration | ts4.ArrowFunction | ts4.FunctionExpression;
|
|
1263
1239
|
/**
|
|
1264
1240
|
* Extract type parameters from declarations like `<T extends Base, K = Default>`
|
|
1265
1241
|
* Also captures variance annotations (in/out) and const modifier.
|
|
@@ -1274,7 +1250,7 @@ declare function isSymbolDeprecated(symbol: ts4.Symbol | undefined): {
|
|
|
1274
1250
|
reason?: string;
|
|
1275
1251
|
};
|
|
1276
1252
|
/** Classify a declaration node into an kind */
|
|
1277
|
-
declare function getExportKind(declaration: ts4.Declaration, type: ts4.Type): SpecExportKind8
|
|
1253
|
+
declare function getExportKind(declaration: ts4.Declaration, type: ts4.Type): Exclude<SpecExportKind8, "module" | "reference" | "external">;
|
|
1278
1254
|
/**
|
|
1279
1255
|
* Target version for JSON Schema generation.
|
|
1280
1256
|
* @see https://standardschema.dev/json-schema
|
|
@@ -1791,4 +1767,4 @@ declare function normalizeMembers(members: SpecMember3[], options?: NormalizeOpt
|
|
|
1791
1767
|
import ts16 from "typescript";
|
|
1792
1768
|
declare function isExported(node: ts16.Node): boolean;
|
|
1793
1769
|
declare function getNodeName(node: ts16.Node): string | undefined;
|
|
1794
|
-
export { zodAdapter, withDescription2 as withDescription, valibotAdapter, typeboxAdapter, toSearchIndexJSON, toSearchIndex2 as toSearchIndex,
|
|
1770
|
+
export { zodAdapter, withDescription2 as 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, query, 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, getExportKind, 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, STRING_PROTOTYPE_METHODS, QueryBuilder, ProjectExtractionOutput, ProjectExtractionInfo, ProgramResult, ProgramOptions, PagefindRecord, PRIMITIVES, OpenpkgConfig, NormalizeOptions, NavOptions, NavItem, NavGroup, NavFormat, NUMBER_PROTOTYPE_METHODS, MemberChangeInfo, MarkdownOptions, LoadOptions, ListExportsResult, ListExportsOptions, JSONSchema, JSONOptions, HTMLOptions, GroupBy, GetExportResult, GetExportOptions, GenericNav, FumadocsMetaItem, FumadocsMeta, FormatSchemaOptions, ForgottenExport, FilterResult, FilterCriteria, ExtractionWarningCode, ExtractionWarning, ExtractStandardSchemasOptions, ExtractResult, ExtractOptions, ExtractFromProjectOptions, ExternalsConfig, ExportVerification, ExportTracker, ExportMarkdownOptions, ExportItem, DocusaurusSidebarItem, DocusaurusSidebar, DocsInstance, DiagnosticItem, Diagnostic, CategorizedBreaking, CacheManagerOptions, CacheManager, CONFIG_FILENAME, BreakingSeverity, BUILTIN_TYPE_SCHEMAS, AlgoliaRecord, ARRAY_PROTOTYPE_METHODS };
|
package/dist/index.js
CHANGED
|
@@ -1191,221 +1191,6 @@ function extractModuleName(exp) {
|
|
|
1191
1191
|
}
|
|
1192
1192
|
return;
|
|
1193
1193
|
}
|
|
1194
|
-
// src/render/react.ts
|
|
1195
|
-
import * as fs3 from "node:fs";
|
|
1196
|
-
import * as path2 from "node:path";
|
|
1197
|
-
function generateFullLayout(spec, componentsPath) {
|
|
1198
|
-
const pkgName = spec.meta.name;
|
|
1199
|
-
return `'use client';
|
|
1200
|
-
|
|
1201
|
-
import type { OpenPkg, SpecExport } from '@openpkg-ts/spec';
|
|
1202
|
-
import spec from './openpkg.json';
|
|
1203
|
-
|
|
1204
|
-
// Add components via: openpkg docs add function-section class-section interface-section
|
|
1205
|
-
// Then uncomment the imports below and customize as needed.
|
|
1206
|
-
|
|
1207
|
-
// import { FunctionSection } from '${componentsPath}/function-section';
|
|
1208
|
-
// import { ClassSection } from '${componentsPath}/class-section';
|
|
1209
|
-
// import { InterfaceSection } from '${componentsPath}/interface-section';
|
|
1210
|
-
// import { VariableSection } from '${componentsPath}/variable-section';
|
|
1211
|
-
// import { EnumSection } from '${componentsPath}/enum-section';
|
|
1212
|
-
|
|
1213
|
-
/**
|
|
1214
|
-
* Renders a single export based on its kind.
|
|
1215
|
-
* Customize this to match your design system.
|
|
1216
|
-
*/
|
|
1217
|
-
function ExportSection({ exp }: { exp: SpecExport }) {
|
|
1218
|
-
// Uncomment the switch once you've added components:
|
|
1219
|
-
// switch (exp.kind) {
|
|
1220
|
-
// case 'function':
|
|
1221
|
-
// return <FunctionSection key={exp.id} export={exp} spec={spec as OpenPkg} />;
|
|
1222
|
-
// case 'class':
|
|
1223
|
-
// return <ClassSection key={exp.id} export={exp} spec={spec as OpenPkg} />;
|
|
1224
|
-
// case 'interface':
|
|
1225
|
-
// case 'type':
|
|
1226
|
-
// return <InterfaceSection key={exp.id} export={exp} spec={spec as OpenPkg} />;
|
|
1227
|
-
// case 'variable':
|
|
1228
|
-
// return <VariableSection key={exp.id} export={exp} spec={spec as OpenPkg} />;
|
|
1229
|
-
// case 'enum':
|
|
1230
|
-
// return <EnumSection key={exp.id} export={exp} spec={spec as OpenPkg} />;
|
|
1231
|
-
// default:
|
|
1232
|
-
// return null;
|
|
1233
|
-
// }
|
|
1234
|
-
|
|
1235
|
-
// Placeholder: replace with component imports above
|
|
1236
|
-
return (
|
|
1237
|
-
<section id={exp.id} className="py-8 border-b">
|
|
1238
|
-
<h2 className="text-xl font-semibold">{exp.name}</h2>
|
|
1239
|
-
<p className="text-muted-foreground">{exp.description || 'No description'}</p>
|
|
1240
|
-
<code className="text-sm">{exp.kind}</code>
|
|
1241
|
-
</section>
|
|
1242
|
-
);
|
|
1243
|
-
}
|
|
1244
|
-
|
|
1245
|
-
/**
|
|
1246
|
-
* Full API Reference Page for ${pkgName}
|
|
1247
|
-
*
|
|
1248
|
-
* This layout renders all exports on a single page.
|
|
1249
|
-
* Customize the grouping, styling, and components to match your docs.
|
|
1250
|
-
*/
|
|
1251
|
-
export default function APIReferencePage() {
|
|
1252
|
-
const typedSpec = spec as OpenPkg;
|
|
1253
|
-
const exports = typedSpec.exports;
|
|
1254
|
-
|
|
1255
|
-
// Group exports by kind
|
|
1256
|
-
const functions = exports.filter((e) => e.kind === 'function');
|
|
1257
|
-
const classes = exports.filter((e) => e.kind === 'class');
|
|
1258
|
-
const interfaces = exports.filter((e) => e.kind === 'interface' || e.kind === 'type');
|
|
1259
|
-
const variables = exports.filter((e) => e.kind === 'variable');
|
|
1260
|
-
const enums = exports.filter((e) => e.kind === 'enum');
|
|
1261
|
-
|
|
1262
|
-
return (
|
|
1263
|
-
<div className="max-w-4xl mx-auto px-4 py-8">
|
|
1264
|
-
<header className="mb-12">
|
|
1265
|
-
<h1 className="text-3xl font-bold">{typedSpec.meta.name}</h1>
|
|
1266
|
-
{typedSpec.meta.description && (
|
|
1267
|
-
<p className="text-lg text-muted-foreground mt-2">{typedSpec.meta.description}</p>
|
|
1268
|
-
)}
|
|
1269
|
-
{typedSpec.meta.version && (
|
|
1270
|
-
<p className="text-sm text-muted-foreground">v{typedSpec.meta.version}</p>
|
|
1271
|
-
)}
|
|
1272
|
-
</header>
|
|
1273
|
-
|
|
1274
|
-
{functions.length > 0 && (
|
|
1275
|
-
<section className="mb-12">
|
|
1276
|
-
<h2 className="text-2xl font-bold mb-6">Functions</h2>
|
|
1277
|
-
{functions.map((exp) => (
|
|
1278
|
-
<ExportSection key={exp.id} exp={exp} />
|
|
1279
|
-
))}
|
|
1280
|
-
</section>
|
|
1281
|
-
)}
|
|
1282
|
-
|
|
1283
|
-
{classes.length > 0 && (
|
|
1284
|
-
<section className="mb-12">
|
|
1285
|
-
<h2 className="text-2xl font-bold mb-6">Classes</h2>
|
|
1286
|
-
{classes.map((exp) => (
|
|
1287
|
-
<ExportSection key={exp.id} exp={exp} />
|
|
1288
|
-
))}
|
|
1289
|
-
</section>
|
|
1290
|
-
)}
|
|
1291
|
-
|
|
1292
|
-
{interfaces.length > 0 && (
|
|
1293
|
-
<section className="mb-12">
|
|
1294
|
-
<h2 className="text-2xl font-bold mb-6">Types & Interfaces</h2>
|
|
1295
|
-
{interfaces.map((exp) => (
|
|
1296
|
-
<ExportSection key={exp.id} exp={exp} />
|
|
1297
|
-
))}
|
|
1298
|
-
</section>
|
|
1299
|
-
)}
|
|
1300
|
-
|
|
1301
|
-
{variables.length > 0 && (
|
|
1302
|
-
<section className="mb-12">
|
|
1303
|
-
<h2 className="text-2xl font-bold mb-6">Variables</h2>
|
|
1304
|
-
{variables.map((exp) => (
|
|
1305
|
-
<ExportSection key={exp.id} exp={exp} />
|
|
1306
|
-
))}
|
|
1307
|
-
</section>
|
|
1308
|
-
)}
|
|
1309
|
-
|
|
1310
|
-
{enums.length > 0 && (
|
|
1311
|
-
<section className="mb-12">
|
|
1312
|
-
<h2 className="text-2xl font-bold mb-6">Enums</h2>
|
|
1313
|
-
{enums.map((exp) => (
|
|
1314
|
-
<ExportSection key={exp.id} exp={exp} />
|
|
1315
|
-
))}
|
|
1316
|
-
</section>
|
|
1317
|
-
)}
|
|
1318
|
-
</div>
|
|
1319
|
-
);
|
|
1320
|
-
}
|
|
1321
|
-
|
|
1322
|
-
export { spec };
|
|
1323
|
-
`;
|
|
1324
|
-
}
|
|
1325
|
-
function generateIndexLayout(spec, componentsPath) {
|
|
1326
|
-
const pkgName = spec.meta.name;
|
|
1327
|
-
return `'use client';
|
|
1328
|
-
|
|
1329
|
-
import type { OpenPkg } from '@openpkg-ts/spec';
|
|
1330
|
-
import spec from './openpkg.json';
|
|
1331
|
-
|
|
1332
|
-
// Add the export-card component: openpkg docs add export-card
|
|
1333
|
-
// import { ExportCard } from '${componentsPath}/export-card';
|
|
1334
|
-
|
|
1335
|
-
/**
|
|
1336
|
-
* API Reference Index Page for ${pkgName}
|
|
1337
|
-
*
|
|
1338
|
-
* Links to individual export pages. Best with file-based routing.
|
|
1339
|
-
* Customize the card component and links to match your docs.
|
|
1340
|
-
*/
|
|
1341
|
-
export default function APIReferenceIndex() {
|
|
1342
|
-
const typedSpec = spec as OpenPkg;
|
|
1343
|
-
const exports = typedSpec.exports;
|
|
1344
|
-
|
|
1345
|
-
// Group exports by kind
|
|
1346
|
-
const groups = [
|
|
1347
|
-
{ title: 'Functions', items: exports.filter((e) => e.kind === 'function') },
|
|
1348
|
-
{ title: 'Classes', items: exports.filter((e) => e.kind === 'class') },
|
|
1349
|
-
{ title: 'Types & Interfaces', items: exports.filter((e) => e.kind === 'interface' || e.kind === 'type') },
|
|
1350
|
-
{ title: 'Variables', items: exports.filter((e) => e.kind === 'variable') },
|
|
1351
|
-
{ title: 'Enums', items: exports.filter((e) => e.kind === 'enum') },
|
|
1352
|
-
].filter((g) => g.items.length > 0);
|
|
1353
|
-
|
|
1354
|
-
return (
|
|
1355
|
-
<div className="max-w-4xl mx-auto px-4 py-8">
|
|
1356
|
-
<header className="mb-12">
|
|
1357
|
-
<h1 className="text-3xl font-bold">{typedSpec.meta.name}</h1>
|
|
1358
|
-
{typedSpec.meta.description && (
|
|
1359
|
-
<p className="text-lg text-muted-foreground mt-2">{typedSpec.meta.description}</p>
|
|
1360
|
-
)}
|
|
1361
|
-
</header>
|
|
1362
|
-
|
|
1363
|
-
{groups.map((group) => (
|
|
1364
|
-
<section key={group.title} className="mb-12">
|
|
1365
|
-
<h2 className="text-2xl font-bold mb-6">{group.title}</h2>
|
|
1366
|
-
<div className="grid gap-4 md:grid-cols-2">
|
|
1367
|
-
{group.items.map((exp) => (
|
|
1368
|
-
// Replace with ExportCard once installed:
|
|
1369
|
-
// <ExportCard key={exp.id} export={exp} href={\`/api/\${exp.name}\`} />
|
|
1370
|
-
<a
|
|
1371
|
-
key={exp.id}
|
|
1372
|
-
href={\`/api/\${exp.name}\`}
|
|
1373
|
-
className="block p-4 border rounded-lg hover:bg-muted transition-colors"
|
|
1374
|
-
>
|
|
1375
|
-
<h3 className="font-semibold">{exp.name}</h3>
|
|
1376
|
-
<p className="text-sm text-muted-foreground line-clamp-2">
|
|
1377
|
-
{exp.description || 'No description'}
|
|
1378
|
-
</p>
|
|
1379
|
-
<span className="text-xs bg-muted px-2 py-1 rounded mt-2 inline-block">
|
|
1380
|
-
{exp.kind}
|
|
1381
|
-
</span>
|
|
1382
|
-
</a>
|
|
1383
|
-
))}
|
|
1384
|
-
</div>
|
|
1385
|
-
</section>
|
|
1386
|
-
))}
|
|
1387
|
-
</div>
|
|
1388
|
-
);
|
|
1389
|
-
}
|
|
1390
|
-
|
|
1391
|
-
export { spec };
|
|
1392
|
-
`;
|
|
1393
|
-
}
|
|
1394
|
-
async function toReact(spec, options) {
|
|
1395
|
-
const { outDir, variant = "full", componentsPath = "@/components/api" } = options;
|
|
1396
|
-
if (!fs3.existsSync(outDir)) {
|
|
1397
|
-
fs3.mkdirSync(outDir, { recursive: true });
|
|
1398
|
-
}
|
|
1399
|
-
const specPath = path2.join(outDir, "openpkg.json");
|
|
1400
|
-
fs3.writeFileSync(specPath, JSON.stringify(spec, null, 2));
|
|
1401
|
-
const layoutContent = variant === "index" ? generateIndexLayout(spec, componentsPath) : generateFullLayout(spec, componentsPath);
|
|
1402
|
-
const layoutPath = path2.join(outDir, "page.tsx");
|
|
1403
|
-
fs3.writeFileSync(layoutPath, layoutContent);
|
|
1404
|
-
}
|
|
1405
|
-
function toReactString(spec, options = {}) {
|
|
1406
|
-
const { variant = "full", componentsPath = "@/components/api" } = options;
|
|
1407
|
-
return variant === "index" ? generateIndexLayout(spec, componentsPath) : generateFullLayout(spec, componentsPath);
|
|
1408
|
-
}
|
|
1409
1194
|
// src/primitives/filter.ts
|
|
1410
1195
|
function matchesExport(exp, criteria) {
|
|
1411
1196
|
if (criteria.kinds && criteria.kinds.length > 0) {
|
|
@@ -1828,8 +1613,8 @@ function getExportKind(declaration, type) {
|
|
|
1828
1613
|
}
|
|
1829
1614
|
|
|
1830
1615
|
// src/compiler/program.ts
|
|
1831
|
-
import * as
|
|
1832
|
-
import * as
|
|
1616
|
+
import * as fs3 from "node:fs";
|
|
1617
|
+
import * as path2 from "node:path";
|
|
1833
1618
|
import ts2 from "typescript";
|
|
1834
1619
|
function isJsFile(file) {
|
|
1835
1620
|
return /\.(js|mjs|cjs|jsx)$/.test(file);
|
|
@@ -1855,16 +1640,16 @@ function resolveProjectReferences(configPath, parsedConfig) {
|
|
|
1855
1640
|
if (!parsedConfig.projectReferences?.length) {
|
|
1856
1641
|
return additionalFiles;
|
|
1857
1642
|
}
|
|
1858
|
-
const configDir =
|
|
1643
|
+
const configDir = path2.dirname(configPath);
|
|
1859
1644
|
for (const ref of parsedConfig.projectReferences) {
|
|
1860
|
-
const refPath =
|
|
1861
|
-
const refConfigPath =
|
|
1862
|
-
if (!
|
|
1645
|
+
const refPath = path2.resolve(configDir, ref.path);
|
|
1646
|
+
const refConfigPath = fs3.existsSync(path2.join(refPath, "tsconfig.json")) ? path2.join(refPath, "tsconfig.json") : refPath;
|
|
1647
|
+
if (!fs3.existsSync(refConfigPath))
|
|
1863
1648
|
continue;
|
|
1864
1649
|
const refConfigFile = ts2.readConfigFile(refConfigPath, ts2.sys.readFile);
|
|
1865
1650
|
if (refConfigFile.error)
|
|
1866
1651
|
continue;
|
|
1867
|
-
const refParsed = ts2.parseJsonConfigFileContent(refConfigFile.config, ts2.sys,
|
|
1652
|
+
const refParsed = ts2.parseJsonConfigFileContent(refConfigFile.config, ts2.sys, path2.dirname(refConfigPath));
|
|
1868
1653
|
additionalFiles.push(...refParsed.fileNames);
|
|
1869
1654
|
}
|
|
1870
1655
|
return additionalFiles;
|
|
@@ -1897,10 +1682,10 @@ function buildWorkspaceMap(baseDir) {
|
|
|
1897
1682
|
let rootDir;
|
|
1898
1683
|
let workspaceGlobs = [];
|
|
1899
1684
|
for (let i = 0;i < 10; i++) {
|
|
1900
|
-
const pnpmPath =
|
|
1901
|
-
if (
|
|
1685
|
+
const pnpmPath = path2.join(currentDir, "pnpm-workspace.yaml");
|
|
1686
|
+
if (fs3.existsSync(pnpmPath)) {
|
|
1902
1687
|
try {
|
|
1903
|
-
const yamlContent =
|
|
1688
|
+
const yamlContent = fs3.readFileSync(pnpmPath, "utf-8");
|
|
1904
1689
|
workspaceGlobs = parsePnpmWorkspace(yamlContent);
|
|
1905
1690
|
if (workspaceGlobs.length > 0) {
|
|
1906
1691
|
rootDir = currentDir;
|
|
@@ -1908,10 +1693,10 @@ function buildWorkspaceMap(baseDir) {
|
|
|
1908
1693
|
}
|
|
1909
1694
|
} catch {}
|
|
1910
1695
|
}
|
|
1911
|
-
const pkgPath =
|
|
1912
|
-
if (
|
|
1696
|
+
const pkgPath = path2.join(currentDir, "package.json");
|
|
1697
|
+
if (fs3.existsSync(pkgPath)) {
|
|
1913
1698
|
try {
|
|
1914
|
-
const pkg = JSON.parse(
|
|
1699
|
+
const pkg = JSON.parse(fs3.readFileSync(pkgPath, "utf-8"));
|
|
1915
1700
|
if (pkg.workspaces) {
|
|
1916
1701
|
rootDir = currentDir;
|
|
1917
1702
|
workspaceGlobs = Array.isArray(pkg.workspaces) ? pkg.workspaces : pkg.workspaces?.packages || [];
|
|
@@ -1919,7 +1704,7 @@ function buildWorkspaceMap(baseDir) {
|
|
|
1919
1704
|
}
|
|
1920
1705
|
} catch {}
|
|
1921
1706
|
}
|
|
1922
|
-
const parent =
|
|
1707
|
+
const parent = path2.dirname(currentDir);
|
|
1923
1708
|
if (parent === currentDir)
|
|
1924
1709
|
break;
|
|
1925
1710
|
currentDir = parent;
|
|
@@ -1928,21 +1713,21 @@ function buildWorkspaceMap(baseDir) {
|
|
|
1928
1713
|
return;
|
|
1929
1714
|
const packages = new Map;
|
|
1930
1715
|
for (const glob of workspaceGlobs) {
|
|
1931
|
-
const globDir =
|
|
1932
|
-
if (!
|
|
1716
|
+
const globDir = path2.join(rootDir, glob.replace(/\/\*$/, ""));
|
|
1717
|
+
if (!fs3.existsSync(globDir) || !fs3.statSync(globDir).isDirectory())
|
|
1933
1718
|
continue;
|
|
1934
|
-
const entries =
|
|
1719
|
+
const entries = fs3.readdirSync(globDir, { withFileTypes: true });
|
|
1935
1720
|
for (const entry of entries) {
|
|
1936
1721
|
if (!entry.isDirectory())
|
|
1937
1722
|
continue;
|
|
1938
|
-
const pkgDir =
|
|
1939
|
-
const pkgJsonPath =
|
|
1940
|
-
if (!
|
|
1723
|
+
const pkgDir = path2.join(globDir, entry.name);
|
|
1724
|
+
const pkgJsonPath = path2.join(pkgDir, "package.json");
|
|
1725
|
+
if (!fs3.existsSync(pkgJsonPath))
|
|
1941
1726
|
continue;
|
|
1942
1727
|
try {
|
|
1943
|
-
const pkg = JSON.parse(
|
|
1728
|
+
const pkg = JSON.parse(fs3.readFileSync(pkgJsonPath, "utf-8"));
|
|
1944
1729
|
if (pkg.name) {
|
|
1945
|
-
const srcDir =
|
|
1730
|
+
const srcDir = fs3.existsSync(path2.join(pkgDir, "src")) ? path2.join(pkgDir, "src") : pkgDir;
|
|
1946
1731
|
packages.set(pkg.name, srcDir);
|
|
1947
1732
|
}
|
|
1948
1733
|
} catch {}
|
|
@@ -1952,7 +1737,7 @@ function buildWorkspaceMap(baseDir) {
|
|
|
1952
1737
|
}
|
|
1953
1738
|
function createProgram({
|
|
1954
1739
|
entryFile,
|
|
1955
|
-
baseDir =
|
|
1740
|
+
baseDir = path2.dirname(entryFile),
|
|
1956
1741
|
content
|
|
1957
1742
|
}) {
|
|
1958
1743
|
let configPath = ts2.findConfigFile(baseDir, ts2.sys.fileExists, "tsconfig.json");
|
|
@@ -1963,7 +1748,7 @@ function createProgram({
|
|
|
1963
1748
|
let additionalRootFiles = [];
|
|
1964
1749
|
if (configPath) {
|
|
1965
1750
|
const configFile = ts2.readConfigFile(configPath, ts2.sys.readFile);
|
|
1966
|
-
const parsedConfig = ts2.parseJsonConfigFileContent(configFile.config, ts2.sys,
|
|
1751
|
+
const parsedConfig = ts2.parseJsonConfigFileContent(configFile.config, ts2.sys, path2.dirname(configPath));
|
|
1967
1752
|
compilerOptions = { ...compilerOptions, ...parsedConfig.options };
|
|
1968
1753
|
additionalRootFiles = resolveProjectReferences(configPath, parsedConfig);
|
|
1969
1754
|
const sourceFiles = parsedConfig.fileNames.filter((f) => !f.includes(".test.") && !f.includes(".spec.") && !f.includes("/dist/") && !f.includes("/node_modules/"));
|
|
@@ -1991,8 +1776,8 @@ function createProgram({
|
|
|
1991
1776
|
return moduleNames.map((moduleName) => {
|
|
1992
1777
|
const srcDir = workspaceMap.packages.get(moduleName);
|
|
1993
1778
|
if (srcDir) {
|
|
1994
|
-
const indexFile =
|
|
1995
|
-
if (
|
|
1779
|
+
const indexFile = path2.join(srcDir, "index.ts");
|
|
1780
|
+
if (fs3.existsSync(indexFile)) {
|
|
1996
1781
|
return { resolvedFileName: indexFile, isExternalLibraryImport: false };
|
|
1997
1782
|
}
|
|
1998
1783
|
}
|
|
@@ -4843,7 +4628,7 @@ function detectExternalPackage(symbol, checker) {
|
|
|
4843
4628
|
return;
|
|
4844
4629
|
}
|
|
4845
4630
|
// src/primitives/list.ts
|
|
4846
|
-
import * as
|
|
4631
|
+
import * as path3 from "node:path";
|
|
4847
4632
|
import ts12 from "typescript";
|
|
4848
4633
|
async function listExports(options) {
|
|
4849
4634
|
const { entryFile, baseDir, content } = options;
|
|
@@ -4904,7 +4689,7 @@ function extractExportItem(symbol, checker, entryFile, entrySourceFile) {
|
|
|
4904
4689
|
return {
|
|
4905
4690
|
name,
|
|
4906
4691
|
kind: "namespace",
|
|
4907
|
-
file:
|
|
4692
|
+
file: path3.relative(path3.dirname(entryFile), declaration.fileName),
|
|
4908
4693
|
line: 1,
|
|
4909
4694
|
reexport: true
|
|
4910
4695
|
};
|
|
@@ -4918,7 +4703,7 @@ function extractExportItem(symbol, checker, entryFile, entrySourceFile) {
|
|
|
4918
4703
|
return {
|
|
4919
4704
|
name,
|
|
4920
4705
|
kind,
|
|
4921
|
-
file:
|
|
4706
|
+
file: path3.relative(path3.dirname(entryFile), sourceFile.fileName),
|
|
4922
4707
|
line: line + 1,
|
|
4923
4708
|
...description ? { description } : {},
|
|
4924
4709
|
...deprecated ? { deprecated: true } : {},
|
|
@@ -4939,8 +4724,8 @@ function getDescriptionPreview(symbol, checker) {
|
|
|
4939
4724
|
return `${firstLine.slice(0, 77)}...`;
|
|
4940
4725
|
}
|
|
4941
4726
|
// src/builder/spec-builder.ts
|
|
4942
|
-
import * as
|
|
4943
|
-
import * as
|
|
4727
|
+
import * as fs6 from "node:fs";
|
|
4728
|
+
import * as path7 from "node:path";
|
|
4944
4729
|
import { SCHEMA_URL, SCHEMA_VERSION } from "@openpkg-ts/spec";
|
|
4945
4730
|
import ts16 from "typescript";
|
|
4946
4731
|
|
|
@@ -4976,9 +4761,9 @@ function resolveExportTarget2(symbol, checker) {
|
|
|
4976
4761
|
|
|
4977
4762
|
// src/schema/standard-schema.ts
|
|
4978
4763
|
import { spawn, spawnSync } from "node:child_process";
|
|
4979
|
-
import * as
|
|
4764
|
+
import * as fs4 from "node:fs";
|
|
4980
4765
|
import * as os from "node:os";
|
|
4981
|
-
import * as
|
|
4766
|
+
import * as path4 from "node:path";
|
|
4982
4767
|
var MAX_BUFFER_SIZE = 10 * 1024 * 1024;
|
|
4983
4768
|
function isStandardJSONSchema(obj) {
|
|
4984
4769
|
if (typeof obj !== "object" || obj === null)
|
|
@@ -5232,21 +5017,21 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
|
|
|
5232
5017
|
result.errors.push("No TypeScript runtime available. Install bun, tsx, or ts-node, or use Node 22+.");
|
|
5233
5018
|
return result;
|
|
5234
5019
|
}
|
|
5235
|
-
if (!
|
|
5020
|
+
if (!fs4.existsSync(tsFilePath)) {
|
|
5236
5021
|
result.errors.push(`TypeScript file not found: ${tsFilePath}`);
|
|
5237
5022
|
return result;
|
|
5238
5023
|
}
|
|
5239
5024
|
const tempDir = os.tmpdir();
|
|
5240
|
-
const workerPath =
|
|
5025
|
+
const workerPath = path4.join(tempDir, `openpkg-extract-worker-${Date.now()}.ts`);
|
|
5241
5026
|
try {
|
|
5242
|
-
|
|
5027
|
+
fs4.writeFileSync(workerPath, TS_WORKER_SCRIPT);
|
|
5243
5028
|
const optionsJson = JSON.stringify({ target, libraryOptions });
|
|
5244
5029
|
const args = [...runtime.args, workerPath, tsFilePath, optionsJson];
|
|
5245
5030
|
return await new Promise((resolve2) => {
|
|
5246
5031
|
const child = spawn(runtime.cmd, args, {
|
|
5247
5032
|
timeout,
|
|
5248
5033
|
stdio: ["ignore", "pipe", "pipe"],
|
|
5249
|
-
cwd:
|
|
5034
|
+
cwd: path4.dirname(tsFilePath)
|
|
5250
5035
|
});
|
|
5251
5036
|
let stdout = "";
|
|
5252
5037
|
let stderr = "";
|
|
@@ -5270,7 +5055,7 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
|
|
|
5270
5055
|
});
|
|
5271
5056
|
child.on("close", (code) => {
|
|
5272
5057
|
try {
|
|
5273
|
-
|
|
5058
|
+
fs4.unlinkSync(workerPath);
|
|
5274
5059
|
} catch (cleanupErr) {
|
|
5275
5060
|
if (cleanupErr?.code !== "ENOENT") {
|
|
5276
5061
|
result.warnings.push({ code: "CLEANUP_FAILED", message: String(cleanupErr) });
|
|
@@ -5324,7 +5109,7 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
|
|
|
5324
5109
|
});
|
|
5325
5110
|
child.on("error", (err) => {
|
|
5326
5111
|
try {
|
|
5327
|
-
|
|
5112
|
+
fs4.unlinkSync(workerPath);
|
|
5328
5113
|
} catch (cleanupErr) {
|
|
5329
5114
|
if (cleanupErr?.code !== "ENOENT") {
|
|
5330
5115
|
result.warnings.push({ code: "CLEANUP_FAILED", message: String(cleanupErr) });
|
|
@@ -5336,7 +5121,7 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
|
|
|
5336
5121
|
});
|
|
5337
5122
|
} catch (e) {
|
|
5338
5123
|
try {
|
|
5339
|
-
|
|
5124
|
+
fs4.unlinkSync(workerPath);
|
|
5340
5125
|
} catch (cleanupErr) {
|
|
5341
5126
|
if (cleanupErr?.code !== "ENOENT") {
|
|
5342
5127
|
result.warnings.push({ code: "CLEANUP_FAILED", message: String(cleanupErr) });
|
|
@@ -5347,12 +5132,12 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
|
|
|
5347
5132
|
}
|
|
5348
5133
|
}
|
|
5349
5134
|
function readTsconfigOutDir(baseDir) {
|
|
5350
|
-
const tsconfigPath =
|
|
5135
|
+
const tsconfigPath = path4.join(baseDir, "tsconfig.json");
|
|
5351
5136
|
try {
|
|
5352
|
-
if (!
|
|
5137
|
+
if (!fs4.existsSync(tsconfigPath)) {
|
|
5353
5138
|
return null;
|
|
5354
5139
|
}
|
|
5355
|
-
const content =
|
|
5140
|
+
const content = fs4.readFileSync(tsconfigPath, "utf-8");
|
|
5356
5141
|
const stripped = content.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*$/gm, "");
|
|
5357
5142
|
const tsconfig = JSON.parse(stripped);
|
|
5358
5143
|
if (tsconfig.compilerOptions?.outDir) {
|
|
@@ -5362,7 +5147,7 @@ function readTsconfigOutDir(baseDir) {
|
|
|
5362
5147
|
return null;
|
|
5363
5148
|
}
|
|
5364
5149
|
function resolveCompiledPath(tsPath, baseDir) {
|
|
5365
|
-
const relativePath =
|
|
5150
|
+
const relativePath = path4.relative(baseDir, tsPath);
|
|
5366
5151
|
const withoutExt = relativePath.replace(/\.tsx?$/, "");
|
|
5367
5152
|
const srcPrefix = withoutExt.replace(/^src\//, "");
|
|
5368
5153
|
const tsconfigOutDir = readTsconfigOutDir(baseDir);
|
|
@@ -5370,7 +5155,7 @@ function resolveCompiledPath(tsPath, baseDir) {
|
|
|
5370
5155
|
const candidates = [];
|
|
5371
5156
|
if (tsconfigOutDir) {
|
|
5372
5157
|
for (const ext of extensions) {
|
|
5373
|
-
candidates.push(
|
|
5158
|
+
candidates.push(path4.join(baseDir, tsconfigOutDir, `${srcPrefix}${ext}`));
|
|
5374
5159
|
}
|
|
5375
5160
|
}
|
|
5376
5161
|
const commonOutDirs = ["dist", "build", "lib", "out"];
|
|
@@ -5378,21 +5163,21 @@ function resolveCompiledPath(tsPath, baseDir) {
|
|
|
5378
5163
|
if (outDir === tsconfigOutDir)
|
|
5379
5164
|
continue;
|
|
5380
5165
|
for (const ext of extensions) {
|
|
5381
|
-
candidates.push(
|
|
5166
|
+
candidates.push(path4.join(baseDir, outDir, `${srcPrefix}${ext}`));
|
|
5382
5167
|
}
|
|
5383
5168
|
}
|
|
5384
5169
|
for (const ext of extensions) {
|
|
5385
|
-
candidates.push(
|
|
5170
|
+
candidates.push(path4.join(baseDir, `${withoutExt}${ext}`));
|
|
5386
5171
|
}
|
|
5387
5172
|
const workspaceMatch = baseDir.match(/^(.+\/packages\/[^/]+)$/);
|
|
5388
5173
|
if (workspaceMatch) {
|
|
5389
5174
|
const pkgRoot = workspaceMatch[1];
|
|
5390
5175
|
for (const ext of extensions) {
|
|
5391
|
-
candidates.push(
|
|
5176
|
+
candidates.push(path4.join(pkgRoot, "dist", `${srcPrefix}${ext}`));
|
|
5392
5177
|
}
|
|
5393
5178
|
}
|
|
5394
5179
|
for (const candidate of candidates) {
|
|
5395
|
-
if (
|
|
5180
|
+
if (fs4.existsSync(candidate)) {
|
|
5396
5181
|
return candidate;
|
|
5397
5182
|
}
|
|
5398
5183
|
}
|
|
@@ -5405,7 +5190,7 @@ async function extractStandardSchemas(compiledJsPath, options = {}) {
|
|
|
5405
5190
|
errors: [],
|
|
5406
5191
|
warnings: []
|
|
5407
5192
|
};
|
|
5408
|
-
if (!
|
|
5193
|
+
if (!fs4.existsSync(compiledJsPath)) {
|
|
5409
5194
|
result.errors.push(`Compiled JS not found: ${compiledJsPath}`);
|
|
5410
5195
|
return result;
|
|
5411
5196
|
}
|
|
@@ -5521,8 +5306,8 @@ async function extractStandardSchemasFromProject(entryFile, baseDir, options = {
|
|
|
5521
5306
|
}
|
|
5522
5307
|
|
|
5523
5308
|
// src/builder/external-resolver.ts
|
|
5524
|
-
import * as
|
|
5525
|
-
import * as
|
|
5309
|
+
import * as fs5 from "node:fs";
|
|
5310
|
+
import * as path5 from "node:path";
|
|
5526
5311
|
import picomatch from "picomatch";
|
|
5527
5312
|
import ts14 from "typescript";
|
|
5528
5313
|
function matchesExternalPattern(packageName, include, exclude) {
|
|
@@ -5556,20 +5341,20 @@ function findPackageJson(resolvedPath, packageName) {
|
|
|
5556
5341
|
const isScoped = packageName.startsWith("@");
|
|
5557
5342
|
const packageParts = isScoped ? packageName.split("/").slice(0, 2) : [packageName.split("/")[0]];
|
|
5558
5343
|
const packageDir = packageParts.join("/");
|
|
5559
|
-
let dir =
|
|
5344
|
+
let dir = path5.dirname(resolvedPath);
|
|
5560
5345
|
const maxDepth = 10;
|
|
5561
5346
|
for (let i = 0;i < maxDepth; i++) {
|
|
5562
5347
|
if (dir.endsWith(`node_modules/${packageDir}`)) {
|
|
5563
|
-
const pkgPath =
|
|
5564
|
-
if (
|
|
5348
|
+
const pkgPath = path5.join(dir, "package.json");
|
|
5349
|
+
if (fs5.existsSync(pkgPath)) {
|
|
5565
5350
|
try {
|
|
5566
|
-
return JSON.parse(
|
|
5351
|
+
return JSON.parse(fs5.readFileSync(pkgPath, "utf-8"));
|
|
5567
5352
|
} catch {
|
|
5568
5353
|
return;
|
|
5569
5354
|
}
|
|
5570
5355
|
}
|
|
5571
5356
|
}
|
|
5572
|
-
const parent =
|
|
5357
|
+
const parent = path5.dirname(dir);
|
|
5573
5358
|
if (parent === dir)
|
|
5574
5359
|
break;
|
|
5575
5360
|
dir = parent;
|
|
@@ -5813,7 +5598,7 @@ function hasInternalTag(typeName, program, sourceFile) {
|
|
|
5813
5598
|
}
|
|
5814
5599
|
|
|
5815
5600
|
// src/builder/verification.ts
|
|
5816
|
-
import * as
|
|
5601
|
+
import * as path6 from "node:path";
|
|
5817
5602
|
var BUILTIN_TYPES2 = new Set([
|
|
5818
5603
|
"Array",
|
|
5819
5604
|
"ArrayBuffer",
|
|
@@ -5902,8 +5687,8 @@ function isExternalType2(definedIn, baseDir) {
|
|
|
5902
5687
|
return true;
|
|
5903
5688
|
if (definedIn.includes("node_modules"))
|
|
5904
5689
|
return true;
|
|
5905
|
-
const normalizedDefined =
|
|
5906
|
-
const normalizedBase =
|
|
5690
|
+
const normalizedDefined = path6.resolve(definedIn);
|
|
5691
|
+
const normalizedBase = path6.resolve(baseDir);
|
|
5907
5692
|
return !normalizedDefined.startsWith(normalizedBase);
|
|
5908
5693
|
}
|
|
5909
5694
|
function shouldSkipDanglingRef(name) {
|
|
@@ -6242,7 +6027,7 @@ async function extract(options) {
|
|
|
6242
6027
|
}
|
|
6243
6028
|
}
|
|
6244
6029
|
const types = ctx.typeRegistry.getAll();
|
|
6245
|
-
const projectBaseDir = baseDir ??
|
|
6030
|
+
const projectBaseDir = baseDir ?? path7.dirname(entryFile);
|
|
6246
6031
|
const definedTypes = new Set(types.map((t) => t.id));
|
|
6247
6032
|
const forgottenExports = collectForgottenExports(exports, types, program, sourceFile, exportedIds, projectBaseDir, definedTypes);
|
|
6248
6033
|
for (const forgotten of forgottenExports) {
|
|
@@ -6275,7 +6060,7 @@ async function extract(options) {
|
|
|
6275
6060
|
}
|
|
6276
6061
|
let runtimeMetadata;
|
|
6277
6062
|
if (options.schemaExtraction === "hybrid") {
|
|
6278
|
-
const projectBaseDir2 = baseDir ||
|
|
6063
|
+
const projectBaseDir2 = baseDir || path7.dirname(entryFile);
|
|
6279
6064
|
const runtimeResult = await extractStandardSchemasFromProject(entryFile, projectBaseDir2, {
|
|
6280
6065
|
target: options.schemaTarget || "draft-2020-12",
|
|
6281
6066
|
timeout: 15000
|
|
@@ -6564,7 +6349,7 @@ function createEmptySpec(entryFile, includeSchema, isDtsSource) {
|
|
|
6564
6349
|
return {
|
|
6565
6350
|
...includeSchema ? { $schema: SCHEMA_URL } : {},
|
|
6566
6351
|
openpkg: SCHEMA_VERSION,
|
|
6567
|
-
meta: { name:
|
|
6352
|
+
meta: { name: path7.basename(entryFile, path7.extname(entryFile)) },
|
|
6568
6353
|
exports: [],
|
|
6569
6354
|
generation: {
|
|
6570
6355
|
generator: "@openpkg-ts/sdk",
|
|
@@ -6580,7 +6365,7 @@ function findTypeInProgram(name, checker, program, sourceFile, symFlags) {
|
|
|
6580
6365
|
const localSym = checker.resolveName(name, sourceFile, symFlags, false);
|
|
6581
6366
|
if (localSym)
|
|
6582
6367
|
return checker.getDeclaredTypeOfSymbol(localSym);
|
|
6583
|
-
const entryDir =
|
|
6368
|
+
const entryDir = path7.dirname(sourceFile.fileName);
|
|
6584
6369
|
for (const sf of program.getSourceFiles()) {
|
|
6585
6370
|
const fn = sf.fileName;
|
|
6586
6371
|
if (fn.includes("/typescript/lib/lib.") || fn.includes("\\typescript\\lib\\lib."))
|
|
@@ -6596,22 +6381,22 @@ function findTypeInProgram(name, checker, program, sourceFile, symFlags) {
|
|
|
6596
6381
|
return;
|
|
6597
6382
|
}
|
|
6598
6383
|
async function getPackageMeta(entryFile, baseDir) {
|
|
6599
|
-
let dir = baseDir ??
|
|
6600
|
-
while (dir !==
|
|
6601
|
-
const pkgPath =
|
|
6384
|
+
let dir = baseDir ?? path7.dirname(entryFile);
|
|
6385
|
+
while (dir !== path7.dirname(dir)) {
|
|
6386
|
+
const pkgPath = path7.join(dir, "package.json");
|
|
6602
6387
|
try {
|
|
6603
|
-
if (
|
|
6604
|
-
const pkg = JSON.parse(
|
|
6388
|
+
if (fs6.existsSync(pkgPath)) {
|
|
6389
|
+
const pkg = JSON.parse(fs6.readFileSync(pkgPath, "utf-8"));
|
|
6605
6390
|
return {
|
|
6606
|
-
name: pkg.name ??
|
|
6391
|
+
name: pkg.name ?? path7.basename(dir),
|
|
6607
6392
|
version: pkg.version,
|
|
6608
6393
|
description: pkg.description
|
|
6609
6394
|
};
|
|
6610
6395
|
}
|
|
6611
6396
|
} catch {}
|
|
6612
|
-
dir =
|
|
6397
|
+
dir = path7.dirname(dir);
|
|
6613
6398
|
}
|
|
6614
|
-
return { name:
|
|
6399
|
+
return { name: path7.basename(baseDir ?? path7.dirname(entryFile)) };
|
|
6615
6400
|
}
|
|
6616
6401
|
|
|
6617
6402
|
// src/primitives/spec.ts
|
|
@@ -6638,8 +6423,6 @@ export {
|
|
|
6638
6423
|
typeboxAdapter,
|
|
6639
6424
|
toSearchIndexJSON,
|
|
6640
6425
|
toSearchIndex,
|
|
6641
|
-
toReactString,
|
|
6642
|
-
toReact,
|
|
6643
6426
|
toPagefindRecords,
|
|
6644
6427
|
toNavigation,
|
|
6645
6428
|
toMarkdown,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpkg-ts/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.38.0",
|
|
4
4
|
"description": "TypeScript API extraction SDK - programmatic primitives for OpenPkg specs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"openpkg",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"lint": "biome check src/",
|
|
40
40
|
"lint:fix": "biome check --write src/",
|
|
41
41
|
"format": "biome format --write src/",
|
|
42
|
+
"typecheck": "tsc --noEmit -p .",
|
|
42
43
|
"test": "bun test"
|
|
43
44
|
},
|
|
44
45
|
"dependencies": {
|
|
@@ -57,7 +58,11 @@
|
|
|
57
58
|
"devDependencies": {
|
|
58
59
|
"@types/bun": "latest",
|
|
59
60
|
"@types/node": "^20.0.0",
|
|
60
|
-
"
|
|
61
|
+
"@types/picomatch": "4.0.3",
|
|
62
|
+
"ajv": "^8.17.1",
|
|
63
|
+
"ajv-formats": "^3.0.1",
|
|
64
|
+
"bunup": "^0.16.20",
|
|
65
|
+
"zod": "^4.3.6"
|
|
61
66
|
},
|
|
62
67
|
"publishConfig": {
|
|
63
68
|
"access": "public"
|