Skip to content
Browse files

exclude name=path packages from node_modules scan

  • Loading branch information...
1 parent f4891b1 commit d40ed0a4a0ae35d7d956c263e2bd72ca3d37cf24 @rvagg rvagg committed
Showing with 38 additions and 29 deletions.
  1. +35 −25 lib/main-build-util.js
  2. +1 −2 lib/package-util.js
  3. +2 −2 test/unit/main-build-util-test.js
View
60 lib/main-build-util.js
@@ -70,28 +70,33 @@ var uniquePackages = function (packages) {
// files and also the directories inside node_modules
, processPackage = function (parents, tree, processSubtree, pkg, callback) {
var name = packageUtil.cleanName(pkg)
- , jsonData
- , jsonDependencies
- , dirDependencies
, getJSONData = function (callback) {
// get dependency list from package.json
packageUtil.readPackageJSON(parents, name, function (err, json) {
if (err) return callback(err) // wrapped in package-util.js
- jsonData = json
- jsonDependencies = packageUtil.getDependenciesFromJSON(json)
- callback()
+ callback(null, {
+ data : json
+ , dependencies : packageUtil.getDependenciesFromJSON(json)
+ })
})
}
+
, getDirectoryDependencies = function (callback) {
- // dependency lits from the package's node_modules directory
+ // dependency list from the package's node_modules directory
+
+ if (packageUtil.isPath(name)) {
+ // not installed under ./node_modules/, 'name' is a dir, so don't fetch deps from dir/node_modules
+ return callback(null, { dependencies: [] })
+ }
+
packageUtil.getDependenciesFromDirectory(parents, name, function (err, dependencies) {
if (err) return callback(err) // wrapped in package-util.js
- dirDependencies = dependencies
- callback()
+ callback(null, { dependencies: dependencies })
})
}
- , finish = function (err) {
+
+ , finish = function (err, data) {
if (err) {
if (err.code == 'ENOENT') {
tree[name] = 'missing'
@@ -102,7 +107,7 @@ var uniquePackages = function (packages) {
// we have the data, now do something with it
tree[name] = {
- packageJSON : jsonData
+ packageJSON : data.json.data
, dependencies : {} // init as empty
, parents : parents.slice(0) // make a copy of parents array
}
@@ -112,16 +117,24 @@ var uniquePackages = function (packages) {
parents.concat([ pkg ])
, tree[name].dependencies
// concat dependencies in node_modules with those in package.json but don't duplicate
- , dirDependencies.concat(jsonDependencies.filter(function (p) {
- return dirDependencies.indexOf(p) == -1
+ , data.dir.dependencies.concat(data.json.dependencies.filter(function (p) {
+ return data.dir.dependencies.indexOf(p) == -1
}))
, callback
)
}
- if (tree[name]) return callback()// already done this part of the tree
+ //TODO: because this is async we can still easily process the same tree part mutliple times
+ // need to memoize or something
+ if (tree[name]) return callback() // already done this part of the tree
- async.parallel([ getJSONData, getDirectoryDependencies ], finish)
+ async.parallel(
+ {
+ json : getJSONData
+ , dir : getDirectoryDependencies
+ }
+ , finish
+ )
}
// recursive function, called for each node
@@ -227,19 +240,16 @@ var uniquePackages = function (packages) {
// gives a list of packages by proper name from package.json, turns a path into a package name
, localizePackageList = function (packages, tree) {
- var newList = []
- packages.forEach(function (p) {
- if (packageUtil.isPath(p)
+ return packages.map(function (p) {
+ return packageUtil.isPath(p)
&& typeof tree[p] == 'object'
&& tree[p].packageJSON
&& tree[p].packageJSON.name
- && tree[tree[p].packageJSON.name]) {
- newList.push(tree[p].packageJSON.name)
- } else
- newList.push(packageUtil.cleanName(p))
- })
- return newList
- }
+ && tree[tree[p].packageJSON.name]
+ ? tree[p].packageJSON.name
+ : packageUtil.cleanName(p)
+ })
+ }
module.exports = {
packageList : packageList
View
3 lib/package-util.js
@@ -48,8 +48,7 @@ var fs = require('fs')
}
, isPath = function (pkg) {
- pkg = cleanName(pkg)
- return pkg === '.' || /[\/\\]/.test(pkg)
+ return (pkg = cleanName(pkg)) === '.' || /[\/\\]/.test(pkg)
}
// given an array of parent packages and a package name, give us a path to the
View
4 test/unit/main-build-util-test.js
@@ -177,7 +177,7 @@ buster.testCase('Build util', {
.withArgs(parents, p)
.callsArgWith(2, null, jsons[id])
packageUtilMock.expects('getDependenciesFromDirectory')
- .once()
+ [/\//.test(id) ? 'never' : 'once']() // we DON'T want to read node_modules dir for path
.withArgs(parents, p)
.callsArgWith(2, null, directories[id])
setupExpectations(parents.concat([ p ]), setupTree[p])
@@ -188,7 +188,7 @@ buster.testCase('Build util', {
.withArgs(parents, p)
.callsArgWith(2, { code: 'ENOENT' })
packageUtilMock.expects('getDependenciesFromDirectory')
- .once()
+ [/\//.test(id) ? 'never' : 'once']() // we DON'T want to read node_modules dir for path
.withArgs(parents, p)
.callsArgWith(2, { code: 'ENOENT' })
}

0 comments on commit d40ed0a

Please sign in to comment.
Something went wrong with that request. Please try again.