Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2011-01-11 01:14:40 +0300
committerisaacs <i@izs.me>2011-01-11 01:15:35 +0300
commit7a9035b8d62c2f71ca14d7c4e8f6c947858d376f (patch)
treef0578c1573c0bd9e8db88994cca8b6a4fb9c20eb
parent2ff1b967392f736c2db02e0d6542b9128e5526d8 (diff)
Revert "Make the bundle folder configurable"
This was a mistake. Sorry, everyone. Bundles are and shall henceforth always be in "./node_modules". This reverts commit 609ed5643a678ade30872cfb57474a5f9ca95811. This reverts commit 2adbbae82462be860ec120c699a1a838f7b9c081.
-rw-r--r--doc/bundle.md3
-rw-r--r--doc/json.md5
-rw-r--r--lib/build.js78
-rw-r--r--lib/bundle.js21
-rw-r--r--lib/link.js4
-rw-r--r--lib/utils/lifecycle.js7
-rw-r--r--lib/utils/load-package-defaults.js2
-rw-r--r--lib/utils/write-shim.js59
-rw-r--r--man1/bundle.14
-rw-r--r--man1/json.14
10 files changed, 77 insertions, 110 deletions
diff --git a/doc/bundle.md b/doc/bundle.md
index 2db26b957..7e0d10fb0 100644
--- a/doc/bundle.md
+++ b/doc/bundle.md
@@ -37,9 +37,6 @@ In this way, a command like
to have a dependency that is not published on the npm registry. (It still
must contain a package.json, though, of course.)
-If there is a `directories.bundle` folder specified in the package.json,
-then it will use that folder rather than `node_modules`.
-
## CAVEATS
Man pages are not installed by bundle.
diff --git a/doc/json.md b/doc/json.md
index f414e06e9..76fe9c763 100644
--- a/doc/json.md
+++ b/doc/json.md
@@ -245,11 +245,6 @@ Put markdown files in here. Eventually, these will be displayed nicely, maybe,
Put example scripts in here. Someday, it might be exposed in some clever way.
-### directories.bundle
-
-The location where bundled dependencies live. This defaults to
-"node_modules", but can be set to anything you like.
-
## repository
Specify the place where your code lives. This is helpful for people who want to
diff --git a/lib/build.js b/lib/build.js
index e2ddf608d..d12b96605 100644
--- a/lib/build.js
+++ b/lib/build.js
@@ -67,14 +67,13 @@ function build (args, cb) {
function rebuildBundle (pkg, cb) {
if (!npm.config.get("rebuild-bundle")) return cb()
- if (!pkg.directories.bundle) return cb()
var bundle = path.join( npm.dir, pkg.name, pkg.version
- , "package", pkg.directories.bundle)
+ , "package", "node_modules")
fs.stat(bundle, function (er, s) {
if (er || !s.isDirectory()) return cb()
log(pkg._id, "rebuilding bundled dependencies")
conf.unshift({ root : bundle
- , binroot : path.join(bundle, ".bin")
+ , binroot : null
, manroot : null
})
npm.commands.rebuild([], function (er, data) {
@@ -166,44 +165,38 @@ function resolveDependencies (pkg, cb) {
// link foo-1.0.3 to ROOT/.npm/{pkg}/{version}/node_modules/foo
// see if it's bundled already
- var bundleDir = pkg.directories.bundle &&
- path.join( npm.dir, pkg.name, pkg.version, "package"
- , pkg.directories.bundle )
- , deps = pkg.dependencies && Object.keys(pkg.dependencies) || []
- log.verbose([pkg._id, deps], "deps being resolved")
- if (!bundleDir) return verifyDeps(pkg, deps, cb)
+ var bundleDir = path.join( npm.dir, pkg.name, pkg.version
+ , "package", "node_modules" )
+ , deps = pkg.dependencies && Object.keys(pkg.dependencies) || []
+ log.verbose([pkg, deps], "deps being resolved")
fs.readdir(bundleDir, function (er, bundledDeps) {
if (er) bundledDeps = []
bundledDeps.forEach(function (bd) {
- log.verbose([pkg._id, bd], "already bundled")
var i = deps.indexOf(bd)
if (i !== -1) deps.splice(i, 1)
})
- verifyDeps(pkg, deps, cb)
- })
-}
-function verifyDeps (pkg, deps, cb) {
- asyncMap(deps, function (i, cb) {
- var req = { name:i, version:pkg.dependencies[i] }
- log.verbose(req.name+"@"+req.version, "required")
+ asyncMap(deps, function (i, cb) {
+ var req = { name:i, version:pkg.dependencies[i] }
+ log.verbose(req.name+"@"+req.version, "required")
- // see if we have this thing installed.
- fs.readdir(path.join(npm.dir, req.name), function (er, versions) {
- if (er) return cb(new Error(
- "Required package: "+req.name+"("+req.version+") not found."))
- // TODO: Get the "stable" version if there is one.
- // Look that up from the registry.
- var satis = semver.maxSatisfying(versions, req.version)
- if (satis) return cb(null, {name:req.name, version:satis})
- return cb(new Error(
- "Required package: "+req.name+"("+req.version+") not found. "+
- "(Found: "+JSON.stringify(versions)+")"))
+ // see if we have this thing installed.
+ fs.readdir(path.join(npm.dir, req.name), function (er, versions) {
+ if (er) return cb(new Error(
+ "Required package: "+req.name+"("+req.version+") not found."))
+ // TODO: Get the "stable" version if there is one.
+ // Look that up from the registry.
+ var satis = semver.maxSatisfying(versions, req.version)
+ if (satis) return cb(null, {name:req.name, version:satis})
+ return cb(new Error(
+ "Required package: "+req.name+"("+req.version+") not found. "+
+ "(Found: "+JSON.stringify(versions)+")"))
+ })
+ }, function (er, found) {
+ // save the resolved dependencies on the pkg data for later
+ pkg._resolvedDeps = found
+ cb(er, found)
})
- }, function (er, found) {
- // save the resolved dependencies on the pkg data for later
- pkg._resolvedDeps = found
- cb(er, found)
})
}
@@ -307,9 +300,9 @@ function linkModules (pkg, target, cb) {
log.silly(pkg.modules, "linkModules")
log.verbose(target, "linkModules")
if (target === npm.root
+ && !target.match(/node_modules$/)
&& -1 === require.paths.indexOf(target)) {
- log.warn("modules installing to "+target+", outside NODE_PATH"
- ,pkg._id)
+ log.warn("modules installing to "+target+", outside NODE_PATH")
}
if (!pkg.modules) pkg.modules = {}
var mod = pkg.modules
@@ -328,9 +321,7 @@ function linkModules (pkg, target, cb) {
writeShim
( path.join(pkgDir, mod[key])
, path.join(target, key.replace(/\.js$/, '')+".js")
- , [ path.join(versionDir, "node_modules")
- , pkg.directories.bundle
- && path.join(versionDir, "package", pkg.directories.bundle) ]
+ , path.join(versionDir, "node_modules")
, cb
)
}, function (er) {
@@ -371,21 +362,18 @@ function linkBins (pkg, binroot, versioned, cb) {
}
}
if (!binroot) return cb()
- var versionDir = path.join(npm.dir, pkg.name, pkg.version)
- , deps = [ path.join(versionDir, "node_modules")
- , pkg.directories.bundle &&
- path.join(versionDir, "package", pkg.directories.bundle) ]
+ var dep = path.join(npm.dir, pkg.name, pkg.version, "node_modules")
asyncMap(Object.keys(pkg.bin).filter(function (i) {
return i.charAt(0) !== "_"
}), function (i, cb) {
log.verbose(i+" "+pkg.bin[i], "linkBin")
var to = path.join(binroot, i+(versioned ? "@"+pkg.version : ""))
, from = path.join(npm.dir, pkg.name, pkg.version, "package", pkg.bin[i])
- shimTest(from, to, deps, cb)
+ shimTest(from, to, dep, cb)
}, log.er(cb, "failed to link bins"))
}
-function shimTest (from, to, deps, cb) {
+function shimTest (from, to, dep, cb) {
// if it needs a shim, then call writeShim
// otherwise, just link it in.
fs.stat(from, function S (er, s) {
@@ -394,14 +382,14 @@ function shimTest (from, to, deps, cb) {
return fs.stat(from, S)
}
if (er) return cb(er)
- if (from.match(/\.(node|js)$/)) return writeShim(from, to, deps, cb)
+ if (from.match(/\.(node|js)$/)) return writeShim(from, to, dep, cb)
fs.readFile(from, function (er, data) {
if (er) return cb(er)
data = data.toString("ascii")
var envNode = data.match(/#!(\/usr\/bin\/)?env node/)
, node = data.match(/#!(\/usr(\/local)?\/bin\/)?node/)
if (envNode && envNode.index === 0 || node && node.index === 0) {
- return writeShim(from, to, deps, cb)
+ return writeShim(from, to, dep, cb)
}
return link(from, to, cb)
})
diff --git a/lib/bundle.js b/lib/bundle.js
index 976e0d505..972776c13 100644
--- a/lib/bundle.js
+++ b/lib/bundle.js
@@ -34,16 +34,8 @@ bundle.completion = function(args, index, cb) {
function bundle (args, dir, cb_) {
if (typeof dir === "function") cb_ = dir, dir = process.cwd()
-
- readJson(path.join(dir, "package.json"), function (er, data) {
- if (er) return log.er(cb_, "Not a package: "+dir)(er)
- bundle_(data, args, dir, cb_)
- })
-}
-function bundle_ (data, args, dir, cb_) {
- var bundleDir = data.directories.bundle || "node_modules"
- , location = path.join(dir, bundleDir)
- , binRoot = path.join(dir, bundleDir, ".bin")
+ var location = path.join(dir, "node_modules")
+ , binRoot = path.join(dir, "node_modules", ".bin")
, pkg = dir
, cmd = args.shift()
function cb (er, data) {
@@ -51,7 +43,7 @@ function bundle_ (data, args, dir, cb_) {
cb_(er, data)
}
mkdir(location, function (er) {
- if (er) return cb_(new Error(bundle.usage))
+ if (er) return cb(new Error(bundle.usage))
var c = { root : location
, binroot : binRoot
, manroot : null
@@ -86,7 +78,12 @@ function bundle_ (data, args, dir, cb_) {
}
// no command given, just install the local deps.
- install(data, location, cb)
+ // just read the package.json from the directory to
+ // avoid adding the whole package to the cache
+ readJson(path.join(pkg, "package.json"), function (er, data) {
+ if (er) return log.er(cb, "Error reading "+pkg+"/package.json")(er)
+ install(data, location, cb)
+ })
})
})
}
diff --git a/lib/link.js b/lib/link.js
index 4058ac2e0..17049e7cf 100644
--- a/lib/link.js
+++ b/lib/link.js
@@ -82,9 +82,7 @@ function getDeps (data, folder, cb) {
function postBundle (er) {
if (er) return cb(er)
// filter out any bundled deps. those don't need to be installed
- if (!data.directories.bundle) return cb(null, deps)
- fs.readdir(path.join(folder, data.directories.bundle),
- function (er, bundled) {
+ fs.readdir(path.join(folder, "node_modules"), function (er, bundled) {
if (er && !bundled) bundled = []
bundled.forEach(function (b) { delete deps[b] })
cb(null, deps)
diff --git a/lib/utils/lifecycle.js b/lib/utils/lifecycle.js
index 9cf7c3f18..0d3bc1733 100644
--- a/lib/utils/lifecycle.js
+++ b/lib/utils/lifecycle.js
@@ -21,8 +21,7 @@ function lifecycle (pkg, stage, wd, cb) {
var env = makeEnv(pkg)
env.npm_lifecycle_event = stage
var pkgDir = path.join(npm.dir, pkg.name, pkg.version)
- if (!pkg.directories) pkg.directories = {}
- env.PATH = path.join(pkgDir, pkg.directories.bundle, ".bin")
+ env.PATH = path.join(pkgDir, "node_modules", ".bin")
+ ":" + path.join(pkgDir, "dep-bin")
+ (env.PATH ? ":" + env.PATH : "")
@@ -52,7 +51,7 @@ function addDepsToEnv (pkg, env, cb_) {
if (er) return cb_(er)
pkg._bundledDeps = bundled
var bundledir = path.join(npm.dir, pkg.name, pkg.version
- ,"package", pkg.directories.bundle, ".npm")
+ ,"package", "node_modules", ".npm")
deps.forEach(add(npm.dir, "npm_dependency_"))
bundled.forEach(add(bundledir, "npm_dependency_"))
bundled.forEach(add(bundledir, "npm_bundle_"))
@@ -68,7 +67,7 @@ function addDepsToEnv (pkg, env, cb_) {
function readDeps (pkg, cb) {
var pkgdir = path.join(npm.dir, pkg.name, pkg.version)
, depdir = path.join(pkgdir, "dependson")
- , bundledir = path.join(pkgdir, "package", pkg.directories.bundle, ".npm")
+ , bundledir = path.join(pkgdir, "package", "node_modules", ".npm")
fs.readdir(depdir, function (er, dn) {
done(er ? [] : dn.map(function (dn) {
dn = dn.split("@")
diff --git a/lib/utils/load-package-defaults.js b/lib/utils/load-package-defaults.js
index db4b0588e..ebb243237 100644
--- a/lib/utils/load-package-defaults.js
+++ b/lib/utils/load-package-defaults.js
@@ -91,8 +91,6 @@ function readDefaultDirs (pkgDir) { return function (pkg, cb) {
, bin : "./bin"
, man : "./man"
, doc : "./doc"
- , plugins: "./plugins"
- , bundle : "./node_modules"
}
asyncMap(Object.keys(defaults), function (d, cb) {
if (dirs[d]) return cb()
diff --git a/lib/utils/write-shim.js b/lib/utils/write-shim.js
index 991639b53..4989a0d6f 100644
--- a/lib/utils/write-shim.js
+++ b/lib/utils/write-shim.js
@@ -8,43 +8,46 @@ var fs = require("./graceful-fs")
, mkdir = require("./mkdir-p")
, log = require("./log")
-function shimIfExists (from, to, deps, cb) {
- if (!cb) cb = deps, deps = false
+function shimIfExists (from, to, dep, cb) {
+ if (!cb) cb = dep, dep = false
fs.stat(from, function (er) {
if (er) return cb()
- writeShim(from, to, deps, cb)
+ writeShim(from, to, dep, cb)
})
}
-function writeShim (from, to, deps, cb) {
- if (!cb) cb = deps, deps = false
+function writeShim (from, to, dep, cb) {
+ if (!cb) cb = dep, dep = false
log.silly([from,to], "writeShim")
- if (deps) {
- deps = deps.filter(function (d) { return d }).map(function (dep) {
- return relativize(dep, to)
- })
- }
+ if (dep) dep = relativize(dep, to)
from = relativize(from, to).replace(/\.(js|node)$/, '')
- // todo: remove this deps juggling somehow.
+ // todo: remove this dep juggling when 0.2.x is deprecated,
+ // and node_modules is picked up automatically.2
var code = "#!/usr/bin/env node\n"
+ "// generated by npm, please don't touch!\n"
- + ( deps ? "var deps = " + JSON.stringify(deps || []) + "\n"
- + " , path = require('path')\n"
- + "deps = deps.map(function (dep, i, deps) {\n"
- + " return require('path').join(__dirname, dep)\n"
- + "}).filter(function (dep, i, deps) {\n"
- + " return -1 !== require.paths.indexOf(dep)\n"
- + "})\n"
- : "" )
- + "require.paths.unshift.apply(require.paths, deps)\n"
- + "module.exports = require("+JSON.stringify(from)+")\n"
- + ( deps ? "deps.forEach(function (dep, i, deps) {\n"
- + " var met = require.paths.indexOf(dep)\n"
- + " if (met !== -1) {\n"
- + " require.paths.splice(met, 1)\n"
- + " }\n"
- + "})\n"
- : "" )
+ + (dep ? "var dep = require('path').join(__dirname, "
+ + JSON.stringify(dep) + ")\n"
+ + "var depMet = require.paths.indexOf(dep) !== -1\n"
+ + "var bundle = dep.replace(/node_modules$/, "
+ + "'package/node_modules')\n"
+ + "var bundleMet = require.paths.indexOf(bundle) !== -1\n"
+ : "")
+ + "var from = "+JSON.stringify(from)+"\n"
+ + "\n"
+ + (dep ? "if (!depMet) require.paths.unshift(dep)\n"
+ + "if (!bundleMet) require.paths.unshift(bundle)\n"
+ : "")
+ + "module.exports = require(from)\n"
+ + "\n"
+ + (dep ? "if (!depMet) {\n"
+ + " var i = require.paths.indexOf(dep)\n"
+ + " if (i !== -1) require.paths.splice(i, 1)\n"
+ + "}\n"
+ + "if (!bundleMet) {\n"
+ + " var i = require.paths.indexOf(bundle)\n"
+ + " if (i !== -1) require.paths.slice(i, 1)\n"
+ + "}\n"
+ : "")
mkdir(path.dirname(to), function (er) {
if (er) return cb(er)
diff --git a/man1/bundle.1 b/man1/bundle.1
index 0be134e02..54268309d 100644
--- a/man1/bundle.1
+++ b/man1/bundle.1
@@ -51,10 +51,6 @@ In this way, a command like \fBnpm bundle install http://github\.com/user/projec
to have a dependency that is not published on the npm registry\. (It still
must contain a package\.json, though, of course\.)
.
-.P
-If there is a \fBdirectories\.bundle\fR folder specified in the package\.json,
-then it will use that folder rather than \fBnode_modules\fR\|\.
-.
.SH "CAVEATS"
Man pages are not installed by bundle\.
.
diff --git a/man1/json.1 b/man1/json.1
index b92b46b19..38a897ec4 100644
--- a/man1/json.1
+++ b/man1/json.1
@@ -336,10 +336,6 @@ Put markdown files in here\. Eventually, these will be displayed nicely, maybe,
.SS "directories\.example"
Put example scripts in here\. Someday, it might be exposed in some clever way\.
.
-.SS "directories\.bundle"
-The location where bundled dependencies live\. This defaults to
-"node_modules", but can be set to anything you like\.
-.
.SH "repository"
Specify the place where your code lives\. This is helpful for people who want to
contribute, as well as perhaps maybe being the underpinning of some magical "track