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:
authorsmikes <smikes@cubane.com>2015-01-09 00:59:18 +0300
committerForrest L Norvell <forrest@npmjs.com>2015-03-03 03:01:28 +0300
commit4ef1412d0061239da2b1c4460ed6db37cc9ded27 (patch)
tree7316018f02d7d50f89c55558287895e1c2362e98
parentad53d0f666125d9f50d661b54901c6e5bab4d603 (diff)
publish, config: move tag-semver test
add usage info to publish move tag-semver check to publish test publish instead of config
-rw-r--r--lib/config/defaults.js9
-rw-r--r--lib/publish.js13
-rw-r--r--test/tap/config-semver-tag.js27
-rw-r--r--test/tap/publish-invalid-semver-tag.js79
4 files changed, 91 insertions, 37 deletions
diff --git a/lib/config/defaults.js b/lib/config/defaults.js
index e49ce210b..3c37f4405 100644
--- a/lib/config/defaults.js
+++ b/lib/config/defaults.js
@@ -47,10 +47,6 @@ nopt.typeDefs.semver = { type: semver, validate: validateSemver }
nopt.typeDefs.Stream = { type: Stream, validate: validateStream }
nopt.typeDefs.Umask = { type: Umask, validate: validateUmask }
-// Don't let --tag=1.2.3 ever be a thing
-var tag = {}
-nopt.typeDefs.tag = { type: tag, validate: validateTag }
-
nopt.invalidHandler = function (k, val, type) {
log.warn("invalid config", k + "=" + JSON.stringify(val))
@@ -60,9 +56,6 @@ nopt.invalidHandler = function (k, val, type) {
}
switch (type) {
- case tag:
- log.warn("invalid config", "Tag must not be a SemVer range")
- break
case Umask:
log.warn("invalid config", "Must be umask, octal number in range 0000..0777")
break
@@ -312,7 +305,7 @@ exports.types =
, "sign-git-tag": Boolean
, spin: ["always", Boolean]
, "strict-ssl": Boolean
- , tag : tag
+ , tag : String
, tmp : path
, unicode : Boolean
, "unsafe-perm" : Boolean
diff --git a/lib/publish.js b/lib/publish.js
index 06a3404af..92a9a9b67 100644
--- a/lib/publish.js
+++ b/lib/publish.js
@@ -13,10 +13,12 @@ var npm = require("./npm.js")
, cachedPackageRoot = require("./cache/cached-package-root.js")
, createReadStream = require("graceful-fs").createReadStream
, npa = require("npm-package-arg")
+ , semver = require('semver')
-publish.usage = "npm publish <tarball>"
- + "\nnpm publish <folder>"
+publish.usage = "npm publish <tarball> [--tag <tagname>]"
+ + "\nnpm publish <folder> [--tag <tagname>]"
+ "\n\nPublishes '.' if no argument supplied"
+ + "\n\nSets tag `latest` if no --tag specified"
publish.completion = function (opts, cb) {
// publish can complete to a folder with a package.json
@@ -34,6 +36,13 @@ function publish (args, isRetry, cb) {
if (args.length !== 1) return cb(publish.usage)
log.verbose("publish", args)
+
+ var t = npm.config.get('tag').trim()
+ if (semver.validRange(t)) {
+ var er = new Error("Tag name must not be a valid SemVer range: " + t)
+ return cb(er)
+ }
+
var arg = args[0]
// if it's a local folder, then run the prepublish there, first.
readJson(path.resolve(arg, "package.json"), function (er, data) {
diff --git a/test/tap/config-semver-tag.js b/test/tap/config-semver-tag.js
deleted file mode 100644
index 4ce1cb219..000000000
--- a/test/tap/config-semver-tag.js
+++ /dev/null
@@ -1,27 +0,0 @@
-var util = require("util")
-var test = require("tap").test
-var npmconf = require("../../lib/config/core.js")
-var common = require("./00-config-setup.js")
-
-var cli = { tag: "v2.x" }
-
-var log = require("npmlog")
-
-test("tag cannot be a SemVer", function (t) {
- var messages = []
- log.warn = function (m) {
- messages.push(m + " " + util.format.apply(util, [].slice.call(arguments, 1)))
- }
-
- var expect = [
- 'invalid config tag="v2.x"',
- "invalid config Tag must not be a SemVer range"
- ]
-
- npmconf.load(cli, common.builtin, function (er, conf) {
- if (er) throw er
- t.equal(conf.get("tag"), "latest")
- t.same(messages, expect)
- t.end()
- })
-})
diff --git a/test/tap/publish-invalid-semver-tag.js b/test/tap/publish-invalid-semver-tag.js
new file mode 100644
index 000000000..1a741d348
--- /dev/null
+++ b/test/tap/publish-invalid-semver-tag.js
@@ -0,0 +1,79 @@
+var common = require('../common-tap.js')
+var test = require('tap').test
+var npm = require('../../lib/npm.js')
+var mkdirp = require('mkdirp')
+var rimraf = require('rimraf')
+var path = require('path')
+var fs = require('fs')
+var mr = require('npm-registry-mock')
+
+var osenv = require('osenv')
+
+var PKG_DIR = path.resolve(__dirname, 'publish-invalid-semver-tag')
+var CACHE_DIR = path.resolve(PKG_DIR, 'cache')
+
+var DEFAULT_PKG = {
+ 'name': 'examples',
+ 'version': '1.2.3'
+}
+
+var mockServer
+
+function resetPackage (options) {
+ rimraf.sync(CACHE_DIR)
+ mkdirp.sync(CACHE_DIR)
+
+ fs.writeFileSync(path.resolve(PKG_DIR, 'package.json'), DEFAULT_PKG)
+}
+
+test('setup', function (t) {
+ process.chdir(osenv.tmpdir())
+ mkdirp.sync(PKG_DIR)
+ process.chdir(PKG_DIR)
+
+ resetPackage({})
+
+ mr({ port: common.port }, function (er, server) {
+ npm.load({
+ cache: CACHE_DIR,
+ registry: common.registry,
+ cwd: PKG_DIR
+ }, function (err) {
+ t.ifError(err, 'started server')
+ mockServer = server
+
+ t.end()
+ })
+ })
+})
+
+test('attempt publish with semver-like version', function (t) {
+ resetPackage({})
+
+ npm.config.set('tag', 'v1.x')
+ npm.commands.publish([], function (err) {
+ t.notEqual(err, null)
+ t.same(err.message, 'Tag name must not be a valid SemVer range: v1.x')
+ t.end()
+ })
+})
+
+test('attempt publish with semver-like version', function (t) {
+ resetPackage({})
+
+ npm.config.set('tag', '1.2.3')
+ npm.commands.publish([], function (err) {
+ t.notEqual(err, null)
+ t.same(err.message, 'Tag name must not be a valid SemVer range: 1.2.3')
+ t.end()
+ })
+})
+
+test('cleanup', function (t) {
+ mockServer.close()
+
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(PKG_DIR)
+
+ t.end()
+})