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-03-04 09:28:25 +0300
committerisaacs <i@izs.me>2011-03-22 01:55:48 +0300
commitce60214c046532b1c91a0595353324fc7faa998d (patch)
tree956fffff5437730a38edaafb226919be94a4a74b
parent69ee100f3de7ee58f1865d942bcd983c12d4d9fc (diff)
Remove some now-unnecessary pieces
-rw-r--r--lib/activate.js157
-rw-r--r--lib/bundle.js113
-rw-r--r--lib/deactivate.js104
-rw-r--r--npm.js41
4 files changed, 20 insertions, 395 deletions
diff --git a/lib/activate.js b/lib/activate.js
deleted file mode 100644
index ca0e86303..000000000
--- a/lib/activate.js
+++ /dev/null
@@ -1,157 +0,0 @@
-
-// activate a version of a package
-// this presumes that it's been installed
-// no need to worry about dependencies, because they were
-// installed into the child package anyhow.
-
-var npm = require("../npm")
- , fs = require("./utils/graceful-fs")
- , log = require("./utils/log")
- , path = require("path")
- , rm = require("./utils/rm-rf")
- , chain = require("./utils/chain")
- , lifecycle = require("./utils/lifecycle")
- , readJson = require("./utils/read-json")
- , link = require("./utils/link")
- , linkIfExists = link.ifExists
- , semver = require("semver")
- , asyncMap = require("./utils/async-map")
- , loadPackageDefaults = require("./utils/load-package-defaults")
-
-module.exports = activate
-
-activate.usage =
- "npm activate <name>@<version> [<name>@<version> ...]"
-
-activate.completion = function (args, index, cb) {
- var installedPkgs = require("./utils/completion/installed-packages")
- installedPkgs(args, index, true, true, cb)
-}
-
-function activate (args, cb) {
- // make sure package and version exists.
- // If there's already an active version, then deactivate it.
- // first, link .npm/{pkg}/{version} to .npm/{pkg}/{active}
- // then, link the things in the root without a version to the active one.
- if (!args.length) return cb(new Error(activate.usage))
- asyncMap(args, preActivate, function (er, data) {
- log.silly(args, "preActivate over")
- if (er) return cb(er)
- asyncMap
- ( data
- , function (d, cb) {
- var from = path.join(npm.dir, d.name, d.version)
- , to = path.join(npm.dir, d.name, "active")
- link(from, to, cb)
- }
- , function (d, cb) {
- var fromMain = path.join(npm.dir, d.name, "active", "main.js")
- , toMain = path.join(npm.root, d.name+".js")
- linkIfExists(fromMain, toMain, cb)
- }
- // todo: remove this step. 0.1.28
- // required because old deps will be linked with - rather than @
- , function (d, cb) {
- var fromLib = path.join(npm.root, d.name + "-" + d.version)
- , toLib = path.join(npm.root, d.name)
- linkIfExists(fromLib, toLib, cb)
- }
- // if both @ and - exist, then this will overwrite the kludge one.
- , function (d, cb) {
- var fromLib = path.join(npm.root, d.name + "@" + d.version)
- , toLib = path.join(npm.root, d.name)
- linkIfExists(fromLib, toLib, cb)
- }
- , linkBins
- , linkMans
- , function (er) {
- if (er) return cb(er)
- asyncMap(data, postActivate, cb)
- }
- )
- })
-}
-
-function postActivate (data, cb) {
- chain
- ( [lifecycle, data, "activate"]
- , [lifecycle, data, "postactivate"]
- , cb
- )
-}
-
-function preActivate (arg, cb) {
- var args = arg.split("@")
- , pkg = args.shift()
- , version = args.join("@")
- , to = path.join(npm.dir, pkg, "active")
- , jsonFile = path.join(npm.dir, pkg, version, "package", "package.json")
-
- if (!version) cb(new Error("Please specify a version to activate: "+pkg))
-
- chain
- ( function (cb) { npm.commands.deactivate([pkg], function () { cb() }) }
- , function (cb) {
- fs.lstat(to, function (er, stat) {
- if (!er) return fs.readlink(to, function (er, active) {
- cb(new Error("Implicit deactivate failed.\n"+
- pkg+"@"+path.dirname(active)+" still active."))
- })
- else cb()
- })
- }
- , function (er) {
- if (er) return cb(er)
- readJson(jsonFile, function (er, data) {
- if (er) return cb(er)
- data.version = version
- data._id = data.name + "@" + data.version
- npm.set(data)
- loadPackageDefaults(data, function (er, data) {
- if (er) return cb(er)
- log.silly(data._id, "defaults loaded")
- lifecycle(data, "preactivate", function (er) { cb(er, data) })
- })
- })
- }
- )
-}
-function linkMans (pkg, cb) {
- log.verbose(pkg._id, "activate linkMans")
- log.silly(pkg.man, "activate linkMans")
- var manroot = npm.config.get("manroot")
- if (!pkg.man || !manroot) return cb()
- asyncMap(pkg.man, function (man, cb) {
- var parseMan = man.match(/(.*)\.([0-9]+)(\.gz)?$/)
- , stem = parseMan[1]
- , sxn = parseMan[2]
- , gz = parseMan[3] || ""
- , bn = path.basename(stem)
- , manStem = path.join( manroot
- , "man"+sxn
- , (bn.indexOf(pkg.name) === 0 ? bn
- : pkg.name + "-" + bn)
- )
- , suff = pkg.version + "." + sxn + gz
- , manDest = manStem + "." + sxn + gz
- log.silly(manDest, "manDest")
- linkIfExists(manStem+"-"+suff, manDest, function (er) {
- if (er) return cb(er)
- linkIfExists(manStem+"@"+suff, manDest, cb)
- })
- }, cb)
-}
-function linkBins (pkg, cb) {
- log.verbose(pkg._id, "activate linkBins")
- log.silly(pkg.bin, "activate linkBins")
- var binroot = npm.config.get("binroot")
- if (!pkg.bin || !binroot) return cb()
- asyncMap(Object.keys(pkg.bin), function (i, cb) {
- var to = path.join(binroot, i)
- , v = pkg.version
- linkIfExists(to+"-"+v, to, function (er) {
- if (er) return cb(er)
- linkIfExists(to+"@"+v, to, cb)
- })
- }, cb)
-}
diff --git a/lib/bundle.js b/lib/bundle.js
deleted file mode 100644
index 6d0f648f7..000000000
--- a/lib/bundle.js
+++ /dev/null
@@ -1,113 +0,0 @@
-
-module.exports = bundle
-
-var npm = require("../npm")
- , path = require("path")
- , log = require("./utils/log")
- , cache = require("./cache")
- , readJson = require("./utils/read-json")
- , mkdir = require("./utils/mkdir-p")
- , fs = require("./utils/graceful-fs")
- , conf = require("./utils/ini").configList
- , rm = require("./utils/rm-rf")
- , url = require("url")
- , notAllowed = [ "adduser", "build", "bundle", "config", "init", "link"
- , "owner", "publish", "restart", "start", "stop", "tag"
- , "unpublish", "update-dependents", "view", "bn" ]
-
-bundle.usage = "npm bundle\n"
- + "npm bundle destroy\n"
- + "npm bundle <cmd> <args>\n"
- + "(run in package dir)"
-
-bundle.completion = function(args, index, cb) {
- var getCompletions = require("./utils/completion/get-completions")
- , subcmdList = npm.fullList.filter(function(c) {
- return notAllowed.indexOf(c) === -1
- }).concat(["destroy"])
- , subcmd = args[0] || ""
-
- if (subcmdList.indexOf(subcmd) !== -1) {
- var subargs = args.slice(1)
- npm.commands[npm.deref(subcmd)].completion(subargs, index - 1, cb)
- } else if (index < 3) cb(null, getCompletions(subcmd, subcmdList))
-}
-
-function bundle (args, dir, cb_) {
- if (typeof dir === "function") cb_ = dir, dir = process.cwd()
- var location = path.join(dir, "node_modules")
- , binRoot = path.join(dir, "node_modules", ".bin")
- , pkg = dir
- , cmd = args.shift()
- function cb (er, data) {
- conf.shift()
- cb_(er, data)
- }
- mkdir(location, function (er) {
- if (er) return cb(new Error(bundle.usage))
- var c = { root : location
- , binroot : binRoot
- , manroot : null
- , "must-install" : false
- }
- conf.unshift(c)
-
- if (cmd && npm.commands[cmd]) {
- cmd = npm.commands[cmd]
- for (var i = 0, l = notAllowed.length; i < l; i ++) {
- var na = notAllowed[i]
- if (cmd === npm.commands[na]) {
- if (na === "init") log.error(
- "\nIt looks like you might be coming from ruby, where\n"+
- "`bundle init` is a thing. The conceptual model is a bit\n"+
- "different with npm. See `npm help developers`\n")
- return cb(new Error(na + " command not allowed in bundle"))
- }
- }
- if (cmd === npm.commands.ls) c.registry = null
- }
-
- if (cmd === "destroy") return rm(location, function (er) {
- if (er) return cb(er)
- log.info(location, "destroyed", cb)
- })
-
- if (cmd === npm.commands.install && args.length === 0) {
- // `npm bundle install` --> npm bundle
- // Don't try to install the cwd inside of ./node_modules
- cmd = null
- }
-
- if (typeof cmd === "function") {
- return cmd(args, cb)
- }
-
- // no command given, just install the local deps.
- // 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)
- })
- })
-}
-
-function install (data, location, cb) {
- if (typeof data.dependencies === 'undefined') {
- return cb(new Error("Package has no dependencies"))
- }
- var depNames = Object.keys(data.dependencies)
- , deps = depNames.map(function (d) {
- var v = data.dependencies[d]
- if (v === "*") v = ""
- var u = url.parse(v)
- if (u && u.protocol && u.host) {
- return u.href
- }
- return v ? d + "@" + v : d
- })
- log.verbose(deps, "bundle deps")
- npm.commands.install(deps, log.er(cb, "Some dependencies failed to bundle\n"
- + "Bundle them separately with\n"
- + " npm bundle install <pkg>"))
-}
diff --git a/lib/deactivate.js b/lib/deactivate.js
deleted file mode 100644
index 458a29c7f..000000000
--- a/lib/deactivate.js
+++ /dev/null
@@ -1,104 +0,0 @@
-
-module.exports = deactivate
-
-deactivate.usage = "npm deactivate <pkg>"
-
-deactivate.completion = function (args, index, cb) {
- var installedPkgs = require("./utils/completion/installed-packages")
- installedPkgs(args, index, false, false, cb)
-}
-
-var npm = require("../npm")
- , fs = require("./utils/graceful-fs")
- , log = require("./utils/log")
- , path = require("path")
- , rm = require("./utils/rm-rf")
- , chain = require("./utils/chain")
- , lifecycle = require("./utils/lifecycle")
- , readJson = require("./utils/read-json")
- , asyncMap = require("./utils/async-map")
- , loadPackageDefaults = require("./utils/load-package-defaults")
-
-function deactivate (args, cb) {
- var rb = npm.ROLLBACK
- npm.ROLLBACK = true
- asyncMap(args.map(function (a) {
- return a.split("@").shift()
- }), preDeactivate, function (er, data) {
- if (er) return cb(er)
- asyncMap
- ( data
- , function (d, cb) { rm(path.join(npm.dir, d.name, "active"), cb) }
- , function (d, cb) { rm(path.join(npm.root, d.name+".js"), cb) }
- , function (d, cb) { rm(path.join(npm.root, d.name), cb) }
- , rmBins
- , rmMans
- , function (er) {
- if (er) return cb(er)
- asyncMap(data, postDeactivate, function (er) {
- npm.ROLLBACK = rb
- cb(er)
- })
- }
- )
- })
-}
-
-function rmBins (data, cb) {
- var binroot = npm.config.get("binroot")
- if (!data.bin || !binroot) return cb()
- asyncMap(Object.getOwnPropertyNames(data.bin)
- .map(function (bin) { return path.join(binroot, bin) })
- , rm
- , cb
- )
-}
-function rmMans (pkg, cb) {
- var manroot = npm.config.get("manroot")
- if (!pkg.man || !manroot) return cb()
- asyncMap(pkg.man, function (man, cb) {
- var parseMan = man.match(/(.*)\.([0-9]+)(\.gz)?$/)
- , stem = parseMan[1]
- , sxn = parseMan[2]
- , gz = parseMan[3] || ""
- , bn = path.basename(stem)
- rm(path.join( manroot
- , "man"+sxn
- , (bn.indexOf(pkg.name) === 0 ? bn
- : pkg.name + "-" + bn)
- + "." + sxn + gz
- ), cb)
- }, cb)
-}
-
-function preDeactivate (pkg, cb) {
- // run the "deactivate" lifecycle event
- // unlink the "active" folder
- // unlink the libs and main.js from the npm.root
- // run the "postdeactivate" lifecycle event
- var active = path.join(npm.dir, pkg, "active")
- , jsonFile = path.join(active, "package", "package.json")
-
- fs.readlink(active, function (er, p) {
- if (er) return cb()
- var version = path.basename(p)
- readJson(jsonFile, function (er, data) {
- if (er) return cb()
- data.version = version
- data._id = data.name+"@"+data.version
- npm.set(data)
- loadPackageDefaults(data, function (er, data) {
- if (er) return cb(er)
- chain
- ( [lifecycle, data, "predeactivate"]
- , [lifecycle, data, "deactivate"]
- , function (er) { cb(er, data) }
- )
- })
- })
- })
-}
-
-function postDeactivate (data, cb) {
- asyncMap(data, function (d, cb) { lifecycle(d, "postdeactivate", cb) }, cb)
-}
diff --git a/npm.js b/npm.js
index 0a76810f0..c6d8773d6 100644
--- a/npm.js
+++ b/npm.js
@@ -60,45 +60,44 @@ var commandCache = {}
, aliasNames = Object.keys(aliases)
// these are filenames in ./lib
, cmdList = [ "install"
- , "activate"
- , "deactivate"
, "uninstall"
, "build"
, "link"
+ , "cache"
+ , "config"
+ , "set"
+ , "get"
+ , "update"
+ , "rebuild"
+ , "outdated"
+
, "publish"
, "tag"
, "adduser"
- , "config"
- , "help"
- , "cache"
- , "test"
- , "stop"
- , "start"
- , "restart"
, "unpublish"
- , "ls"
, "owner"
- , "update"
- , "update-dependents"
+ , "deprecate"
+
+ , "help"
+ , "ls"
, "view"
- , "rebuild"
- , "bundle"
- , "outdated"
, "init"
- , "deprecate"
, "version"
, "edit"
, "explore"
, "docs"
, "faq"
- , "run-script"
- , "set"
- , "get"
, "xmas"
- , "unbuild"
+
+ , "test"
+ , "stop"
+ , "start"
+ , "restart"
+ , "run-script"
+
]
, plumbing = [ "build"
- , "update-dependents"
+ , "unbuild"
, "completion"
]
, fullList = npm.fullList = cmdList.concat(aliasNames).filter(function (c) {