Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Remove warning about installing globally if package is dep #3254

Closed
wants to merge 4 commits into from

2 participants

@Ralt

PR for #1648

@Ralt

Right now, this reads the built package's package.json for every dependency. Should I refactor so that it does it only once? The drawback is that it would somehow pollute other code that has nothing to do with the warning.

@domenic
Collaborator

+1, @isaacs?

@domenic
Collaborator

Looks like this was merged as 7bd570a, w00t.

@domenic domenic closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 13, 2013
  1. @Ralt
  2. @Ralt

    Merge of master into 1648 branch.

    Ralt authored
Commits on Mar 14, 2013
  1. @Ralt
Commits on Mar 16, 2013
  1. @Ralt

    Uses the less controversial way.

    Ralt authored
This page is out of date. Refresh to see the latest.
Showing with 34 additions and 9 deletions.
  1. +34 −9 lib/build.js
View
43 lib/build.js
@@ -83,16 +83,41 @@ function linkStuff (pkg, folder, global, didRB, cb) {
log.verbose("linkStuff", [global, gnm, gtop, parent])
log.info("linkStuff", pkg._id)
- if (top && pkg.preferGlobal && !global) {
- log.warn("prefer global", pkg._id + " should be installed with -g")
- }
+ shouldWarn(pkg, folder, global, function() {
+ asyncMap( [linkBins, linkMans, !didRB && rebuildBundles]
+ , function (fn, cb) {
+ if (!fn) return cb()
+ log.verbose(fn.name, pkg._id)
+ fn(pkg, folder, parent, gtop, cb)
+ }, cb)
+ })
+}
- asyncMap( [linkBins, linkMans, !didRB && rebuildBundles]
- , function (fn, cb) {
- if (!fn) return cb()
- log.verbose(fn.name, pkg._id)
- fn(pkg, folder, parent, gtop, cb)
- }, cb)
+function shouldWarn(pkg, folder, global, cb) {
+ var parent = path.dirname(folder)
+ , top = parent === npm.dir
+ , cwd = process.cwd()
+
+ readJson(path.resolve(cwd, "package.json"), function(er, topPkg) {
+ if (er) return cb(er)
+
+ var linkedPkg = path.basename(cwd)
+ , currentPkg = path.basename(folder)
+
+ // current searched package is the linked package on first call
+ if (linkedPkg !== currentPkg) {
+
+ // don't generate a warning if it's listed in dependencies
+ if (Object.keys(topPkg.dependencies).indexOf(currentPkg) === -1) {
+
+ if (top && pkg.preferGlobal && !global) {
+ log.warn("prefer global", pkg._id + " should be installed with -g")
+ }
+ }
+ }
+
+ cb()
+ })
}
function rebuildBundles (pkg, folder, parent, gtop, cb) {
Something went wrong with that request. Please try again.