Skip to content

Commit 58f2e01

Browse files
author
Vieltojarvi
committed
moved missing changesets check to function
1 parent c21e963 commit 58f2e01

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

scripts/check_changeset_completeness.ts

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,16 @@ enum VersionTypeEnum {
1111
'MAJOR' = 3,
1212
}
1313

14-
const getModifiedPackages = (changedFiles: string[]): Set<string> => {
14+
const checkForMissingChangesets = async (
15+
releasePlan: ReleasePlan,
16+
gitClient: GitClient,
17+
baseRef: string
18+
) => {
19+
const packagesWithChangeset = new Set(
20+
releasePlan.releases.map((release) => release.name)
21+
);
22+
23+
const changedFiles = await gitClient.getChangedFiles(baseRef);
1524
const modifiedPackageDirs = new Set<string>();
1625

1726
changedFiles
@@ -24,7 +33,26 @@ const getModifiedPackages = (changedFiles: string[]): Set<string> => {
2433
changedPackageFile.split('/').slice(0, 2).join('/')
2534
);
2635
});
27-
return modifiedPackageDirs;
36+
37+
const packagesMissingChangesets = [];
38+
for (const modifiedPackageDir of modifiedPackageDirs) {
39+
const { name: modifiedPackageName, private: isPrivate } =
40+
await readPackageJson(modifiedPackageDir);
41+
if (isPrivate) {
42+
continue;
43+
}
44+
if (!packagesWithChangeset.has(modifiedPackageName)) {
45+
packagesMissingChangesets.push(modifiedPackageName);
46+
}
47+
}
48+
49+
if (packagesMissingChangesets.length > 0) {
50+
throw new Error(
51+
`The following packages have changes but are not included in any changeset:${EOL}${EOL}${packagesMissingChangesets.join(
52+
EOL
53+
)}${EOL}${EOL}Add a changeset using 'npx changeset add'.`
54+
);
55+
}
2856
};
2957

3058
const convertVersionType = (version: VersionType): VersionTypeEnum => {
@@ -105,32 +133,5 @@ if (baseRef === undefined) {
105133

106134
const releasePlan = await getReleasePlan(process.cwd());
107135

108-
const packagesWithChangeset = new Set(
109-
releasePlan.releases.map((release) => release.name)
110-
);
111-
112-
const changedFiles = await gitClient.getChangedFiles(baseRef);
113-
114-
const modifiedPackageDirs = getModifiedPackages(changedFiles);
115-
116-
const packagesMissingChangesets = [];
117-
for (const modifiedPackageDir of modifiedPackageDirs) {
118-
const { name: modifiedPackageName, private: isPrivate } =
119-
await readPackageJson(modifiedPackageDir);
120-
if (isPrivate) {
121-
continue;
122-
}
123-
if (!packagesWithChangeset.has(modifiedPackageName)) {
124-
packagesMissingChangesets.push(modifiedPackageName);
125-
}
126-
}
127-
128-
if (packagesMissingChangesets.length > 0) {
129-
throw new Error(
130-
`The following packages have changes but are not included in any changeset:${EOL}${EOL}${packagesMissingChangesets.join(
131-
EOL
132-
)}${EOL}${EOL}Add a changeset using 'npx changeset add'.`
133-
);
134-
}
135-
136+
await checkForMissingChangesets(releasePlan, gitClient, baseRef);
136137
checkBackendDependenciesVersion(releasePlan);

0 commit comments

Comments
 (0)