Last active
October 8, 2022 10:45
-
-
Save VottusCode/7700a2db3193f30d3699b8d54a571a80 to your computer and use it in GitHub Desktop.
Small JS script to bump all Yarn dependencies to the latest version available. Supports Yarn workspaces.
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
const { exec } = require('child_process') | |
const path = require('path') | |
const glob = require('glob').sync | |
const bumpDeps = async (depsList, dev = false, workspace) => { | |
await new Promise((resolve, reject) => { | |
const _workspace = workspace ? `workspace ${workspace}` : '-W' | |
const _devFlag = dev ? '-D' : '' | |
const cmd = `yarn ${_workspace} add ${_devFlag} ${Object.keys(depsList).join(' ')}` | |
console.log(`$$ ${cmd}`) | |
const e = exec(cmd) | |
if (!e.stdout) return reject(new Error("There's no stdout.")) | |
e.stdout.pipe(process.stdout) | |
e.stdout.on('end', resolve) | |
}) | |
} | |
;(async () => { | |
const _root = require('./package.json') | |
await bumpDeps(_root.dependencies, false) | |
await bumpDeps(_root.devDependencies, true) | |
if (_root.workspaces) { | |
_root.workspaces.forEach(async (workspace) => { | |
for (const str of glob(workspace)) { | |
const _pkg = require(path.join(__dirname, str, 'package.json')) | |
await bumpDeps(_pkg.dependencies, false, _pkg.name) | |
await bumpDeps(_pkg.devDependencies, true, _pkg.name) | |
} | |
}) | |
} | |
})() |
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
{ | |
"name": "bump-deps-major", | |
"version": "1.0.0", | |
"license": "MIT", | |
"author": "VottusCode <vottus@vott.us>", | |
"main": "./bump-deps-major.js", | |
"bin": "./bump-deps-major.js" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment