@doccov/sdk 0.3.6 → 0.3.7

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.
Files changed (2) hide show
  1. package/dist/index.js +142 -97
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1299,101 +1299,6 @@ var resolvedTypeScriptModule = (() => {
1299
1299
  })();
1300
1300
  var ts2 = resolvedTypeScriptModule;
1301
1301
 
1302
- // src/analysis/context.ts
1303
- import * as path2 from "node:path";
1304
-
1305
- // src/options.ts
1306
- var DEFAULT_OPTIONS = {
1307
- includePrivate: false,
1308
- followImports: true
1309
- };
1310
- function normalizeDocCovOptions(options = {}) {
1311
- return {
1312
- ...DEFAULT_OPTIONS,
1313
- ...options
1314
- };
1315
- }
1316
- var normalizeOpenPkgOptions = normalizeDocCovOptions;
1317
-
1318
- // src/analysis/program.ts
1319
- import * as path from "node:path";
1320
- var DEFAULT_COMPILER_OPTIONS = {
1321
- target: ts2.ScriptTarget.Latest,
1322
- module: ts2.ModuleKind.CommonJS,
1323
- lib: ["lib.es2021.d.ts"],
1324
- declaration: true,
1325
- moduleResolution: ts2.ModuleResolutionKind.NodeJs
1326
- };
1327
- function createProgram({
1328
- entryFile,
1329
- baseDir = path.dirname(entryFile),
1330
- content
1331
- }) {
1332
- const configPath = ts2.findConfigFile(baseDir, ts2.sys.fileExists, "tsconfig.json");
1333
- let compilerOptions = { ...DEFAULT_COMPILER_OPTIONS };
1334
- if (configPath) {
1335
- const configFile = ts2.readConfigFile(configPath, ts2.sys.readFile);
1336
- const parsedConfig = ts2.parseJsonConfigFileContent(configFile.config, ts2.sys, path.dirname(configPath));
1337
- compilerOptions = { ...compilerOptions, ...parsedConfig.options };
1338
- }
1339
- const allowJsVal = compilerOptions.allowJs;
1340
- if (typeof allowJsVal === "boolean" && allowJsVal) {
1341
- compilerOptions = { ...compilerOptions, allowJs: false, checkJs: false };
1342
- }
1343
- const compilerHost = ts2.createCompilerHost(compilerOptions, true);
1344
- let inMemorySource;
1345
- if (content !== undefined) {
1346
- inMemorySource = ts2.createSourceFile(entryFile, content, ts2.ScriptTarget.Latest, true, ts2.ScriptKind.TS);
1347
- const originalGetSourceFile = compilerHost.getSourceFile.bind(compilerHost);
1348
- compilerHost.getSourceFile = (fileName, languageVersion, onError, shouldCreateNewSourceFile) => {
1349
- if (fileName === entryFile) {
1350
- return inMemorySource;
1351
- }
1352
- return originalGetSourceFile(fileName, languageVersion, onError, shouldCreateNewSourceFile);
1353
- };
1354
- }
1355
- const program = ts2.createProgram([entryFile], compilerOptions, compilerHost);
1356
- const sourceFile = inMemorySource ?? program.getSourceFile(entryFile);
1357
- return {
1358
- program,
1359
- compilerHost,
1360
- compilerOptions,
1361
- sourceFile,
1362
- configPath
1363
- };
1364
- }
1365
-
1366
- // src/analysis/context.ts
1367
- function createAnalysisContext({
1368
- entryFile,
1369
- packageDir,
1370
- content,
1371
- options
1372
- }) {
1373
- const baseDir = packageDir ?? path2.dirname(entryFile);
1374
- const normalizedOptions = normalizeOpenPkgOptions(options);
1375
- const programResult = createProgram({ entryFile, baseDir, content });
1376
- if (!programResult.sourceFile) {
1377
- throw new Error(`Could not load ${entryFile}`);
1378
- }
1379
- return {
1380
- entryFile,
1381
- baseDir,
1382
- program: programResult.program,
1383
- checker: programResult.program.getTypeChecker(),
1384
- sourceFile: programResult.sourceFile,
1385
- compilerOptions: programResult.compilerOptions,
1386
- compilerHost: programResult.compilerHost,
1387
- options: normalizedOptions,
1388
- configPath: programResult.configPath
1389
- };
1390
- }
1391
-
1392
- // src/analysis/spec-builder.ts
1393
- import * as fs from "node:fs";
1394
- import * as path3 from "node:path";
1395
- import { SCHEMA_URL } from "@openpkg-ts/spec";
1396
-
1397
1302
  // src/utils/type-utils.ts
1398
1303
  function getTypeId(type, typeChecker) {
1399
1304
  const internalId = type.id;
@@ -1515,6 +1420,30 @@ function collectReferencedTypesFromNode(node, typeChecker, referencedTypes) {
1515
1420
  });
1516
1421
  }
1517
1422
  function isBuiltInType(name) {
1423
+ if (name.length === 1 && /^[A-Z]$/.test(name)) {
1424
+ return true;
1425
+ }
1426
+ if (/^T[A-Z][a-zA-Z]*$/.test(name)) {
1427
+ return true;
1428
+ }
1429
+ const libraryInternals = [
1430
+ "UnionStatic",
1431
+ "IntersectStatic",
1432
+ "ObjectStatic",
1433
+ "ArrayStatic",
1434
+ "StaticDecode",
1435
+ "StaticEncode",
1436
+ "ZodType",
1437
+ "ZodObject",
1438
+ "ZodString",
1439
+ "ZodNumber",
1440
+ "ZodArray",
1441
+ "ZodUnion",
1442
+ "ZodIntersection"
1443
+ ];
1444
+ if (libraryInternals.includes(name)) {
1445
+ return true;
1446
+ }
1518
1447
  const builtIns = [
1519
1448
  "string",
1520
1449
  "number",
@@ -1523,6 +1452,8 @@ function isBuiltInType(name) {
1523
1452
  "symbol",
1524
1453
  "undefined",
1525
1454
  "null",
1455
+ "true",
1456
+ "false",
1526
1457
  "any",
1527
1458
  "unknown",
1528
1459
  "never",
@@ -1566,11 +1497,125 @@ function isBuiltInType(name) {
1566
1497
  "Proxy",
1567
1498
  "Intl",
1568
1499
  "globalThis",
1500
+ "Record",
1501
+ "Partial",
1502
+ "Required",
1503
+ "Readonly",
1504
+ "Pick",
1505
+ "Omit",
1506
+ "Exclude",
1507
+ "Extract",
1508
+ "NonNullable",
1509
+ "ReturnType",
1510
+ "Parameters",
1511
+ "InstanceType",
1512
+ "ConstructorParameters",
1513
+ "Awaited",
1514
+ "ThisType",
1515
+ "Uppercase",
1516
+ "Lowercase",
1517
+ "Capitalize",
1518
+ "Uncapitalize",
1569
1519
  "__type"
1570
1520
  ];
1571
1521
  return builtIns.includes(name);
1572
1522
  }
1573
1523
 
1524
+ // src/analysis/context.ts
1525
+ import * as path2 from "node:path";
1526
+
1527
+ // src/options.ts
1528
+ var DEFAULT_OPTIONS = {
1529
+ includePrivate: false,
1530
+ followImports: true
1531
+ };
1532
+ function normalizeDocCovOptions(options = {}) {
1533
+ return {
1534
+ ...DEFAULT_OPTIONS,
1535
+ ...options
1536
+ };
1537
+ }
1538
+ var normalizeOpenPkgOptions = normalizeDocCovOptions;
1539
+
1540
+ // src/analysis/program.ts
1541
+ import * as path from "node:path";
1542
+ var DEFAULT_COMPILER_OPTIONS = {
1543
+ target: ts2.ScriptTarget.Latest,
1544
+ module: ts2.ModuleKind.CommonJS,
1545
+ lib: ["lib.es2021.d.ts"],
1546
+ declaration: true,
1547
+ moduleResolution: ts2.ModuleResolutionKind.NodeJs
1548
+ };
1549
+ function createProgram({
1550
+ entryFile,
1551
+ baseDir = path.dirname(entryFile),
1552
+ content
1553
+ }) {
1554
+ const configPath = ts2.findConfigFile(baseDir, ts2.sys.fileExists, "tsconfig.json");
1555
+ let compilerOptions = { ...DEFAULT_COMPILER_OPTIONS };
1556
+ if (configPath) {
1557
+ const configFile = ts2.readConfigFile(configPath, ts2.sys.readFile);
1558
+ const parsedConfig = ts2.parseJsonConfigFileContent(configFile.config, ts2.sys, path.dirname(configPath));
1559
+ compilerOptions = { ...compilerOptions, ...parsedConfig.options };
1560
+ }
1561
+ const allowJsVal = compilerOptions.allowJs;
1562
+ if (typeof allowJsVal === "boolean" && allowJsVal) {
1563
+ compilerOptions = { ...compilerOptions, allowJs: false, checkJs: false };
1564
+ }
1565
+ const compilerHost = ts2.createCompilerHost(compilerOptions, true);
1566
+ let inMemorySource;
1567
+ if (content !== undefined) {
1568
+ inMemorySource = ts2.createSourceFile(entryFile, content, ts2.ScriptTarget.Latest, true, ts2.ScriptKind.TS);
1569
+ const originalGetSourceFile = compilerHost.getSourceFile.bind(compilerHost);
1570
+ compilerHost.getSourceFile = (fileName, languageVersion, onError, shouldCreateNewSourceFile) => {
1571
+ if (fileName === entryFile) {
1572
+ return inMemorySource;
1573
+ }
1574
+ return originalGetSourceFile(fileName, languageVersion, onError, shouldCreateNewSourceFile);
1575
+ };
1576
+ }
1577
+ const program = ts2.createProgram([entryFile], compilerOptions, compilerHost);
1578
+ const sourceFile = inMemorySource ?? program.getSourceFile(entryFile);
1579
+ return {
1580
+ program,
1581
+ compilerHost,
1582
+ compilerOptions,
1583
+ sourceFile,
1584
+ configPath
1585
+ };
1586
+ }
1587
+
1588
+ // src/analysis/context.ts
1589
+ function createAnalysisContext({
1590
+ entryFile,
1591
+ packageDir,
1592
+ content,
1593
+ options
1594
+ }) {
1595
+ const baseDir = packageDir ?? path2.dirname(entryFile);
1596
+ const normalizedOptions = normalizeOpenPkgOptions(options);
1597
+ const programResult = createProgram({ entryFile, baseDir, content });
1598
+ if (!programResult.sourceFile) {
1599
+ throw new Error(`Could not load ${entryFile}`);
1600
+ }
1601
+ return {
1602
+ entryFile,
1603
+ baseDir,
1604
+ program: programResult.program,
1605
+ checker: programResult.program.getTypeChecker(),
1606
+ sourceFile: programResult.sourceFile,
1607
+ compilerOptions: programResult.compilerOptions,
1608
+ compilerHost: programResult.compilerHost,
1609
+ options: normalizedOptions,
1610
+ configPath: programResult.configPath
1611
+ };
1612
+ }
1613
+
1614
+ // src/analysis/spec-builder.ts
1615
+ import * as fs from "node:fs";
1616
+ import * as path3 from "node:path";
1617
+ import { SCHEMA_URL } from "@openpkg-ts/spec";
1618
+
1574
1619
  // src/utils/parameter-utils.ts
1575
1620
  var BUILTIN_TYPE_SCHEMAS = {
1576
1621
  Date: { type: "string", format: "date-time" },
@@ -3705,10 +3750,10 @@ function collectDanglingRefs(spec) {
3705
3750
  const referencedTypes = new Set;
3706
3751
  collectAllRefs(spec.exports, referencedTypes);
3707
3752
  collectAllRefs(spec.types, referencedTypes);
3708
- return Array.from(referencedTypes).filter((ref) => !definedTypes.has(ref));
3753
+ return Array.from(referencedTypes).filter((ref) => !definedTypes.has(ref) && !isBuiltInType(ref));
3709
3754
  }
3710
3755
  function collectExternalTypes(spec) {
3711
- return (spec.types ?? []).filter((t) => t.kind === "external").map((t) => t.id);
3756
+ return (spec.types ?? []).filter((t) => t.kind === "external").map((t) => t.id).filter((id) => !isBuiltInType(id));
3712
3757
  }
3713
3758
  function hasExternalImports(sourceFile) {
3714
3759
  let found = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doccov/sdk",
3
- "version": "0.3.6",
3
+ "version": "0.3.7",
4
4
  "description": "DocCov SDK - Documentation coverage and drift detection for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",