Skip to content

Instantly share code, notes, and snippets.

@tanem
Created June 11, 2018 04:23
Show Gist options
  • Save tanem/b81d8175abe616f569ec79e1d6359f93 to your computer and use it in GitHub Desktop.
Save tanem/b81d8175abe616f569ec79e1d6359f93 to your computer and use it in GitHub Desktop.
install fixed versions of currently installed deps
// Usage: `node fix-deps.js`
// Pre-req: Ensure `save-prefix ""` is set in `.yarnrc`.
const {exec} = require('child_process')
// `yarn ls --depth=0` doesn't quite do what we want, see:
// https://github.com/yarnpkg/yarn/issues/3569#issuecomment-362832264.
exec('npm ls --depth 0', (_, stdout) => {
const deps = stdout
.trim()
.replace(/UNMET PEER DEPENDENCY |├── |└── /g, '')
.split('\n')
.slice(1)
.filter(d => !d.endsWith('extraneous'))
.join(' ')
// There may be some console warnings, but dev & prod dependencies should
// still install in the right places.
exec(`yarn add ${deps}`, (_, stdout) => {
console.log(stdout)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment