MCPcopy Create free account
hub / github.com/cloudflare/agents / checkPackage

Function checkPackage

scripts/check-exports.ts:33–65  ·  view source on GitHub ↗

* Check if all files referenced in a package's exports field exist

(packageJsonPath: string)

Source from the content-addressed store, hash-verified

31 * Check if all files referenced in a package's exports field exist
32 */
33function 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
68async function main() {

Callers 1

mainFunction · 0.85

Calls 3

extractFilePathsFunction · 0.85
parseMethod · 0.80
dirnameFunction · 0.50

Tested by

no test coverage detected