Skip to content

Instantly share code, notes, and snippets.

@VottusCode
Last active October 8, 2022 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VottusCode/7700a2db3193f30d3699b8d54a571a80 to your computer and use it in GitHub Desktop.
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.
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)
}
})
}
})()
{
"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