Permalink
Browse files

Link bins for linked packages globally.

  • Loading branch information...
1 parent 0b249b6 commit 01bd302f3a3fec2d78fdb2a490f50d03e0b4d88e @isaacs isaacs committed Mar 21, 2011
Showing with 19 additions and 10 deletions.
  1. +15 −9 lib/build.js
  2. +2 −0 lib/install.js
  3. +2 −1 lib/link.js
View
24 lib/build.js
@@ -23,32 +23,36 @@ var npm = require("../npm")
module.exports = build
build.usage = "npm build <folder>\n(this is plumbing)"
-function build (args, cb) { asyncMap(args, build_, cb) }
+function build (args, global, cb) {
+ if (typeof cb !== "function") cb = global, global = npm.config.get("global")
+ asyncMap(args, build_(global), cb)
+}
-function build_ (folder, cb) {
+function build_ (global) { return function (folder, cb) {
folder = path.resolve(folder)
log(folder, "build")
readJson(path.resolve(folder, "package.json"), function (er, pkg) {
if (er) return cb(er)
chain
( [lifecycle, pkg, "preinstall", folder]
- , [linkStuff, pkg, folder]
+ , [linkStuff, pkg, folder, global]
, [lifecycle, pkg, "install", folder]
, [lifecycle, pkg, "postinstall", folder]
, npm.config.get("npat") && [lifecycle, pkg, "test", folder]
+ || function (cb) { cb() }
, cb )
})
-}
+}}
-function linkStuff (pkg, folder, cb) {
+function linkStuff (pkg, folder, global, cb) {
// if it's global, and folder is in {prefix}/node_modules,
// then bins are in {prefix}/bin
// otherwise, then bins are in folder/../.bin
var parent = path.dirname(folder)
- , gnm = npm.config.get("global")
- && path.resolve(npm.prefix, "node_modules")
+ , gnm = global && path.resolve(npm.config.get("prefix"), "node_modules")
, top = gnm === parent
+ log.warn([global, gnm, top, parent], "linkStuff")
log(pkg._id, "linkStuff")
asyncMap([linkBins, linkMans, rebuildBundles], function (fn, cb) {
log(pkg._id, fn.name)
@@ -64,6 +68,7 @@ function rebuildBundles (pkg, folder, parent, top, cb) {
, bundles = pkg.bundleDependencies || pkg.bundledDependencies || []
fs.readdir(path.resolve(folder, "node_modules"), function (er, files) {
+ log.verbose([er, files], "rebuildBundles")
// error means no bundles
if (er) return cb()
@@ -74,20 +79,21 @@ function rebuildBundles (pkg, folder, parent, top, cb) {
}).map(function (file) {
return path.resolve(folder, "node_modules", file)
}), function (file, cb) {
+ log.verbose(file, "rebuild bundle")
// if not a dir, then don't do it.
fs.lstat(file, function (er, st) {
if (er || !st.isDirectory()) return cb()
- build_(file, cb)
+ build_(false)(file, cb)
})
}, cb)
})
}
function linkBins (pkg, folder, parent, top, cb) {
if (!pkg.bin) return cb()
- log(pkg.bin, "bins linking")
var binRoot = top ? path.resolve(npm.config.get("prefix"), "bin")
: path.resolve(parent, ".bin")
+ log([pkg.bin, binRoot], "bins linking")
asyncMap(Object.keys(pkg.bin), function (b, cb) {
linkIfExists(path.resolve(folder, pkg.bin[b])
,path.resolve(binRoot, b)
View
2 lib/install.js
@@ -142,7 +142,9 @@ function install (args, cb) {
previously[data.name] = data.version
installMany(deps.map(function (dep) {
var target = data.dependencies[dep]
+ log.warn(target)
if (!url.parse(target).protocol) {
+ log.warn(target, "not url")
target = dep + "@" + target
}
return target
View
3 lib/link.js
@@ -80,7 +80,8 @@ function linkPkg (folder, cb) {
if (er) return cb(er)
symlink(me, target, function (er) {
if (er) return cb(er)
- npm.commands.build([target], function (er) {
+ log.verbose(target, "link: build target")
+ npm.commands.build([target], true, function (er) {
if (er) return cb(er)
resultPrinter(path.basename(me), me, target, cb)
})

0 comments on commit 01bd302

Please sign in to comment.