Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement --deep flag to update deps in monorepo #522

Closed
2 tasks done
mkungla opened this issue Mar 21, 2019 · 9 comments · Fixed by #785
Closed
2 tasks done

Implement --deep flag to update deps in monorepo #522

mkungla opened this issue Mar 21, 2019 · 9 comments · Fixed by #785

Comments

@mkungla
Copy link
Contributor

mkungla commented Mar 21, 2019

Similar to #154, but would it be idea to add --deep or similar flag to check updates in monorepo to update multiple packages found in repository?

use case would be doing something like bellow, but more elegantly:

const glob = require('glob')
const childProcess = require('child_process')

const check = (pkgJsonPath) => {
  try {
    return childProcess.execSync(`./node_modules/.bin/ncu --error-level 2 --packageFileDir --packageFile ${pkgJsonPath}`).toString()
  } catch (error) {
    console.log('exec error: ' + error.message)
    process.exit(error.status)
  }
}
glob('./packages/**/package.json', {}, (er, files) => {
  files.forEach((file) => {
    if (file.includes('node_modules')) {
      return
    }
    console.log(`command to update: ./node_modules/.bin/ncu --packageFileDir --packageFile ${file} -u -i`)
    console.log(check(file))
  })
})
  • node version: *
  • npm version: *
  • npm-check-updates version: *

@revelt
Copy link

revelt commented Mar 29, 2019

In the meantime, you can use update-versions from yours truly. I wrote it to help with monorepo maintenance, after I moved to Lerna.

It does two tasks: 1. updates dependencies; 2. enforces ^x.x.x notation. The second task can be very sneaky since as you know, Lerna will not properly bootstrap dependencies marked with latest, * or whatever else. Also, update-versions works on normal repos, it's probably faster than npm-check-updates anyway because it's simpler and uses npm's native pacote (instead of in-house solution that npm-check-updates uses).

@stoically
Copy link
Collaborator

it's probably faster than npm-check-updates anyway

Testing with a rather extreme example of ~1500 dependencies

time ncu
real	0m10.082s

time upd
real	1m7.172s

@revelt
Copy link

revelt commented Mar 29, 2019

^ interesting!

@mikestopcontinues
Copy link

No offense to @revelt or lerna-update-wizard, but neither option meets my needs. I would love to see this feature in ncu. Reason being, I use exact versions and I want to update everything at once.

@prma85
Copy link

prma85 commented Apr 2, 2020

In the meantime, you can use update-versions from yours truly. I wrote it to help with monorepo maintenance, after I moved to Lerna.

It does two tasks: 1. updates dependencies; 2. enforces ^x.x.x notation. The second task can be very sneaky since as you know, Lerna will not properly bootstrap dependencies marked with latest, * or whatever else. Also, update-versions works on normal repos, it's probably faster than npm-check-updates anyway because it's simpler and uses npm's native pacote (instead of in-house solution that npm-check-updates uses).

@revelt It is a nice extension. However, I tried to use it today in a lerna/yarn monorepo on windows and the issue that even if I have ^x.x.x it is still doing a major version update. On my case, it is changing "antd": "^3.26.9", to "antd": "^4.1.0"` :(

@ScriptedAlchemy
Copy link

Update-versions doesn't seem to offer the same level of interactivity. Or it's docs are terrible. Will be forking ncu and publishing a --deep option that was mentioned above.

@kachkaev
Copy link

kachkaev commented Jan 8, 2021

I managed to use this command as a workaround in a monorepo:

find . -name package.json -not -path "./node_modules/*" -exec npm-check-updates --upgrade --packageFile {} \;

This works but having --deep (or packageFileGlob) would be better indeed. The benefit of the new feature compared to running find -exec is in speed. At the moment, ncu needs to fetch package metadata independently for every monorepo packages, which is slow and error-prone (I’ve seen some 503s in stdout which made the results potentially incomplete).

mkungla added a commit to mkungla/npm-check-updates that referenced this issue Jan 12, 2021
…hine#522

Implement --deep flag as alias of
`--packageFile '{,*[!node_modules]/**/}package.json'`
@mkungla
Copy link
Contributor Author

mkungla commented Jan 12, 2021

I like the @kachkaev idea of --packageFileGlob made rough PR #785.
Which allows to use glob pattern as --packageFile arg and added -deep flag which is alias of enhanced --packageFile '{,*[!node_modules]/**/}package.json'

so

ncu --packageFile '{,*[!node_modules]/**/}package.json'

is same as

ncu --deep

@mkungla
Copy link
Contributor Author

mkungla commented Jan 12, 2021

Please go ahead and test it and let me know is that behavior what you are expecting...
e.g. use case ncu --packageFile '{,*[!(node_modules|tmp|test)]/**/}package.json'

mkungla added a commit to mkungla/npm-check-updates that referenced this issue Jan 20, 2021
…hine#522

Implement --deep flag as alias of
`--packageFile '{,*[!node_modules]/**/}package.json'`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants