diff --git a/src/changelog-check.ts b/src/changelog-check.ts index a8a45615..1de17f25 100644 --- a/src/changelog-check.ts +++ b/src/changelog-check.ts @@ -5,6 +5,7 @@ import path from 'path'; type PackageJson = { workspaces: string[]; + private?: boolean; }; /** @@ -160,6 +161,34 @@ async function isVersionOnlyChange( } } +/** + * Checks if a package is marked as private in its package.json. + * + * @param repoPath - The path to the repository. + * @param packageJsonPath - The path to the package.json file. + * @returns Promise that resolves to true if the package is private, false otherwise. + */ +async function isPrivatePackage( + repoPath: string, + packageJsonPath: string, +): Promise { + try { + const content = await fs.readFile( + path.join(repoPath, packageJsonPath), + 'utf-8', + ); + const packageJson = JSON.parse(content) as PackageJson; + return packageJson.private === true; + } catch (error) { + logError( + `Failed to check if package is private: ${ + error instanceof Error ? error.message : String(error) + }`, + ); + return false; + } +} + /** * Reads and validates a changelog file. * @@ -220,6 +249,7 @@ async function getChangedPackages( }[] > { const changedPackages = new Map(); + const privatePackageCache = new Map(); for (const file of files) { // Skip workflow files @@ -229,6 +259,21 @@ async function getChangedPackages( const packageInfo = getPackageInfo(file, workspacePatterns); if (packageInfo) { + let isPrivate = privatePackageCache.get(packageInfo.package); + if (isPrivate === undefined) { + const packageJsonPath = path.join( + packageInfo.base, + packageInfo.package, + 'package.json', + ); + isPrivate = await isPrivatePackage(repoPath, packageJsonPath); + privatePackageCache.set(packageInfo.package, isPrivate); + } + + if (isPrivate) { + continue; + } + // Skip test files, docs, and changelog files if ( !file.match(/\.(test|spec)\./u) &&