fix for pkg.name fields that aren't requirable #2538

Closed
wants to merge 3 commits into
from
View
@@ -127,6 +127,14 @@ function install (args, cb_) {
, explicit: false
, parent: data
, wrap: null }
+
+ if (data.name !== path.basename(where) ||
+ path.basename(path.dirname(where)) !== 'node_modules') {
+ // there's a pkg.name, but it can't be required, so shim the name out
+ // to something unresolvable so the real deps will resolve
+ data.name = null
+ }
+
context.family[data.name] = context.ancestors[data.name] = data.version
installManyTop(deps.map(function (dep) {
var target = data.dependencies[dep]
View
@@ -102,14 +102,15 @@
"osenv"
],
"devDependencies": {
- "ronn": "https://github.com/isaacs/ronnjs/tarball/master"
+ "ronn": "https://github.com/isaacs/ronnjs/tarball/master",
+ "tap": "~0.2.5"
},
"engines": {
"node": "0.6 || 0.7 || 0.8",
"npm": "1"
},
"scripts": {
- "test": "node ./test/run.js",
+ "test": "node ./test/run.js && tap test/tap/*.js",
"prepublish": "npm prune ; make -j4 doc",
"dumpconf": "env | grep npm | sort | uniq"
},
View
@@ -0,0 +1,29 @@
+var test = require('tap').test
+ , fs = require('fs')
+ , path = require('path')
+ , existsSync = fs.existsSync || path.existsSync
+ , spawn = require('child_process').spawn
+ , npm = require('../../')
+
+test('not every pkg.name can be required', function (t) {
+ t.plan(1)
+
+ setup(function () {
+ npm.install('.', function (err) {
+ if (err) return t.fail(err)
+ t.ok(existsSync(__dirname +
+ '/false_name/node_modules/tap/node_modules/buffer-equal'))
+ })
+ })
+})
+
+function setup (cb) {
+ process.chdir(__dirname + '/false_name')
+ npm.load(function () {
+ spawn('rm', [ '-rf', __dirname + '/false_name/node_modules' ])
+ .on('exit', function () {
+ fs.mkdirSync(__dirname + '/false_name/node_modules')
+ cb()
+ })
+ })
+}
@@ -0,0 +1 @@
+module.exports = true
@@ -0,0 +1,8 @@
+{
+ "name": "buffer-equal",
+ "version": "0.0.0",
+ "main": "index.js",
+ "dependencies": {
+ "tap": "0.2.5"
+ }
+}