diff options
author | isaacs <i@izs.me> | 2014-03-19 20:10:16 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2014-03-19 20:10:16 +0400 |
commit | f6712869ee0f3f2cfa705aa626ae374213ef0fef (patch) | |
tree | 8ee31f8cc12dc6ae53885db06899c8071175a686 | |
parent | d4c5d27bc17f8ef9e84d4d73de820c83cd50e0c6 (diff) |
read-installed@2.0.1
-rw-r--r-- | node_modules/read-installed/package.json | 4 | ||||
-rw-r--r-- | node_modules/read-installed/read-installed.js | 27 | ||||
-rw-r--r-- | node_modules/read-installed/test/extraneous.js | 17 | ||||
-rw-r--r-- | node_modules/read-installed/test/fixtures/extraneous-detected/package.json | 7 | ||||
-rw-r--r-- | package.json | 2 |
5 files changed, 50 insertions, 7 deletions
diff --git a/node_modules/read-installed/package.json b/node_modules/read-installed/package.json index ed86f4361..7887f71a9 100644 --- a/node_modules/read-installed/package.json +++ b/node_modules/read-installed/package.json @@ -1,7 +1,7 @@ { "name": "read-installed", "description": "Read all the installed packages in a folder, and return a tree structure with all the data.", - "version": "2.0.0", + "version": "2.0.1", "repository": { "type": "git", "url": "git://github.com/isaacs/read-installed" @@ -35,6 +35,6 @@ "url": "https://github.com/isaacs/read-installed/issues" }, "homepage": "https://github.com/isaacs/read-installed", - "_id": "read-installed@2.0.0", + "_id": "read-installed@2.0.1", "_from": "read-installed@latest" } diff --git a/node_modules/read-installed/read-installed.js b/node_modules/read-installed/read-installed.js index 7b3749d60..f9104934d 100644 --- a/node_modules/read-installed/read-installed.js +++ b/node_modules/read-installed/read-installed.js @@ -126,6 +126,7 @@ function readInstalled (folder, opts, cb) { // now obj has all the installed things, where they're installed // figure out the inheritance links, now that the object is built. resolveInheritance(obj, opts) + markExtraneous(obj) cb(null, obj) }) } @@ -312,8 +313,6 @@ function findUnmet (obj, opts) { +found.path+",\nwhich is version "+found.version ) found.invalid = true - } else { - found.extraneous = false } deps[d] = found } @@ -337,8 +336,6 @@ function findUnmet (obj, opts) { if (!dependency) return - dependency.extraneous = false - if (!semver.satisfies(dependency.version, peerDeps[d], true)) { dependency.peerInvalid = true } @@ -347,6 +344,28 @@ function findUnmet (obj, opts) { return obj } +function recursivelyMarkExtraneous (obj, extraneous) { + // stop recursion if we're not changing anything + if (obj.extraneous === extraneous) return + + obj.extraneous = extraneous + var deps = obj.dependencies = obj.dependencies || {} + Object.keys(deps).forEach(function(d){ + recursivelyMarkExtraneous(deps[d], extraneous) + }); +} + +function markExtraneous (obj) { + // start from the root object and mark as non-extraneous all modules that haven't been previously flagged as + // extraneous then propagate to all their dependencies + var deps = obj.dependencies = obj.dependencies || {} + Object.keys(deps).forEach(function(d){ + if (!deps[d].extraneous){ + recursivelyMarkExtraneous(deps[d], false); + } + }); +} + function copy (obj) { if (!obj || typeof obj !== 'object') return obj if (Array.isArray(obj)) return obj.map(copy) diff --git a/node_modules/read-installed/test/extraneous.js b/node_modules/read-installed/test/extraneous.js new file mode 100644 index 000000000..2cc0d04e7 --- /dev/null +++ b/node_modules/read-installed/test/extraneous.js @@ -0,0 +1,17 @@ +var readInstalled = require('../read-installed.js') +var test = require('tap').test +var path = require('path'); + +test('extraneous detected', function(t) { + // This test verifies read-installed#16 + readInstalled( + path.join(__dirname, 'fixtures/extraneous-detected'), + { log: console.error }, + function(err, map) { + t.ok(map.dependencies.foo.extraneous, 'foo is extraneous, it\'s not required by any module') + t.ok(map.dependencies.bar.extraneous, 'bar is extraneous, it\'s not required by any module') + t.notOk(map.dependencies.asdf.extraneous, 'asdf is not extraneous, it\'s required by ghjk') + t.notOk(map.dependencies.ghjk.extraneous, 'ghjk is not extraneous, it\'s required by our root module') + t.end(); + }) +}) diff --git a/node_modules/read-installed/test/fixtures/extraneous-detected/package.json b/node_modules/read-installed/test/fixtures/extraneous-detected/package.json new file mode 100644 index 000000000..f61531551 --- /dev/null +++ b/node_modules/read-installed/test/fixtures/extraneous-detected/package.json @@ -0,0 +1,7 @@ +{ + "name": "extraneous-detected", + "version": "0.0.0", + "dependencies": { + "ghjk": "0.0.0" + } +} diff --git a/package.json b/package.json index fde558557..32440e9ad 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "osenv": "0", "path-is-inside": "~1.0.0", "read": "~1.0.4", - "read-installed": "^2.0.0", + "read-installed": "~2.0.1", "read-package-json": "~1.1.8", "request": "~2.30.0", "retry": "~0.6.0", |