mirror of
https://github.com/nodejs/node.git
synced 2025-05-13 16:39:33 +00:00

Contains the following npm releases: - v3.9.0: https://github.com/npm/npm/releases/tag/v3.9.0 - v3.9.1: https://github.com/npm/npm/releases/tag/v3.9.1 - v3.9.2: https://github.com/npm/npm/releases/tag/v3.9.2 - v3.9.3: https://github.com/npm/npm/releases/tag/v3.9.3 PR-URL: https://github.com/nodejs/node/pull/7030 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
34 lines
949 B
JavaScript
34 lines
949 B
JavaScript
'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.replace(/\\/g, '/')
|
|
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
|
|
}
|