Files
babel/benchmark/update-baselines.mjs
Huáng JùnliàngandGitHub 254525d565 Enforce node protocol import (#17207)
* enable prefer-node-protocol rule

* prefer node protocol import

* fix broken scripts

* fix e2e-old-babel error

* strip node: protocol for old node versions

* update Makefile.mjs
2025-03-31 10:49:22 -04:00

38 lines
1.3 KiB
JavaScript

import path from "node:path";
import { readFileSync, writeFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const packageFilePath = path.join(__dirname, "package.json");
const packageFile = readFileSync(packageFilePath, "utf8");
const packageFileObj = JSON.parse(packageFile);
for (const name of Object.keys(packageFileObj.devDependencies)) {
const resolution = packageFileObj.devDependencies[name];
const version = resolution.substring(resolution.lastIndexOf("@") + 1);
if (!name.startsWith("@babel-baseline/")) continue;
const lastVersion = JSON.parse(
readFileSync(
path.join(
__dirname,
"../packages",
name.replace("@babel-baseline/", "babel-"),
"package.json"
)
)
).version;
if (version !== lastVersion) {
console.log(`Updating ${name} ${version} -> ${lastVersion}`);
packageFileObj.devDependencies[name] =
resolution.substring(0, resolution.lastIndexOf("@")) + "@" + lastVersion;
}
}
const newFile = JSON.stringify(packageFileObj, null, 2) + "\n";
if (packageFile !== newFile) {
writeFileSync(packageFilePath, newFile, "utf8");
console.log("Please run `yarn` to apply changes.");
}