Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Remove warning about installing globally if package is dep #3254

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 34 additions & 9 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down