apisurf
Version:
Analyze API surface changes between npm package versions to catch breaking changes
42 lines (41 loc) • 1.48 kB
JavaScript
import * as fs from 'fs';
import * as path from 'path';
/**
* Finds packages to analyze in the current repository.
* Supports both monorepo and single package setups.
*/
export function findPackagesToAnalyze(_pattern) {
const packagesDir = path.join(process.cwd(), 'packages');
if (!fs.existsSync(packagesDir)) {
// Single package repo
if (fs.existsSync('package.json')) {
try {
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
return [{ name: pkg.name || 'package', path: '.' }];
}
catch (error) {
console.warn('Warning: Could not parse package.json:', error);
return [];
}
}
return [];
}
// Monorepo
const packages = [];
const dirs = fs.readdirSync(packagesDir);
for (const dir of dirs) {
const pkgPath = path.join(packagesDir, dir);
const packageJsonPath = path.join(pkgPath, 'package.json');
if (fs.existsSync(packageJsonPath)) {
try {
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
packages.push({ name: pkg.name || dir, path: pkgPath });
}
catch (error) {
// Skip packages with invalid package.json files
console.warn(`Warning: Could not parse package.json at ${packageJsonPath}:`, error);
}
}
}
return packages;
}