@openpkg-ts/extract 0.16.0 → 0.17.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/bin/tspec.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  extract
4
- } from "../shared/chunk-2v40ecks.js";
4
+ } from "../shared/chunk-6p1dq6jb.js";
5
5
 
6
6
  // src/cli/spec.ts
7
7
  import * as fs from "node:fs";
@@ -1488,7 +1488,7 @@ function summary(options) {
1488
1488
  import { normalize, validateSpec } from "@openpkg-ts/spec";
1489
1489
  import { Command } from "commander";
1490
1490
  function createProgram() {
1491
- const program = new Command("tspec").description("Extract TypeScript package API to OpenPkg spec").argument("[entry]", "Entry point file").option("-o, --output <file>", "Output file", "openpkg.json").option("--max-depth <n>", "Max type depth (default: 4)").option("--skip-resolve", "Skip external type resolution").option("--runtime", "Enable Standard Schema runtime extraction").option("-v, --verbose", "Show detailed output").action(async (entry, options) => {
1491
+ const program = new Command("tspec").description("Extract TypeScript package API to OpenPkg spec").argument("[entry]", "Entry point file").option("-o, --output <file>", "Output file", "openpkg.json").option("--max-depth <n>", "Max type depth (default: 4)").option("--skip-resolve", "Skip external type resolution").option("--runtime", "Enable Standard Schema runtime extraction").option("--only <exports>", "Only extract these exports (comma-separated, supports * wildcards)").option("--ignore <exports>", "Ignore these exports (comma-separated, supports * wildcards)").option("-v, --verbose", "Show detailed output").action(async (entry, options) => {
1492
1492
  let entryFile;
1493
1493
  let fromDts = false;
1494
1494
  if (entry) {
@@ -1513,7 +1513,9 @@ function createProgram() {
1513
1513
  entryFile: path.resolve(entryFile),
1514
1514
  ...options.maxDepth ? { maxTypeDepth: parseInt(options.maxDepth) } : {},
1515
1515
  resolveExternalTypes: !options.skipResolve,
1516
- schemaExtraction: options.runtime ? "hybrid" : "static"
1516
+ schemaExtraction: options.runtime ? "hybrid" : "static",
1517
+ ...options.only ? { only: options.only.split(",").map((s) => s.trim()) } : {},
1518
+ ...options.ignore ? { ignore: options.ignore.split(",").map((s) => s.trim()) } : {}
1517
1519
  });
1518
1520
  const normalized = normalize(result.spec);
1519
1521
  const validation = validateSpec(normalized);
@@ -661,12 +661,33 @@ function parseExamplesFromTags(tags) {
661
661
  }
662
662
  return examples;
663
663
  }
664
+ function stripParamSeparator(text) {
665
+ if (!text)
666
+ return;
667
+ const stripped = text.replace(/^-\s*/, "").trim();
668
+ return stripped || undefined;
669
+ }
670
+ function stripTypeParamSeparator(text) {
671
+ if (!text)
672
+ return;
673
+ const match = text.match(/^\w+\s+-\s*(.*)$/s);
674
+ if (match) {
675
+ return match[1].trim() || undefined;
676
+ }
677
+ return text.trim() || undefined;
678
+ }
664
679
  function getJSDocComment(node) {
665
680
  const jsDocTags = ts3.getJSDocTags(node);
666
- const tags = jsDocTags.map((tag) => ({
667
- name: tag.tagName.text,
668
- text: typeof tag.comment === "string" ? tag.comment : ts3.getTextOfJSDocComment(tag.comment) ?? ""
669
- }));
681
+ const tags = jsDocTags.map((tag) => {
682
+ const rawText = typeof tag.comment === "string" ? tag.comment : ts3.getTextOfJSDocComment(tag.comment) ?? "";
683
+ let text = rawText;
684
+ if (tag.tagName.text === "param") {
685
+ text = stripParamSeparator(rawText) ?? "";
686
+ } else if (tag.tagName.text === "typeParam") {
687
+ text = stripTypeParamSeparator(rawText) ?? "";
688
+ }
689
+ return { name: tag.tagName.text, text };
690
+ });
670
691
  const jsDocComments = node.jsDoc;
671
692
  let description;
672
693
  if (jsDocComments && jsDocComments.length > 0) {
@@ -694,7 +715,7 @@ function getParamDescription(propertyName, jsdocTags, inferredAlias) {
694
715
  const isMatch = tagParamName === propertyName || inferredAlias && tagParamName === `${inferredAlias}.${propertyName}` || tagParamName.endsWith(`.${propertyName}`);
695
716
  if (isMatch) {
696
717
  const comment = typeof tag.comment === "string" ? tag.comment : ts3.getTextOfJSDocComment(tag.comment);
697
- return comment?.trim() || undefined;
718
+ return stripParamSeparator(comment);
698
719
  }
699
720
  }
700
721
  return;
@@ -1541,6 +1562,20 @@ var BUILTIN_TYPES2 = new Set([
1541
1562
  "InstanceType",
1542
1563
  "ThisType"
1543
1564
  ]);
1565
+ function matchesPattern(name, pattern) {
1566
+ if (!pattern.includes("*"))
1567
+ return name === pattern;
1568
+ const regex = new RegExp("^" + pattern.replace(/\*/g, ".*") + "$");
1569
+ return regex.test(name);
1570
+ }
1571
+ function shouldIncludeExport(name, only, ignore) {
1572
+ if (ignore?.some((p) => matchesPattern(name, p)))
1573
+ return false;
1574
+ if (only && only.length > 0) {
1575
+ return only.some((p) => matchesPattern(name, p));
1576
+ }
1577
+ return true;
1578
+ }
1544
1579
  function shouldSkipDanglingRef(name) {
1545
1580
  if (name.startsWith("__"))
1546
1581
  return true;
@@ -1560,7 +1595,9 @@ async function extract(options) {
1560
1595
  maxTypeDepth,
1561
1596
  maxExternalTypeDepth,
1562
1597
  resolveExternalTypes,
1563
- includeSchema
1598
+ includeSchema,
1599
+ only,
1600
+ ignore
1564
1601
  } = options;
1565
1602
  const diagnostics = [];
1566
1603
  const exports = [];
@@ -1593,6 +1630,8 @@ async function extract(options) {
1593
1630
  ctx.exportedIds = exportedIds;
1594
1631
  for (const symbol of exportedSymbols) {
1595
1632
  const exportName = symbol.getName();
1633
+ if (!shouldIncludeExport(exportName, only, ignore))
1634
+ continue;
1596
1635
  try {
1597
1636
  const { declaration, targetSymbol } = resolveExportTarget(symbol, typeChecker);
1598
1637
  if (!declaration)
@@ -75,6 +75,10 @@ interface ExtractOptions {
75
75
  schemaExtraction?: "static" | "hybrid";
76
76
  /** Include $schema URL in output */
77
77
  includeSchema?: boolean;
78
+ /** Only extract these exports (supports * wildcards) */
79
+ only?: string[];
80
+ /** Ignore these exports (supports * wildcards) */
81
+ ignore?: string[];
78
82
  }
79
83
  interface ExtractResult {
80
84
  spec: OpenPkg;
package/dist/src/index.js CHANGED
@@ -26,7 +26,7 @@ import {
26
26
  serializeTypeAlias,
27
27
  serializeVariable,
28
28
  withDescription
29
- } from "../shared/chunk-2v40ecks.js";
29
+ } from "../shared/chunk-6p1dq6jb.js";
30
30
  // src/schema/registry.ts
31
31
  function isTypeReference(type) {
32
32
  return !!(type.flags & 524288 && type.objectFlags && type.objectFlags & 4);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpkg-ts/extract",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "TypeScript export extraction to OpenPkg spec",
5
5
  "keywords": [
6
6
  "openpkg",