-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a pre-commit hook to check benchmark dependencies (#45)
Ref. #31 (comment).
- Loading branch information
1 parent
b7ab00f
commit c891603
Showing
2 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Check if benchmark dependencies have explicit versions | ||
const semver = require("semver"); | ||
const { EOL } = require("os"); | ||
|
||
const { dependencies } = require("../../package.json"); | ||
const { targetList } = require("../../src/cli-flags-helper"); | ||
|
||
// babel -> @babel/standalone | ||
targetList.delete("babel"); | ||
targetList.add("@babel/standalone"); | ||
|
||
const invalid = [...targetList].reduce((list, dependency) => { | ||
const version = dependencies[dependency]; | ||
if (!semver.valid(version)) { | ||
list.push({ dependency, version }); | ||
} | ||
return list; | ||
}, []); | ||
|
||
|
||
if (invalid.length > 0) { | ||
console.error( | ||
`ERROR: Benchmark dependencies must have explicit versions.${EOL}` | ||
); | ||
console.error(`Invalid dependencies:`); | ||
invalid.forEach(({ dependency, version }) => { | ||
console.error(`- ${dependency}: ${version}`); | ||
}); | ||
|
||
process.exit(1); | ||
} |