From b74ab889236ca940ef5d20ecde06c4304d8fbc97 Mon Sep 17 00:00:00 2001 From: Salah-Eddine Saakoun Date: Mon, 5 May 2025 23:09:56 +0200 Subject: [PATCH 1/2] chore(changelog-check): exclude private packages from changelog check --- src/changelog-check.ts | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/changelog-check.ts b/src/changelog-check.ts index a8a45615..871da7e3 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,31 @@ async function isVersionOnlyChange( } } +/** + * Checks if a package is marked as private in its package.json. + * + * @param repoPath - The path to the repository. + * @param filePath - 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, + filePath: string, +): Promise { + try { + const content = await fs.readFile(path.join(repoPath, filePath), '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 +246,7 @@ async function getChangedPackages( }[] > { const changedPackages = new Map(); + const privatePackageCache = new Map(); for (const file of files) { // Skip workflow files @@ -229,6 +256,23 @@ async function getChangedPackages( const packageInfo = getPackageInfo(file, workspacePatterns); if (packageInfo) { + // Check if we've already determined if this package is private + let isPrivate = privatePackageCache.get(packageInfo.package); + if (isPrivate === undefined) { + // If not in cache, check and cache the result + 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) && From a43767d562cfccbe7ab9ffe19663b55b6c13a102 Mon Sep 17 00:00:00 2001 From: Salah-Eddine Saakoun Date: Mon, 5 May 2025 23:28:31 +0200 Subject: [PATCH 2/2] fix: jsdoc + remove useless comments --- src/changelog-check.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/changelog-check.ts b/src/changelog-check.ts index 871da7e3..1de17f25 100644 --- a/src/changelog-check.ts +++ b/src/changelog-check.ts @@ -165,15 +165,18 @@ async function isVersionOnlyChange( * Checks if a package is marked as private in its package.json. * * @param repoPath - The path to the repository. - * @param filePath - The path to the package.json file. + * @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, - filePath: string, + packageJsonPath: string, ): Promise { try { - const content = await fs.readFile(path.join(repoPath, filePath), 'utf-8'); + const content = await fs.readFile( + path.join(repoPath, packageJsonPath), + 'utf-8', + ); const packageJson = JSON.parse(content) as PackageJson; return packageJson.private === true; } catch (error) { @@ -256,10 +259,8 @@ async function getChangedPackages( const packageInfo = getPackageInfo(file, workspacePatterns); if (packageInfo) { - // Check if we've already determined if this package is private let isPrivate = privatePackageCache.get(packageInfo.package); if (isPrivate === undefined) { - // If not in cache, check and cache the result const packageJsonPath = path.join( packageInfo.base, packageInfo.package,