@doccov/sdk 0.6.0 → 0.7.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.d.ts +633 -8
- package/dist/index.js +564 -41
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -314,13 +314,15 @@ declare function readPackageJson(fs: FileSystem, dir: string): Promise<PackageJs
|
|
|
314
314
|
*
|
|
315
315
|
* @example
|
|
316
316
|
* ```typescript
|
|
317
|
+
* import { NodeFileSystem, analyzeProject } from '@doccov/sdk';
|
|
318
|
+
*
|
|
317
319
|
* // Single package
|
|
318
|
-
* const
|
|
319
|
-
* const
|
|
320
|
+
* const singleFs = new NodeFileSystem('/path/to/package');
|
|
321
|
+
* const singleProject = await analyzeProject(singleFs);
|
|
320
322
|
*
|
|
321
323
|
* // Monorepo with target package
|
|
322
|
-
* const
|
|
323
|
-
* const
|
|
324
|
+
* const monoFs = new NodeFileSystem('/path/to/monorepo');
|
|
325
|
+
* const monoProject = await analyzeProject(monoFs, { targetPackage: '@scope/core' });
|
|
324
326
|
* ```
|
|
325
327
|
*/
|
|
326
328
|
declare function analyzeProject2(fs: FileSystem, options?: AnalyzeProjectOptions): Promise<ProjectInfo>;
|
|
@@ -337,6 +339,141 @@ interface FilterOptions {
|
|
|
337
339
|
include?: string[];
|
|
338
340
|
exclude?: string[];
|
|
339
341
|
}
|
|
342
|
+
/**
|
|
343
|
+
* Configuration types for DocCov.
|
|
344
|
+
* These types are shared between CLI and API.
|
|
345
|
+
*/
|
|
346
|
+
/**
|
|
347
|
+
* Documentation configuration options.
|
|
348
|
+
*/
|
|
349
|
+
interface DocsConfig {
|
|
350
|
+
/** Glob patterns for markdown docs to include */
|
|
351
|
+
include?: string[];
|
|
352
|
+
/** Glob patterns for markdown docs to exclude */
|
|
353
|
+
exclude?: string[];
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Check command configuration options.
|
|
357
|
+
*/
|
|
358
|
+
interface CheckConfig {
|
|
359
|
+
/** Enable lint checks (default: true) */
|
|
360
|
+
lint?: boolean;
|
|
361
|
+
/** Enable typecheck for examples (default: true) */
|
|
362
|
+
typecheck?: boolean;
|
|
363
|
+
/** Enable runtime execution of examples (default: false) */
|
|
364
|
+
exec?: boolean;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Lint severity level.
|
|
368
|
+
*/
|
|
369
|
+
type LintSeverity = "error" | "warn" | "off";
|
|
370
|
+
/**
|
|
371
|
+
* Lint rules configuration.
|
|
372
|
+
*/
|
|
373
|
+
interface LintRulesConfig {
|
|
374
|
+
/** Rule severity overrides */
|
|
375
|
+
rules?: Record<string, LintSeverity>;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Normalized DocCov configuration.
|
|
379
|
+
* This is the parsed/normalized form used by commands.
|
|
380
|
+
*/
|
|
381
|
+
interface DocCovConfig {
|
|
382
|
+
/** Export include patterns */
|
|
383
|
+
include?: string[];
|
|
384
|
+
/** Export exclude patterns */
|
|
385
|
+
exclude?: string[];
|
|
386
|
+
/** Plugins (future) */
|
|
387
|
+
plugins?: unknown[];
|
|
388
|
+
/** Documentation configuration */
|
|
389
|
+
docs?: DocsConfig;
|
|
390
|
+
/** Check command configuration */
|
|
391
|
+
check?: CheckConfig;
|
|
392
|
+
/** Lint configuration */
|
|
393
|
+
lint?: LintRulesConfig;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Define a DocCov configuration.
|
|
397
|
+
* Helper function for type-safe configuration in doccov.config.ts.
|
|
398
|
+
*
|
|
399
|
+
* @param config - Configuration object
|
|
400
|
+
* @returns The configuration object (for type inference)
|
|
401
|
+
*
|
|
402
|
+
* @example
|
|
403
|
+
* ```typescript
|
|
404
|
+
* // doccov.config.ts
|
|
405
|
+
* import { defineConfig } from '@doccov/sdk';
|
|
406
|
+
*
|
|
407
|
+
* defineConfig({
|
|
408
|
+
* include: ['MyClass', 'myFunction'],
|
|
409
|
+
* exclude: ['internal*'],
|
|
410
|
+
* docs: {
|
|
411
|
+
* include: ['docs/**\/*.md'],
|
|
412
|
+
* },
|
|
413
|
+
* lint: {
|
|
414
|
+
* rules: {
|
|
415
|
+
* 'require-description': 'error',
|
|
416
|
+
* 'require-example': 'warn',
|
|
417
|
+
* },
|
|
418
|
+
* },
|
|
419
|
+
* });
|
|
420
|
+
* ```
|
|
421
|
+
*/
|
|
422
|
+
declare function defineConfig(config: DocCovConfig): DocCovConfig;
|
|
423
|
+
/**
|
|
424
|
+
* Source of filter options.
|
|
425
|
+
*/
|
|
426
|
+
type FilterSource = "config" | "override" | "combined";
|
|
427
|
+
/**
|
|
428
|
+
* Resolved filter options after merging config and overrides.
|
|
429
|
+
*/
|
|
430
|
+
interface ResolvedFilters {
|
|
431
|
+
/** Include patterns */
|
|
432
|
+
include?: string[];
|
|
433
|
+
/** Exclude patterns */
|
|
434
|
+
exclude?: string[];
|
|
435
|
+
/** Source of the filters */
|
|
436
|
+
source?: FilterSource;
|
|
437
|
+
/** Whether filters were applied from config */
|
|
438
|
+
fromConfig: boolean;
|
|
439
|
+
/** Whether filters were applied from overrides */
|
|
440
|
+
fromOverride: boolean;
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Parse a comma-separated list flag into an array.
|
|
444
|
+
*
|
|
445
|
+
* @param value - String or string array from CLI flag
|
|
446
|
+
* @returns Parsed array, or undefined if empty
|
|
447
|
+
*
|
|
448
|
+
* @example
|
|
449
|
+
* ```typescript
|
|
450
|
+
* parseListFlag('a,b,c'); // ['a', 'b', 'c']
|
|
451
|
+
* parseListFlag(['a,b', 'c']); // ['a', 'b', 'c']
|
|
452
|
+
* parseListFlag(undefined); // undefined
|
|
453
|
+
* ```
|
|
454
|
+
*/
|
|
455
|
+
declare function parseListFlag(value?: string | string[]): string[] | undefined;
|
|
456
|
+
/**
|
|
457
|
+
* Merge filter options from config and CLI/API overrides.
|
|
458
|
+
*
|
|
459
|
+
* Merge behavior:
|
|
460
|
+
* - Include: CLI values intersect with config values (narrowing)
|
|
461
|
+
* - Exclude: CLI values are added to config values (expanding)
|
|
462
|
+
*
|
|
463
|
+
* @param config - Configuration (from doccov.config.ts)
|
|
464
|
+
* @param overrides - Override filters (from CLI flags or API params)
|
|
465
|
+
* @returns Merged filter options
|
|
466
|
+
*
|
|
467
|
+
* @example
|
|
468
|
+
* ```typescript
|
|
469
|
+
* const config = { include: ['A', 'B', 'C'] };
|
|
470
|
+
* const overrides = { include: ['B', 'C', 'D'] };
|
|
471
|
+
*
|
|
472
|
+
* const resolved = mergeFilters(config, overrides);
|
|
473
|
+
* // resolved.include = ['B', 'C'] (intersection)
|
|
474
|
+
* ```
|
|
475
|
+
*/
|
|
476
|
+
declare function mergeFilters(config: DocCovConfig | null, overrides: FilterOptions): ResolvedFilters;
|
|
340
477
|
import { SpecDocDrift as SpecDocDrift2, SpecExport as SpecExport2 } from "@openpkg-ts/spec";
|
|
341
478
|
import * as TS from "typescript";
|
|
342
479
|
/**
|
|
@@ -474,7 +611,7 @@ declare function categorizeDrifts(drifts: SpecDocDrift2[]): {
|
|
|
474
611
|
};
|
|
475
612
|
import { SpecExport as SpecExport4 } from "@openpkg-ts/spec";
|
|
476
613
|
import { SpecExport as SpecExport3 } from "@openpkg-ts/spec";
|
|
477
|
-
type
|
|
614
|
+
type LintSeverity2 = "error" | "warn" | "off";
|
|
478
615
|
interface LintViolation {
|
|
479
616
|
rule: string;
|
|
480
617
|
severity: "error" | "warn";
|
|
@@ -484,12 +621,12 @@ interface LintViolation {
|
|
|
484
621
|
}
|
|
485
622
|
interface LintRule {
|
|
486
623
|
name: string;
|
|
487
|
-
defaultSeverity:
|
|
624
|
+
defaultSeverity: LintSeverity2;
|
|
488
625
|
check(exp: SpecExport3, rawJSDoc?: string): LintViolation[];
|
|
489
626
|
fix?(exp: SpecExport3, rawJSDoc?: string): JSDocPatch | null;
|
|
490
627
|
}
|
|
491
628
|
interface LintConfig {
|
|
492
|
-
rules: Record<string,
|
|
629
|
+
rules: Record<string, LintSeverity2>;
|
|
493
630
|
}
|
|
494
631
|
interface LintResult {
|
|
495
632
|
violations: LintViolation[];
|
|
@@ -702,6 +839,10 @@ interface DiffWithDocsOptions {
|
|
|
702
839
|
* @example
|
|
703
840
|
* ```ts
|
|
704
841
|
* import { diffSpecWithDocs, parseMarkdownFiles } from '@doccov/sdk';
|
|
842
|
+
* import type { OpenPkg } from '@openpkg-ts/spec';
|
|
843
|
+
*
|
|
844
|
+
* const oldSpec: OpenPkg = { openpkg: '0.2.0', meta: { name: 'my-pkg' }, exports: [] };
|
|
845
|
+
* const newSpec: OpenPkg = { openpkg: '0.2.1', meta: { name: 'my-pkg' }, exports: [] };
|
|
705
846
|
*
|
|
706
847
|
* const markdownFiles = parseMarkdownFiles([
|
|
707
848
|
* { path: 'docs/guide.md', content: '...' },
|
|
@@ -846,4 +987,488 @@ declare function typecheckExample(example: string, packagePath: string, options?
|
|
|
846
987
|
* Type-check multiple examples
|
|
847
988
|
*/
|
|
848
989
|
declare function typecheckExamples(examples: string[], packagePath: string, options?: TypecheckOptions): TypecheckResult;
|
|
849
|
-
|
|
990
|
+
/**
|
|
991
|
+
* Scan types for CLI, API, and SDK consumers.
|
|
992
|
+
* Single source of truth for scan-related interfaces.
|
|
993
|
+
*/
|
|
994
|
+
/**
|
|
995
|
+
* Result of scanning a repository for documentation coverage.
|
|
996
|
+
* Used by CLI scan command, API endpoints, and SDK consumers.
|
|
997
|
+
*/
|
|
998
|
+
interface ScanResult {
|
|
999
|
+
/** GitHub repository owner */
|
|
1000
|
+
owner: string;
|
|
1001
|
+
/** GitHub repository name */
|
|
1002
|
+
repo: string;
|
|
1003
|
+
/** Git ref (branch/tag) that was scanned */
|
|
1004
|
+
ref: string;
|
|
1005
|
+
/** Package name if scanning a monorepo package */
|
|
1006
|
+
packageName?: string;
|
|
1007
|
+
/** Overall documentation coverage percentage (0-100) */
|
|
1008
|
+
coverage: number;
|
|
1009
|
+
/** Number of public exports analyzed */
|
|
1010
|
+
exportCount: number;
|
|
1011
|
+
/** Number of types analyzed */
|
|
1012
|
+
typeCount: number;
|
|
1013
|
+
/** Number of documentation drift issues found */
|
|
1014
|
+
driftCount: number;
|
|
1015
|
+
/** Names of exports missing documentation */
|
|
1016
|
+
undocumented: string[];
|
|
1017
|
+
/** Drift issues found during analysis */
|
|
1018
|
+
drift: DriftIssue[];
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* A documentation drift issue.
|
|
1022
|
+
*/
|
|
1023
|
+
interface DriftIssue {
|
|
1024
|
+
/** Name of the with drift */
|
|
1025
|
+
export: string;
|
|
1026
|
+
/** Type of drift (e.g., 'param-mismatch', 'return-type') */
|
|
1027
|
+
type: string;
|
|
1028
|
+
/** Human-readable description of the issue */
|
|
1029
|
+
issue: string;
|
|
1030
|
+
/** Optional suggestion for fixing the issue */
|
|
1031
|
+
suggestion?: string;
|
|
1032
|
+
}
|
|
1033
|
+
/**
|
|
1034
|
+
* Options for running a scan.
|
|
1035
|
+
*/
|
|
1036
|
+
interface ScanOptions {
|
|
1037
|
+
/** GitHub URL or owner/repo shorthand */
|
|
1038
|
+
url: string;
|
|
1039
|
+
/** Git ref (branch/tag) to scan */
|
|
1040
|
+
ref?: string;
|
|
1041
|
+
/** Target package name for monorepos */
|
|
1042
|
+
package?: string;
|
|
1043
|
+
/** Skip dependency installation */
|
|
1044
|
+
skipInstall?: boolean;
|
|
1045
|
+
/** Skip external type resolution */
|
|
1046
|
+
skipResolve?: boolean;
|
|
1047
|
+
}
|
|
1048
|
+
/**
|
|
1049
|
+
* Stages of the scan pipeline.
|
|
1050
|
+
*/
|
|
1051
|
+
type ProgressStage = "cloning" | "detecting" | "installing" | "building" | "analyzing" | "complete";
|
|
1052
|
+
/**
|
|
1053
|
+
* Progress event emitted during scan operations.
|
|
1054
|
+
*/
|
|
1055
|
+
interface ProgressEvent {
|
|
1056
|
+
/** Current stage of the scan */
|
|
1057
|
+
stage: ProgressStage;
|
|
1058
|
+
/** Human-readable message */
|
|
1059
|
+
message: string;
|
|
1060
|
+
/** Progress percentage (0-100), if known */
|
|
1061
|
+
progress?: number;
|
|
1062
|
+
}
|
|
1063
|
+
/**
|
|
1064
|
+
* Callback for receiving progress events.
|
|
1065
|
+
*/
|
|
1066
|
+
type ProgressCallback = (event: ProgressEvent) => void;
|
|
1067
|
+
import { OpenPkg as OpenPkg5 } from "@openpkg-ts/spec";
|
|
1068
|
+
/**
|
|
1069
|
+
* Summary of a spec's documentation coverage.
|
|
1070
|
+
* Simpler than full ReportStats - focused on scan output.
|
|
1071
|
+
*/
|
|
1072
|
+
interface SpecSummary {
|
|
1073
|
+
/** Overall coverage percentage */
|
|
1074
|
+
coverage: number;
|
|
1075
|
+
/** Number of exports */
|
|
1076
|
+
exportCount: number;
|
|
1077
|
+
/** Number of types */
|
|
1078
|
+
typeCount: number;
|
|
1079
|
+
/** Number of drift issues */
|
|
1080
|
+
driftCount: number;
|
|
1081
|
+
/** Names of undocumented or partially documented exports */
|
|
1082
|
+
undocumented: string[];
|
|
1083
|
+
/** Drift issues */
|
|
1084
|
+
drift: DriftIssue[];
|
|
1085
|
+
}
|
|
1086
|
+
/**
|
|
1087
|
+
* Extract a summary from an OpenPkg spec.
|
|
1088
|
+
*
|
|
1089
|
+
* This consolidates the logic previously duplicated in:
|
|
1090
|
+
* - CLI scan.ts (drift collection)
|
|
1091
|
+
* - CLI reports/stats.ts (computeStats)
|
|
1092
|
+
* - API scan-stream.ts (inline extraction script)
|
|
1093
|
+
*
|
|
1094
|
+
* @param spec - The OpenPkg spec to summarize
|
|
1095
|
+
* @returns Summary of documentation coverage
|
|
1096
|
+
*
|
|
1097
|
+
* @example
|
|
1098
|
+
* ```typescript
|
|
1099
|
+
* import { extractSpecSummary } from '@doccov/sdk';
|
|
1100
|
+
*
|
|
1101
|
+
* const summary = extractSpecSummary(spec);
|
|
1102
|
+
* console.log(`Coverage: ${summary.coverage}%`);
|
|
1103
|
+
* console.log(`Undocumented: ${summary.undocumented.length}`);
|
|
1104
|
+
* ```
|
|
1105
|
+
*/
|
|
1106
|
+
declare function extractSpecSummary(spec: OpenPkg5): SpecSummary;
|
|
1107
|
+
import { OpenPkg as OpenPkg7 } from "@openpkg-ts/spec";
|
|
1108
|
+
/**
|
|
1109
|
+
* Result of running a command.
|
|
1110
|
+
*/
|
|
1111
|
+
interface CommandResult {
|
|
1112
|
+
/** Exit code (0 = success) */
|
|
1113
|
+
exitCode: number;
|
|
1114
|
+
/** Standard output */
|
|
1115
|
+
stdout: string;
|
|
1116
|
+
/** Standard error */
|
|
1117
|
+
stderr: string;
|
|
1118
|
+
}
|
|
1119
|
+
/**
|
|
1120
|
+
* Function that runs a shell command.
|
|
1121
|
+
* Abstracts the difference between Node.js execSync and Sandbox runCommand.
|
|
1122
|
+
*/
|
|
1123
|
+
type CommandRunner = (cmd: string, args: string[], options: {
|
|
1124
|
+
cwd: string;
|
|
1125
|
+
timeout?: number;
|
|
1126
|
+
}) => Promise<CommandResult>;
|
|
1127
|
+
/**
|
|
1128
|
+
* Result of dependency installation.
|
|
1129
|
+
*/
|
|
1130
|
+
interface InstallResult {
|
|
1131
|
+
/** Whether installation succeeded */
|
|
1132
|
+
success: boolean;
|
|
1133
|
+
/** Package manager that was used */
|
|
1134
|
+
packageManager: PackageManager;
|
|
1135
|
+
/** If a fallback was used, which one */
|
|
1136
|
+
fallbackUsed?: PackageManager;
|
|
1137
|
+
/** Error message if installation failed */
|
|
1138
|
+
error?: string;
|
|
1139
|
+
/** Detailed error messages from each attempt */
|
|
1140
|
+
errors?: string[];
|
|
1141
|
+
}
|
|
1142
|
+
/**
|
|
1143
|
+
* Options for dependency installation.
|
|
1144
|
+
*/
|
|
1145
|
+
interface InstallOptions {
|
|
1146
|
+
/** Timeout in milliseconds for install commands (default: 180000) */
|
|
1147
|
+
timeout?: number;
|
|
1148
|
+
/** Order of fallback package managers to try */
|
|
1149
|
+
fallbackOrder?: PackageManager[];
|
|
1150
|
+
/** Progress callback for status updates */
|
|
1151
|
+
onProgress?: ProgressCallback;
|
|
1152
|
+
}
|
|
1153
|
+
/**
|
|
1154
|
+
* Install dependencies for a project.
|
|
1155
|
+
*
|
|
1156
|
+
* This consolidates the install logic from CLI scan.ts and API scan-stream.ts:
|
|
1157
|
+
* 1. Detect package manager from lockfile
|
|
1158
|
+
* 2. Try primary install command
|
|
1159
|
+
* 3. Fall back to other package managers if primary fails
|
|
1160
|
+
*
|
|
1161
|
+
* @param fs - FileSystem implementation for package manager detection
|
|
1162
|
+
* @param cwd - Working directory to install in
|
|
1163
|
+
* @param runCommand - Function to run shell commands
|
|
1164
|
+
* @param options - Installation options
|
|
1165
|
+
* @returns Result of the installation attempt
|
|
1166
|
+
*
|
|
1167
|
+
* @example
|
|
1168
|
+
* ```typescript
|
|
1169
|
+
* import { NodeFileSystem, installDependencies, createNodeCommandRunner } from '@doccov/sdk';
|
|
1170
|
+
*
|
|
1171
|
+
* const fs = new NodeFileSystem('/path/to/repo');
|
|
1172
|
+
* const result = await installDependencies(fs, '/path/to/repo', createNodeCommandRunner());
|
|
1173
|
+
*
|
|
1174
|
+
* if (result.success) {
|
|
1175
|
+
* console.log(`Installed using ${result.packageManager}`);
|
|
1176
|
+
* } else {
|
|
1177
|
+
* console.error(`Install failed: ${result.error}`);
|
|
1178
|
+
* }
|
|
1179
|
+
* ```
|
|
1180
|
+
*/
|
|
1181
|
+
declare function installDependencies(fs: FileSystem, cwd: string, runCommand: CommandRunner, options?: InstallOptions): Promise<InstallResult>;
|
|
1182
|
+
/**
|
|
1183
|
+
* Create a command runner for Node.js environments using execSync.
|
|
1184
|
+
* This is used by the CLI for local dependency installation.
|
|
1185
|
+
*
|
|
1186
|
+
* @returns CommandRunner that uses child_process.execSync
|
|
1187
|
+
*
|
|
1188
|
+
* @example
|
|
1189
|
+
* ```typescript
|
|
1190
|
+
* const runner = createNodeCommandRunner();
|
|
1191
|
+
* const result = await runner('npm', ['install'], { cwd: '/path/to/repo' });
|
|
1192
|
+
* ```
|
|
1193
|
+
*/
|
|
1194
|
+
declare function createNodeCommandRunner(): CommandRunner;
|
|
1195
|
+
import { OpenPkg as OpenPkg6 } from "@openpkg-ts/spec";
|
|
1196
|
+
/**
|
|
1197
|
+
* Parsed components of a GitHub URL.
|
|
1198
|
+
*/
|
|
1199
|
+
interface ParsedGitHubUrl {
|
|
1200
|
+
/** Repository owner (user or org) */
|
|
1201
|
+
owner: string;
|
|
1202
|
+
/** Repository name */
|
|
1203
|
+
repo: string;
|
|
1204
|
+
/** Git ref (branch or tag) */
|
|
1205
|
+
ref: string;
|
|
1206
|
+
}
|
|
1207
|
+
/**
|
|
1208
|
+
* Parse a GitHub URL or shorthand into components.
|
|
1209
|
+
*
|
|
1210
|
+
* Supported formats:
|
|
1211
|
+
* - https://github.com/owner/repo
|
|
1212
|
+
* - https://github.com/owner/repo/tree/branch
|
|
1213
|
+
* - https://github.com/owner/repo/tree/v1.0.0
|
|
1214
|
+
* - github.com/owner/repo
|
|
1215
|
+
* - owner/repo (shorthand)
|
|
1216
|
+
* - git@github.com:owner/repo.git
|
|
1217
|
+
*
|
|
1218
|
+
* @param input - GitHub URL or shorthand
|
|
1219
|
+
* @param defaultRef - Default ref if not specified in URL (default: 'main')
|
|
1220
|
+
* @returns Parsed components
|
|
1221
|
+
* @throws Error if the URL format is invalid
|
|
1222
|
+
*
|
|
1223
|
+
* @example
|
|
1224
|
+
* ```typescript
|
|
1225
|
+
* import { parseGitHubUrl } from '@doccov/sdk';
|
|
1226
|
+
*
|
|
1227
|
+
* const parsed = parseGitHubUrl('https://github.com/vercel/next.js/tree/canary');
|
|
1228
|
+
* // { owner: 'vercel', repo: 'next.js', ref: 'canary' }
|
|
1229
|
+
*
|
|
1230
|
+
* const shorthand = parseGitHubUrl('vercel/next.js');
|
|
1231
|
+
* // { owner: 'vercel', repo: 'next.js', ref: 'main' }
|
|
1232
|
+
* ```
|
|
1233
|
+
*/
|
|
1234
|
+
declare function parseGitHubUrl(input: string, defaultRef?: string): ParsedGitHubUrl;
|
|
1235
|
+
/**
|
|
1236
|
+
* Build a clone URL from parsed components.
|
|
1237
|
+
*
|
|
1238
|
+
* @param parsed - Parsed GitHub URL components
|
|
1239
|
+
* @returns HTTPS clone URL
|
|
1240
|
+
*
|
|
1241
|
+
* @example
|
|
1242
|
+
* ```typescript
|
|
1243
|
+
* const cloneUrl = buildCloneUrl({ owner: 'vercel', repo: 'next.js', ref: 'main' });
|
|
1244
|
+
* // 'https://github.com/vercel/next.js.git'
|
|
1245
|
+
* ```
|
|
1246
|
+
*/
|
|
1247
|
+
declare function buildCloneUrl(parsed: ParsedGitHubUrl): string;
|
|
1248
|
+
/**
|
|
1249
|
+
* Build a display-friendly URL (without protocol or .git suffix).
|
|
1250
|
+
*
|
|
1251
|
+
* @param parsed - Parsed GitHub URL components
|
|
1252
|
+
* @returns Display URL like 'github.com/owner/repo'
|
|
1253
|
+
*
|
|
1254
|
+
* @example
|
|
1255
|
+
* ```typescript
|
|
1256
|
+
* const displayUrl = buildDisplayUrl({ owner: 'vercel', repo: 'next.js', ref: 'main' });
|
|
1257
|
+
* // 'github.com/vercel/next.js'
|
|
1258
|
+
* ```
|
|
1259
|
+
*/
|
|
1260
|
+
declare function buildDisplayUrl(parsed: ParsedGitHubUrl): string;
|
|
1261
|
+
/**
|
|
1262
|
+
* Build a raw.githubusercontent.com URL for a file.
|
|
1263
|
+
*
|
|
1264
|
+
* @param parsed - Parsed GitHub URL components
|
|
1265
|
+
* @param filePath - Path to the file in the repo
|
|
1266
|
+
* @returns Raw content URL
|
|
1267
|
+
*/
|
|
1268
|
+
declare function buildRawUrl(parsed: ParsedGitHubUrl, filePath: string): string;
|
|
1269
|
+
/**
|
|
1270
|
+
* Fetch an OpenPkg spec from a GitHub repository.
|
|
1271
|
+
*
|
|
1272
|
+
* Tries the specified ref first, then falls back to 'master' if not found.
|
|
1273
|
+
*
|
|
1274
|
+
* @param parsed - Parsed GitHub URL components
|
|
1275
|
+
* @returns The OpenPkg spec, or null if not found
|
|
1276
|
+
*
|
|
1277
|
+
* @example
|
|
1278
|
+
* ```typescript
|
|
1279
|
+
* import { parseGitHubUrl, fetchSpecFromGitHub } from '@doccov/sdk';
|
|
1280
|
+
*
|
|
1281
|
+
* const parsed = parseGitHubUrl('vercel/next.js');
|
|
1282
|
+
* const spec = await fetchSpecFromGitHub(parsed);
|
|
1283
|
+
* if (spec) {
|
|
1284
|
+
* console.log(`Coverage: ${spec.docs?.coverageScore}%`);
|
|
1285
|
+
* }
|
|
1286
|
+
* ```
|
|
1287
|
+
*/
|
|
1288
|
+
declare function fetchSpecFromGitHub(parsed: ParsedGitHubUrl): Promise<OpenPkg6 | null>;
|
|
1289
|
+
/**
|
|
1290
|
+
* Fetch an OpenPkg spec from a GitHub repository by owner/repo/branch.
|
|
1291
|
+
*
|
|
1292
|
+
* Convenience function that creates ParsedGitHubUrl internally.
|
|
1293
|
+
*
|
|
1294
|
+
* @param owner - Repository owner
|
|
1295
|
+
* @param repo - Repository name
|
|
1296
|
+
* @param branch - Branch name (default: 'main')
|
|
1297
|
+
* @returns The OpenPkg spec, or null if not found
|
|
1298
|
+
*/
|
|
1299
|
+
declare function fetchSpec(owner: string, repo: string, branch?: string): Promise<OpenPkg6 | null>;
|
|
1300
|
+
/**
|
|
1301
|
+
* Options for creating a ScanOrchestrator.
|
|
1302
|
+
*/
|
|
1303
|
+
interface ScanOrchestratorOptions {
|
|
1304
|
+
/** Progress callback for status updates */
|
|
1305
|
+
onProgress?: ProgressCallback;
|
|
1306
|
+
/** Command runner for executing shell commands */
|
|
1307
|
+
commandRunner?: CommandRunner;
|
|
1308
|
+
/** Skip external type resolution */
|
|
1309
|
+
skipResolve?: boolean;
|
|
1310
|
+
}
|
|
1311
|
+
/**
|
|
1312
|
+
* Context for the current scan operation.
|
|
1313
|
+
*/
|
|
1314
|
+
interface ScanContext {
|
|
1315
|
+
/** Parsed GitHub URL info */
|
|
1316
|
+
parsed: ParsedGitHubUrl;
|
|
1317
|
+
/** Target package name for monorepos */
|
|
1318
|
+
packageName?: string;
|
|
1319
|
+
/** Working directory for the scan */
|
|
1320
|
+
workDir: string;
|
|
1321
|
+
/** Entry point file path */
|
|
1322
|
+
entryFile?: string;
|
|
1323
|
+
}
|
|
1324
|
+
/**
|
|
1325
|
+
* Orchestrates the scan workflow.
|
|
1326
|
+
*
|
|
1327
|
+
* The orchestrator coordinates:
|
|
1328
|
+
* 1. Repository cloning (for remote URLs)
|
|
1329
|
+
* 2. Monorepo detection and package resolution
|
|
1330
|
+
* 3. Entry point detection
|
|
1331
|
+
* 4. Dependency installation
|
|
1332
|
+
* 5. Build execution (if needed)
|
|
1333
|
+
* 6. Documentation analysis
|
|
1334
|
+
* 7. Summary extraction
|
|
1335
|
+
*
|
|
1336
|
+
* It's designed to be FileSystem-agnostic so it works with both:
|
|
1337
|
+
* - NodeFileSystem (CLI - local execution)
|
|
1338
|
+
* - SandboxFileSystem (API - isolated execution)
|
|
1339
|
+
*
|
|
1340
|
+
* @example
|
|
1341
|
+
* ```typescript
|
|
1342
|
+
* import { ScanOrchestrator, NodeFileSystem, createNodeCommandRunner } from '@doccov/sdk';
|
|
1343
|
+
*
|
|
1344
|
+
* const fs = new NodeFileSystem('/path/to/repo');
|
|
1345
|
+
* const orchestrator = new ScanOrchestrator(fs, {
|
|
1346
|
+
* commandRunner: createNodeCommandRunner(),
|
|
1347
|
+
* onProgress: (event) => console.log(event.message),
|
|
1348
|
+
* });
|
|
1349
|
+
*
|
|
1350
|
+
* const result = await orchestrator.scan({
|
|
1351
|
+
* url: 'https://github.com/owner/repo',
|
|
1352
|
+
* ref: 'main',
|
|
1353
|
+
* });
|
|
1354
|
+
*
|
|
1355
|
+
* console.log(`Coverage: ${result.coverage}%`);
|
|
1356
|
+
* ```
|
|
1357
|
+
*/
|
|
1358
|
+
declare class ScanOrchestrator {
|
|
1359
|
+
private readonly fs;
|
|
1360
|
+
private readonly options;
|
|
1361
|
+
constructor(fs: FileSystem, options?: ScanOrchestratorOptions);
|
|
1362
|
+
/**
|
|
1363
|
+
* Emit a progress event.
|
|
1364
|
+
*/
|
|
1365
|
+
private emit;
|
|
1366
|
+
/**
|
|
1367
|
+
* Detect monorepo and resolve target package.
|
|
1368
|
+
*
|
|
1369
|
+
* @param packageName - Target package name (required for monorepos)
|
|
1370
|
+
* @returns Target directory path (relative to workDir)
|
|
1371
|
+
* @throws Error if monorepo requires --package flag
|
|
1372
|
+
*/
|
|
1373
|
+
detectPackage(packageName?: string): Promise<{
|
|
1374
|
+
targetPath: string;
|
|
1375
|
+
resolvedPackage?: string;
|
|
1376
|
+
}>;
|
|
1377
|
+
/**
|
|
1378
|
+
* Detect entry point for the package.
|
|
1379
|
+
*
|
|
1380
|
+
* @param targetPath - Path to the package directory
|
|
1381
|
+
* @returns Entry point file path (relative to workDir)
|
|
1382
|
+
*/
|
|
1383
|
+
detectEntry(targetPath: string): Promise<string>;
|
|
1384
|
+
/**
|
|
1385
|
+
* Install dependencies for the project.
|
|
1386
|
+
*
|
|
1387
|
+
* @param workDir - Working directory (absolute path)
|
|
1388
|
+
* @returns Installation result
|
|
1389
|
+
*/
|
|
1390
|
+
install(workDir: string): Promise<InstallResult>;
|
|
1391
|
+
/**
|
|
1392
|
+
* Run build if needed.
|
|
1393
|
+
*
|
|
1394
|
+
* @param workDir - Working directory (absolute path)
|
|
1395
|
+
* @param targetPath - Target package path (relative)
|
|
1396
|
+
*/
|
|
1397
|
+
build(workDir: string, targetPath: string): Promise<void>;
|
|
1398
|
+
/**
|
|
1399
|
+
* Run documentation analysis.
|
|
1400
|
+
*
|
|
1401
|
+
* @param entryFile - Path to entry file (absolute)
|
|
1402
|
+
* @returns OpenPkg spec
|
|
1403
|
+
*/
|
|
1404
|
+
analyze(entryFile: string): Promise<OpenPkg7>;
|
|
1405
|
+
/**
|
|
1406
|
+
* Run a complete scan workflow.
|
|
1407
|
+
*
|
|
1408
|
+
* @param options - Scan options
|
|
1409
|
+
* @returns Scan result with coverage statistics
|
|
1410
|
+
*/
|
|
1411
|
+
scan(options: ScanOptions): Promise<ScanResult>;
|
|
1412
|
+
}
|
|
1413
|
+
/**
|
|
1414
|
+
* Error thrown when a monorepo is detected but no package is specified.
|
|
1415
|
+
*/
|
|
1416
|
+
declare class MonorepoRequiresPackageError extends Error {
|
|
1417
|
+
/** Available package names */
|
|
1418
|
+
readonly availablePackages: string[];
|
|
1419
|
+
constructor(availablePackages: string[]);
|
|
1420
|
+
}
|
|
1421
|
+
/**
|
|
1422
|
+
* Options for resolving a target package/entry point.
|
|
1423
|
+
*/
|
|
1424
|
+
interface ResolveTargetOptions {
|
|
1425
|
+
/** Working directory (usually process.cwd()) */
|
|
1426
|
+
cwd: string;
|
|
1427
|
+
/** Target package name for monorepos */
|
|
1428
|
+
package?: string;
|
|
1429
|
+
/** Explicit entry point path (relative to cwd or package dir) */
|
|
1430
|
+
entry?: string;
|
|
1431
|
+
}
|
|
1432
|
+
/**
|
|
1433
|
+
* Result of resolving a target package/entry point.
|
|
1434
|
+
*/
|
|
1435
|
+
interface ResolvedTarget {
|
|
1436
|
+
/** Resolved directory containing the package */
|
|
1437
|
+
targetDir: string;
|
|
1438
|
+
/** Resolved entry point file path (absolute) */
|
|
1439
|
+
entryFile: string;
|
|
1440
|
+
/** Package info if this is a monorepo package */
|
|
1441
|
+
packageInfo?: WorkspacePackage;
|
|
1442
|
+
/** Entry point detection info */
|
|
1443
|
+
entryPointInfo: EntryPointInfo;
|
|
1444
|
+
}
|
|
1445
|
+
/**
|
|
1446
|
+
* Resolve a target package and entry point.
|
|
1447
|
+
*
|
|
1448
|
+
* This consolidates the repeated pattern from CLI commands:
|
|
1449
|
+
* 1. If --package specified, detect monorepo and find the package
|
|
1450
|
+
* 2. If no entry specified, auto-detect entry point
|
|
1451
|
+
* 3. If entry is a directory, detect entry point within it
|
|
1452
|
+
*
|
|
1453
|
+
* @param fs - FileSystem implementation (NodeFileSystem or SandboxFileSystem)
|
|
1454
|
+
* @param options - Resolution options
|
|
1455
|
+
* @returns Resolved target info
|
|
1456
|
+
* @throws Error if monorepo package not found, or entry point detection fails
|
|
1457
|
+
*
|
|
1458
|
+
* @example
|
|
1459
|
+
* ```typescript
|
|
1460
|
+
* import { NodeFileSystem, resolveTarget } from '@doccov/sdk';
|
|
1461
|
+
*
|
|
1462
|
+
* // Simple usage
|
|
1463
|
+
* const fs = new NodeFileSystem(process.cwd());
|
|
1464
|
+
* const { targetDir, entryFile } = await resolveTarget(fs, { cwd: process.cwd() });
|
|
1465
|
+
*
|
|
1466
|
+
* // With monorepo package
|
|
1467
|
+
* const { targetDir, entryFile, packageInfo } = await resolveTarget(fs, {
|
|
1468
|
+
* cwd: process.cwd(),
|
|
1469
|
+
* package: '@myorg/core',
|
|
1470
|
+
* });
|
|
1471
|
+
* ```
|
|
1472
|
+
*/
|
|
1473
|
+
declare function resolveTarget(fs: FileSystem, options: ResolveTargetOptions): Promise<ResolvedTarget>;
|
|
1474
|
+
export { typecheckExamples, typecheckExample, serializeJSDoc, safeParseJson, runExamplesWithPackage, runExamples, runExample, resolveTarget, requireExample, requireDescription, readPackageJson, parseMarkdownFiles, parseMarkdownFile, parseListFlag, parseJSDocToPatch, parseGitHubUrl, parseAssertions, noEmptyReturns, mergeFixes, mergeFilters, mergeConfig, lintExports, lintExport, isFixableDrift, isExecutableLang, installDependencies, hasNonAssertionComments, hasDocsImpact, hasDocsForExport, getUndocumentedExports, getRunCommand, getRule, getPrimaryBuildScript, getInstallCommand, getDocumentedExports, getDocsImpactSummary, getDefaultConfig, generateFixesForExport, generateFix, formatPackageList, findRemovedReferences, findPackageByName, findJSDocLocation, findExportReferences, findDeprecatedReferences, fetchSpecFromGitHub, fetchSpec, extractSpecSummary, extractPackageSpec, extractImports, extractFunctionCalls, diffSpecWithDocs, detectPackageManager, detectMonorepo, detectExampleRuntimeErrors, detectExampleAssertionFailures, detectEntryPoint, detectBuildInfo, defineConfig, createSourceFile, createNodeCommandRunner, consistentParamStyle, categorizeDrifts, buildRawUrl, buildDisplayUrl, buildCloneUrl, blockReferencesExport, applyPatchToJSDoc, applyEdits, analyzeProject2 as analyzeProject, analyzeFile, analyzeDocsImpact, analyze, allRules, WorkspacePackage, TypecheckResult, TypecheckOptions, SpecSummary, SpecDiffWithDocs, ScanResult, ScanOrchestratorOptions, ScanOrchestrator, ScanOptions, ScanContext, SandboxFileSystem, RunExamplesWithPackageResult, RunExamplesWithPackageOptions, RunExampleOptions, ResolvedTarget, ResolvedFilters, ResolveTargetOptions, ProjectInfo, ProgressStage, ProgressEvent, ProgressCallback, ParsedGitHubUrl, PackageManagerInfo, PackageManager, PackageJson, PackageExports, OpenPkgSpec, OpenPkgOptions, OpenPkg4 as OpenPkg, NodeFileSystem, MonorepoType, MonorepoRequiresPackageError, MonorepoInfo, MemberChange, MarkdownDocFile, MarkdownCodeBlock, LintViolation, LintSeverity2 as LintSeverity, LintRulesConfig, LintRule, LintResult, LintConfig, JSDocTag, JSDocReturn, JSDocPatch, JSDocParam, JSDocEdit, InstallResult, InstallOptions, FixType, FixSuggestion, FilterSource, FilterOptions, FileSystem, ExportReference, ExampleTypeError, ExampleRunResult, EntryPointSource, EntryPointInfo, DriftIssue, DocsImpactResult, DocsImpactReference, DocsImpact, DocsConfig, DocsChangeType, DocCovOptions, DocCovConfig, DocCov, DiffWithDocsOptions, Diagnostic, CommandRunner, CommandResult, CheckConfig, BuildInfo, ApplyEditsResult, AnalyzeProjectOptions, AnalyzeOptions, AnalysisResult };
|