* Check if all files referenced in a package's exports field exist
(packageJsonPath: string)
| 31 | * Check if all files referenced in a package's exports field exist |
| 32 | */ |
| 33 | function checkPackage(packageJsonPath: string): { |
| 34 | packageName: string; |
| 35 | missing: string[]; |
| 36 | } { |
| 37 | const packageDir = dirname(packageJsonPath); |
| 38 | const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8")); |
| 39 | const packageName = packageJson.name || packageJsonPath; |
| 40 | |
| 41 | const missing: string[] = []; |
| 42 | |
| 43 | if (!packageJson.exports) { |
| 44 | // No exports field, nothing to check |
| 45 | return { packageName, missing }; |
| 46 | } |
| 47 | |
| 48 | // Extract all file paths from exports |
| 49 | const filePaths = extractFilePaths(packageJson.exports); |
| 50 | |
| 51 | // Check if each file exists |
| 52 | for (const filePath of filePaths) { |
| 53 | // Skip non-file paths (like package names or special conditions) |
| 54 | if (!filePath.startsWith(".")) { |
| 55 | continue; |
| 56 | } |
| 57 | |
| 58 | const fullPath = resolve(packageDir, filePath); |
| 59 | if (!existsSync(fullPath)) { |
| 60 | missing.push(filePath); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | return { packageName, missing }; |
| 65 | } |
| 66 | |
| 67 | // Main execution |
| 68 | async function main() { |
no test coverage detected