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

Commit

Permalink
Link bins for linked packages globally.
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Mar 21, 2011
1 parent 0b249b6 commit 01bd302
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
24 changes: 15 additions & 9 deletions lib/build.js
Expand Up @@ -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)
Expand All @@ -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()

Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions lib/install.js
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/link.js
Expand Up @@ -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)
})
Expand Down

0 comments on commit 01bd302

Please sign in to comment.