import fs from "fs"; import semver from "semver"; import { dirnames, getPackageJsonPath, getPackagePath, resolve } from "../path"; import * as local from "../local"; import { colorify, getProgressBar } from "../log"; import * as npm from "../npm"; import { loadJson, repeat, saveJson } from "../utils"; (async function() { const progress = getProgressBar(colorify.bold("Bumping package.json versions")); const latestVersions: Record = { }; let updated = false; const output: Array = [ ]; // For each package, detect diff between tarball and remote for (let i = 0; i < dirnames.length; i++) { progress(i / dirnames.length); const dirname = dirnames[i]; const pLocal = local.getPackage(dirname); const pNpm = await npm.getPackage(dirname); const tarballHash = local.computeTarballHash(dirname); let version = pNpm.version; if (tarballHash !== pNpm.tarballHash) { version = semver.inc(version, "patch"); output.push([ " ", colorify.blue(pLocal.name), repeat(" ", 47 - pLocal.name.length - pNpm.version.length), pNpm.version, colorify.bold(" => "), colorify.green(version) ].join("")); local.updateJson(getPackageJsonPath(dirname), { gitHead: undefined, tarballHash, version }, true); updated = true; } latestVersions[pLocal.name] = version; // Write out the _version.ts if (!pLocal._ethers_nobuild) { const code = "export const version = " + JSON.stringify(dirname + "/" + pLocal.version) + ";\n"; fs.writeFileSync(resolve(getPackagePath(dirname), "src.ts/_version.ts"), code); } } progress(1); if (updated) { const filename = resolve("packages/ethers/package.json") const info = loadJson(filename); Object.keys(info.dependencies).forEach((name) => { const version = latestVersions[name]; if (name == null) { return; } info.dependencies[name] = version; }); saveJson(filename, info); } output.forEach((line) => { console.log(line); }); })().catch((error) => { console.log(`Error running ${ process.argv[0] }: ${ error.message }`); process.exit(1); });