@openpkg-ts/sdk 0.37.0 → 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/dist/index.js CHANGED
@@ -29,7 +29,7 @@ import {
29
29
  toPagefindRecords,
30
30
  toSearchIndex,
31
31
  toSearchIndexJSON
32
- } from "./shared/chunk-hnajr1tb.js";
32
+ } from "./shared/chunk-zrx9s0n4.js";
33
33
 
34
34
  // src/primitives/diff.ts
35
35
  import {
@@ -86,6 +86,9 @@ import * as fs2 from "node:fs";
86
86
  import { validateSpec } from "@openpkg-ts/spec";
87
87
 
88
88
  // src/render/html.ts
89
+ import {
90
+ KIND_LABELS
91
+ } from "@openpkg-ts/spec";
89
92
  var defaultCSS = `
90
93
  :root {
91
94
  --text: #1a1a1a;
@@ -381,14 +384,14 @@ function toHTML(spec, options = {}) {
381
384
  const byKind = groupByKind(specExports);
382
385
  const navItems = Object.entries(byKind).map(([kind, exports]) => {
383
386
  const links = exports.map((e) => `<a href="#${e.id}">${escapeHTML(e.name)}</a>`).join("");
384
- return `<li><strong>${kind}s:</strong> ${links}</li>`;
387
+ return `<li><strong>${KIND_LABELS[kind] ?? kind}:</strong> ${links}</li>`;
385
388
  }).join("");
386
389
  const nav = `<nav><ul>${navItems}</ul></nav>`;
387
390
  const sections = KIND_ORDER.filter((kind) => byKind[kind]?.length).map((kind) => {
388
391
  const exports = byKind[kind].map(renderExport).join("");
389
392
  return `
390
393
  <section class="kind-section">
391
- <h2>${kind.charAt(0).toUpperCase() + kind.slice(1)}s</h2>
394
+ <h2>${KIND_LABELS[kind]}</h2>
392
395
  ${exports}
393
396
  </section>`;
394
397
  }).join("");
@@ -533,6 +536,9 @@ function toJSONString(spec, options = {}) {
533
536
  }
534
537
 
535
538
  // src/render/markdown.ts
539
+ import {
540
+ KIND_LABELS as KIND_LABELS2
541
+ } from "@openpkg-ts/spec";
536
542
  var defaultSections = {
537
543
  signature: true,
538
544
  description: true,
@@ -898,7 +904,7 @@ function toMarkdown(spec, options = {}) {
898
904
  const exports = byKind[kind];
899
905
  if (!exports?.length)
900
906
  continue;
901
- parts.push(`## ${kind.charAt(0).toUpperCase() + kind.slice(1)}s`);
907
+ parts.push(`## ${KIND_LABELS2[kind]}`);
902
908
  parts.push("");
903
909
  for (const exp of exports) {
904
910
  const content = exportToMarkdown(exp, {
@@ -915,18 +921,7 @@ function toMarkdown(spec, options = {}) {
915
921
  }
916
922
 
917
923
  // src/render/nav.ts
918
- var defaultKindLabels = {
919
- function: "Functions",
920
- class: "Classes",
921
- interface: "Interfaces",
922
- type: "Types",
923
- enum: "Enums",
924
- variable: "Variables",
925
- namespace: "Namespaces",
926
- module: "Modules",
927
- reference: "References",
928
- external: "External"
929
- };
924
+ import { KIND_LABELS as KIND_LABELS3 } from "@openpkg-ts/spec";
930
925
  var defaultSlugify = (name) => name.toLowerCase().replace(/[^a-z0-9]+/g, "-");
931
926
  function getModuleName(exp) {
932
927
  if (exp.source?.file) {
@@ -980,9 +975,9 @@ function toGenericNav(spec, options) {
980
975
  sortAlphabetically = true,
981
976
  includeGroupIndex = false
982
977
  } = options;
983
- const labels = { ...defaultKindLabels, ...kindLabels };
978
+ const labels = { ...KIND_LABELS3, ...kindLabels };
984
979
  const grouped = groupExports(spec.exports, groupBy);
985
- const groups = [];
980
+ const keyedGroups = [];
986
981
  for (const [key, exports] of grouped) {
987
982
  const sortedExports = sortAlphabetically ? sortByName(exports) : exports;
988
983
  const items = sortedExports.map((exp) => ({
@@ -990,19 +985,19 @@ function toGenericNav(spec, options) {
990
985
  href: `${basePath}/${slugify(exp.name)}`
991
986
  }));
992
987
  const title = groupBy === "kind" ? labels[key] || key : key;
993
- groups.push({
994
- title,
995
- items,
996
- index: includeGroupIndex ? `${basePath}/${slugify(key)}` : undefined
988
+ keyedGroups.push({
989
+ key,
990
+ group: {
991
+ title,
992
+ items,
993
+ index: includeGroupIndex ? `${basePath}/${slugify(key)}` : undefined
994
+ }
997
995
  });
998
996
  }
999
997
  if (groupBy === "kind") {
1000
- groups.sort((a, b) => {
1001
- const aIdx = KIND_ORDER.indexOf(a.title.toLowerCase().replace(/s$/, ""));
1002
- const bIdx = KIND_ORDER.indexOf(b.title.toLowerCase().replace(/s$/, ""));
1003
- return aIdx - bIdx;
1004
- });
998
+ keyedGroups.sort((a, b) => KIND_ORDER.indexOf(a.key) - KIND_ORDER.indexOf(b.key));
1005
999
  }
1000
+ const groups = keyedGroups.map((g) => g.group);
1006
1001
  const flatItems = groupBy === "none" ? groups.flatMap((g) => g.items) : groups.map((g) => ({
1007
1002
  title: g.title,
1008
1003
  items: g.items
@@ -1196,221 +1191,6 @@ function extractModuleName(exp) {
1196
1191
  }
1197
1192
  return;
1198
1193
  }
1199
- // src/render/react.ts
1200
- import * as fs3 from "node:fs";
1201
- import * as path2 from "node:path";
1202
- function generateFullLayout(spec, componentsPath) {
1203
- const pkgName = spec.meta.name;
1204
- return `'use client';
1205
-
1206
- import type { OpenPkg, SpecExport } from '@openpkg-ts/spec';
1207
- import spec from './openpkg.json';
1208
-
1209
- // Add components via: openpkg docs add function-section class-section interface-section
1210
- // Then uncomment the imports below and customize as needed.
1211
-
1212
- // import { FunctionSection } from '${componentsPath}/function-section';
1213
- // import { ClassSection } from '${componentsPath}/class-section';
1214
- // import { InterfaceSection } from '${componentsPath}/interface-section';
1215
- // import { VariableSection } from '${componentsPath}/variable-section';
1216
- // import { EnumSection } from '${componentsPath}/enum-section';
1217
-
1218
- /**
1219
- * Renders a single export based on its kind.
1220
- * Customize this to match your design system.
1221
- */
1222
- function ExportSection({ exp }: { exp: SpecExport }) {
1223
- // Uncomment the switch once you've added components:
1224
- // switch (exp.kind) {
1225
- // case 'function':
1226
- // return <FunctionSection key={exp.id} export={exp} spec={spec as OpenPkg} />;
1227
- // case 'class':
1228
- // return <ClassSection key={exp.id} export={exp} spec={spec as OpenPkg} />;
1229
- // case 'interface':
1230
- // case 'type':
1231
- // return <InterfaceSection key={exp.id} export={exp} spec={spec as OpenPkg} />;
1232
- // case 'variable':
1233
- // return <VariableSection key={exp.id} export={exp} spec={spec as OpenPkg} />;
1234
- // case 'enum':
1235
- // return <EnumSection key={exp.id} export={exp} spec={spec as OpenPkg} />;
1236
- // default:
1237
- // return null;
1238
- // }
1239
-
1240
- // Placeholder: replace with component imports above
1241
- return (
1242
- <section id={exp.id} className="py-8 border-b">
1243
- <h2 className="text-xl font-semibold">{exp.name}</h2>
1244
- <p className="text-muted-foreground">{exp.description || 'No description'}</p>
1245
- <code className="text-sm">{exp.kind}</code>
1246
- </section>
1247
- );
1248
- }
1249
-
1250
- /**
1251
- * Full API Reference Page for ${pkgName}
1252
- *
1253
- * This layout renders all exports on a single page.
1254
- * Customize the grouping, styling, and components to match your docs.
1255
- */
1256
- export default function APIReferencePage() {
1257
- const typedSpec = spec as OpenPkg;
1258
- const exports = typedSpec.exports;
1259
-
1260
- // Group exports by kind
1261
- const functions = exports.filter((e) => e.kind === 'function');
1262
- const classes = exports.filter((e) => e.kind === 'class');
1263
- const interfaces = exports.filter((e) => e.kind === 'interface' || e.kind === 'type');
1264
- const variables = exports.filter((e) => e.kind === 'variable');
1265
- const enums = exports.filter((e) => e.kind === 'enum');
1266
-
1267
- return (
1268
- <div className="max-w-4xl mx-auto px-4 py-8">
1269
- <header className="mb-12">
1270
- <h1 className="text-3xl font-bold">{typedSpec.meta.name}</h1>
1271
- {typedSpec.meta.description && (
1272
- <p className="text-lg text-muted-foreground mt-2">{typedSpec.meta.description}</p>
1273
- )}
1274
- {typedSpec.meta.version && (
1275
- <p className="text-sm text-muted-foreground">v{typedSpec.meta.version}</p>
1276
- )}
1277
- </header>
1278
-
1279
- {functions.length > 0 && (
1280
- <section className="mb-12">
1281
- <h2 className="text-2xl font-bold mb-6">Functions</h2>
1282
- {functions.map((exp) => (
1283
- <ExportSection key={exp.id} exp={exp} />
1284
- ))}
1285
- </section>
1286
- )}
1287
-
1288
- {classes.length > 0 && (
1289
- <section className="mb-12">
1290
- <h2 className="text-2xl font-bold mb-6">Classes</h2>
1291
- {classes.map((exp) => (
1292
- <ExportSection key={exp.id} exp={exp} />
1293
- ))}
1294
- </section>
1295
- )}
1296
-
1297
- {interfaces.length > 0 && (
1298
- <section className="mb-12">
1299
- <h2 className="text-2xl font-bold mb-6">Types & Interfaces</h2>
1300
- {interfaces.map((exp) => (
1301
- <ExportSection key={exp.id} exp={exp} />
1302
- ))}
1303
- </section>
1304
- )}
1305
-
1306
- {variables.length > 0 && (
1307
- <section className="mb-12">
1308
- <h2 className="text-2xl font-bold mb-6">Variables</h2>
1309
- {variables.map((exp) => (
1310
- <ExportSection key={exp.id} exp={exp} />
1311
- ))}
1312
- </section>
1313
- )}
1314
-
1315
- {enums.length > 0 && (
1316
- <section className="mb-12">
1317
- <h2 className="text-2xl font-bold mb-6">Enums</h2>
1318
- {enums.map((exp) => (
1319
- <ExportSection key={exp.id} exp={exp} />
1320
- ))}
1321
- </section>
1322
- )}
1323
- </div>
1324
- );
1325
- }
1326
-
1327
- export { spec };
1328
- `;
1329
- }
1330
- function generateIndexLayout(spec, componentsPath) {
1331
- const pkgName = spec.meta.name;
1332
- return `'use client';
1333
-
1334
- import type { OpenPkg } from '@openpkg-ts/spec';
1335
- import spec from './openpkg.json';
1336
-
1337
- // Add the export-card component: openpkg docs add export-card
1338
- // import { ExportCard } from '${componentsPath}/export-card';
1339
-
1340
- /**
1341
- * API Reference Index Page for ${pkgName}
1342
- *
1343
- * Links to individual export pages. Best with file-based routing.
1344
- * Customize the card component and links to match your docs.
1345
- */
1346
- export default function APIReferenceIndex() {
1347
- const typedSpec = spec as OpenPkg;
1348
- const exports = typedSpec.exports;
1349
-
1350
- // Group exports by kind
1351
- const groups = [
1352
- { title: 'Functions', items: exports.filter((e) => e.kind === 'function') },
1353
- { title: 'Classes', items: exports.filter((e) => e.kind === 'class') },
1354
- { title: 'Types & Interfaces', items: exports.filter((e) => e.kind === 'interface' || e.kind === 'type') },
1355
- { title: 'Variables', items: exports.filter((e) => e.kind === 'variable') },
1356
- { title: 'Enums', items: exports.filter((e) => e.kind === 'enum') },
1357
- ].filter((g) => g.items.length > 0);
1358
-
1359
- return (
1360
- <div className="max-w-4xl mx-auto px-4 py-8">
1361
- <header className="mb-12">
1362
- <h1 className="text-3xl font-bold">{typedSpec.meta.name}</h1>
1363
- {typedSpec.meta.description && (
1364
- <p className="text-lg text-muted-foreground mt-2">{typedSpec.meta.description}</p>
1365
- )}
1366
- </header>
1367
-
1368
- {groups.map((group) => (
1369
- <section key={group.title} className="mb-12">
1370
- <h2 className="text-2xl font-bold mb-6">{group.title}</h2>
1371
- <div className="grid gap-4 md:grid-cols-2">
1372
- {group.items.map((exp) => (
1373
- // Replace with ExportCard once installed:
1374
- // <ExportCard key={exp.id} export={exp} href={\`/api/\${exp.name}\`} />
1375
- <a
1376
- key={exp.id}
1377
- href={\`/api/\${exp.name}\`}
1378
- className="block p-4 border rounded-lg hover:bg-muted transition-colors"
1379
- >
1380
- <h3 className="font-semibold">{exp.name}</h3>
1381
- <p className="text-sm text-muted-foreground line-clamp-2">
1382
- {exp.description || 'No description'}
1383
- </p>
1384
- <span className="text-xs bg-muted px-2 py-1 rounded mt-2 inline-block">
1385
- {exp.kind}
1386
- </span>
1387
- </a>
1388
- ))}
1389
- </div>
1390
- </section>
1391
- ))}
1392
- </div>
1393
- );
1394
- }
1395
-
1396
- export { spec };
1397
- `;
1398
- }
1399
- async function toReact(spec, options) {
1400
- const { outDir, variant = "full", componentsPath = "@/components/api" } = options;
1401
- if (!fs3.existsSync(outDir)) {
1402
- fs3.mkdirSync(outDir, { recursive: true });
1403
- }
1404
- const specPath = path2.join(outDir, "openpkg.json");
1405
- fs3.writeFileSync(specPath, JSON.stringify(spec, null, 2));
1406
- const layoutContent = variant === "index" ? generateIndexLayout(spec, componentsPath) : generateFullLayout(spec, componentsPath);
1407
- const layoutPath = path2.join(outDir, "page.tsx");
1408
- fs3.writeFileSync(layoutPath, layoutContent);
1409
- }
1410
- function toReactString(spec, options = {}) {
1411
- const { variant = "full", componentsPath = "@/components/api" } = options;
1412
- return variant === "index" ? generateIndexLayout(spec, componentsPath) : generateFullLayout(spec, componentsPath);
1413
- }
1414
1194
  // src/primitives/filter.ts
1415
1195
  function matchesExport(exp, criteria) {
1416
1196
  if (criteria.kinds && criteria.kinds.length > 0) {
@@ -1517,211 +1297,8 @@ function filterSpec(spec, criteria) {
1517
1297
  // src/primitives/get.ts
1518
1298
  import ts11 from "typescript";
1519
1299
 
1520
- // src/compiler/program.ts
1521
- import * as fs4 from "node:fs";
1522
- import * as path3 from "node:path";
1523
- import ts from "typescript";
1524
- function isJsFile(file) {
1525
- return /\.(js|mjs|cjs|jsx)$/.test(file);
1526
- }
1527
- function getScriptKind(file) {
1528
- if (/\.tsx$/.test(file))
1529
- return ts.ScriptKind.TSX;
1530
- if (/\.jsx$/.test(file))
1531
- return ts.ScriptKind.JSX;
1532
- if (/\.(js|mjs|cjs)$/.test(file))
1533
- return ts.ScriptKind.JS;
1534
- return ts.ScriptKind.TS;
1535
- }
1536
- var DEFAULT_COMPILER_OPTIONS = {
1537
- target: ts.ScriptTarget.Latest,
1538
- module: ts.ModuleKind.CommonJS,
1539
- lib: ["lib.es2021.d.ts"],
1540
- declaration: true,
1541
- moduleResolution: ts.ModuleResolutionKind.NodeJs
1542
- };
1543
- function resolveProjectReferences(configPath, parsedConfig) {
1544
- const additionalFiles = [];
1545
- if (!parsedConfig.projectReferences?.length) {
1546
- return additionalFiles;
1547
- }
1548
- const configDir = path3.dirname(configPath);
1549
- for (const ref of parsedConfig.projectReferences) {
1550
- const refPath = path3.resolve(configDir, ref.path);
1551
- const refConfigPath = fs4.existsSync(path3.join(refPath, "tsconfig.json")) ? path3.join(refPath, "tsconfig.json") : refPath;
1552
- if (!fs4.existsSync(refConfigPath))
1553
- continue;
1554
- const refConfigFile = ts.readConfigFile(refConfigPath, ts.sys.readFile);
1555
- if (refConfigFile.error)
1556
- continue;
1557
- const refParsed = ts.parseJsonConfigFileContent(refConfigFile.config, ts.sys, path3.dirname(refConfigPath));
1558
- additionalFiles.push(...refParsed.fileNames);
1559
- }
1560
- return additionalFiles;
1561
- }
1562
- function parsePnpmWorkspace(yamlContent) {
1563
- const globs = [];
1564
- const lines = yamlContent.split(`
1565
- `);
1566
- let inPackages = false;
1567
- for (const line of lines) {
1568
- const trimmed = line.trim();
1569
- if (trimmed === "packages:") {
1570
- inPackages = true;
1571
- continue;
1572
- }
1573
- if (inPackages) {
1574
- if (!line.startsWith(" ") && !line.startsWith("-") && trimmed) {
1575
- break;
1576
- }
1577
- const match = trimmed.match(/^-\s*['"]?([^'"]+)['"]?$/);
1578
- if (match) {
1579
- globs.push(match[1]);
1580
- }
1581
- }
1582
- }
1583
- return globs;
1584
- }
1585
- function buildWorkspaceMap(baseDir) {
1586
- let currentDir = baseDir;
1587
- let rootDir;
1588
- let workspaceGlobs = [];
1589
- for (let i = 0;i < 10; i++) {
1590
- const pnpmPath = path3.join(currentDir, "pnpm-workspace.yaml");
1591
- if (fs4.existsSync(pnpmPath)) {
1592
- try {
1593
- const yamlContent = fs4.readFileSync(pnpmPath, "utf-8");
1594
- workspaceGlobs = parsePnpmWorkspace(yamlContent);
1595
- if (workspaceGlobs.length > 0) {
1596
- rootDir = currentDir;
1597
- break;
1598
- }
1599
- } catch {}
1600
- }
1601
- const pkgPath = path3.join(currentDir, "package.json");
1602
- if (fs4.existsSync(pkgPath)) {
1603
- try {
1604
- const pkg = JSON.parse(fs4.readFileSync(pkgPath, "utf-8"));
1605
- if (pkg.workspaces) {
1606
- rootDir = currentDir;
1607
- workspaceGlobs = Array.isArray(pkg.workspaces) ? pkg.workspaces : pkg.workspaces?.packages || [];
1608
- break;
1609
- }
1610
- } catch {}
1611
- }
1612
- const parent = path3.dirname(currentDir);
1613
- if (parent === currentDir)
1614
- break;
1615
- currentDir = parent;
1616
- }
1617
- if (!rootDir || workspaceGlobs.length === 0)
1618
- return;
1619
- const packages = new Map;
1620
- for (const glob of workspaceGlobs) {
1621
- const globDir = path3.join(rootDir, glob.replace(/\/\*$/, ""));
1622
- if (!fs4.existsSync(globDir) || !fs4.statSync(globDir).isDirectory())
1623
- continue;
1624
- const entries = fs4.readdirSync(globDir, { withFileTypes: true });
1625
- for (const entry of entries) {
1626
- if (!entry.isDirectory())
1627
- continue;
1628
- const pkgDir = path3.join(globDir, entry.name);
1629
- const pkgJsonPath = path3.join(pkgDir, "package.json");
1630
- if (!fs4.existsSync(pkgJsonPath))
1631
- continue;
1632
- try {
1633
- const pkg = JSON.parse(fs4.readFileSync(pkgJsonPath, "utf-8"));
1634
- if (pkg.name) {
1635
- const srcDir = fs4.existsSync(path3.join(pkgDir, "src")) ? path3.join(pkgDir, "src") : pkgDir;
1636
- packages.set(pkg.name, srcDir);
1637
- }
1638
- } catch {}
1639
- }
1640
- }
1641
- return packages.size > 0 ? { packages, rootDir } : undefined;
1642
- }
1643
- function createProgram({
1644
- entryFile,
1645
- baseDir = path3.dirname(entryFile),
1646
- content
1647
- }) {
1648
- let configPath = ts.findConfigFile(baseDir, ts.sys.fileExists, "tsconfig.json");
1649
- if (!configPath) {
1650
- configPath = ts.findConfigFile(baseDir, ts.sys.fileExists, "jsconfig.json");
1651
- }
1652
- let compilerOptions = { ...DEFAULT_COMPILER_OPTIONS };
1653
- let additionalRootFiles = [];
1654
- if (configPath) {
1655
- const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
1656
- const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path3.dirname(configPath));
1657
- compilerOptions = { ...compilerOptions, ...parsedConfig.options };
1658
- additionalRootFiles = resolveProjectReferences(configPath, parsedConfig);
1659
- const sourceFiles = parsedConfig.fileNames.filter((f) => !f.includes(".test.") && !f.includes(".spec.") && !f.includes("/dist/") && !f.includes("/node_modules/"));
1660
- additionalRootFiles.push(...sourceFiles);
1661
- }
1662
- if (isJsFile(entryFile)) {
1663
- compilerOptions = {
1664
- ...compilerOptions,
1665
- allowJs: true,
1666
- checkJs: true,
1667
- isolatedDeclarations: false
1668
- };
1669
- } else {
1670
- const allowJsVal = compilerOptions.allowJs;
1671
- if (typeof allowJsVal === "boolean" && allowJsVal) {
1672
- compilerOptions = { ...compilerOptions, allowJs: false, checkJs: false };
1673
- }
1674
- }
1675
- const workspaceMap = buildWorkspaceMap(baseDir);
1676
- const compilerHost = ts.createCompilerHost(compilerOptions, true);
1677
- let inMemorySource;
1678
- if (workspaceMap) {
1679
- const originalResolveModuleNames = compilerHost.resolveModuleNames?.bind(compilerHost);
1680
- compilerHost.resolveModuleNames = (moduleNames, containingFile, _reusedNames, redirectedReference, options) => {
1681
- return moduleNames.map((moduleName) => {
1682
- const srcDir = workspaceMap.packages.get(moduleName);
1683
- if (srcDir) {
1684
- const indexFile = path3.join(srcDir, "index.ts");
1685
- if (fs4.existsSync(indexFile)) {
1686
- return { resolvedFileName: indexFile, isExternalLibraryImport: false };
1687
- }
1688
- }
1689
- if (originalResolveModuleNames) {
1690
- const result = originalResolveModuleNames([moduleName], containingFile, _reusedNames, redirectedReference, options);
1691
- return result[0];
1692
- }
1693
- const resolved = ts.resolveModuleName(moduleName, containingFile, options, compilerHost);
1694
- return resolved.resolvedModule;
1695
- });
1696
- };
1697
- }
1698
- if (content !== undefined) {
1699
- inMemorySource = ts.createSourceFile(entryFile, content, ts.ScriptTarget.Latest, true, getScriptKind(entryFile));
1700
- const originalGetSourceFile = compilerHost.getSourceFile.bind(compilerHost);
1701
- compilerHost.getSourceFile = (fileName, languageVersion, onError, shouldCreateNewSourceFile) => {
1702
- if (fileName === entryFile) {
1703
- return inMemorySource;
1704
- }
1705
- return originalGetSourceFile(fileName, languageVersion, onError, shouldCreateNewSourceFile);
1706
- };
1707
- }
1708
- const rootFiles = [entryFile, ...additionalRootFiles];
1709
- const program = ts.createProgram(rootFiles, compilerOptions, compilerHost);
1710
- const sourceFile = inMemorySource ?? program.getSourceFile(entryFile);
1711
- return {
1712
- program,
1713
- compilerHost,
1714
- compilerOptions,
1715
- sourceFile,
1716
- configPath
1717
- };
1718
- }
1719
-
1720
- // src/serializers/classes.ts
1721
- import ts7 from "typescript";
1722
-
1723
1300
  // src/ast/utils.ts
1724
- import ts2 from "typescript";
1301
+ import ts from "typescript";
1725
1302
  function parseExamplesFromTags(tags) {
1726
1303
  const examples = [];
1727
1304
  for (const tag of tags) {
@@ -1783,12 +1360,12 @@ function extractSeeTagText(tag) {
1783
1360
  if (Array.isArray(tag.comment)) {
1784
1361
  const parts = [];
1785
1362
  for (const part of tag.comment) {
1786
- if (ts2.isJSDocLink(part) || ts2.isJSDocLinkCode(part) || ts2.isJSDocLinkPlain(part)) {
1363
+ if (ts.isJSDocLink(part) || ts.isJSDocLinkCode(part) || ts.isJSDocLinkPlain(part)) {
1787
1364
  if (part.name) {
1788
1365
  try {
1789
1366
  parts.push(part.name.getText());
1790
1367
  } catch {
1791
- if (ts2.isIdentifier(part.name)) {
1368
+ if (ts.isIdentifier(part.name)) {
1792
1369
  parts.push(part.name.text);
1793
1370
  }
1794
1371
  }
@@ -1796,7 +1373,7 @@ function extractSeeTagText(tag) {
1796
1373
  if (part.text) {
1797
1374
  parts.push(part.text);
1798
1375
  }
1799
- } else if (part.kind === ts2.SyntaxKind.JSDocText) {
1376
+ } else if (part.kind === ts.SyntaxKind.JSDocText) {
1800
1377
  parts.push(part.text);
1801
1378
  }
1802
1379
  }
@@ -1805,12 +1382,12 @@ function extractSeeTagText(tag) {
1805
1382
  return result;
1806
1383
  }
1807
1384
  }
1808
- return typeof tag.comment === "string" ? tag.comment : ts2.getTextOfJSDocComment(tag.comment) ?? "";
1385
+ return typeof tag.comment === "string" ? tag.comment : ts.getTextOfJSDocComment(tag.comment) ?? "";
1809
1386
  }
1810
1387
  function getJSDocComment(node, symbol, checker) {
1811
- const jsDocTags = ts2.getJSDocTags(node);
1388
+ const jsDocTags = ts.getJSDocTags(node);
1812
1389
  const tags = jsDocTags.map((tag) => {
1813
- const rawText = typeof tag.comment === "string" ? tag.comment : ts2.getTextOfJSDocComment(tag.comment) ?? "";
1390
+ const rawText = typeof tag.comment === "string" ? tag.comment : ts.getTextOfJSDocComment(tag.comment) ?? "";
1814
1391
  if (tag.tagName.text === "param") {
1815
1392
  const paramTag = tag;
1816
1393
  let paramName = "";
@@ -1845,12 +1422,12 @@ function getJSDocComment(node, symbol, checker) {
1845
1422
  }
1846
1423
  return { name: tag.tagName.text, text: rawText };
1847
1424
  });
1848
- const jsDocComments = ts2.getJSDocCommentsAndTags(node).filter(ts2.isJSDoc);
1425
+ const jsDocComments = ts.getJSDocCommentsAndTags(node).filter(ts.isJSDoc);
1849
1426
  let description;
1850
1427
  if (jsDocComments.length > 0) {
1851
1428
  const firstDoc = jsDocComments[0];
1852
1429
  if (firstDoc.comment) {
1853
- description = typeof firstDoc.comment === "string" ? firstDoc.comment : ts2.getTextOfJSDocComment(firstDoc.comment);
1430
+ description = typeof firstDoc.comment === "string" ? firstDoc.comment : ts.getTextOfJSDocComment(firstDoc.comment);
1854
1431
  }
1855
1432
  }
1856
1433
  if (!description && symbol && checker) {
@@ -1883,7 +1460,7 @@ function getParamDescription(propertyName, jsdocTags, inferredAlias) {
1883
1460
  }
1884
1461
  const isMatch = tagParamName === propertyName || inferredAlias && tagParamName === `${inferredAlias}.${propertyName}` || tagParamName.endsWith(`.${propertyName}`);
1885
1462
  if (isMatch) {
1886
- const comment = typeof tag.comment === "string" ? tag.comment : ts2.getTextOfJSDocComment(tag.comment);
1463
+ const comment = typeof tag.comment === "string" ? tag.comment : ts.getTextOfJSDocComment(tag.comment);
1887
1464
  return stripParamSeparator(comment);
1888
1465
  }
1889
1466
  }
@@ -1896,11 +1473,11 @@ function extractVarianceModifiers(modifiers) {
1896
1473
  let hasOut = false;
1897
1474
  let isConst;
1898
1475
  for (const mod of modifiers) {
1899
- if (mod.kind === ts2.SyntaxKind.InKeyword)
1476
+ if (mod.kind === ts.SyntaxKind.InKeyword)
1900
1477
  hasIn = true;
1901
- if (mod.kind === ts2.SyntaxKind.OutKeyword)
1478
+ if (mod.kind === ts.SyntaxKind.OutKeyword)
1902
1479
  hasOut = true;
1903
- if (mod.kind === ts2.SyntaxKind.ConstKeyword)
1480
+ if (mod.kind === ts.SyntaxKind.ConstKeyword)
1904
1481
  isConst = true;
1905
1482
  }
1906
1483
  const variance = hasIn && hasOut ? "inout" : hasIn ? "in" : hasOut ? "out" : undefined;
@@ -1922,7 +1499,7 @@ function extractTypeParameters(node, checker) {
1922
1499
  const defType = checker.getTypeAtLocation(tp.default);
1923
1500
  defaultType = checker.typeToString(defType);
1924
1501
  }
1925
- const { variance, isConst } = extractVarianceModifiers(ts2.getModifiers(tp));
1502
+ const { variance, isConst } = extractVarianceModifiers(ts.getModifiers(tp));
1926
1503
  return {
1927
1504
  name,
1928
1505
  ...constraint ? { constraint } : {},
@@ -1943,7 +1520,7 @@ function isSymbolDeprecated(symbol) {
1943
1520
  return { deprecated: true, reason };
1944
1521
  }
1945
1522
  for (const declaration of symbol.getDeclarations() ?? []) {
1946
- const tag = ts2.getJSDocDeprecatedTag(declaration);
1523
+ const tag = ts.getJSDocDeprecatedTag(declaration);
1947
1524
  if (tag) {
1948
1525
  let reason;
1949
1526
  if (typeof tag.comment === "string") {
@@ -1953,10 +1530,10 @@ function isSymbolDeprecated(symbol) {
1953
1530
  }
1954
1531
  return { deprecated: true, reason };
1955
1532
  }
1956
- if (ts2.isExportSpecifier(declaration)) {
1533
+ if (ts.isExportSpecifier(declaration)) {
1957
1534
  const exportDecl = declaration.parent?.parent;
1958
- if (exportDecl && ts2.isExportDeclaration(exportDecl)) {
1959
- const parentTag = ts2.getJSDocDeprecatedTag(exportDecl);
1535
+ if (exportDecl && ts.isExportDeclaration(exportDecl)) {
1536
+ const parentTag = ts.getJSDocDeprecatedTag(exportDecl);
1960
1537
  if (parentTag) {
1961
1538
  let reason;
1962
1539
  if (typeof parentTag.comment === "string") {
@@ -2001,8 +1578,8 @@ function extractTypeParametersFromSignature(signature, checker) {
2001
1578
  const tpSymbol = tp.getSymbol();
2002
1579
  const declarations = tpSymbol?.getDeclarations() ?? [];
2003
1580
  for (const decl of declarations) {
2004
- if (ts2.isTypeParameterDeclaration(decl)) {
2005
- ({ variance, isConst } = extractVarianceModifiers(ts2.getModifiers(decl)));
1581
+ if (ts.isTypeParameterDeclaration(decl)) {
1582
+ ({ variance, isConst } = extractVarianceModifiers(ts.getModifiers(decl)));
2006
1583
  break;
2007
1584
  }
2008
1585
  }
@@ -2016,25 +1593,228 @@ function extractTypeParametersFromSignature(signature, checker) {
2016
1593
  });
2017
1594
  }
2018
1595
  function getExportKind(declaration, type) {
2019
- if (ts2.isFunctionDeclaration(declaration) || ts2.isFunctionExpression(declaration))
1596
+ if (ts.isFunctionDeclaration(declaration) || ts.isFunctionExpression(declaration))
2020
1597
  return "function";
2021
- if (ts2.isClassDeclaration(declaration))
1598
+ if (ts.isClassDeclaration(declaration))
2022
1599
  return "class";
2023
- if (ts2.isInterfaceDeclaration(declaration))
1600
+ if (ts.isInterfaceDeclaration(declaration))
2024
1601
  return "interface";
2025
- if (ts2.isTypeAliasDeclaration(declaration))
1602
+ if (ts.isTypeAliasDeclaration(declaration))
2026
1603
  return "type";
2027
- if (ts2.isEnumDeclaration(declaration))
1604
+ if (ts.isEnumDeclaration(declaration))
2028
1605
  return "enum";
2029
- if (ts2.isModuleDeclaration(declaration) || ts2.isNamespaceExport(declaration))
1606
+ if (ts.isModuleDeclaration(declaration) || ts.isNamespaceExport(declaration))
2030
1607
  return "namespace";
2031
- if (ts2.isVariableDeclaration(declaration) && type.getConstructSignatures().length > 0)
1608
+ if (ts.isVariableDeclaration(declaration) && type.getConstructSignatures().length > 0)
2032
1609
  return "class";
2033
- if (ts2.isVariableDeclaration(declaration) && type.getCallSignatures().length > 0)
1610
+ if (ts.isVariableDeclaration(declaration) && type.getCallSignatures().length > 0)
2034
1611
  return "function";
2035
1612
  return "variable";
2036
1613
  }
2037
1614
 
1615
+ // src/compiler/program.ts
1616
+ import * as fs3 from "node:fs";
1617
+ import * as path2 from "node:path";
1618
+ import ts2 from "typescript";
1619
+ function isJsFile(file) {
1620
+ return /\.(js|mjs|cjs|jsx)$/.test(file);
1621
+ }
1622
+ function getScriptKind(file) {
1623
+ if (/\.tsx$/.test(file))
1624
+ return ts2.ScriptKind.TSX;
1625
+ if (/\.jsx$/.test(file))
1626
+ return ts2.ScriptKind.JSX;
1627
+ if (/\.(js|mjs|cjs)$/.test(file))
1628
+ return ts2.ScriptKind.JS;
1629
+ return ts2.ScriptKind.TS;
1630
+ }
1631
+ var DEFAULT_COMPILER_OPTIONS = {
1632
+ target: ts2.ScriptTarget.Latest,
1633
+ module: ts2.ModuleKind.CommonJS,
1634
+ lib: ["lib.es2021.d.ts"],
1635
+ declaration: true,
1636
+ moduleResolution: ts2.ModuleResolutionKind.NodeJs
1637
+ };
1638
+ function resolveProjectReferences(configPath, parsedConfig) {
1639
+ const additionalFiles = [];
1640
+ if (!parsedConfig.projectReferences?.length) {
1641
+ return additionalFiles;
1642
+ }
1643
+ const configDir = path2.dirname(configPath);
1644
+ for (const ref of parsedConfig.projectReferences) {
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))
1648
+ continue;
1649
+ const refConfigFile = ts2.readConfigFile(refConfigPath, ts2.sys.readFile);
1650
+ if (refConfigFile.error)
1651
+ continue;
1652
+ const refParsed = ts2.parseJsonConfigFileContent(refConfigFile.config, ts2.sys, path2.dirname(refConfigPath));
1653
+ additionalFiles.push(...refParsed.fileNames);
1654
+ }
1655
+ return additionalFiles;
1656
+ }
1657
+ function parsePnpmWorkspace(yamlContent) {
1658
+ const globs = [];
1659
+ const lines = yamlContent.split(`
1660
+ `);
1661
+ let inPackages = false;
1662
+ for (const line of lines) {
1663
+ const trimmed = line.trim();
1664
+ if (trimmed === "packages:") {
1665
+ inPackages = true;
1666
+ continue;
1667
+ }
1668
+ if (inPackages) {
1669
+ if (!line.startsWith(" ") && !line.startsWith("-") && trimmed) {
1670
+ break;
1671
+ }
1672
+ const match = trimmed.match(/^-\s*['"]?([^'"]+)['"]?$/);
1673
+ if (match) {
1674
+ globs.push(match[1]);
1675
+ }
1676
+ }
1677
+ }
1678
+ return globs;
1679
+ }
1680
+ function buildWorkspaceMap(baseDir) {
1681
+ let currentDir = baseDir;
1682
+ let rootDir;
1683
+ let workspaceGlobs = [];
1684
+ for (let i = 0;i < 10; i++) {
1685
+ const pnpmPath = path2.join(currentDir, "pnpm-workspace.yaml");
1686
+ if (fs3.existsSync(pnpmPath)) {
1687
+ try {
1688
+ const yamlContent = fs3.readFileSync(pnpmPath, "utf-8");
1689
+ workspaceGlobs = parsePnpmWorkspace(yamlContent);
1690
+ if (workspaceGlobs.length > 0) {
1691
+ rootDir = currentDir;
1692
+ break;
1693
+ }
1694
+ } catch {}
1695
+ }
1696
+ const pkgPath = path2.join(currentDir, "package.json");
1697
+ if (fs3.existsSync(pkgPath)) {
1698
+ try {
1699
+ const pkg = JSON.parse(fs3.readFileSync(pkgPath, "utf-8"));
1700
+ if (pkg.workspaces) {
1701
+ rootDir = currentDir;
1702
+ workspaceGlobs = Array.isArray(pkg.workspaces) ? pkg.workspaces : pkg.workspaces?.packages || [];
1703
+ break;
1704
+ }
1705
+ } catch {}
1706
+ }
1707
+ const parent = path2.dirname(currentDir);
1708
+ if (parent === currentDir)
1709
+ break;
1710
+ currentDir = parent;
1711
+ }
1712
+ if (!rootDir || workspaceGlobs.length === 0)
1713
+ return;
1714
+ const packages = new Map;
1715
+ for (const glob of workspaceGlobs) {
1716
+ const globDir = path2.join(rootDir, glob.replace(/\/\*$/, ""));
1717
+ if (!fs3.existsSync(globDir) || !fs3.statSync(globDir).isDirectory())
1718
+ continue;
1719
+ const entries = fs3.readdirSync(globDir, { withFileTypes: true });
1720
+ for (const entry of entries) {
1721
+ if (!entry.isDirectory())
1722
+ continue;
1723
+ const pkgDir = path2.join(globDir, entry.name);
1724
+ const pkgJsonPath = path2.join(pkgDir, "package.json");
1725
+ if (!fs3.existsSync(pkgJsonPath))
1726
+ continue;
1727
+ try {
1728
+ const pkg = JSON.parse(fs3.readFileSync(pkgJsonPath, "utf-8"));
1729
+ if (pkg.name) {
1730
+ const srcDir = fs3.existsSync(path2.join(pkgDir, "src")) ? path2.join(pkgDir, "src") : pkgDir;
1731
+ packages.set(pkg.name, srcDir);
1732
+ }
1733
+ } catch {}
1734
+ }
1735
+ }
1736
+ return packages.size > 0 ? { packages, rootDir } : undefined;
1737
+ }
1738
+ function createProgram({
1739
+ entryFile,
1740
+ baseDir = path2.dirname(entryFile),
1741
+ content
1742
+ }) {
1743
+ let configPath = ts2.findConfigFile(baseDir, ts2.sys.fileExists, "tsconfig.json");
1744
+ if (!configPath) {
1745
+ configPath = ts2.findConfigFile(baseDir, ts2.sys.fileExists, "jsconfig.json");
1746
+ }
1747
+ let compilerOptions = { ...DEFAULT_COMPILER_OPTIONS };
1748
+ let additionalRootFiles = [];
1749
+ if (configPath) {
1750
+ const configFile = ts2.readConfigFile(configPath, ts2.sys.readFile);
1751
+ const parsedConfig = ts2.parseJsonConfigFileContent(configFile.config, ts2.sys, path2.dirname(configPath));
1752
+ compilerOptions = { ...compilerOptions, ...parsedConfig.options };
1753
+ additionalRootFiles = resolveProjectReferences(configPath, parsedConfig);
1754
+ const sourceFiles = parsedConfig.fileNames.filter((f) => !f.includes(".test.") && !f.includes(".spec.") && !f.includes("/dist/") && !f.includes("/node_modules/"));
1755
+ additionalRootFiles.push(...sourceFiles);
1756
+ }
1757
+ if (isJsFile(entryFile)) {
1758
+ compilerOptions = {
1759
+ ...compilerOptions,
1760
+ allowJs: true,
1761
+ checkJs: true,
1762
+ isolatedDeclarations: false
1763
+ };
1764
+ } else {
1765
+ const allowJsVal = compilerOptions.allowJs;
1766
+ if (typeof allowJsVal === "boolean" && allowJsVal) {
1767
+ compilerOptions = { ...compilerOptions, allowJs: false, checkJs: false };
1768
+ }
1769
+ }
1770
+ const workspaceMap = buildWorkspaceMap(baseDir);
1771
+ const compilerHost = ts2.createCompilerHost(compilerOptions, true);
1772
+ let inMemorySource;
1773
+ if (workspaceMap) {
1774
+ const originalResolveModuleNames = compilerHost.resolveModuleNames?.bind(compilerHost);
1775
+ compilerHost.resolveModuleNames = (moduleNames, containingFile, _reusedNames, redirectedReference, options) => {
1776
+ return moduleNames.map((moduleName) => {
1777
+ const srcDir = workspaceMap.packages.get(moduleName);
1778
+ if (srcDir) {
1779
+ const indexFile = path2.join(srcDir, "index.ts");
1780
+ if (fs3.existsSync(indexFile)) {
1781
+ return { resolvedFileName: indexFile, isExternalLibraryImport: false };
1782
+ }
1783
+ }
1784
+ if (originalResolveModuleNames) {
1785
+ const result = originalResolveModuleNames([moduleName], containingFile, _reusedNames, redirectedReference, options);
1786
+ return result[0];
1787
+ }
1788
+ const resolved = ts2.resolveModuleName(moduleName, containingFile, options, compilerHost);
1789
+ return resolved.resolvedModule;
1790
+ });
1791
+ };
1792
+ }
1793
+ if (content !== undefined) {
1794
+ inMemorySource = ts2.createSourceFile(entryFile, content, ts2.ScriptTarget.Latest, true, getScriptKind(entryFile));
1795
+ const originalGetSourceFile = compilerHost.getSourceFile.bind(compilerHost);
1796
+ compilerHost.getSourceFile = (fileName, languageVersion, onError, shouldCreateNewSourceFile) => {
1797
+ if (fileName === entryFile) {
1798
+ return inMemorySource;
1799
+ }
1800
+ return originalGetSourceFile(fileName, languageVersion, onError, shouldCreateNewSourceFile);
1801
+ };
1802
+ }
1803
+ const rootFiles = [entryFile, ...additionalRootFiles];
1804
+ const program = ts2.createProgram(rootFiles, compilerOptions, compilerHost);
1805
+ const sourceFile = inMemorySource ?? program.getSourceFile(entryFile);
1806
+ return {
1807
+ program,
1808
+ compilerHost,
1809
+ compilerOptions,
1810
+ sourceFile,
1811
+ configPath
1812
+ };
1813
+ }
1814
+
1815
+ // src/serializers/classes.ts
1816
+ import ts7 from "typescript";
1817
+
2038
1818
  // src/types/parameters.ts
2039
1819
  import ts4 from "typescript";
2040
1820
 
@@ -2595,7 +2375,7 @@ function buildSchemaInternal(type, checker, ctx) {
2595
2375
  return { type: checker.typeToString(type) };
2596
2376
  } finally {
2597
2377
  if (addedToVisited) {
2598
- ctx.visitedTypes.delete(type);
2378
+ ctx?.visitedTypes.delete(type);
2599
2379
  }
2600
2380
  }
2601
2381
  }
@@ -4647,12 +4427,20 @@ async function getExport(options) {
4647
4427
  const result = createProgram({ entryFile, baseDir, content });
4648
4428
  const { program, sourceFile } = result;
4649
4429
  if (!sourceFile) {
4650
- return { export: null, types: [], errors: [`Entry file not found: ${entryFile}. Specify with: drift get src/index.ts <name>`] };
4430
+ return {
4431
+ export: null,
4432
+ types: [],
4433
+ errors: [`Entry file not found: ${entryFile}. Specify with: drift get src/index.ts <name>`]
4434
+ };
4651
4435
  }
4652
4436
  const checker = program.getTypeChecker();
4653
4437
  const moduleSymbol = checker.getSymbolAtLocation(sourceFile);
4654
4438
  if (!moduleSymbol) {
4655
- return { export: null, types: [], errors: [`No exports found in ${entryFile}. Is this the right entry point?`] };
4439
+ return {
4440
+ export: null,
4441
+ types: [],
4442
+ errors: [`No exports found in ${entryFile}. Is this the right entry point?`]
4443
+ };
4656
4444
  }
4657
4445
  const exportedSymbols = checker.getExportsOfModule(moduleSymbol);
4658
4446
  const targetSymbol = exportedSymbols.find((s) => s.getName() === exportName);
@@ -4671,7 +4459,11 @@ async function getExport(options) {
4671
4459
  if (isNamespaceExportDecl) {
4672
4460
  const spec2 = serializeNamespaceForGet(targetSymbol, exportName, ctx);
4673
4461
  const types2 = ctx.typeRegistry.getAll().map((t) => normalizeType(t, { dialect: "draft-2020-12" }));
4674
- return { export: normalizeExport(spec2, { dialect: "draft-2020-12" }), types: types2, errors };
4462
+ return {
4463
+ export: normalizeExport(spec2, { dialect: "draft-2020-12" }),
4464
+ types: types2,
4465
+ errors
4466
+ };
4675
4467
  }
4676
4468
  const { declaration, resolvedSymbol, isTypeOnly } = resolveExportTarget(targetSymbol, checker);
4677
4469
  if (!declaration) {
@@ -4836,7 +4628,7 @@ function detectExternalPackage(symbol, checker) {
4836
4628
  return;
4837
4629
  }
4838
4630
  // src/primitives/list.ts
4839
- import * as path4 from "node:path";
4631
+ import * as path3 from "node:path";
4840
4632
  import ts12 from "typescript";
4841
4633
  async function listExports(options) {
4842
4634
  const { entryFile, baseDir, content } = options;
@@ -4845,12 +4637,18 @@ async function listExports(options) {
4845
4637
  const result = createProgram({ entryFile, baseDir, content });
4846
4638
  const { program, sourceFile } = result;
4847
4639
  if (!sourceFile) {
4848
- return { exports: [], errors: [`Entry file not found: ${entryFile}. Specify with: drift list src/index.ts`] };
4640
+ return {
4641
+ exports: [],
4642
+ errors: [`Entry file not found: ${entryFile}. Specify with: drift list src/index.ts`]
4643
+ };
4849
4644
  }
4850
4645
  const checker = program.getTypeChecker();
4851
4646
  const moduleSymbol = checker.getSymbolAtLocation(sourceFile);
4852
4647
  if (!moduleSymbol) {
4853
- return { exports: [], errors: [`No exports found in ${entryFile}. Is this the right entry point?`] };
4648
+ return {
4649
+ exports: [],
4650
+ errors: [`No exports found in ${entryFile}. Is this the right entry point?`]
4651
+ };
4854
4652
  }
4855
4653
  const exportedSymbols = checker.getExportsOfModule(moduleSymbol);
4856
4654
  for (const symbol of exportedSymbols) {
@@ -4891,7 +4689,7 @@ function extractExportItem(symbol, checker, entryFile, entrySourceFile) {
4891
4689
  return {
4892
4690
  name,
4893
4691
  kind: "namespace",
4894
- file: path4.relative(path4.dirname(entryFile), declaration.fileName),
4692
+ file: path3.relative(path3.dirname(entryFile), declaration.fileName),
4895
4693
  line: 1,
4896
4694
  reexport: true
4897
4695
  };
@@ -4905,7 +4703,7 @@ function extractExportItem(symbol, checker, entryFile, entrySourceFile) {
4905
4703
  return {
4906
4704
  name,
4907
4705
  kind,
4908
- file: path4.relative(path4.dirname(entryFile), sourceFile.fileName),
4706
+ file: path3.relative(path3.dirname(entryFile), sourceFile.fileName),
4909
4707
  line: line + 1,
4910
4708
  ...description ? { description } : {},
4911
4709
  ...deprecated ? { deprecated: true } : {},
@@ -4926,8 +4724,8 @@ function getDescriptionPreview(symbol, checker) {
4926
4724
  return `${firstLine.slice(0, 77)}...`;
4927
4725
  }
4928
4726
  // src/builder/spec-builder.ts
4929
- import * as fs7 from "node:fs";
4930
- import * as path8 from "node:path";
4727
+ import * as fs6 from "node:fs";
4728
+ import * as path7 from "node:path";
4931
4729
  import { SCHEMA_URL, SCHEMA_VERSION } from "@openpkg-ts/spec";
4932
4730
  import ts16 from "typescript";
4933
4731
 
@@ -4963,9 +4761,9 @@ function resolveExportTarget2(symbol, checker) {
4963
4761
 
4964
4762
  // src/schema/standard-schema.ts
4965
4763
  import { spawn, spawnSync } from "node:child_process";
4966
- import * as fs5 from "node:fs";
4764
+ import * as fs4 from "node:fs";
4967
4765
  import * as os from "node:os";
4968
- import * as path5 from "node:path";
4766
+ import * as path4 from "node:path";
4969
4767
  var MAX_BUFFER_SIZE = 10 * 1024 * 1024;
4970
4768
  function isStandardJSONSchema(obj) {
4971
4769
  if (typeof obj !== "object" || obj === null)
@@ -5219,21 +5017,21 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
5219
5017
  result.errors.push("No TypeScript runtime available. Install bun, tsx, or ts-node, or use Node 22+.");
5220
5018
  return result;
5221
5019
  }
5222
- if (!fs5.existsSync(tsFilePath)) {
5020
+ if (!fs4.existsSync(tsFilePath)) {
5223
5021
  result.errors.push(`TypeScript file not found: ${tsFilePath}`);
5224
5022
  return result;
5225
5023
  }
5226
5024
  const tempDir = os.tmpdir();
5227
- const workerPath = path5.join(tempDir, `openpkg-extract-worker-${Date.now()}.ts`);
5025
+ const workerPath = path4.join(tempDir, `openpkg-extract-worker-${Date.now()}.ts`);
5228
5026
  try {
5229
- fs5.writeFileSync(workerPath, TS_WORKER_SCRIPT);
5027
+ fs4.writeFileSync(workerPath, TS_WORKER_SCRIPT);
5230
5028
  const optionsJson = JSON.stringify({ target, libraryOptions });
5231
5029
  const args = [...runtime.args, workerPath, tsFilePath, optionsJson];
5232
5030
  return await new Promise((resolve2) => {
5233
5031
  const child = spawn(runtime.cmd, args, {
5234
5032
  timeout,
5235
5033
  stdio: ["ignore", "pipe", "pipe"],
5236
- cwd: path5.dirname(tsFilePath)
5034
+ cwd: path4.dirname(tsFilePath)
5237
5035
  });
5238
5036
  let stdout = "";
5239
5037
  let stderr = "";
@@ -5257,7 +5055,7 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
5257
5055
  });
5258
5056
  child.on("close", (code) => {
5259
5057
  try {
5260
- fs5.unlinkSync(workerPath);
5058
+ fs4.unlinkSync(workerPath);
5261
5059
  } catch (cleanupErr) {
5262
5060
  if (cleanupErr?.code !== "ENOENT") {
5263
5061
  result.warnings.push({ code: "CLEANUP_FAILED", message: String(cleanupErr) });
@@ -5311,7 +5109,7 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
5311
5109
  });
5312
5110
  child.on("error", (err) => {
5313
5111
  try {
5314
- fs5.unlinkSync(workerPath);
5112
+ fs4.unlinkSync(workerPath);
5315
5113
  } catch (cleanupErr) {
5316
5114
  if (cleanupErr?.code !== "ENOENT") {
5317
5115
  result.warnings.push({ code: "CLEANUP_FAILED", message: String(cleanupErr) });
@@ -5323,7 +5121,7 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
5323
5121
  });
5324
5122
  } catch (e) {
5325
5123
  try {
5326
- fs5.unlinkSync(workerPath);
5124
+ fs4.unlinkSync(workerPath);
5327
5125
  } catch (cleanupErr) {
5328
5126
  if (cleanupErr?.code !== "ENOENT") {
5329
5127
  result.warnings.push({ code: "CLEANUP_FAILED", message: String(cleanupErr) });
@@ -5334,12 +5132,12 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
5334
5132
  }
5335
5133
  }
5336
5134
  function readTsconfigOutDir(baseDir) {
5337
- const tsconfigPath = path5.join(baseDir, "tsconfig.json");
5135
+ const tsconfigPath = path4.join(baseDir, "tsconfig.json");
5338
5136
  try {
5339
- if (!fs5.existsSync(tsconfigPath)) {
5137
+ if (!fs4.existsSync(tsconfigPath)) {
5340
5138
  return null;
5341
5139
  }
5342
- const content = fs5.readFileSync(tsconfigPath, "utf-8");
5140
+ const content = fs4.readFileSync(tsconfigPath, "utf-8");
5343
5141
  const stripped = content.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*$/gm, "");
5344
5142
  const tsconfig = JSON.parse(stripped);
5345
5143
  if (tsconfig.compilerOptions?.outDir) {
@@ -5349,7 +5147,7 @@ function readTsconfigOutDir(baseDir) {
5349
5147
  return null;
5350
5148
  }
5351
5149
  function resolveCompiledPath(tsPath, baseDir) {
5352
- const relativePath = path5.relative(baseDir, tsPath);
5150
+ const relativePath = path4.relative(baseDir, tsPath);
5353
5151
  const withoutExt = relativePath.replace(/\.tsx?$/, "");
5354
5152
  const srcPrefix = withoutExt.replace(/^src\//, "");
5355
5153
  const tsconfigOutDir = readTsconfigOutDir(baseDir);
@@ -5357,7 +5155,7 @@ function resolveCompiledPath(tsPath, baseDir) {
5357
5155
  const candidates = [];
5358
5156
  if (tsconfigOutDir) {
5359
5157
  for (const ext of extensions) {
5360
- candidates.push(path5.join(baseDir, tsconfigOutDir, `${srcPrefix}${ext}`));
5158
+ candidates.push(path4.join(baseDir, tsconfigOutDir, `${srcPrefix}${ext}`));
5361
5159
  }
5362
5160
  }
5363
5161
  const commonOutDirs = ["dist", "build", "lib", "out"];
@@ -5365,21 +5163,21 @@ function resolveCompiledPath(tsPath, baseDir) {
5365
5163
  if (outDir === tsconfigOutDir)
5366
5164
  continue;
5367
5165
  for (const ext of extensions) {
5368
- candidates.push(path5.join(baseDir, outDir, `${srcPrefix}${ext}`));
5166
+ candidates.push(path4.join(baseDir, outDir, `${srcPrefix}${ext}`));
5369
5167
  }
5370
5168
  }
5371
5169
  for (const ext of extensions) {
5372
- candidates.push(path5.join(baseDir, `${withoutExt}${ext}`));
5170
+ candidates.push(path4.join(baseDir, `${withoutExt}${ext}`));
5373
5171
  }
5374
5172
  const workspaceMatch = baseDir.match(/^(.+\/packages\/[^/]+)$/);
5375
5173
  if (workspaceMatch) {
5376
5174
  const pkgRoot = workspaceMatch[1];
5377
5175
  for (const ext of extensions) {
5378
- candidates.push(path5.join(pkgRoot, "dist", `${srcPrefix}${ext}`));
5176
+ candidates.push(path4.join(pkgRoot, "dist", `${srcPrefix}${ext}`));
5379
5177
  }
5380
5178
  }
5381
5179
  for (const candidate of candidates) {
5382
- if (fs5.existsSync(candidate)) {
5180
+ if (fs4.existsSync(candidate)) {
5383
5181
  return candidate;
5384
5182
  }
5385
5183
  }
@@ -5392,7 +5190,7 @@ async function extractStandardSchemas(compiledJsPath, options = {}) {
5392
5190
  errors: [],
5393
5191
  warnings: []
5394
5192
  };
5395
- if (!fs5.existsSync(compiledJsPath)) {
5193
+ if (!fs4.existsSync(compiledJsPath)) {
5396
5194
  result.errors.push(`Compiled JS not found: ${compiledJsPath}`);
5397
5195
  return result;
5398
5196
  }
@@ -5508,8 +5306,8 @@ async function extractStandardSchemasFromProject(entryFile, baseDir, options = {
5508
5306
  }
5509
5307
 
5510
5308
  // src/builder/external-resolver.ts
5511
- import * as fs6 from "node:fs";
5512
- import * as path6 from "node:path";
5309
+ import * as fs5 from "node:fs";
5310
+ import * as path5 from "node:path";
5513
5311
  import picomatch from "picomatch";
5514
5312
  import ts14 from "typescript";
5515
5313
  function matchesExternalPattern(packageName, include, exclude) {
@@ -5543,20 +5341,20 @@ function findPackageJson(resolvedPath, packageName) {
5543
5341
  const isScoped = packageName.startsWith("@");
5544
5342
  const packageParts = isScoped ? packageName.split("/").slice(0, 2) : [packageName.split("/")[0]];
5545
5343
  const packageDir = packageParts.join("/");
5546
- let dir = path6.dirname(resolvedPath);
5344
+ let dir = path5.dirname(resolvedPath);
5547
5345
  const maxDepth = 10;
5548
5346
  for (let i = 0;i < maxDepth; i++) {
5549
5347
  if (dir.endsWith(`node_modules/${packageDir}`)) {
5550
- const pkgPath = path6.join(dir, "package.json");
5551
- if (fs6.existsSync(pkgPath)) {
5348
+ const pkgPath = path5.join(dir, "package.json");
5349
+ if (fs5.existsSync(pkgPath)) {
5552
5350
  try {
5553
- return JSON.parse(fs6.readFileSync(pkgPath, "utf-8"));
5351
+ return JSON.parse(fs5.readFileSync(pkgPath, "utf-8"));
5554
5352
  } catch {
5555
5353
  return;
5556
5354
  }
5557
5355
  }
5558
5356
  }
5559
- const parent = path6.dirname(dir);
5357
+ const parent = path5.dirname(dir);
5560
5358
  if (parent === dir)
5561
5359
  break;
5562
5360
  dir = parent;
@@ -5800,7 +5598,7 @@ function hasInternalTag(typeName, program, sourceFile) {
5800
5598
  }
5801
5599
 
5802
5600
  // src/builder/verification.ts
5803
- import * as path7 from "node:path";
5601
+ import * as path6 from "node:path";
5804
5602
  var BUILTIN_TYPES2 = new Set([
5805
5603
  "Array",
5806
5604
  "ArrayBuffer",
@@ -5889,8 +5687,8 @@ function isExternalType2(definedIn, baseDir) {
5889
5687
  return true;
5890
5688
  if (definedIn.includes("node_modules"))
5891
5689
  return true;
5892
- const normalizedDefined = path7.resolve(definedIn);
5893
- const normalizedBase = path7.resolve(baseDir);
5690
+ const normalizedDefined = path6.resolve(definedIn);
5691
+ const normalizedBase = path6.resolve(baseDir);
5894
5692
  return !normalizedDefined.startsWith(normalizedBase);
5895
5693
  }
5896
5694
  function shouldSkipDanglingRef(name) {
@@ -6056,7 +5854,12 @@ async function extract(options) {
6056
5854
  if (!sourceFile) {
6057
5855
  return {
6058
5856
  spec: createEmptySpec(entryFile, includeSchema, isDtsSource),
6059
- diagnostics: [{ message: `Entry file not found: ${entryFile}. Specify with: drift list src/index.ts`, severity: "error" }]
5857
+ diagnostics: [
5858
+ {
5859
+ message: `Entry file not found: ${entryFile}. Specify with: drift list src/index.ts`,
5860
+ severity: "error"
5861
+ }
5862
+ ]
6060
5863
  };
6061
5864
  }
6062
5865
  const typeChecker = program.getTypeChecker();
@@ -6064,7 +5867,12 @@ async function extract(options) {
6064
5867
  if (!moduleSymbol) {
6065
5868
  return {
6066
5869
  spec: createEmptySpec(entryFile, includeSchema, isDtsSource),
6067
- diagnostics: [{ message: `No exports found in ${entryFile}. Is this the right entry point?`, severity: "warning" }]
5870
+ diagnostics: [
5871
+ {
5872
+ message: `No exports found in ${entryFile}. Is this the right entry point?`,
5873
+ severity: "warning"
5874
+ }
5875
+ ]
6068
5876
  };
6069
5877
  }
6070
5878
  const exportedSymbols = typeChecker.getExportsOfModule(moduleSymbol);
@@ -6219,7 +6027,7 @@ async function extract(options) {
6219
6027
  }
6220
6028
  }
6221
6029
  const types = ctx.typeRegistry.getAll();
6222
- const projectBaseDir = baseDir ?? path8.dirname(entryFile);
6030
+ const projectBaseDir = baseDir ?? path7.dirname(entryFile);
6223
6031
  const definedTypes = new Set(types.map((t) => t.id));
6224
6032
  const forgottenExports = collectForgottenExports(exports, types, program, sourceFile, exportedIds, projectBaseDir, definedTypes);
6225
6033
  for (const forgotten of forgottenExports) {
@@ -6252,7 +6060,7 @@ async function extract(options) {
6252
6060
  }
6253
6061
  let runtimeMetadata;
6254
6062
  if (options.schemaExtraction === "hybrid") {
6255
- const projectBaseDir2 = baseDir || path8.dirname(entryFile);
6063
+ const projectBaseDir2 = baseDir || path7.dirname(entryFile);
6256
6064
  const runtimeResult = await extractStandardSchemasFromProject(entryFile, projectBaseDir2, {
6257
6065
  target: options.schemaTarget || "draft-2020-12",
6258
6066
  timeout: 15000
@@ -6541,7 +6349,7 @@ function createEmptySpec(entryFile, includeSchema, isDtsSource) {
6541
6349
  return {
6542
6350
  ...includeSchema ? { $schema: SCHEMA_URL } : {},
6543
6351
  openpkg: SCHEMA_VERSION,
6544
- meta: { name: path8.basename(entryFile, path8.extname(entryFile)) },
6352
+ meta: { name: path7.basename(entryFile, path7.extname(entryFile)) },
6545
6353
  exports: [],
6546
6354
  generation: {
6547
6355
  generator: "@openpkg-ts/sdk",
@@ -6557,7 +6365,7 @@ function findTypeInProgram(name, checker, program, sourceFile, symFlags) {
6557
6365
  const localSym = checker.resolveName(name, sourceFile, symFlags, false);
6558
6366
  if (localSym)
6559
6367
  return checker.getDeclaredTypeOfSymbol(localSym);
6560
- const entryDir = path8.dirname(sourceFile.fileName);
6368
+ const entryDir = path7.dirname(sourceFile.fileName);
6561
6369
  for (const sf of program.getSourceFiles()) {
6562
6370
  const fn = sf.fileName;
6563
6371
  if (fn.includes("/typescript/lib/lib.") || fn.includes("\\typescript\\lib\\lib."))
@@ -6573,22 +6381,22 @@ function findTypeInProgram(name, checker, program, sourceFile, symFlags) {
6573
6381
  return;
6574
6382
  }
6575
6383
  async function getPackageMeta(entryFile, baseDir) {
6576
- let dir = baseDir ?? path8.dirname(entryFile);
6577
- while (dir !== path8.dirname(dir)) {
6578
- const pkgPath = path8.join(dir, "package.json");
6384
+ let dir = baseDir ?? path7.dirname(entryFile);
6385
+ while (dir !== path7.dirname(dir)) {
6386
+ const pkgPath = path7.join(dir, "package.json");
6579
6387
  try {
6580
- if (fs7.existsSync(pkgPath)) {
6581
- const pkg = JSON.parse(fs7.readFileSync(pkgPath, "utf-8"));
6388
+ if (fs6.existsSync(pkgPath)) {
6389
+ const pkg = JSON.parse(fs6.readFileSync(pkgPath, "utf-8"));
6582
6390
  return {
6583
- name: pkg.name ?? path8.basename(dir),
6391
+ name: pkg.name ?? path7.basename(dir),
6584
6392
  version: pkg.version,
6585
6393
  description: pkg.description
6586
6394
  };
6587
6395
  }
6588
6396
  } catch {}
6589
- dir = path8.dirname(dir);
6397
+ dir = path7.dirname(dir);
6590
6398
  }
6591
- return { name: path8.basename(baseDir ?? path8.dirname(entryFile)) };
6399
+ return { name: path7.basename(baseDir ?? path7.dirname(entryFile)) };
6592
6400
  }
6593
6401
 
6594
6402
  // src/primitives/spec.ts
@@ -6615,8 +6423,6 @@ export {
6615
6423
  typeboxAdapter,
6616
6424
  toSearchIndexJSON,
6617
6425
  toSearchIndex,
6618
- toReactString,
6619
- toReact,
6620
6426
  toPagefindRecords,
6621
6427
  toNavigation,
6622
6428
  toMarkdown,