babel/scripts/integration-tests/utils/bump-babel-dependencies.js
Nicolò Ribaudo 63567f0667
Run jest's tests in the e2e tests (#12202)
Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
2020-10-16 23:19:39 +02:00

30 lines
844 B
JavaScript

const fs = require("fs");
const path = require("path");
const cwd = process.cwd();
const packageJSONPath = path.resolve(cwd, "./package.json");
const content = JSON.parse(fs.readFileSync(packageJSONPath));
let bumped = false;
function bumpBabelDependency(dependencies, version) {
for (const dep of Object.keys(dependencies)) {
if (dep.startsWith("@babel/") && !dependencies[dep].includes(":")) {
dependencies[dep] = version;
bumped = true;
}
}
}
if ("peerDependencies" in content) {
bumpBabelDependency(content.peerDependencies, "*");
}
if ("devDependencies" in content) {
bumpBabelDependency(content.devDependencies, "latest");
}
if ("dependencies" in content) {
bumpBabelDependency(content.dependencies, "latest");
}
if (bumped) {
fs.writeFileSync(packageJSONPath, JSON.stringify(content, undefined, 2));
}