Skip to content

Commit 7c705fa

Browse files
committed
chore: add CONTRIBUTING version guardrail check
Signed-off-by: Nsanjayboruds <nishantborude555@gmail.com>
1 parent e16f740 commit 7c705fa

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

.github/scripts/check-contributing-versions.cjs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,28 @@ const pkg = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
1111
const contributing = fs.readFileSync(contributingPath, "utf8");
1212
const lines = contributing.split(/\r?\n/);
1313

14-
const reactVersion = pkg.dependencies?.react;
15-
const gatsbyVersion = pkg.dependencies?.gatsby;
14+
function getPackageVersion(name) {
15+
const sections = [
16+
pkg.dependencies,
17+
pkg.devDependencies,
18+
pkg.peerDependencies,
19+
pkg.optionalDependencies,
20+
];
21+
22+
for (const section of sections) {
23+
if (section?.[name]) {
24+
return section[name];
25+
}
26+
}
27+
28+
return undefined;
29+
}
30+
31+
const reactVersion = getPackageVersion("react");
32+
const gatsbyVersion = getPackageVersion("gatsby");
1633

1734
if (!reactVersion || !gatsbyVersion) {
18-
console.error("Missing react or gatsby dependency in package.json.");
35+
console.error("Missing react or gatsby version in package.json dependency sections.");
1936
process.exit(1);
2037
}
2138

0 commit comments

Comments
 (0)