Permalink
Browse files

Add preferGlobal json option

  • Loading branch information...
1 parent 5c034f6 commit 5d86b330edfbbd3bae4fadedbefee3f75a5d9c64 @isaacs isaacs committed Apr 6, 2011
Showing with 24 additions and 20 deletions.
  1. +6 −9 doc/json.md
  2. +17 −11 lib/build.js
  3. +1 −0 package.json
View
@@ -384,14 +384,11 @@ If you specify an "engines" field, then npm will require that "node" be
somewhere on that list. If "engines" is omitted, then npm will just assume
that it works on node.
-## tag
+## preferGlobal
-By default, when a package is published, it gets tagged with the value
-of the `tag` config, or `"latest"` if nothing is specified. By setting
-a "tag" member in the package.json, the package will get tagged
-differently. This enabled limited releases with a "beta" or "rc" tag,
-so that users can do `npm install foo@beta` to get the package version
-tagged "beta".
+If your package is primarily a command-line application that should be
+installed globally, then set this value to `true` to provide a warning
+if it is installed locally.
-To update it to latest, either remove the "tag" member and re-publish,
-or do `npm tag foo@1.2.3 latest`.
+It doesn't actually prevent users from installing it locally, but it
+does help prevent some confusion if it doesn't work as expected.
View
@@ -50,17 +50,23 @@ function linkStuff (pkg, folder, global, cb) {
var parent = path.dirname(folder)
, gnm = global && path.resolve(npm.config.get("prefix")
, "lib", "node_modules")
- , top = gnm === parent
+ , top = parent === npm.root
+ , gtop = parent === gnm
- log.verbose([global, gnm, top, parent], "linkStuff")
+ log.verbose([global, gnm, gtop, parent], "linkStuff")
log(pkg._id, "linkStuff")
+
+ if (top && pkg.preferGlobal && !global) {
+ log.warn(pkg._id + " should be installed with -g", "prefer global")
+ }
+
asyncMap([linkBins, linkMans, rebuildBundles], function (fn, cb) {
log(pkg._id, fn.name)
- fn(pkg, folder, parent, top, cb)
+ fn(pkg, folder, parent, gtop, cb)
}, cb)
}
-function rebuildBundles (pkg, folder, parent, top, cb) {
+function rebuildBundles (pkg, folder, parent, gtop, cb) {
if (!npm.config.get("rebuild-bundle")) return cb()
var deps = Object.keys(pkg.dependencies || {})
@@ -89,25 +95,25 @@ function rebuildBundles (pkg, folder, parent, top, cb) {
})
}
-function linkBins (pkg, folder, parent, top, cb) {
+function linkBins (pkg, folder, parent, gtop, cb) {
if (!pkg.bin) return cb()
- var binRoot = top ? path.resolve(npm.config.get("prefix"), "bin")
+ var binRoot = gtop ? 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)
- ,top && folder
+ ,gtop && folder
,function (er) {
- if (er || !top) return cb(er)
+ if (er || !gtop) return cb(er)
output.write(path.resolve(binRoot, b)+" -> "
+path.resolve(folder, pkg.bin[b]), cb)
})
}, cb)
}
-function linkMans (pkg, folder, parent, top, cb) {
- if (!pkg.man || !top) return cb()
+function linkMans (pkg, folder, parent, gtop, cb) {
+ if (!pkg.man || !gtop) return cb()
var manRoot = path.resolve(npm.config.get("prefix"), "share", "man")
asyncMap(pkg.man, function (man, cb) {
var parseMan = man.match(/(.*)\.([0-9]+)(\.gz)?$/)
@@ -122,6 +128,6 @@ function linkMans (pkg, folder, parent, top, cb) {
: pkg.name + "-" + bn)
+ "." + sxn + gz
)
- linkIfExists(manSrc, manDest, top && folder, cb)
+ linkIfExists(manSrc, manDest, gtop && folder, cb)
}, cb)
}
View
@@ -2,6 +2,7 @@
, "description" : "A package manager for node"
, "keywords" : [ "package manager", "modules", "install", "package.json" ]
, "version" : "1.0.1rc5"
+, "preferGlobal" : true
, "tag" : "rc"
, "homepage" : "http://npmjs.org/"
, "author" : "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me)"

0 comments on commit 5d86b33

Please sign in to comment.