Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

"install ./pkg@1.2.3" should install local module

  • Loading branch information...
commit 46d876821d1dd94c050d5ebc86444bed12c56739 1 parent 9ae71de
@rlidwka rlidwka authored isaacs committed
View
15 lib/cache.js
@@ -252,11 +252,16 @@ function add (args, cb) {
// it could be that we got name@http://blah
// in that case, we will not have a protocol now, but if we
// split and check, we will.
- if (!name && !p.protocol && spec.indexOf("@") !== -1) {
- spec = spec.split("@")
- name = spec.shift()
- spec = spec.join("@")
- return add([name, spec], cb)
+ if (!name && spec.indexOf("@") !== -1) {
+ var tmp = spec.split("@")
+
+ // split name@2.3.4 only if name is a valid package name,
+ // don't split in case of "./test@example.com/" (local path)
+ if (!tmp[0].match(/[\/@\s\+%:]/)) {
+ name = tmp.shift()
+ spec = tmp.join("@")
+ return add([name, spec], cb)
+ }
}
switch (p.protocol) {
View
34 test/tap/install-at-locally.js
@@ -0,0 +1,34 @@
+var common = require('../common-tap.js')
+var test = require('tap').test
+var npm = require('../../')
+var osenv = require('osenv')
+var path = require('path')
+var fs = require('fs')
+var rimraf = require('rimraf')
+var mkdirp = require('mkdirp')
+var pkg = path.join(__dirname, 'install-at-locally')
+
+test('"npm install ./package@1.2.3" should install local pkg', function(t) {
+ setup()
+ t.plan(1)
+ npm.load(function() {
+ npm.commands.install(['./package@1.2.3'], function(err) {
+ var p = path.resolve(pkg, 'node_modules/install-at-locally/package.json')
+ t.ok(JSON.parse(fs.readFileSync(p, 'utf8')))
+ t.end()
+ })
+ })
+})
+
+function setup() {
+ mkdirp.sync(pkg)
+ mkdirp.sync(path.resolve(pkg, 'node_modules'))
+ process.chdir(pkg)
+}
+
+test('cleanup', function(t) {
+ process.chdir(__dirname)
+ rimraf.sync(path.resolve(pkg, 'node_modules'))
+ t.end()
+})
+
View
5 test/tap/install-at-locally/package@1.2.3/package.json
@@ -0,0 +1,5 @@
+{
+ "name": "install-at-locally",
+ "version": "0.0.0",
+ "description": "Test for 404-parent"
+}
Please sign in to comment.
Something went wrong with that request. Please try again.