Skip to content

Commit

Permalink
Add a pre-commit hook to check benchmark dependencies (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
alopezsanchez authored and mathiasbynens committed Mar 21, 2018
1 parent b7ab00f commit c891603
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build:uglify-js-bundled": "node node_modules/uglify-js/bin/uglifyjs -b preamble=\"'const UglifyJS = module.exports = {};'\" --self > build/uglify-js-bundled.js",
"build": "webpack",
"postinstall": "npm run build:uglify-es-bundled && npm run build:uglify-js-bundled && npm run build",
"precommit": "lint-staged",
"precommit": "node tools/hooks/pre-commit && lint-staged",
"test": "jest",
"benchmark": "node dist/cli.js"
},
Expand Down Expand Up @@ -64,6 +64,7 @@
"node-libs-browser": "^2.1.0",
"os-browserify": "^0.3.0",
"raw-loader": "github:bmeurer/raw-loader#escape",
"semver": "^5.5.0",
"webpack": "^3.8.1"
}
}
31 changes: 31 additions & 0 deletions tools/hooks/pre-commit.js
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);
}

0 comments on commit c891603

Please sign in to comment.