diff options
author | Forrest L Norvell <forrest@npmjs.com> | 2014-07-17 12:07:41 +0400 |
---|---|---|
committer | Forrest L Norvell <forrest@npmjs.com> | 2014-07-17 12:07:41 +0400 |
commit | 4b278d1d4d4b6f1adb561d318c642c527cd525f8 (patch) | |
tree | c27abe3656320b949f847e17455757da5756d0e3 | |
parent | 18a3385bcf8bfb8312239216afbffb7eec759150 (diff) |
a.split('@') → npa(a)
-rw-r--r-- | lib/ls.js | 6 | ||||
-rw-r--r-- | lib/rebuild.js | 7 | ||||
-rw-r--r-- | lib/repo.js | 3 | ||||
-rw-r--r-- | lib/tag.js | 7 | ||||
-rw-r--r-- | lib/unpublish.js | 12 | ||||
-rw-r--r-- | lib/view.js | 7 |
6 files changed, 24 insertions, 18 deletions
@@ -29,9 +29,9 @@ function ls (args, silent, cb) { // npm ls 'foo@~1.3' bar 'baz@<2' if (!args) args = [] else args = args.map(function (a) { - var nv = a.split("@") - , name = nv.shift() - , ver = semver.validRange(nv.join("@")) || "" + var p = npa(a) + , name = p.name + , ver = semver.validRange(p.rawSpec) || "" return [ name, ver ] }) diff --git a/lib/rebuild.js b/lib/rebuild.js index e296451b7..ab372c6ec 100644 --- a/lib/rebuild.js +++ b/lib/rebuild.js @@ -5,6 +5,7 @@ var readInstalled = require("read-installed") , semver = require("semver") , log = require("npmlog") , npm = require("./npm.js") + , npa = require("npm-package-arg") rebuild.usage = "npm rebuild [<name>[@<version>] [name[@<version>] ...]]" @@ -46,9 +47,9 @@ function filter (data, args, set, seen) { else if (data.name && data._id) { for (var i = 0, l = args.length; i < l; i ++) { var arg = args[i] - , nv = arg.split("@") - , n = nv.shift() - , v = nv.join("@") + , nv = npa(arg) + , n = nv.name + , v = nv.rawSpec if (n !== data.name) continue if (!semver.satisfies(data.version, v, true)) continue pass = true diff --git a/lib/repo.js b/lib/repo.js index 1fe81f293..c6db8e37b 100644 --- a/lib/repo.js +++ b/lib/repo.js @@ -24,9 +24,10 @@ var npm = require("./npm.js") , fs = require("fs") , url_ = require("url") , mapToRegistry = require("./utils/map-to-registry.js") + , npa = require("npm-package-arg") function repo (args, cb) { - var n = args.length && args[0].split("@").shift() || "." + var n = args.length && npa(args[0]).name || "." fs.stat(n, function (er, s) { if (er && er.code === "ENOENT") return callRegistry(n, cb) else if (er) return cb(er) diff --git a/lib/tag.js b/lib/tag.js index cf7752a69..0d32712cb 100644 --- a/lib/tag.js +++ b/lib/tag.js @@ -8,11 +8,12 @@ tag.completion = require("./unpublish.js").completion var npm = require("./npm.js") , registry = npm.registry , mapToRegistry = require("./utils/map-to-registry.js") + , npa = require("npm-package-arg") function tag (args, cb) { - var thing = (args.shift() || "").split("@") - , project = thing.shift() - , version = thing.join("@") + var thing = npa(args.shift() || "") + , project = thing.name + , version = thing.rawSpec , t = args.shift() || npm.config.get("tag") if (!project || !version || !t) return cb("Usage:\n"+tag.usage) mapToRegistry(project, npm.config, function (er, uri) { diff --git a/lib/unpublish.js b/lib/unpublish.js index f4bb05f10..0f2e7224d 100644 --- a/lib/unpublish.js +++ b/lib/unpublish.js @@ -7,6 +7,7 @@ var log = require("npmlog") , readJson = require("read-package-json") , path = require("path") , mapToRegistry = require("./utils/map-to-registry.js") + , npa = require("npm-package-arg") unpublish.usage = "npm unpublish <project>[@<version>]" @@ -27,8 +28,7 @@ unpublish.completion = function (opts, cb) { // accidentally a whole project. pkgs = pkgs[un] if (!pkgs || !pkgs.length) return cb() - var partial = opts.partialWord.split("@") - , pp = partial.shift() + var pp = npa(opts.partialWord).name pkgs = pkgs.filter(function (p) { return p.indexOf(pp) === 0 }) @@ -53,10 +53,12 @@ unpublish.completion = function (opts, cb) { function unpublish (args, cb) { if (args.length > 1) return cb(unpublish.usage) - var thing = args.length ? args.shift().split("@") : [] - , project = thing.shift() - , version = thing.join("@") + var thing = args.length ? npa(args[0]) : {} + , project = thing.name + , version = thing.rawSpec + log.silly("unpublish", "args[0]", args[0]) + log.silly("unpublish", "thing", thing) if (!version && !npm.config.get("force")) { return cb("Refusing to delete entire project.\n" + "Run with --force to do this.\n" diff --git a/lib/view.js b/lib/view.js index 8e0c97cf8..43d09cbbc 100644 --- a/lib/view.js +++ b/lib/view.js @@ -53,14 +53,15 @@ var npm = require("./npm.js") , util = require("util") , semver = require("semver") , mapToRegistry = require("./utils/map-to-registry.js") + , npa = require("npm-package-arg") function view (args, silent, cb) { if (typeof cb !== "function") cb = silent, silent = false if (!args.length) return cb("Usage: "+view.usage) var pkg = args.shift() - , nv = pkg.split("@") - , name = nv.shift() - , version = nv.join("@") || npm.config.get("tag") + , nv = npa(pkg) + , name = nv.name + , version = nv.rawSpec || npm.config.get("tag") if (name === ".") return cb(view.usage) |