@openpkg-ts/extract 0.16.1 → 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-bgnmsw8f.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);
@@ -1562,6 +1562,20 @@ var BUILTIN_TYPES2 = new Set([
1562
1562
  "InstanceType",
1563
1563
  "ThisType"
1564
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
+ }
1565
1579
  function shouldSkipDanglingRef(name) {
1566
1580
  if (name.startsWith("__"))
1567
1581
  return true;
@@ -1581,7 +1595,9 @@ async function extract(options) {
1581
1595
  maxTypeDepth,
1582
1596
  maxExternalTypeDepth,
1583
1597
  resolveExternalTypes,
1584
- includeSchema
1598
+ includeSchema,
1599
+ only,
1600
+ ignore
1585
1601
  } = options;
1586
1602
  const diagnostics = [];
1587
1603
  const exports = [];
@@ -1614,6 +1630,8 @@ async function extract(options) {
1614
1630
  ctx.exportedIds = exportedIds;
1615
1631
  for (const symbol of exportedSymbols) {
1616
1632
  const exportName = symbol.getName();
1633
+ if (!shouldIncludeExport(exportName, only, ignore))
1634
+ continue;
1617
1635
  try {
1618
1636
  const { declaration, targetSymbol } = resolveExportTarget(symbol, typeChecker);
1619
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-bgnmsw8f.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.1",
3
+ "version": "0.17.0",
4
4
  "description": "TypeScript export extraction to OpenPkg spec",
5
5
  "keywords": [
6
6
  "openpkg",