dep-context-mcp 1.0.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/README.md +380 -0
- package/dist/analysis/relationships.d.ts +25 -0
- package/dist/analysis/relationships.d.ts.map +1 -0
- package/dist/analysis/relationships.js +26 -0
- package/dist/analysis/relationships.js.map +1 -0
- package/dist/build-info.d.ts +15 -0
- package/dist/build-info.d.ts.map +1 -0
- package/dist/build-info.js +24 -0
- package/dist/build-info.js.map +1 -0
- package/dist/cache/manager.d.ts +19 -0
- package/dist/cache/manager.d.ts.map +1 -0
- package/dist/cache/manager.js +131 -0
- package/dist/cache/manager.js.map +1 -0
- package/dist/cache/registry.d.ts +44 -0
- package/dist/cache/registry.d.ts.map +1 -0
- package/dist/cache/registry.js +92 -0
- package/dist/cache/registry.js.map +1 -0
- package/dist/config/loader.d.ts +62 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +193 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/extraction/examples.d.ts +22 -0
- package/dist/extraction/examples.d.ts.map +1 -0
- package/dist/extraction/examples.js +109 -0
- package/dist/extraction/examples.js.map +1 -0
- package/dist/extraction/external-resolver.d.ts +26 -0
- package/dist/extraction/external-resolver.d.ts.map +1 -0
- package/dist/extraction/external-resolver.js +79 -0
- package/dist/extraction/external-resolver.js.map +1 -0
- package/dist/extraction/import-tracker.d.ts +58 -0
- package/dist/extraction/import-tracker.d.ts.map +1 -0
- package/dist/extraction/import-tracker.js +113 -0
- package/dist/extraction/import-tracker.js.map +1 -0
- package/dist/extraction/readme.d.ts +19 -0
- package/dist/extraction/readme.d.ts.map +1 -0
- package/dist/extraction/readme.js +79 -0
- package/dist/extraction/readme.js.map +1 -0
- package/dist/extraction/snapshot.d.ts +32 -0
- package/dist/extraction/snapshot.d.ts.map +1 -0
- package/dist/extraction/snapshot.js +258 -0
- package/dist/extraction/snapshot.js.map +1 -0
- package/dist/extraction/typescript.d.ts +104 -0
- package/dist/extraction/typescript.d.ts.map +1 -0
- package/dist/extraction/typescript.js +647 -0
- package/dist/extraction/typescript.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +329 -0
- package/dist/index.js.map +1 -0
- package/dist/resolver/package.d.ts +62 -0
- package/dist/resolver/package.d.ts.map +1 -0
- package/dist/resolver/package.js +334 -0
- package/dist/resolver/package.js.map +1 -0
- package/dist/tools/get-dependency.d.ts +55 -0
- package/dist/tools/get-dependency.d.ts.map +1 -0
- package/dist/tools/get-dependency.js +105 -0
- package/dist/tools/get-dependency.js.map +1 -0
- package/dist/tools/index-dependencies.d.ts +51 -0
- package/dist/tools/index-dependencies.d.ts.map +1 -0
- package/dist/tools/index-dependencies.js +90 -0
- package/dist/tools/index-dependencies.js.map +1 -0
- package/dist/tools/index-status.d.ts +36 -0
- package/dist/tools/index-status.d.ts.map +1 -0
- package/dist/tools/index-status.js +45 -0
- package/dist/tools/index-status.js.map +1 -0
- package/dist/tools/list.d.ts +48 -0
- package/dist/tools/list.d.ts.map +1 -0
- package/dist/tools/list.js +55 -0
- package/dist/tools/list.js.map +1 -0
- package/dist/tools/refresh.d.ts +59 -0
- package/dist/tools/refresh.d.ts.map +1 -0
- package/dist/tools/refresh.js +109 -0
- package/dist/tools/refresh.js.map +1 -0
- package/dist/tools/relationships.d.ts +41 -0
- package/dist/tools/relationships.d.ts.map +1 -0
- package/dist/tools/relationships.js +36 -0
- package/dist/tools/relationships.js.map +1 -0
- package/dist/tools/search-codebase.d.ts +64 -0
- package/dist/tools/search-codebase.d.ts.map +1 -0
- package/dist/tools/search-codebase.js +117 -0
- package/dist/tools/search-codebase.js.map +1 -0
- package/dist/tools/search.d.ts +37 -0
- package/dist/tools/search.d.ts.map +1 -0
- package/dist/tools/search.js +77 -0
- package/dist/tools/search.js.map +1 -0
- package/dist/utils/logger.d.ts +19 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +71 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/vector/chroma.d.ts +38 -0
- package/dist/vector/chroma.d.ts.map +1 -0
- package/dist/vector/chroma.js +69 -0
- package/dist/vector/chroma.js.map +1 -0
- package/dist/vector/chunker.d.ts +29 -0
- package/dist/vector/chunker.d.ts.map +1 -0
- package/dist/vector/chunker.js +205 -0
- package/dist/vector/chunker.js.map +1 -0
- package/dist/vector/embeddings.d.ts +36 -0
- package/dist/vector/embeddings.d.ts.map +1 -0
- package/dist/vector/embeddings.js +106 -0
- package/dist/vector/embeddings.js.map +1 -0
- package/dist/vector/file-store.d.ts +10 -0
- package/dist/vector/file-store.d.ts.map +1 -0
- package/dist/vector/file-store.js +80 -0
- package/dist/vector/file-store.js.map +1 -0
- package/dist/vector/index-manager.d.ts +39 -0
- package/dist/vector/index-manager.d.ts.map +1 -0
- package/dist/vector/index-manager.js +105 -0
- package/dist/vector/index-manager.js.map +1 -0
- package/dist/vector/provider-factory.d.ts +23 -0
- package/dist/vector/provider-factory.d.ts.map +1 -0
- package/dist/vector/provider-factory.js +50 -0
- package/dist/vector/provider-factory.js.map +1 -0
- package/dist/vector/storage-factory.d.ts +17 -0
- package/dist/vector/storage-factory.d.ts.map +1 -0
- package/dist/vector/storage-factory.js +55 -0
- package/dist/vector/storage-factory.js.map +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External Package Resolver - Resolves type definitions from external packages
|
|
3
|
+
*
|
|
4
|
+
* When a package re-exports from external dependencies (e.g., vitest re-exports from @vitest/runner),
|
|
5
|
+
* this resolver finds the type definitions in those external packages.
|
|
6
|
+
*/
|
|
7
|
+
import { createPackageResolver } from '../resolver/package.js';
|
|
8
|
+
/**
|
|
9
|
+
* Creates an ExternalPackageResolver with caching
|
|
10
|
+
*/
|
|
11
|
+
export function createExternalPackageResolver(projectRoot) {
|
|
12
|
+
// Cache for successfully resolved packages
|
|
13
|
+
const resolvedCache = new Map();
|
|
14
|
+
// Set of packages that failed to resolve (to avoid repeated attempts)
|
|
15
|
+
const failedPackages = new Set();
|
|
16
|
+
// Use the existing package resolver
|
|
17
|
+
const packageResolver = createPackageResolver(projectRoot);
|
|
18
|
+
return {
|
|
19
|
+
async resolve(packageName) {
|
|
20
|
+
// Check failed cache first
|
|
21
|
+
if (failedPackages.has(packageName)) {
|
|
22
|
+
return {
|
|
23
|
+
success: false,
|
|
24
|
+
typesPath: undefined,
|
|
25
|
+
metadata: undefined,
|
|
26
|
+
error: `Package '${packageName}' previously failed to resolve`
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
// Check success cache
|
|
30
|
+
const cached = resolvedCache.get(packageName);
|
|
31
|
+
if (cached) {
|
|
32
|
+
return cached;
|
|
33
|
+
}
|
|
34
|
+
// Attempt to resolve
|
|
35
|
+
try {
|
|
36
|
+
const resolved = await packageResolver.resolve(packageName);
|
|
37
|
+
if (!resolved.success || !resolved.metadata) {
|
|
38
|
+
failedPackages.add(packageName);
|
|
39
|
+
return {
|
|
40
|
+
success: false,
|
|
41
|
+
typesPath: undefined,
|
|
42
|
+
metadata: undefined,
|
|
43
|
+
error: resolved.error ?? `Package '${packageName}' not found`
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const result = {
|
|
47
|
+
success: true,
|
|
48
|
+
typesPath: resolved.metadata.typesPath,
|
|
49
|
+
metadata: resolved.metadata,
|
|
50
|
+
error: undefined
|
|
51
|
+
};
|
|
52
|
+
// Cache successful resolution
|
|
53
|
+
resolvedCache.set(packageName, result);
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
58
|
+
failedPackages.add(packageName);
|
|
59
|
+
return {
|
|
60
|
+
success: false,
|
|
61
|
+
typesPath: undefined,
|
|
62
|
+
metadata: undefined,
|
|
63
|
+
error: `Failed to resolve '${packageName}': ${message}`
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
clearCache() {
|
|
68
|
+
resolvedCache.clear();
|
|
69
|
+
failedPackages.clear();
|
|
70
|
+
},
|
|
71
|
+
getCacheStats() {
|
|
72
|
+
return {
|
|
73
|
+
resolved: resolvedCache.size,
|
|
74
|
+
failed: failedPackages.size
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=external-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"external-resolver.js","sourceRoot":"","sources":["../../src/extraction/external-resolver.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,qBAAqB,EAAwB,MAAM,wBAAwB,CAAA;AAepF;;GAEG;AACH,MAAM,UAAU,6BAA6B,CAAC,WAAmB;IAC/D,2CAA2C;IAC3C,MAAM,aAAa,GAAG,IAAI,GAAG,EAAkC,CAAA;IAE/D,sEAAsE;IACtE,MAAM,cAAc,GAAG,IAAI,GAAG,EAAU,CAAA;IAExC,oCAAoC;IACpC,MAAM,eAAe,GAAG,qBAAqB,CAAC,WAAW,CAAC,CAAA;IAE1D,OAAO;QACL,KAAK,CAAC,OAAO,CAAC,WAAmB;YAC/B,2BAA2B;YAC3B,IAAI,cAAc,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;gBACpC,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,SAAS,EAAE,SAAS;oBACpB,QAAQ,EAAE,SAAS;oBACnB,KAAK,EAAE,YAAY,WAAW,gCAAgC;iBAC/D,CAAA;YACH,CAAC;YAED,sBAAsB;YACtB,MAAM,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;YAC7C,IAAI,MAAM,EAAE,CAAC;gBACX,OAAO,MAAM,CAAA;YACf,CAAC;YAED,qBAAqB;YACrB,IAAI,CAAC;gBACH,MAAM,QAAQ,GAAG,MAAM,eAAe,CAAC,OAAO,CAAC,WAAW,CAA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AC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Import Tracker - Tracks import declarations for resolving export-from-import patterns
|
|
3
|
+
*
|
|
4
|
+
* Many packages use the pattern:
|
|
5
|
+
* import { foo } from './internal/foo.js';
|
|
6
|
+
* export { foo };
|
|
7
|
+
*
|
|
8
|
+
* This module tracks imports so we can follow them when resolving exports.
|
|
9
|
+
*/
|
|
10
|
+
import * as ts from 'typescript';
|
|
11
|
+
/**
|
|
12
|
+
* Represents an imported symbol
|
|
13
|
+
*/
|
|
14
|
+
export interface ImportedSymbol {
|
|
15
|
+
/** Name used in the current file */
|
|
16
|
+
localName: string;
|
|
17
|
+
/** Original name in the source file (may differ if aliased) */
|
|
18
|
+
originalName: string;
|
|
19
|
+
/** Relative path to the source module */
|
|
20
|
+
sourcePath: string;
|
|
21
|
+
/** Whether this is a namespace import (import * as ns) */
|
|
22
|
+
isNamespace: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Tracks imports from a TypeScript source file
|
|
26
|
+
*/
|
|
27
|
+
export declare class ImportTracker {
|
|
28
|
+
private imports;
|
|
29
|
+
/**
|
|
30
|
+
* Process an import declaration and track all imported symbols
|
|
31
|
+
*/
|
|
32
|
+
trackImport(node: ts.ImportDeclaration, _sourceFile: ts.SourceFile): void;
|
|
33
|
+
/**
|
|
34
|
+
* Check if a name refers to an imported symbol
|
|
35
|
+
*/
|
|
36
|
+
isImported(name: string): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Get the import information for a symbol
|
|
39
|
+
*/
|
|
40
|
+
getImport(name: string): ImportedSymbol | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Get all tracked imports
|
|
43
|
+
*/
|
|
44
|
+
getAllImports(): ImportedSymbol[];
|
|
45
|
+
/**
|
|
46
|
+
* Get all imports from a specific source path
|
|
47
|
+
*/
|
|
48
|
+
getImportsFromSource(sourcePath: string): ImportedSymbol[];
|
|
49
|
+
/**
|
|
50
|
+
* Clear all tracked imports
|
|
51
|
+
*/
|
|
52
|
+
clear(): void;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Create an ImportTracker and populate it from a source file
|
|
56
|
+
*/
|
|
57
|
+
export declare function createImportTracker(sourceFile: ts.SourceFile): ImportTracker;
|
|
58
|
+
//# sourceMappingURL=import-tracker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-tracker.d.ts","sourceRoot":"","sources":["../../src/extraction/import-tracker.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAA;AAEhC;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,oCAAoC;IACpC,SAAS,EAAE,MAAM,CAAA;IACjB,+DAA+D;IAC/D,YAAY,EAAE,MAAM,CAAA;IACpB,yCAAyC;IACzC,UAAU,EAAE,MAAM,CAAA;IAClB,0DAA0D;IAC1D,WAAW,EAAE,OAAO,CAAA;CACrB;AAED;;GAEG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,OAAO,CAAyC;IAExD;;OAEG;IACH,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC,iBAAiB,EAAE,WAAW,EAAE,EAAE,CAAC,UAAU,GAAG,IAAI;IA0DzE;;OAEG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIjC;;OAEG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAInD;;OAEG;IACH,aAAa,IAAI,cAAc,EAAE;IAIjC;;OAEG;IACH,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,cAAc,EAAE;IAK1D;;OAEG;IACH,KAAK,IAAI,IAAI;CAGd;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,GAAG,aAAa,CAU5E"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Import Tracker - Tracks import declarations for resolving export-from-import patterns
|
|
3
|
+
*
|
|
4
|
+
* Many packages use the pattern:
|
|
5
|
+
* import { foo } from './internal/foo.js';
|
|
6
|
+
* export { foo };
|
|
7
|
+
*
|
|
8
|
+
* This module tracks imports so we can follow them when resolving exports.
|
|
9
|
+
*/
|
|
10
|
+
import * as ts from 'typescript';
|
|
11
|
+
/**
|
|
12
|
+
* Tracks imports from a TypeScript source file
|
|
13
|
+
*/
|
|
14
|
+
export class ImportTracker {
|
|
15
|
+
imports = new Map();
|
|
16
|
+
/**
|
|
17
|
+
* Process an import declaration and track all imported symbols
|
|
18
|
+
*/
|
|
19
|
+
trackImport(node, _sourceFile) {
|
|
20
|
+
// Get the module specifier (the path being imported from)
|
|
21
|
+
if (!ts.isStringLiteral(node.moduleSpecifier)) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const sourcePath = node.moduleSpecifier.text;
|
|
25
|
+
const importClause = node.importClause;
|
|
26
|
+
if (!importClause) {
|
|
27
|
+
// Side-effect import: import './module'
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
// Handle default import: import foo from './module'
|
|
31
|
+
if (importClause.name) {
|
|
32
|
+
this.imports.set(importClause.name.text, {
|
|
33
|
+
localName: importClause.name.text,
|
|
34
|
+
originalName: 'default',
|
|
35
|
+
sourcePath,
|
|
36
|
+
isNamespace: false
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
// Handle named bindings
|
|
40
|
+
const namedBindings = importClause.namedBindings;
|
|
41
|
+
if (!namedBindings) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
// Namespace import: import * as ns from './module'
|
|
45
|
+
if (ts.isNamespaceImport(namedBindings)) {
|
|
46
|
+
this.imports.set(namedBindings.name.text, {
|
|
47
|
+
localName: namedBindings.name.text,
|
|
48
|
+
originalName: '*',
|
|
49
|
+
sourcePath,
|
|
50
|
+
isNamespace: true
|
|
51
|
+
});
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
// Named imports: import { a, b as c } from './module'
|
|
55
|
+
if (ts.isNamedImports(namedBindings)) {
|
|
56
|
+
for (const element of namedBindings.elements) {
|
|
57
|
+
const localName = element.name.text;
|
|
58
|
+
// If aliased (import { x as y }), propertyName is the original, name is the alias
|
|
59
|
+
const originalName = element.propertyName?.text ?? localName;
|
|
60
|
+
this.imports.set(localName, {
|
|
61
|
+
localName,
|
|
62
|
+
originalName,
|
|
63
|
+
sourcePath,
|
|
64
|
+
isNamespace: false
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Check if a name refers to an imported symbol
|
|
71
|
+
*/
|
|
72
|
+
isImported(name) {
|
|
73
|
+
return this.imports.has(name);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get the import information for a symbol
|
|
77
|
+
*/
|
|
78
|
+
getImport(name) {
|
|
79
|
+
return this.imports.get(name);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get all tracked imports
|
|
83
|
+
*/
|
|
84
|
+
getAllImports() {
|
|
85
|
+
return Array.from(this.imports.values());
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get all imports from a specific source path
|
|
89
|
+
*/
|
|
90
|
+
getImportsFromSource(sourcePath) {
|
|
91
|
+
return Array.from(this.imports.values())
|
|
92
|
+
.filter(imp => imp.sourcePath === sourcePath);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Clear all tracked imports
|
|
96
|
+
*/
|
|
97
|
+
clear() {
|
|
98
|
+
this.imports.clear();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Create an ImportTracker and populate it from a source file
|
|
103
|
+
*/
|
|
104
|
+
export function createImportTracker(sourceFile) {
|
|
105
|
+
const tracker = new ImportTracker();
|
|
106
|
+
for (const statement of sourceFile.statements) {
|
|
107
|
+
if (ts.isImportDeclaration(statement)) {
|
|
108
|
+
tracker.trackImport(statement, sourceFile);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return tracker;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=import-tracker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-tracker.js","sourceRoot":"","sources":["../../src/extraction/import-tracker.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAA;AAgBhC;;GAEG;AACH,MAAM,OAAO,aAAa;IAChB,OAAO,GAAgC,IAAI,GAAG,EAAE,CAAA;IAExD;;OAEG;IACH,WAAW,CAAC,IAA0B,EAAE,WAA0B;QAChE,0DAA0D;QAC1D,IAAI,CAAC,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC;YAC9C,OAAM;QACR,CAAC;QAED,MAAM,UAAU,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAAA;QAC5C,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,CAAA;QAEtC,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,wCAAwC;YACxC,OAAM;QACR,CAAC;QAED,oDAAoD;QACpD,IAAI,YAAY,CAAC,IAAI,EAAE,CAAC;YACtB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE;gBACvC,SAAS,EAAE,YAAY,CAAC,IAAI,CAAC,IAAI;gBACjC,YAAY,EAAE,SAAS;gBACvB,UAAU;gBACV,WAAW,EAAE,KAAK;aACnB,CAAC,CAAA;QACJ,CAAC;QAED,wBAAwB;QACxB,MAAM,aAAa,GAAG,YAAY,CAAC,aAAa,CAAA;QAChD,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,OAAM;QACR,CAAC;QAED,mDAAmD;QACnD,IAAI,EAAE,CAAC,iBAAiB,CAAC,aAAa,CAAC,EAAE,CAAC;YACxC,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IACjD,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;IACtB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,UAAyB;IAC3D,MAAM,OAAO,GAAG,IAAI,aAAa,EAAE,CAAA;IAEnC,KAAK,MAAM,SAAS,IAAI,UAAU,CAAC,UAAU,EAAE,CAAC;QAC9C,IAAI,EAAE,CAAC,mBAAmB,CAAC,SAAS,CAAC,EAAE,CAAC;YACtC,OAAO,CAAC,WAAW,CAAC,SAAS,EAAE,UAAU,CAAC,CAAA;QAC5C,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAA;AAChB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* README extractor - reads and parses README.md from packages
|
|
3
|
+
*/
|
|
4
|
+
export interface ReadmeContent {
|
|
5
|
+
raw: string;
|
|
6
|
+
truncated: string;
|
|
7
|
+
codeExamples: string[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Extracts README content from a package directory
|
|
11
|
+
*/
|
|
12
|
+
export declare function extractReadme(packagePath: string, maxLength?: number): Promise<ReadmeContent | undefined>;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a ReadmeExtractor instance
|
|
15
|
+
*/
|
|
16
|
+
export declare function createReadmeExtractor(): {
|
|
17
|
+
extract: typeof extractReadme;
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=readme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readme.d.ts","sourceRoot":"","sources":["../../src/extraction/readme.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAA;IACX,SAAS,EAAE,MAAM,CAAA;IACjB,YAAY,EAAE,MAAM,EAAE,CAAA;CACvB;AA0CD;;GAEG;AACH,wBAAsB,aAAa,CACjC,WAAW,EAAE,MAAM,EACnB,SAAS,GAAE,MAAa,GACvB,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAiCpC;AAED;;GAEG;AACH,wBAAgB,qBAAqB;;EAIpC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* README extractor - reads and parses README.md from packages
|
|
3
|
+
*/
|
|
4
|
+
import { readFile } from 'node:fs/promises';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { existsSync } from 'node:fs';
|
|
7
|
+
/**
|
|
8
|
+
* Extracts code blocks from markdown content
|
|
9
|
+
*/
|
|
10
|
+
function extractCodeBlocks(content) {
|
|
11
|
+
const codeBlockRegex = /```[\w]*\n([\s\S]*?)```/g;
|
|
12
|
+
const blocks = [];
|
|
13
|
+
let match;
|
|
14
|
+
while ((match = codeBlockRegex.exec(content)) !== null) {
|
|
15
|
+
blocks.push(match[1].trim());
|
|
16
|
+
}
|
|
17
|
+
return blocks;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Truncates content to a maximum word count while preserving complete sentences
|
|
21
|
+
*/
|
|
22
|
+
function truncateToWords(content, maxWords) {
|
|
23
|
+
const words = content.split(/\s+/);
|
|
24
|
+
if (words.length <= maxWords) {
|
|
25
|
+
return content;
|
|
26
|
+
}
|
|
27
|
+
// Take maxWords and try to end at a sentence boundary
|
|
28
|
+
const truncated = words.slice(0, maxWords).join(' ');
|
|
29
|
+
// Find the last sentence boundary
|
|
30
|
+
const lastPeriod = truncated.lastIndexOf('.');
|
|
31
|
+
const lastNewline = truncated.lastIndexOf('\n\n');
|
|
32
|
+
const boundary = Math.max(lastPeriod, lastNewline);
|
|
33
|
+
if (boundary > truncated.length * 0.5) {
|
|
34
|
+
return truncated.slice(0, boundary + 1) + '\n\n[truncated]';
|
|
35
|
+
}
|
|
36
|
+
return truncated + '...\n\n[truncated]';
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Extracts README content from a package directory
|
|
40
|
+
*/
|
|
41
|
+
export async function extractReadme(packagePath, maxLength = 5000) {
|
|
42
|
+
// Try common README filenames
|
|
43
|
+
const readmeNames = ['README.md', 'readme.md', 'Readme.md', 'README.MD', 'README'];
|
|
44
|
+
let readmePath;
|
|
45
|
+
for (const name of readmeNames) {
|
|
46
|
+
const candidate = join(packagePath, name);
|
|
47
|
+
if (existsSync(candidate)) {
|
|
48
|
+
readmePath = candidate;
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (!readmePath) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
const raw = await readFile(readmePath, 'utf-8');
|
|
57
|
+
const codeExamples = extractCodeBlocks(raw);
|
|
58
|
+
// Calculate max words (rough estimate: 5 chars per word)
|
|
59
|
+
const maxWords = Math.floor(maxLength / 5);
|
|
60
|
+
const truncated = truncateToWords(raw, maxWords);
|
|
61
|
+
return {
|
|
62
|
+
raw,
|
|
63
|
+
truncated,
|
|
64
|
+
codeExamples
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Creates a ReadmeExtractor instance
|
|
73
|
+
*/
|
|
74
|
+
export function createReadmeExtractor() {
|
|
75
|
+
return {
|
|
76
|
+
extract: extractReadme
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=readme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readme.js","sourceRoot":"","sources":["../../src/extraction/readme.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAQpC;;GAEG;AACH,SAAS,iBAAiB,CAAC,OA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AAG,CAAC,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAA;IAElF,IAAI,UAA8B,CAAA;IAClC,KAAK,MAAM,IAAI,IAAI,WAAW,EAAE,CAAC;QAC/B,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAA;QACzC,IAAI,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;YAC1B,UAAU,GAAG,SAAS,CAAA;YACtB,MAAK;QACP,CAAC;IACH,CAAC;IAED,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;QAC/C,MAAM,YAAY,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAA;QAE3C,yDAAyD;QACzD,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC,CAAA;QAC1C,MAAM,SAAS,GAAG,eAAe,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;QAEhD,OAAO;YACL,GAAG;YACH,SAAS;YACT,YAAY;SACb,CAAA;IACH,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB;IACnC,OAAO;QACL,OAAO,EAAE,aAAa;KACvB,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Snapshot generator - creates AI-optimised markdown from extracted types
|
|
3
|
+
*/
|
|
4
|
+
import type { PackageMetadata } from '../resolver/package.js';
|
|
5
|
+
import type { ExtractionResult } from './typescript.js';
|
|
6
|
+
import type { ReadmeContent } from './readme.js';
|
|
7
|
+
import type { CodeExample } from './examples.js';
|
|
8
|
+
export interface SnapshotOptions {
|
|
9
|
+
includeReadme: boolean;
|
|
10
|
+
includeJsDoc: boolean;
|
|
11
|
+
includeExamples: boolean;
|
|
12
|
+
maxReadmeLength: number;
|
|
13
|
+
maxExamples: number;
|
|
14
|
+
}
|
|
15
|
+
export interface Snapshot {
|
|
16
|
+
packageName: string;
|
|
17
|
+
version: string;
|
|
18
|
+
generatedAt: string;
|
|
19
|
+
content: string;
|
|
20
|
+
checksum: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Generates a snapshot from extracted API information
|
|
24
|
+
*/
|
|
25
|
+
export declare function generateSnapshot(metadata: PackageMetadata, extraction: ExtractionResult, readme: ReadmeContent | undefined, options: SnapshotOptions, examples?: CodeExample[]): Snapshot;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a SnapshotGenerator instance
|
|
28
|
+
*/
|
|
29
|
+
export declare function createSnapshotGenerator(): {
|
|
30
|
+
generate: typeof generateSnapshot;
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=snapshot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../../src/extraction/snapshot.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,KAAK,EACV,gBAAgB,EAOjB,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAEhD,MAAM,WAAW,eAAe;IAC9B,aAAa,EAAE,OAAO,CAAA;IACtB,YAAY,EAAE,OAAO,CAAA;IACrB,eAAe,EAAE,OAAO,CAAA;IACxB,eAAe,EAAE,MAAM,CAAA;IACvB,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,QAAQ;IACvB,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;CACjB;AAuLD;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,eAAe,EACzB,UAAU,EAAE,gBAAgB,EAC5B,MAAM,EAAE,aAAa,GAAG,SAAS,EACjC,OAAO,EAAE,eAAe,EACxB,QAAQ,GAAE,WAAW,EAAO,GAC3B,QAAQ,CA4GV;AAED;;GAEG;AACH,wBAAgB,uBAAuB;;EAItC"}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Snapshot generator - creates AI-optimised markdown from extracted types
|
|
3
|
+
*/
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
/**
|
|
6
|
+
* Formats a function for markdown output
|
|
7
|
+
*/
|
|
8
|
+
function formatFunction(fn, includeJsDoc) {
|
|
9
|
+
const lines = [];
|
|
10
|
+
lines.push(`### ${fn.name}`);
|
|
11
|
+
lines.push('');
|
|
12
|
+
lines.push('```');
|
|
13
|
+
lines.push(`function ${fn.signature}`);
|
|
14
|
+
lines.push('```');
|
|
15
|
+
if (includeJsDoc && fn.jsDoc) {
|
|
16
|
+
lines.push('');
|
|
17
|
+
lines.push(fn.jsDoc);
|
|
18
|
+
}
|
|
19
|
+
if (fn.parameters.length > 0) {
|
|
20
|
+
lines.push('');
|
|
21
|
+
lines.push('**Parameters:**');
|
|
22
|
+
for (const param of fn.parameters) {
|
|
23
|
+
const optional = param.optional ? ' (optional)' : '';
|
|
24
|
+
lines.push(`- \`${param.name}\`: \`${param.type}\`${optional}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
lines.push('');
|
|
28
|
+
lines.push(`**Returns:** \`${fn.returnType}\``);
|
|
29
|
+
return lines.join('\n');
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Formats a method for markdown output
|
|
33
|
+
*/
|
|
34
|
+
function formatMethod(method) {
|
|
35
|
+
const staticPrefix = method.isStatic ? 'static ' : '';
|
|
36
|
+
const asyncPrefix = method.isAsync ? 'async ' : '';
|
|
37
|
+
return `- \`${staticPrefix}${asyncPrefix}${method.signature}\``;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Formats a property for markdown output
|
|
41
|
+
*/
|
|
42
|
+
function formatProperty(prop) {
|
|
43
|
+
const readonly = prop.readonly ? 'readonly ' : '';
|
|
44
|
+
const optional = prop.optional ? '?' : '';
|
|
45
|
+
return `- \`${readonly}${prop.name}${optional}: ${prop.type}\``;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Formats a class for markdown output
|
|
49
|
+
*/
|
|
50
|
+
function formatClass(cls, includeJsDoc) {
|
|
51
|
+
const lines = [];
|
|
52
|
+
lines.push(`### ${cls.name}`);
|
|
53
|
+
lines.push('');
|
|
54
|
+
if (includeJsDoc && cls.jsDoc) {
|
|
55
|
+
lines.push(cls.jsDoc);
|
|
56
|
+
lines.push('');
|
|
57
|
+
}
|
|
58
|
+
if (cls.constructorSignature) {
|
|
59
|
+
lines.push('**Constructor:**');
|
|
60
|
+
lines.push('```');
|
|
61
|
+
lines.push(cls.constructorSignature);
|
|
62
|
+
lines.push('```');
|
|
63
|
+
lines.push('');
|
|
64
|
+
}
|
|
65
|
+
if (cls.properties.length > 0) {
|
|
66
|
+
lines.push('**Properties:**');
|
|
67
|
+
for (const prop of cls.properties) {
|
|
68
|
+
lines.push(formatProperty(prop));
|
|
69
|
+
}
|
|
70
|
+
lines.push('');
|
|
71
|
+
}
|
|
72
|
+
if (cls.methods.length > 0) {
|
|
73
|
+
lines.push('**Methods:**');
|
|
74
|
+
for (const method of cls.methods) {
|
|
75
|
+
lines.push(formatMethod(method));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return lines.join('\n');
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Formats an interface for markdown output
|
|
82
|
+
*/
|
|
83
|
+
function formatInterface(iface, includeJsDoc) {
|
|
84
|
+
const lines = [];
|
|
85
|
+
lines.push(`### ${iface.name}`);
|
|
86
|
+
lines.push('');
|
|
87
|
+
if (includeJsDoc && iface.jsDoc) {
|
|
88
|
+
lines.push(iface.jsDoc);
|
|
89
|
+
lines.push('');
|
|
90
|
+
}
|
|
91
|
+
lines.push('```');
|
|
92
|
+
lines.push(`interface ${iface.name} {`);
|
|
93
|
+
for (const prop of iface.properties) {
|
|
94
|
+
const optional = prop.optional ? '?' : '';
|
|
95
|
+
const readonly = prop.readonly ? 'readonly ' : '';
|
|
96
|
+
lines.push(` ${readonly}${prop.name}${optional}: ${prop.type}`);
|
|
97
|
+
}
|
|
98
|
+
for (const method of iface.methods) {
|
|
99
|
+
lines.push(` ${method.signature}`);
|
|
100
|
+
}
|
|
101
|
+
lines.push('}');
|
|
102
|
+
lines.push('```');
|
|
103
|
+
return lines.join('\n');
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Formats a type alias for markdown output
|
|
107
|
+
*/
|
|
108
|
+
function formatType(type, includeJsDoc) {
|
|
109
|
+
const lines = [];
|
|
110
|
+
lines.push(`### ${type.name}`);
|
|
111
|
+
lines.push('');
|
|
112
|
+
if (includeJsDoc && type.jsDoc) {
|
|
113
|
+
lines.push(type.jsDoc);
|
|
114
|
+
lines.push('');
|
|
115
|
+
}
|
|
116
|
+
lines.push('```');
|
|
117
|
+
lines.push(`type ${type.name} = ${type.definition}`);
|
|
118
|
+
lines.push('```');
|
|
119
|
+
return lines.join('\n');
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Generates a checksum for the snapshot content
|
|
123
|
+
*/
|
|
124
|
+
function generateChecksum(content) {
|
|
125
|
+
return createHash('sha256').update(content).digest('hex').slice(0, 16);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Formats code examples for markdown output
|
|
129
|
+
*/
|
|
130
|
+
function formatExamples(examples) {
|
|
131
|
+
if (examples.length === 0)
|
|
132
|
+
return '';
|
|
133
|
+
const lines = [];
|
|
134
|
+
lines.push('## Examples');
|
|
135
|
+
lines.push('');
|
|
136
|
+
for (const example of examples) {
|
|
137
|
+
if (example.context) {
|
|
138
|
+
lines.push(example.context);
|
|
139
|
+
lines.push('');
|
|
140
|
+
}
|
|
141
|
+
lines.push('```' + example.language);
|
|
142
|
+
lines.push(example.code);
|
|
143
|
+
lines.push('```');
|
|
144
|
+
lines.push('');
|
|
145
|
+
if (example.associatedExports.length > 0) {
|
|
146
|
+
lines.push(`*Uses: ${example.associatedExports.join(', ')}*`);
|
|
147
|
+
lines.push('');
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return lines.join('\n');
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Generates a snapshot from extracted API information
|
|
154
|
+
*/
|
|
155
|
+
export function generateSnapshot(metadata, extraction, readme, options, examples = []) {
|
|
156
|
+
const lines = [];
|
|
157
|
+
const generatedAt = new Date().toISOString();
|
|
158
|
+
// Header
|
|
159
|
+
lines.push(`# ${metadata.name} v${metadata.version}`);
|
|
160
|
+
lines.push('');
|
|
161
|
+
if (metadata.description) {
|
|
162
|
+
lines.push(metadata.description);
|
|
163
|
+
lines.push('');
|
|
164
|
+
}
|
|
165
|
+
if (metadata.repository) {
|
|
166
|
+
lines.push(`**Repository:** ${metadata.repository}`);
|
|
167
|
+
lines.push('');
|
|
168
|
+
}
|
|
169
|
+
lines.push('---');
|
|
170
|
+
lines.push('');
|
|
171
|
+
// Overview from README
|
|
172
|
+
if (options.includeReadme && readme) {
|
|
173
|
+
lines.push('## Overview');
|
|
174
|
+
lines.push('');
|
|
175
|
+
lines.push(readme.truncated);
|
|
176
|
+
lines.push('');
|
|
177
|
+
lines.push('---');
|
|
178
|
+
lines.push('');
|
|
179
|
+
}
|
|
180
|
+
// Functions
|
|
181
|
+
if (extraction.functions.length > 0) {
|
|
182
|
+
lines.push('## Functions');
|
|
183
|
+
lines.push('');
|
|
184
|
+
for (const fn of extraction.functions) {
|
|
185
|
+
lines.push(formatFunction(fn, options.includeJsDoc));
|
|
186
|
+
lines.push('');
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
// Classes
|
|
190
|
+
if (extraction.classes.length > 0) {
|
|
191
|
+
lines.push('## Classes');
|
|
192
|
+
lines.push('');
|
|
193
|
+
for (const cls of extraction.classes) {
|
|
194
|
+
lines.push(formatClass(cls, options.includeJsDoc));
|
|
195
|
+
lines.push('');
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
// Interfaces
|
|
199
|
+
if (extraction.interfaces.length > 0) {
|
|
200
|
+
lines.push('## Interfaces');
|
|
201
|
+
lines.push('');
|
|
202
|
+
for (const iface of extraction.interfaces) {
|
|
203
|
+
lines.push(formatInterface(iface, options.includeJsDoc));
|
|
204
|
+
lines.push('');
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// Types
|
|
208
|
+
if (extraction.types.length > 0) {
|
|
209
|
+
lines.push('## Types');
|
|
210
|
+
lines.push('');
|
|
211
|
+
for (const type of extraction.types) {
|
|
212
|
+
lines.push(formatType(type, options.includeJsDoc));
|
|
213
|
+
lines.push('');
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
// Examples (from README)
|
|
217
|
+
if (options.includeExamples && examples.length > 0) {
|
|
218
|
+
lines.push(formatExamples(examples.slice(0, options.maxExamples)));
|
|
219
|
+
}
|
|
220
|
+
// Dependencies
|
|
221
|
+
const deps = Object.entries(metadata.dependencies);
|
|
222
|
+
if (deps.length > 0) {
|
|
223
|
+
lines.push('## Dependencies');
|
|
224
|
+
lines.push('');
|
|
225
|
+
for (const [name, version] of deps) {
|
|
226
|
+
lines.push(`- \`${name}\` ${version}`);
|
|
227
|
+
}
|
|
228
|
+
lines.push('');
|
|
229
|
+
}
|
|
230
|
+
// Extraction errors (if any)
|
|
231
|
+
if (extraction.errors.length > 0) {
|
|
232
|
+
lines.push('## Notes');
|
|
233
|
+
lines.push('');
|
|
234
|
+
lines.push('Some exports could not be fully extracted:');
|
|
235
|
+
for (const error of extraction.errors) {
|
|
236
|
+
lines.push(`- ${error}`);
|
|
237
|
+
}
|
|
238
|
+
lines.push('');
|
|
239
|
+
}
|
|
240
|
+
const content = lines.join('\n');
|
|
241
|
+
const checksum = generateChecksum(content);
|
|
242
|
+
return {
|
|
243
|
+
packageName: metadata.name,
|
|
244
|
+
version: metadata.version,
|
|
245
|
+
generatedAt,
|
|
246
|
+
content,
|
|
247
|
+
checksum
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Creates a SnapshotGenerator instance
|
|
252
|
+
*/
|
|
253
|
+
export function createSnapshotGenerator() {
|
|
254
|
+
return {
|
|
255
|
+
generate: generateSnapshot
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
//# sourceMappingURL=snapshot.js.map
|