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
path: root/lib
diff options
context:
space:
mode:
authorRebecca Turner <me@re-becca.org>2015-10-07 01:45:41 +0300
committerRebecca Turner <me@re-becca.org>2015-10-09 02:24:32 +0300
commitb78fec9dac12176f29618c783aaf231a2c767b54 (patch)
treebdd2301f9740ed197dd54e6fd1d65ec24d21c5da /lib
parent2289234e11b30c878585aebee68d4a3a5bd63cce (diff)
module-name: Factor out module name reading
Bring consistent guarding against null/undefined and consistent business logic. PR-URL: //github.com/npm/npm/pull/9890 Fixes: #9766
Diffstat (limited to 'lib')
-rw-r--r--lib/dedupe.js7
-rw-r--r--lib/install.js3
-rw-r--r--lib/install/action/fetch.js3
-rw-r--r--lib/install/actions.js5
-rw-r--r--lib/install/deps.js39
-rw-r--r--lib/install/flatten-tree.js3
-rw-r--r--lib/install/get-package-id.js12
-rw-r--r--lib/install/inflate-bundled.js5
-rw-r--r--lib/install/inflate-shrinkwrap.js3
-rw-r--r--lib/install/mutate-into-logical-tree.js7
-rw-r--r--lib/install/save.js5
-rw-r--r--lib/install/validate-args.js2
-rw-r--r--lib/outdated.js15
-rw-r--r--lib/shrinkwrap.js7
-rw-r--r--lib/utils/module-name.js33
-rw-r--r--lib/utils/tar.js5
16 files changed, 101 insertions, 53 deletions
diff --git a/lib/dedupe.js b/lib/dedupe.js
index 2feaa9f88..295a2aa2c 100644
--- a/lib/dedupe.js
+++ b/lib/dedupe.js
@@ -16,6 +16,7 @@ var loadExtraneous = require('./install/deps.js').loadExtraneous
var filterInvalidActions = require('./install/filter-invalid-actions.js')
var recalculateMetadata = require('./install/deps.js').recalculateMetadata
var sortActions = require('./install/diff-trees.js').sortActions
+var moduleName = require('./utils/module-name.js')
module.exports = dedupe
module.exports.Deduper = Deduper
@@ -48,7 +49,7 @@ Deduper.prototype.normalizeTree = function (log, cb) {
if (npm.config.get('global')) {
var args = this.args
this.currentTree.children = this.currentTree.children.filter(function (child) {
- return args.filter(function (arg) { return arg === child.package.name }).length
+ return args.filter(function (arg) { return arg === moduleName(child) }).length
})
}
Installer.prototype.normalizeTree.call(this, log, cb)
@@ -97,7 +98,7 @@ function move (node, hoistTo, diff) {
node.parent.children = without(node.parent.children, node)
hoistTo.children.push(node)
node.fromPath = node.path
- node.path = path.resolve(hoistTo.path, 'node_modules', node.package.name)
+ node.path = path.resolve(hoistTo.path, 'node_modules', moduleName(node))
node.parent = hoistTo
if (!diff.filter(function (action) { return action[0] === 'move' && action[1] === node }).length) {
diff.push(['move', node])
@@ -135,7 +136,7 @@ function hoistChildren_ (tree, diff, seen, next) {
seen[tree.path] = true
asyncMap(tree.children, function (child, done) {
if (!tree.parent) return hoistChildren_(child, diff, seen, done)
- var better = findRequirement(tree.parent, child.package.name, child.package._requested || npa(child.package.name + '@' + child.package.version))
+ var better = findRequirement(tree.parent, moduleName(child), child.package._requested || npa(child.package.name + '@' + child.package.version))
if (better) {
return chain([
[remove, child, diff],
diff --git a/lib/install.js b/lib/install.js
index 3ebb3b3bb..84da53ac3 100644
--- a/lib/install.js
+++ b/lib/install.js
@@ -133,6 +133,7 @@ var doReverseSerialActions = require('./install/actions.js').doReverseSerial
var doParallelActions = require('./install/actions.js').doParallel
var doOneAction = require('./install/actions.js').doOne
var getPackageId = require('./install/get-package-id.js')
+var moduleName = require('./utils/module-name.js')
function unlockCB (lockPath, name, cb) {
validate('SSF', arguments)
@@ -428,7 +429,7 @@ Installer.prototype.computeLinked = function (cb) {
}
function isLinkable (pkg, cb) {
- var globalPackage = path.resolve(npm.globalPrefix, 'lib', 'node_modules', pkg.package.name)
+ var globalPackage = path.resolve(npm.globalPrefix, 'lib', 'node_modules', moduleName(pkg))
var globalPackageJson = path.resolve(globalPackage, 'package.json')
fs.stat(globalPackage, function (er) {
if (er) return cb(true, true)
diff --git a/lib/install/action/fetch.js b/lib/install/action/fetch.js
index 16a94244b..3c3ab143f 100644
--- a/lib/install/action/fetch.js
+++ b/lib/install/action/fetch.js
@@ -1,5 +1,6 @@
'use strict'
// var cache = require('../../cache.js')
+// var moduleName = require('../../utils/module-name.js')
module.exports = function (top, buildpath, pkg, log, next) {
next()
@@ -8,7 +9,7 @@ module.exports = function (top, buildpath, pkg, log, next) {
// is progressively seeming to be likely for the indefinite future.
// ALSO fails for local deps specified with relative URLs outside of the top level.
- var name = pkg.package.name
+ var name = moduleName(pkg)
var version
switch (pkg.package._requested.type) {
case 'version':
diff --git a/lib/install/actions.js b/lib/install/actions.js
index 84d987faf..96d1c927d 100644
--- a/lib/install/actions.js
+++ b/lib/install/actions.js
@@ -8,6 +8,7 @@ var log = require('npmlog')
var andFinishTracker = require('./and-finish-tracker.js')
var andAddParentToErrors = require('./and-add-parent-to-errors.js')
var failedDependency = require('./deps.js').failedDependency
+var moduleName = require('../utils/module-name.js')
var actions = {}
@@ -81,9 +82,9 @@ function prepareAction (staging, log) {
var cmd = action[0]
var pkg = action[1]
if (!actions[cmd]) throw new Error('Unknown decomposed command "' + cmd + '" (is it new?)')
- var buildpath = uniqueFilename(staging, pkg.package.name, pkg.realpath)
+ var buildpath = uniqueFilename(staging, moduleName(pkg), pkg.realpath)
var top = path.resolve(staging, '../..')
- return [actions[cmd], top, buildpath, pkg, log.newGroup(cmd + ':' + pkg.package.name)]
+ return [actions[cmd], top, buildpath, pkg, log.newGroup(cmd + ':' + moduleName(pkg))]
}
}
diff --git a/lib/install/deps.js b/lib/install/deps.js
index ab1620874..9c0ec8292 100644
--- a/lib/install/deps.js
+++ b/lib/install/deps.js
@@ -26,17 +26,19 @@ var resetMetadata = require('./node.js').reset
var andIgnoreErrors = require('./and-ignore-errors.js')
var isInstallable = require('./validate-args.js').isInstallable
var getPackageId = require('./get-package-id.js')
+var moduleName = require('../utils/module-name.js')
// The export functions in this module mutate a dependency tree, adding
// items to them.
function isDep (tree, child) {
if (child.fromShrinkwrap) return true
- var requested = isProdDep(tree, child.package.name)
+ var name = moduleName(child)
+ var requested = isProdDep(tree, name)
var matches
if (requested) matches = doesChildVersionMatch(child, requested)
if (matches) return matches
- requested = isDevDep(tree, child.package.name)
+ requested = isDevDep(tree, name)
if (!requested) return
return doesChildVersionMatch(child, requested)
}
@@ -122,7 +124,7 @@ function recalculateMetadata (tree, log, seen, next) {
function addRequiredDep (tree, child) {
if (!isDep(tree, child)) return false
- var name = isProdDep(tree, child.package.name) ? flatNameFromTree(tree) : '#DEV:' + flatNameFromTree(tree)
+ var name = isProdDep(tree, moduleName(child)) ? flatNameFromTree(tree) : '#DEV:' + flatNameFromTree(tree)
child.package._requiredBy = union(child.package._requiredBy || [], [name])
child.requiredBy = union(child.requiredBy || [], [tree])
tree.requires = union(tree.requires || [], [child])
@@ -174,20 +176,22 @@ exports.loadRequestedDeps = function (args, tree, saveToDependencies, log, next)
validate('AOOF', [args, tree, log, next])
asyncMap(args, function (pkg, done) {
var depLoaded = andAddParentToErrors(tree, done)
+ var pkgName = moduleName(pkg)
tree.children = tree.children.filter(function (child) {
- return child.package.name !== pkg.name
+ return moduleName(child) !== pkgName
})
resolveWithNewModule(pkg, tree, log.newGroup('loadRequestedDeps'), iferr(depLoaded, function (child, tracker) {
validate('OO', arguments)
if (npm.config.get('global')) {
child.isGlobal = true
}
+ var childName = moduleName(child)
if (saveToDependencies) {
- tree.package[saveToDependencies][child.package.name] =
+ tree.package[saveToDependencies][childName] =
child.package._requested.rawSpec || child.package._requested.spec
}
if (saveToDependencies && saveToDependencies !== 'devDependencies') {
- tree.package.dependencies[child.package.name] =
+ tree.package.dependencies[childName] =
child.package._requested.rawSpec || child.package._requested.spec
}
child.directlyRequested = true
@@ -210,14 +214,15 @@ exports.loadRequestedDeps = function (args, tree, saveToDependencies, log, next)
exports.removeDeps = function (args, tree, saveToDependencies, log, next) {
validate('AOOF', [args, tree, log, next])
args.forEach(function (pkg) {
+ var pkgName = moduleName(pkg)
if (saveToDependencies) {
- var toRemove = tree.children.filter(function (child) { return child.package.name === pkg.name })
+ var toRemove = tree.children.filter(function (child) { return moduleName(child) === pkgName })
tree.removed = union(tree.removed || [], toRemove)
toRemove.forEach(function (parent) {
parent.save = saveToDependencies
})
}
- tree.children = tree.children.filter(function (child) { return child.package.name !== pkg.name })
+ tree.children = tree.children.filter(function (child) { return moduleName(child) !== pkgName })
})
log.finish()
next()
@@ -238,7 +243,7 @@ function andForEachChild (load, next) {
cmds.push([load, children[ii], logs[ii]])
}
var sortedCmds = cmds.sort(function installOrder (aa, bb) {
- return aa[1].package.name.localeCompare(bb[1].package.name)
+ return moduleName(aa[1]).localeCompare(moduleName(bb[1]))
})
chain(sortedCmds, next)
}
@@ -256,10 +261,10 @@ var failedDependency = exports.failedDependency = function (tree, name_pkg) {
name = name_pkg
} else {
pkg = name_pkg
- name = pkg.name || pkg.package.name
+ name = moduleName(pkg)
}
- tree.children = tree.children.filter(function (child) { return child.package.name !== name })
+ tree.children = tree.children.filter(function (child) { return moduleName(child) !== name })
if (isDepOptional(tree, name)) {
return false
@@ -285,7 +290,7 @@ function andHandleOptionalErrors (log, tree, name, done) {
if (!er) return done(er, child, childLog)
var isFatal = failedDependency(tree, name)
if (er && !isFatal) {
- tree.children = tree.children.filter(function (child) { return child.package.name !== name })
+ tree.children = tree.children.filter(function (child) { return moduleName(child) !== name })
log.warn('install', "Couldn't install optional dependency:", er.message)
log.verbose('install', er.stack)
return done()
@@ -382,7 +387,7 @@ var updatePhantomChildren = exports.updatePhantomChildren = function (current, c
while (current && current !== child.parent) {
// FIXME: phantomChildren doesn't actually belong in the package.json
if (!current.package._phantomChildren) current.package._phantomChildren = {}
- current.package._phantomChildren[child.package.name] = child.package.version
+ current.package._phantomChildren[moduleName(child)] = child.package.version
current = current.parent
}
}
@@ -411,6 +416,8 @@ function resolveWithNewModule (pkg, tree, log, next) {
}))
}
+ var pkgName = moduleName(pkg)
+
if (!pkg._from) {
pkg._from = pkg._requested.name + '@' + pkg._requested.spec
}
@@ -426,7 +433,7 @@ function resolveWithNewModule (pkg, tree, log, next) {
isLink: tree.isLink
})
- parent.children = parent.children.filter(function (pkg) { return pkg.package.name !== child.package.name })
+ parent.children = parent.children.filter(function (pkg) { return pkgName !== moduleName(pkg) })
parent.children.push(child)
addRequiredDep(tree, child)
pkg._location = flatNameFromTree(child)
@@ -474,7 +481,7 @@ function validateAllPeerDeps (tree, onInvalid, seen) {
var findRequirement = exports.findRequirement = function (tree, name, requested) {
validate('OSO', arguments)
var nameMatch = function (child) {
- return child.package.name === name && child.parent
+ return moduleName(child) === name && child.parent
}
var versionMatch = function (child) {
return doesChildVersionMatch(child, requested)
@@ -503,7 +510,7 @@ var findRequirement = exports.findRequirement = function (tree, name, requested)
var earliestInstallable = exports.earliestInstallable = function (requiredBy, tree, pkg) {
validate('OOO', arguments)
var nameMatch = function (child) {
- return child.package.name === pkg.name
+ return moduleName(child) === pkg.name
}
if (tree.children.some(nameMatch)) return null
diff --git a/lib/install/flatten-tree.js b/lib/install/flatten-tree.js
index a0c6b7a79..869685a4e 100644
--- a/lib/install/flatten-tree.js
+++ b/lib/install/flatten-tree.js
@@ -1,5 +1,6 @@
'use strict'
var validate = require('aproba')
+var moduleName = require('../utils/module-name.js')
module.exports = function (tree) {
validate('O', arguments)
@@ -25,5 +26,5 @@ module.exports = function (tree) {
var flatName = module.exports.flatName = function (path, child) {
validate('SO', arguments)
- return path + (child.package.name || 'TOP')
+ return path + (moduleName(child) || 'TOP')
}
diff --git a/lib/install/get-package-id.js b/lib/install/get-package-id.js
index 076eb1423..9291bbe77 100644
--- a/lib/install/get-package-id.js
+++ b/lib/install/get-package-id.js
@@ -1,19 +1,15 @@
'use strict'
-var path = require('path')
+var moduleName = require('../utils/module-name.js')
module.exports = function (tree) {
var pkg = tree.package || tree
// FIXME: Excluding the '@' here is cleaning up after the mess that
// read-package-json makes. =(
if (pkg._id && pkg._id !== '@') return pkg._id
- var name = pkg.name || (tree && tree.logical && path.basename(tree.logical))
- if (name && pkg.version) {
+ var name = moduleName(tree)
+ if (pkg.version) {
return name + '@' + pkg.version
- } else if (tree) {
- return tree.path
- } else if (name) {
- return name
} else {
- return ''
+ return name
}
}
diff --git a/lib/install/inflate-bundled.js b/lib/install/inflate-bundled.js
index c27acd1dc..66555221f 100644
--- a/lib/install/inflate-bundled.js
+++ b/lib/install/inflate-bundled.js
@@ -1,14 +1,15 @@
'use strict'
var path = require('path')
var validate = require('aproba')
+var moduleName = require('../utils/module-name.js')
module.exports = function inflateBundled (parent, children) {
validate('OA', arguments)
children.forEach(function (child) {
child.fromBundle = true
child.parent = parent
- child.path = path.join(parent.path, child.package.name)
- child.realpath = path.resolve(parent.realpath, child.package.name)
+ child.path = path.join(parent.path, moduleName(child))
+ child.realpath = path.resolve(parent.realpath, moduleName(child))
child.isLink = child.isLink || parent.isLink || parent.target
inflateBundled(child, child.children)
})
diff --git a/lib/install/inflate-shrinkwrap.js b/lib/install/inflate-shrinkwrap.js
index dd32583f6..a57b3f0b9 100644
--- a/lib/install/inflate-shrinkwrap.js
+++ b/lib/install/inflate-shrinkwrap.js
@@ -10,12 +10,13 @@ var addBundled = require('../fetch-package-metadata.js').addBundled
var inflateBundled = require('./inflate-bundled.js')
var npm = require('../npm.js')
var createChild = require('./node.js').create
+var moduleName = require('../utils/module-name.js')
var inflateShrinkwrap = module.exports = function (tree, swdeps, finishInflating) {
validate('OOF', arguments)
if (!npm.config.get('shrinkwrap')) return finishInflating()
var onDisk = {}
- tree.children.forEach(function (child) { onDisk[child.package.name] = child })
+ tree.children.forEach(function (child) { onDisk[moduleName(child)] = child })
tree.children = []
asyncMap(Object.keys(swdeps), function (name, next) {
var sw = swdeps[name]
diff --git a/lib/install/mutate-into-logical-tree.js b/lib/install/mutate-into-logical-tree.js
index 0fbedcb9d..f2186fcd2 100644
--- a/lib/install/mutate-into-logical-tree.js
+++ b/lib/install/mutate-into-logical-tree.js
@@ -6,6 +6,7 @@ var flattenTree = require('./flatten-tree.js')
var isExtraneous = require('./is-extraneous.js')
var validateAllPeerDeps = require('./deps.js').validateAllPeerDeps
var getPackageId = require('./get-package-id.js')
+var moduleName = require('../utils/module-name.js')
var mutateIntoLogicalTree = module.exports = function (tree) {
validate('O', arguments)
@@ -29,8 +30,8 @@ var mutateIntoLogicalTree = module.exports = function (tree) {
var requiredByNames = requiredBy.filter(function (parentFlatname) {
var parentNode = getNode(parentFlatname)
if (!parentNode) return false
- return parentNode.package.dependencies[node.package.name] ||
- (parentNode.package.devDependencies && parentNode.package.devDependencies[node.package.name])
+ return parentNode.package.dependencies[moduleName(node)] ||
+ (parentNode.package.devDependencies && parentNode.package.devDependencies[moduleName(node)])
})
requiredBy = requiredByNames.map(getNode)
@@ -67,7 +68,7 @@ function translateTree_ (tree, seen) {
pkg._dependencies = pkg.dependencies
pkg.dependencies = {}
tree.children.forEach(function (child) {
- pkg.dependencies[child.package.name] = translateTree_(child, seen)
+ pkg.dependencies[moduleName(child)] = translateTree_(child, seen)
})
Object.keys(tree.missingDeps).forEach(function (name) {
if (pkg.dependencies[name]) {
diff --git a/lib/install/save.js b/lib/install/save.js
index dffd3a0cd..aaa801a63 100644
--- a/lib/install/save.js
+++ b/lib/install/save.js
@@ -11,6 +11,7 @@ var without = require('lodash.without')
var npm = require('../npm.js')
var deepSortObject = require('../utils/deep-sort-object.js')
var parseJSON = require('../utils/parse-json.js')
+var moduleName = require('../utils/module-name.js')
// if the -S|--save option is specified, then write installed packages
// as dependencies to a package.json file.
@@ -171,7 +172,7 @@ function getThingsToSave (tree) {
return child.save
}).map(function (child) {
return {
- name: child.package.name,
+ name: moduleName(child),
spec: computeVersionSpec(child),
save: child.save
}
@@ -184,7 +185,7 @@ function getThingsToRemove (args, tree) {
if (!tree.removed) return []
var toRemove = tree.removed.map(function (child) {
return {
- name: child.package.name,
+ name: moduleName(child),
save: child.save
}
})
diff --git a/lib/install/validate-args.js b/lib/install/validate-args.js
index 75ae3e362..653dc1b4a 100644
--- a/lib/install/validate-args.js
+++ b/lib/install/validate-args.js
@@ -30,7 +30,7 @@ var isInstallable = module.exports.isInstallable = function (pkg, next) {
}
function checkSelf (idealTree, pkg, force, next) {
- if (idealTree.package.name !== pkg.name) return next()
+ if (idealTree.package && idealTree.package.name !== pkg.name) return next()
if (force) {
var warn = new Error("Wouldn't install " + pkg.name + ' as a dependency of itself, but being forced')
warn.code = 'ENOSELF'
diff --git a/lib/outdated.js b/lib/outdated.js
index 61eb3beb9..40506f2af 100644
--- a/lib/outdated.js
+++ b/lib/outdated.js
@@ -39,6 +39,7 @@ var long = npm.config.get('long')
var mapToRegistry = require('./utils/map-to-registry.js')
var isExtraneous = require('./install/is-extraneous.js')
var recalculateMetadata = require('./install/deps.js').recalculateMetadata
+var moduleName = require('./utils/module-name.js')
function uniqName (item) {
return item[0].path + '|' + item[1] + '|' + item[7]
@@ -212,7 +213,7 @@ function outdated_ (args, path, tree, parentHas, depth, cb) {
var deps = tree.children.filter(function (child) { return !isExtraneous(child) }) || []
deps.forEach(function (dep) {
- types[dep.package.name] = 'dependencies'
+ types[moduleName(dep)] = 'dependencies'
})
Object.keys(tree.missingDeps).forEach(function (name) {
@@ -250,17 +251,17 @@ function outdated_ (args, path, tree, parentHas, depth, cb) {
}
if (npm.config.get('save-dev')) {
- deps = deps.filter(function (dep) { return pkg.devDependencies[dep.package.name] })
+ deps = deps.filter(function (dep) { return pkg.devDependencies[moduleName(dep)] })
deps.forEach(function (dep) {
- types[dep.package.name] = 'devDependencies'
+ types[moduleName(dep)] = 'devDependencies'
})
} else if (npm.config.get('save')) {
// remove optional dependencies from dependencies during --save.
- deps = deps.filter(function (dep) { return !pkg.optionalDependencies[dep.package.name] })
+ deps = deps.filter(function (dep) { return !pkg.optionalDependencies[moduleName(dep)] })
} else if (npm.config.get('save-optional')) {
- deps = deps.filter(function (dep) { return pkg.optionalDependencies[dep.package.name] })
+ deps = deps.filter(function (dep) { return pkg.optionalDependencies[moduleName(dep)] })
deps.forEach(function (dep) {
- types[dep.package.name] = 'optionalDependencies'
+ types[moduleName(dep)] = 'optionalDependencies'
})
}
var doUpdate = dev || (
@@ -292,7 +293,7 @@ function outdated_ (args, path, tree, parentHas, depth, cb) {
// if has[dep] !== shouldHave[dep], then cb with the data
// otherwise dive into the folder
asyncMap(deps, function (dep, cb) {
- var name = dep.package.name
+ var name = moduleName(dep)
var required = (tree.package.dependencies)[name] ||
(tree.package.optionalDependencies)[name] ||
(tree.package.devDependencies)[name] ||
diff --git a/lib/shrinkwrap.js b/lib/shrinkwrap.js
index 2a8cc7a29..5cb2ad095 100644
--- a/lib/shrinkwrap.js
+++ b/lib/shrinkwrap.js
@@ -15,6 +15,7 @@ var validatePeerDeps = require('./install/deps.js').validatePeerDeps
var isExtraneous = require('./install/is-extraneous.js')
var isOnlyDev = require('./install/is-dev.js').isOnlyDev
var getPackageId = require('./install/get-package-id.js')
+var moduleName = require('./utils/module-name.js')
shrinkwrap.usage = 'npm shrinkwrap'
@@ -64,7 +65,7 @@ function shrinkwrapDeps (dev, problems, deps, tree, seen) {
if (seen[tree.path]) return
seen[tree.path] = true
Object.keys(tree.missingDeps).forEach(function (name) {
- var invalid = tree.children.filter(function (dep) { return dep.package.name === name })[0]
+ var invalid = tree.children.filter(function (dep) { return moduleName(dep) === name })[0]
if (invalid) {
problems.push('invalid: have ' + invalid.package._id + ' (expected: ' + tree.missingDeps[name] + ') ' + invalid.path)
} else {
@@ -73,12 +74,12 @@ function shrinkwrapDeps (dev, problems, deps, tree, seen) {
(topname ? ', required by ' + topname : ''))
}
})
- tree.children.sort(function (aa, bb) { return aa.package.name.localeCompare(bb.package.name) }).forEach(function (child) {
+ tree.children.sort(function (aa, bb) { return moduleName(aa).localeCompare(moduleName(bb)) }).forEach(function (child) {
if (!dev && isOnlyDev(child)) {
log.warn('shrinkwrap', 'Excluding devDependency: %s', child.package.name, child.parent.package.dependencies)
return
}
- var pkginfo = deps[child.package.name] = {}
+ var pkginfo = deps[moduleName(child)] = {}
pkginfo.version = child.package.version
pkginfo.from = child.package._from
pkginfo.resolved = child.package._resolved
diff --git a/lib/utils/module-name.js b/lib/utils/module-name.js
new file mode 100644
index 000000000..7ca175487
--- /dev/null
+++ b/lib/utils/module-name.js
@@ -0,0 +1,33 @@
+'use strict'
+var path = require('path')
+var validate = require('aproba')
+
+module.exports = moduleName
+module.exports.test = {}
+
+module.exports.test.pathToPackageName = pathToPackageName
+function pathToPackageName (dir) {
+ if (dir == null) return ''
+ if (dir === '') return ''
+ var name = path.relative(path.resolve(dir, '..'), dir)
+ var scoped = path.relative(path.resolve(dir, '../..'), dir)
+ if (scoped[0] === '@') return scoped
+ return name
+}
+
+module.exports.test.isNotEmpty = isNotEmpty
+function isNotEmpty (str) {
+ return str != null && str !== ''
+}
+
+var unknown = 0
+function moduleName (tree) {
+ validate('O', arguments)
+ var pkg = tree.package || tree
+ if (isNotEmpty(pkg.name)) return pkg.name
+ var pkgName = pathToPackageName(tree.path)
+ if (pkgName !== '') return pkgName
+ if (tree._invalidName != null) return tree._invalidName
+ tree._invalidName = '!invalid#' + (++unknown)
+ return tree._invalidName
+}
diff --git a/lib/utils/tar.js b/lib/utils/tar.js
index 5b20160ea..ca027e17e 100644
--- a/lib/utils/tar.js
+++ b/lib/utils/tar.js
@@ -21,6 +21,7 @@ var myGid = process.getgid && process.getgid()
var readPackageTree = require('read-package-tree')
var union = require('lodash.union')
var flattenTree = require('../install/flatten-tree.js')
+var moduleName = require('./module-name.js')
if (process.env.SUDO_UID && myUid === 0) {
if (!isNaN(process.env.SUDO_UID)) myUid = +process.env.SUDO_UID
@@ -133,7 +134,7 @@ BundledPacker.prototype.applyIgnores = function (entry, partial, entryObj) {
return Packer.prototype.applyIgnores.call(this, entry, partial, entryObj)
}
-function nameMatch (name) { return function (other) { return name === other.package.name } }
+function nameMatch (name) { return function (other) { return name === moduleName(other) } }
function pack_ (tarball, folder, tree, flatTree, pkg, cb) {
function InstancePacker (props) {
@@ -161,7 +162,7 @@ function pack_ (tarball, folder, tree, flatTree, pkg, cb) {
seen[req] = true
var reqPkg = flatTree[req]
if (!reqPkg) continue
- if (reqPkg.parent === tree && bd.indexOf(reqPkg.package.name) !== -1) {
+ if (reqPkg.parent === tree && bd.indexOf(moduleName(reqPkg)) !== -1) {
return true
}
requiredBy = union(requiredBy, reqPkg.package._requiredBy)