Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/changelog-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import path from 'path';

type PackageJson = {
workspaces: string[];
private?: boolean;
};

/**
Expand Down Expand Up @@ -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<boolean> {
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.
*
Expand Down Expand Up @@ -220,6 +249,7 @@ async function getChangedPackages(
}[]
> {
const changedPackages = new Map<string, { base: string; package: string }>();
const privatePackageCache = new Map<string, boolean>();

for (const file of files) {
// Skip workflow files
Expand All @@ -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) &&
Expand Down
Loading