Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

#1213: add "checkdeps" command #1279

Closed
wants to merge 3 commits into from

5 participants

@thejh

See #1213.

@isaacs
Owner

This is pretty good.

  1. I like to avoid stuff like "returns true if not ok". It'd be better if _checkdeps return value was reversed, or if the function was renamed to somethingMissing or hasProblem something, so that "true" means "yes".
  2. It'd be better if the data returned was somewhat useful. Maybe return which package is missing, and where. If you did that, you could even spit out the appropriate install commands for the user to copy and paste :)
  3. Note that something could be missing beyond the first level. If the item isn't a string, then you need to recursively check its deps as well.

@isaacs, about number 3: Have a look at line 20, shouldn't that work?

Owner

Oh, right, I missed that.

Can't you end up with cycles? I think the readInstalled data structure may set a pointer to an object higher up the tree if that's the thing that satisfies the dependency.

Could well be... :(

@thejh

Ok, fixed point 1, too.

@thejh

Alright, fancy output :)

[jann@Jann-PC express]$ node ../npm/bin/npm checkdeps
status:not ok
Please execute "npm install" to install connect, mime and qs and to fix connect-redis and stylus
[jann@Jann-PC express]$
@isaacs
Owner

Few issues:

  1. There are some style issues. if blocks should always have {} if they continue to the next line.
  2. The output should be a bit more helpful, maybe mention what's missing, and catch invalid options as well.
  3. If the parseable config flag is set, then the output should match npm ls --parseable --long
@dshaw

Perhaps npm uptodate is a better semantic. I'm not sure about the implementation, but I definitely want this feature.

Especially in development, I'm looking for a good, lightweight mechanism (preferably programmatic) to be able to notify team members that they need to update their dependencies.

@temas

Is this concept dead or orphaned?

@scottgonzalez

@isaacs What's needed for this to land? I'd be happy to fix any remaining issues or clean up any coding style problems.

@isaacs
Owner

It's unclear that this is necessary.

There's already a npm outdated command that is essentially what @dshaw was asking for.

And npm ls will tell you (quite loudly) about missing dependencies.

I think it's better to just close this.

@isaacs isaacs closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 75 additions and 0 deletions.
  1. +74 −0 lib/checkdeps.js
  2. +1 −0  npm.js
View
74 lib/checkdeps.js
@@ -0,0 +1,74 @@
+
+// test whether everything needed is installed
+
+module.exports = exports = checkdeps
+
+var npm = require("../npm.js")
+ , output = require("./utils/output.js")
+ , log = require("./utils/log.js")
+ , ls = npm.commands.ls
+
+checkdeps.usage = "npm checkdeps"
+
+function _missingDeps(data) {
+ if (!data.dependencies) return []
+ return Object.keys(data.dependencies).map(function (name) {
+ var value = data.dependencies[name]
+ if (typeof value === "string")
+ return name
+ var subResult = _missingDeps(value)
+ // not an empty array
+ if (subResult.length !== 0)
+ return [name, subResult]
+ return false
+ }).filter(function (data) {
+ return data !== false
+ })
+}
+
+function checkdeps(args, silent, cb) {
+ if (typeof cb !== "function") cb = silent, silent = false
+
+ if (args.length) {
+ log.warn("checkdeps doesn't take positional args")
+ }
+
+ ls([], true, function(err, data){
+ if (err) return cb(err, null)
+ var result = _missingDeps(data)
+ var ok = result.length === 0
+ if (silent) return cb(null, ok)
+ if (!silent) {
+ var resultstr = 'status:'+(ok?'ok':'not ok')
+ if (!ok) {
+ var objectives = []
+ var needsInstall = result.filter(not(Array.isArray))
+ if (needsInstall.length)
+ objectives.push('to install '+coolJoin(needsInstall))
+ var needsFix = result.filter(Array.isArray).map(function(arr) {
+ return arr[0]
+ })
+ if (needsFix.length)
+ objectives.push('to fix '+coolJoin(needsFix))
+ objectives = objectives.join(' and ')
+ resultstr += '\nPlease execute "npm install" '+objectives
+ }
+ output.write(resultstr, function (er) { cb(er, ok) })
+ }
+ })
+}
+
+function not(func) {
+ return function() {
+ return !func.apply(this, arguments)
+ }
+}
+
+function coolJoin(array) {
+ if (array.length >= 2) {
+ array = array.concat()
+ var last = array.pop()
+ array.push(array.pop()+' and '+last)
+ }
+ return array.join(', ')
+}
View
1  npm.js
@@ -105,6 +105,7 @@ var commandCache = {}
, "help"
, "help-search"
, "ls"
+ , "checkdeps"
, "search"
, "view"
, "init"
Something went wrong with that request. Please try again.