@node-cli/bundlecheck 1.4.0 → 1.5.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.
@@ -0,0 +1,330 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ /**
4
+ * Resolve a relative import path to an absolute file path.
5
+ */ function resolveImportPath(basePath, importPath) {
6
+ // Remove quotes and trim.
7
+ let cleanPath = importPath.replace(/['"]/g, "").trim();
8
+ // Only handle relative imports.
9
+ if (!cleanPath.startsWith(".")) {
10
+ return null;
11
+ }
12
+ /**
13
+ * Strip .js/.mjs extension if present (TypeScript uses .js in imports but
14
+ * .d.ts for types).
15
+ */ cleanPath = cleanPath.replace(/\.(m?js)$/, "");
16
+ const baseDir = path.dirname(basePath);
17
+ const resolved = path.resolve(baseDir, cleanPath);
18
+ // Try different extensions for the resolved path.
19
+ const extensions = [
20
+ ".d.ts",
21
+ ".d.mts",
22
+ ".ts",
23
+ ""
24
+ ];
25
+ for (const ext of extensions){
26
+ const tryPath = resolved + ext;
27
+ if (fs.existsSync(tryPath) && fs.statSync(tryPath).isFile()) {
28
+ return tryPath;
29
+ }
30
+ }
31
+ // Try index files in directory.
32
+ for (const ext of [
33
+ ".d.ts",
34
+ ".d.mts",
35
+ ".ts"
36
+ ]){
37
+ const indexPath = path.join(resolved, `index${ext}`);
38
+ if (fs.existsSync(indexPath) && fs.statSync(indexPath).isFile()) {
39
+ return indexPath;
40
+ }
41
+ }
42
+ return null;
43
+ }
44
+ /**
45
+ * Parse a TypeScript declaration file (.d.ts) to extract named exports.
46
+ * Recursively follows re-exports up to a maximum depth.
47
+ */ function parseDeclarationFile(filePath, content, visited = new Set(), depth = 0) {
48
+ const MAX_DEPTH = 10;
49
+ const MAX_FILES = 500;
50
+ if (depth > MAX_DEPTH || visited.size > MAX_FILES) {
51
+ return [];
52
+ }
53
+ // Avoid circular imports.
54
+ const normalizedPath = path.resolve(filePath);
55
+ if (visited.has(normalizedPath)) {
56
+ return [];
57
+ }
58
+ visited.add(normalizedPath);
59
+ const exports = [];
60
+ const seenNames = new Set();
61
+ const addExport = (name, kind)=>{
62
+ // Skip internal/private exports and TypeScript utility types.
63
+ if (name.startsWith("_") || name === "default" || seenNames.has(name)) {
64
+ return;
65
+ }
66
+ seenNames.add(name);
67
+ exports.push({
68
+ name,
69
+ kind
70
+ });
71
+ };
72
+ // Pattern for: export * from './path'.
73
+ const reExportAllPattern = /export\s+\*\s+from\s+['"]([^'"]+)['"]/g;
74
+ // Pattern for: export type { Name, Name2 } from './path' (type-only exports).
75
+ const reExportTypePattern = /export\s+type\s+\{([^}]+)\}\s+from\s+['"]([^'"]+)['"]/g;
76
+ /**
77
+ * Pattern for: export { Name, Name2 } from './path' (value exports - NOT
78
+ * type).
79
+ */ const reExportValuePattern = /export\s+\{([^}]+)\}\s+from\s+['"]([^'"]+)['"]/g;
80
+ // Pattern for: export declare function Name.
81
+ const functionPattern = /export\s+declare\s+function\s+(\w+)/g;
82
+ // Pattern for: export declare class Name.
83
+ const classPattern = /export\s+declare\s+class\s+(\w+)/g;
84
+ // Pattern for: export declare const Name.
85
+ const constPattern = /export\s+declare\s+const\s+(\w+)/g;
86
+ // Pattern for: export declare type Name.
87
+ const typePattern = /export\s+declare\s+type\s+(\w+)/g;
88
+ // Pattern for: export type Name = ... (without declare).
89
+ const typePattern2 = /export\s+type\s+(\w+)\s*[=<]/g;
90
+ // Pattern for: export type { Name } (local re-export without from).
91
+ const typeExportPattern = /export\s+type\s+\{([^}]+)\}\s*;/g;
92
+ // Pattern for: export interface Name.
93
+ const interfacePattern = /export\s+(?:declare\s+)?interface\s+(\w+)/g;
94
+ // Pattern for: export declare enum Name.
95
+ const enumPattern = /export\s+declare\s+enum\s+(\w+)/g;
96
+ // Pattern for: export { Name, Name2 } (without from - local exports).
97
+ const namedExportPattern = /export\s+\{([^}]+)\}\s*;/g;
98
+ // Pattern for: export declare const Name: ... (component style).
99
+ const componentPattern = /export\s+declare\s+const\s+(\w+)\s*:/g;
100
+ // Pattern for: export function Name (without declare).
101
+ const functionPattern2 = /export\s+function\s+(\w+)/g;
102
+ // Pattern for: export class Name (without declare).
103
+ const classPattern2 = /export\s+class\s+(\w+)/g;
104
+ // Pattern for: export const Name (without declare).
105
+ const constPattern2 = /export\s+const\s+(\w+)/g;
106
+ // Helper to extract all matches from a regex.
107
+ const extractMatches = (pattern, text)=>{
108
+ const matches = [];
109
+ let result = pattern.exec(text);
110
+ while(result !== null){
111
+ matches.push(result);
112
+ result = pattern.exec(text);
113
+ }
114
+ return matches;
115
+ };
116
+ // Handle: export * from './path' - recursively parse.
117
+ for (const match of extractMatches(reExportAllPattern, content)){
118
+ const importPath = match[1];
119
+ const resolvedPath = resolveImportPath(filePath, importPath);
120
+ if (resolvedPath) {
121
+ try {
122
+ const importedContent = fs.readFileSync(resolvedPath, "utf-8");
123
+ const importedExports = parseDeclarationFile(resolvedPath, importedContent, visited, depth + 1);
124
+ for (const exp of importedExports){
125
+ addExport(exp.name, exp.kind);
126
+ }
127
+ } catch {
128
+ // Ignore read errors.
129
+ }
130
+ }
131
+ }
132
+ // Handle: export type { Name } from './path' (type-only exports).
133
+ for (const match of extractMatches(reExportTypePattern, content)){
134
+ const exportList = match[1];
135
+ const names = exportList.split(",").map((s)=>{
136
+ const trimmed = s.trim();
137
+ // Handle "Name as Alias".
138
+ const asMatch = trimmed.match(/(\w+)\s+as\s+(\w+)/);
139
+ if (asMatch) {
140
+ return asMatch[2];
141
+ }
142
+ return trimmed;
143
+ });
144
+ for (const name of names){
145
+ if (name && /^\w+$/.test(name)) {
146
+ addExport(name, "type");
147
+ }
148
+ }
149
+ }
150
+ // Handle: export { Name } from './path' (value exports).
151
+ for (const match of extractMatches(reExportValuePattern, content)){
152
+ // Skip if this is actually a type export (already handled above).
153
+ const fullMatch = match[0];
154
+ if (fullMatch.includes("export type")) {
155
+ continue;
156
+ }
157
+ const exportList = match[1];
158
+ const names = exportList.split(",").map((s)=>{
159
+ const trimmed = s.trim();
160
+ // Handle "Name as Alias".
161
+ const asMatch = trimmed.match(/(\w+)\s+as\s+(\w+)/);
162
+ if (asMatch) {
163
+ return asMatch[2];
164
+ }
165
+ // Handle "type Name" syntax within the braces.
166
+ const typeMatch = trimmed.match(/type\s+(\w+)/);
167
+ if (typeMatch) {
168
+ /**
169
+ * This is a type being re-exported, skip it (will be handled by type
170
+ * pattern).
171
+ */ return null;
172
+ }
173
+ return trimmed;
174
+ });
175
+ for (const name of names){
176
+ if (name && /^\w+$/.test(name)) {
177
+ addExport(name, "unknown");
178
+ }
179
+ }
180
+ }
181
+ // Extract functions.
182
+ for (const match of extractMatches(functionPattern, content)){
183
+ addExport(match[1], "function");
184
+ }
185
+ for (const match of extractMatches(functionPattern2, content)){
186
+ addExport(match[1], "function");
187
+ }
188
+ // Extract classes.
189
+ for (const match of extractMatches(classPattern, content)){
190
+ addExport(match[1], "class");
191
+ }
192
+ for (const match of extractMatches(classPattern2, content)){
193
+ addExport(match[1], "class");
194
+ }
195
+ // Extract const (includes React components).
196
+ for (const match of extractMatches(constPattern, content)){
197
+ addExport(match[1], "const");
198
+ }
199
+ for (const match of extractMatches(constPattern2, content)){
200
+ addExport(match[1], "const");
201
+ }
202
+ // Also catch component-style declarations.
203
+ for (const match of extractMatches(componentPattern, content)){
204
+ addExport(match[1], "const");
205
+ }
206
+ // Extract types (declare type).
207
+ for (const match of extractMatches(typePattern, content)){
208
+ addExport(match[1], "type");
209
+ }
210
+ // Extract types (export type X =).
211
+ for (const match of extractMatches(typePattern2, content)){
212
+ addExport(match[1], "type");
213
+ }
214
+ // Extract type exports (export type { X }).
215
+ for (const match of extractMatches(typeExportPattern, content)){
216
+ const exportList = match[1];
217
+ const names = exportList.split(",").map((s)=>s.trim());
218
+ for (const name of names){
219
+ if (name && /^\w+$/.test(name)) {
220
+ addExport(name, "type");
221
+ }
222
+ }
223
+ }
224
+ // Extract interfaces.
225
+ for (const match of extractMatches(interfacePattern, content)){
226
+ addExport(match[1], "interface");
227
+ }
228
+ // Extract enums.
229
+ for (const match of extractMatches(enumPattern, content)){
230
+ addExport(match[1], "enum");
231
+ }
232
+ /**
233
+ * Extract named exports from export { ... } (without from - these are local
234
+ * exports).
235
+ */ for (const match of extractMatches(namedExportPattern, content)){
236
+ const exportList = match[1];
237
+ // Skip if this looks like a type export (already handled above).
238
+ if (content.substring(match.index - 5, match.index).includes("type")) {
239
+ continue;
240
+ }
241
+ const names = exportList.split(",").map((s)=>{
242
+ const trimmed = s.trim();
243
+ const asMatch = trimmed.match(/(\w+)\s+as\s+(\w+)/);
244
+ if (asMatch) {
245
+ return asMatch[2];
246
+ }
247
+ const typeMatch = trimmed.match(/type\s+(\w+)/);
248
+ if (typeMatch) {
249
+ return typeMatch[1];
250
+ }
251
+ return trimmed;
252
+ });
253
+ for (const name of names){
254
+ if (name && /^\w+$/.test(name)) {
255
+ addExport(name, "unknown");
256
+ }
257
+ }
258
+ }
259
+ return exports;
260
+ }
261
+ /**
262
+ * Get named exports from an installed package by parsing its type definitions.
263
+ *
264
+ * @param tmpDir - The temporary directory where the package is installed
265
+ * @param packageName - The package name (e.g., "@mantine/core")
266
+ * @returns ParsedExports containing the list of exports and count
267
+ *
268
+ */ export function getNamedExports(tmpDir, packageName) {
269
+ const packageDir = path.join(tmpDir, "node_modules", packageName);
270
+ const emptyResult = {
271
+ exports: [],
272
+ count: 0,
273
+ runtimeExports: [],
274
+ runtimeCount: 0
275
+ };
276
+ // Try to read package.json to find the types entry.
277
+ const pkgJsonPath = path.join(packageDir, "package.json");
278
+ if (!fs.existsSync(pkgJsonPath)) {
279
+ return emptyResult;
280
+ }
281
+ let typesEntry;
282
+ try {
283
+ const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8"));
284
+ // Look for types in order of preference.
285
+ typesEntry = pkgJson.types || pkgJson.typings || pkgJson.exports?.["."]?.types || typeof pkgJson.exports?.["."] === "object" && pkgJson.exports["."].types;
286
+ // If no types field, try common patterns.
287
+ if (!typesEntry) {
288
+ const commonPaths = [
289
+ "dist/index.d.ts",
290
+ "lib/index.d.ts",
291
+ "index.d.ts",
292
+ "types/index.d.ts"
293
+ ];
294
+ for (const tryPath of commonPaths){
295
+ if (fs.existsSync(path.join(packageDir, tryPath))) {
296
+ typesEntry = tryPath;
297
+ break;
298
+ }
299
+ }
300
+ }
301
+ } catch {
302
+ return emptyResult;
303
+ }
304
+ if (!typesEntry) {
305
+ return emptyResult;
306
+ }
307
+ // Read and parse the types file.
308
+ const typesPath = path.join(packageDir, typesEntry);
309
+ if (!fs.existsSync(typesPath)) {
310
+ return emptyResult;
311
+ }
312
+ try {
313
+ const content = fs.readFileSync(typesPath, "utf-8");
314
+ const exports = parseDeclarationFile(typesPath, content);
315
+ // Sort exports by name for consistent output.
316
+ exports.sort((a, b)=>a.name.localeCompare(b.name));
317
+ // Filter to runtime-only exports (exclude types and interfaces).
318
+ const runtimeExports = exports.filter((e)=>e.kind !== "type" && e.kind !== "interface");
319
+ return {
320
+ exports,
321
+ count: exports.length,
322
+ runtimeExports,
323
+ runtimeCount: runtimeExports.length
324
+ };
325
+ } catch {
326
+ return emptyResult;
327
+ }
328
+ }
329
+
330
+ //# sourceMappingURL=exports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/exports.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\n\n/**\n * Represents a named export from a package.\n */\nexport type NamedExport = {\n\t/**\n\t * The export name (e.g., \"Button\", \"useState\").\n\t */\n\tname: string;\n\t/**\n\t * The type of export.\n\t */\n\tkind:\n\t\t| \"function\"\n\t\t| \"class\"\n\t\t| \"const\"\n\t\t| \"type\"\n\t\t| \"interface\"\n\t\t| \"enum\"\n\t\t| \"unknown\";\n};\n\n/**\n * Result from parsing package exports.\n */\nexport type ParsedExports = {\n\t/**\n\t * Array of all named exports found in the package (including types).\n\t */\n\texports: NamedExport[];\n\t/**\n\t * Total count of all named exports (including types).\n\t */\n\tcount: number;\n\t/**\n\t * Array of runtime exports only (excluding types and interfaces).\n\t */\n\truntimeExports: NamedExport[];\n\t/**\n\t * Count of runtime exports only (functions, classes, const, enums).\n\t */\n\truntimeCount: number;\n};\n\n/**\n * Resolve a relative import path to an absolute file path.\n */\nfunction resolveImportPath(\n\tbasePath: string,\n\timportPath: string,\n): string | null {\n\t// Remove quotes and trim.\n\tlet cleanPath = importPath.replace(/['\"]/g, \"\").trim();\n\n\t// Only handle relative imports.\n\tif (!cleanPath.startsWith(\".\")) {\n\t\treturn null;\n\t}\n\n\t/**\n\t * Strip .js/.mjs extension if present (TypeScript uses .js in imports but\n\t * .d.ts for types).\n\t */\n\tcleanPath = cleanPath.replace(/\\.(m?js)$/, \"\");\n\n\tconst baseDir = path.dirname(basePath);\n\tconst resolved = path.resolve(baseDir, cleanPath);\n\n\t// Try different extensions for the resolved path.\n\tconst extensions = [\".d.ts\", \".d.mts\", \".ts\", \"\"];\n\tfor (const ext of extensions) {\n\t\tconst tryPath = resolved + ext;\n\t\tif (fs.existsSync(tryPath) && fs.statSync(tryPath).isFile()) {\n\t\t\treturn tryPath;\n\t\t}\n\t}\n\n\t// Try index files in directory.\n\tfor (const ext of [\".d.ts\", \".d.mts\", \".ts\"]) {\n\t\tconst indexPath = path.join(resolved, `index${ext}`);\n\t\tif (fs.existsSync(indexPath) && fs.statSync(indexPath).isFile()) {\n\t\t\treturn indexPath;\n\t\t}\n\t}\n\n\treturn null;\n}\n\n/**\n * Parse a TypeScript declaration file (.d.ts) to extract named exports.\n * Recursively follows re-exports up to a maximum depth.\n */\nfunction parseDeclarationFile(\n\tfilePath: string,\n\tcontent: string,\n\tvisited: Set<string> = new Set(),\n\tdepth = 0,\n): NamedExport[] {\n\tconst MAX_DEPTH = 10;\n\tconst MAX_FILES = 500;\n\n\tif (depth > MAX_DEPTH || visited.size > MAX_FILES) {\n\t\treturn [];\n\t}\n\n\t// Avoid circular imports.\n\tconst normalizedPath = path.resolve(filePath);\n\tif (visited.has(normalizedPath)) {\n\t\treturn [];\n\t}\n\tvisited.add(normalizedPath);\n\n\tconst exports: NamedExport[] = [];\n\tconst seenNames = new Set<string>();\n\n\tconst addExport = (name: string, kind: NamedExport[\"kind\"]) => {\n\t\t// Skip internal/private exports and TypeScript utility types.\n\t\tif (name.startsWith(\"_\") || name === \"default\" || seenNames.has(name)) {\n\t\t\treturn;\n\t\t}\n\t\tseenNames.add(name);\n\t\texports.push({ name, kind });\n\t};\n\n\t// Pattern for: export * from './path'.\n\tconst reExportAllPattern = /export\\s+\\*\\s+from\\s+['\"]([^'\"]+)['\"]/g;\n\n\t// Pattern for: export type { Name, Name2 } from './path' (type-only exports).\n\tconst reExportTypePattern =\n\t\t/export\\s+type\\s+\\{([^}]+)\\}\\s+from\\s+['\"]([^'\"]+)['\"]/g;\n\n\t/**\n\t * Pattern for: export { Name, Name2 } from './path' (value exports - NOT\n\t * type).\n\t */\n\tconst reExportValuePattern =\n\t\t/export\\s+\\{([^}]+)\\}\\s+from\\s+['\"]([^'\"]+)['\"]/g;\n\n\t// Pattern for: export declare function Name.\n\tconst functionPattern = /export\\s+declare\\s+function\\s+(\\w+)/g;\n\t// Pattern for: export declare class Name.\n\tconst classPattern = /export\\s+declare\\s+class\\s+(\\w+)/g;\n\t// Pattern for: export declare const Name.\n\tconst constPattern = /export\\s+declare\\s+const\\s+(\\w+)/g;\n\t// Pattern for: export declare type Name.\n\tconst typePattern = /export\\s+declare\\s+type\\s+(\\w+)/g;\n\t// Pattern for: export type Name = ... (without declare).\n\tconst typePattern2 = /export\\s+type\\s+(\\w+)\\s*[=<]/g;\n\t// Pattern for: export type { Name } (local re-export without from).\n\tconst typeExportPattern = /export\\s+type\\s+\\{([^}]+)\\}\\s*;/g;\n\t// Pattern for: export interface Name.\n\tconst interfacePattern = /export\\s+(?:declare\\s+)?interface\\s+(\\w+)/g;\n\t// Pattern for: export declare enum Name.\n\tconst enumPattern = /export\\s+declare\\s+enum\\s+(\\w+)/g;\n\t// Pattern for: export { Name, Name2 } (without from - local exports).\n\tconst namedExportPattern = /export\\s+\\{([^}]+)\\}\\s*;/g;\n\t// Pattern for: export declare const Name: ... (component style).\n\tconst componentPattern = /export\\s+declare\\s+const\\s+(\\w+)\\s*:/g;\n\t// Pattern for: export function Name (without declare).\n\tconst functionPattern2 = /export\\s+function\\s+(\\w+)/g;\n\t// Pattern for: export class Name (without declare).\n\tconst classPattern2 = /export\\s+class\\s+(\\w+)/g;\n\t// Pattern for: export const Name (without declare).\n\tconst constPattern2 = /export\\s+const\\s+(\\w+)/g;\n\n\t// Helper to extract all matches from a regex.\n\tconst extractMatches = (pattern: RegExp, text: string): RegExpExecArray[] => {\n\t\tconst matches: RegExpExecArray[] = [];\n\t\tlet result = pattern.exec(text);\n\t\twhile (result !== null) {\n\t\t\tmatches.push(result);\n\t\t\tresult = pattern.exec(text);\n\t\t}\n\t\treturn matches;\n\t};\n\n\t// Handle: export * from './path' - recursively parse.\n\tfor (const match of extractMatches(reExportAllPattern, content)) {\n\t\tconst importPath = match[1];\n\t\tconst resolvedPath = resolveImportPath(filePath, importPath);\n\t\tif (resolvedPath) {\n\t\t\ttry {\n\t\t\t\tconst importedContent = fs.readFileSync(resolvedPath, \"utf-8\");\n\t\t\t\tconst importedExports = parseDeclarationFile(\n\t\t\t\t\tresolvedPath,\n\t\t\t\t\timportedContent,\n\t\t\t\t\tvisited,\n\t\t\t\t\tdepth + 1,\n\t\t\t\t);\n\t\t\t\tfor (const exp of importedExports) {\n\t\t\t\t\taddExport(exp.name, exp.kind);\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t// Ignore read errors.\n\t\t\t}\n\t\t}\n\t}\n\n\t// Handle: export type { Name } from './path' (type-only exports).\n\tfor (const match of extractMatches(reExportTypePattern, content)) {\n\t\tconst exportList = match[1];\n\t\tconst names = exportList.split(\",\").map((s) => {\n\t\t\tconst trimmed = s.trim();\n\t\t\t// Handle \"Name as Alias\".\n\t\t\tconst asMatch = trimmed.match(/(\\w+)\\s+as\\s+(\\w+)/);\n\t\t\tif (asMatch) {\n\t\t\t\treturn asMatch[2];\n\t\t\t}\n\t\t\treturn trimmed;\n\t\t});\n\n\t\tfor (const name of names) {\n\t\t\tif (name && /^\\w+$/.test(name)) {\n\t\t\t\taddExport(name, \"type\");\n\t\t\t}\n\t\t}\n\t}\n\n\t// Handle: export { Name } from './path' (value exports).\n\tfor (const match of extractMatches(reExportValuePattern, content)) {\n\t\t// Skip if this is actually a type export (already handled above).\n\t\tconst fullMatch = match[0];\n\t\tif (fullMatch.includes(\"export type\")) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst exportList = match[1];\n\t\tconst names = exportList.split(\",\").map((s) => {\n\t\t\tconst trimmed = s.trim();\n\t\t\t// Handle \"Name as Alias\".\n\t\t\tconst asMatch = trimmed.match(/(\\w+)\\s+as\\s+(\\w+)/);\n\t\t\tif (asMatch) {\n\t\t\t\treturn asMatch[2];\n\t\t\t}\n\t\t\t// Handle \"type Name\" syntax within the braces.\n\t\t\tconst typeMatch = trimmed.match(/type\\s+(\\w+)/);\n\t\t\tif (typeMatch) {\n\t\t\t\t/**\n\t\t\t\t * This is a type being re-exported, skip it (will be handled by type\n\t\t\t\t * pattern).\n\t\t\t\t */\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn trimmed;\n\t\t});\n\n\t\tfor (const name of names) {\n\t\t\tif (name && /^\\w+$/.test(name)) {\n\t\t\t\taddExport(name, \"unknown\");\n\t\t\t}\n\t\t}\n\t}\n\n\t// Extract functions.\n\tfor (const match of extractMatches(functionPattern, content)) {\n\t\taddExport(match[1], \"function\");\n\t}\n\tfor (const match of extractMatches(functionPattern2, content)) {\n\t\taddExport(match[1], \"function\");\n\t}\n\n\t// Extract classes.\n\tfor (const match of extractMatches(classPattern, content)) {\n\t\taddExport(match[1], \"class\");\n\t}\n\tfor (const match of extractMatches(classPattern2, content)) {\n\t\taddExport(match[1], \"class\");\n\t}\n\n\t// Extract const (includes React components).\n\tfor (const match of extractMatches(constPattern, content)) {\n\t\taddExport(match[1], \"const\");\n\t}\n\tfor (const match of extractMatches(constPattern2, content)) {\n\t\taddExport(match[1], \"const\");\n\t}\n\n\t// Also catch component-style declarations.\n\tfor (const match of extractMatches(componentPattern, content)) {\n\t\taddExport(match[1], \"const\");\n\t}\n\n\t// Extract types (declare type).\n\tfor (const match of extractMatches(typePattern, content)) {\n\t\taddExport(match[1], \"type\");\n\t}\n\n\t// Extract types (export type X =).\n\tfor (const match of extractMatches(typePattern2, content)) {\n\t\taddExport(match[1], \"type\");\n\t}\n\n\t// Extract type exports (export type { X }).\n\tfor (const match of extractMatches(typeExportPattern, content)) {\n\t\tconst exportList = match[1];\n\t\tconst names = exportList.split(\",\").map((s) => s.trim());\n\t\tfor (const name of names) {\n\t\t\tif (name && /^\\w+$/.test(name)) {\n\t\t\t\taddExport(name, \"type\");\n\t\t\t}\n\t\t}\n\t}\n\n\t// Extract interfaces.\n\tfor (const match of extractMatches(interfacePattern, content)) {\n\t\taddExport(match[1], \"interface\");\n\t}\n\n\t// Extract enums.\n\tfor (const match of extractMatches(enumPattern, content)) {\n\t\taddExport(match[1], \"enum\");\n\t}\n\n\t/**\n\t * Extract named exports from export { ... } (without from - these are local\n\t * exports).\n\t */\n\tfor (const match of extractMatches(namedExportPattern, content)) {\n\t\tconst exportList = match[1];\n\t\t// Skip if this looks like a type export (already handled above).\n\t\tif (content.substring(match.index - 5, match.index).includes(\"type\")) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst names = exportList.split(\",\").map((s) => {\n\t\t\tconst trimmed = s.trim();\n\t\t\tconst asMatch = trimmed.match(/(\\w+)\\s+as\\s+(\\w+)/);\n\t\t\tif (asMatch) {\n\t\t\t\treturn asMatch[2];\n\t\t\t}\n\t\t\tconst typeMatch = trimmed.match(/type\\s+(\\w+)/);\n\t\t\tif (typeMatch) {\n\t\t\t\treturn typeMatch[1];\n\t\t\t}\n\t\t\treturn trimmed;\n\t\t});\n\n\t\tfor (const name of names) {\n\t\t\tif (name && /^\\w+$/.test(name)) {\n\t\t\t\taddExport(name, \"unknown\");\n\t\t\t}\n\t\t}\n\t}\n\n\treturn exports;\n}\n\n/**\n * Get named exports from an installed package by parsing its type definitions.\n *\n * @param tmpDir - The temporary directory where the package is installed\n * @param packageName - The package name (e.g., \"@mantine/core\")\n * @returns ParsedExports containing the list of exports and count\n *\n */\nexport function getNamedExports(\n\ttmpDir: string,\n\tpackageName: string,\n): ParsedExports {\n\tconst packageDir = path.join(tmpDir, \"node_modules\", packageName);\n\n\tconst emptyResult: ParsedExports = {\n\t\texports: [],\n\t\tcount: 0,\n\t\truntimeExports: [],\n\t\truntimeCount: 0,\n\t};\n\n\t// Try to read package.json to find the types entry.\n\tconst pkgJsonPath = path.join(packageDir, \"package.json\");\n\tif (!fs.existsSync(pkgJsonPath)) {\n\t\treturn emptyResult;\n\t}\n\n\tlet typesEntry: string | undefined;\n\ttry {\n\t\tconst pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, \"utf-8\"));\n\n\t\t// Look for types in order of preference.\n\t\ttypesEntry =\n\t\t\tpkgJson.types ||\n\t\t\tpkgJson.typings ||\n\t\t\tpkgJson.exports?.[\".\"]?.types ||\n\t\t\t(typeof pkgJson.exports?.[\".\"] === \"object\" &&\n\t\t\t\tpkgJson.exports[\".\"].types);\n\n\t\t// If no types field, try common patterns.\n\t\tif (!typesEntry) {\n\t\t\tconst commonPaths = [\n\t\t\t\t\"dist/index.d.ts\",\n\t\t\t\t\"lib/index.d.ts\",\n\t\t\t\t\"index.d.ts\",\n\t\t\t\t\"types/index.d.ts\",\n\t\t\t];\n\t\t\tfor (const tryPath of commonPaths) {\n\t\t\t\tif (fs.existsSync(path.join(packageDir, tryPath))) {\n\t\t\t\t\ttypesEntry = tryPath;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} catch {\n\t\treturn emptyResult;\n\t}\n\n\tif (!typesEntry) {\n\t\treturn emptyResult;\n\t}\n\n\t// Read and parse the types file.\n\tconst typesPath = path.join(packageDir, typesEntry);\n\tif (!fs.existsSync(typesPath)) {\n\t\treturn emptyResult;\n\t}\n\n\ttry {\n\t\tconst content = fs.readFileSync(typesPath, \"utf-8\");\n\t\tconst exports = parseDeclarationFile(typesPath, content);\n\n\t\t// Sort exports by name for consistent output.\n\t\texports.sort((a, b) => a.name.localeCompare(b.name));\n\n\t\t// Filter to runtime-only exports (exclude types and interfaces).\n\t\tconst runtimeExports = exports.filter(\n\t\t\t(e) => e.kind !== \"type\" && e.kind !== \"interface\",\n\t\t);\n\n\t\treturn {\n\t\t\texports,\n\t\t\tcount: exports.length,\n\t\t\truntimeExports,\n\t\t\truntimeCount: runtimeExports.length,\n\t\t};\n\t} catch {\n\t\treturn emptyResult;\n\t}\n}\n"],"names":["fs","path","resolveImportPath","basePath","importPath","cleanPath","replace","trim","startsWith","baseDir","dirname","resolved","resolve","extensions","ext","tryPath","existsSync","statSync","isFile","indexPath","join","parseDeclarationFile","filePath","content","visited","Set","depth","MAX_DEPTH","MAX_FILES","size","normalizedPath","has","add","exports","seenNames","addExport","name","kind","push","reExportAllPattern","reExportTypePattern","reExportValuePattern","functionPattern","classPattern","constPattern","typePattern","typePattern2","typeExportPattern","interfacePattern","enumPattern","namedExportPattern","componentPattern","functionPattern2","classPattern2","constPattern2","extractMatches","pattern","text","matches","result","exec","match","resolvedPath","importedContent","readFileSync","importedExports","exp","exportList","names","split","map","s","trimmed","asMatch","test","fullMatch","includes","typeMatch","substring","index","getNamedExports","tmpDir","packageName","packageDir","emptyResult","count","runtimeExports","runtimeCount","pkgJsonPath","typesEntry","pkgJson","JSON","parse","types","typings","commonPaths","typesPath","sort","a","b","localeCompare","filter","e","length"],"mappings":"AAAA,OAAOA,QAAQ,UAAU;AACzB,OAAOC,UAAU,YAAY;AA6C7B;;CAEC,GACD,SAASC,kBACRC,QAAgB,EAChBC,UAAkB;IAElB,0BAA0B;IAC1B,IAAIC,YAAYD,WAAWE,OAAO,CAAC,SAAS,IAAIC,IAAI;IAEpD,gCAAgC;IA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