diff options
author | isaacs <i@izs.me> | 2014-08-01 05:02:32 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2014-08-01 05:02:32 +0400 |
commit | 9b318e21559546cebd6715f9366a6b058ab2d5b3 (patch) | |
tree | d6e69a948e854a1e90e443541d8a27558a74e9c6 /node_modules/read-installed | |
parent | 9d73de7f8a0285bfb9f4fc8f4ca1300c387fdd05 (diff) |
read-installed@3.0.0
Fixes extraneous peer dependent looping devDependencies in --production mode.
CC @davglass
Diffstat (limited to 'node_modules/read-installed')
11 files changed, 328 insertions, 80 deletions
diff --git a/node_modules/read-installed/node_modules/debuglog/LICENSE b/node_modules/read-installed/node_modules/debuglog/LICENSE new file mode 100644 index 000000000..a3187cc10 --- /dev/null +++ b/node_modules/read-installed/node_modules/debuglog/LICENSE @@ -0,0 +1,19 @@ +Copyright Joyent, Inc. and other Node contributors. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. diff --git a/node_modules/read-installed/node_modules/debuglog/README.md b/node_modules/read-installed/node_modules/debuglog/README.md new file mode 100644 index 000000000..dc6fccecc --- /dev/null +++ b/node_modules/read-installed/node_modules/debuglog/README.md @@ -0,0 +1,40 @@ +# debuglog - backport of util.debuglog() from node v0.11 + +To facilitate using the `util.debuglog()` function that will be available when +node v0.12 is released now, this is a copy extracted from the source. + +## require('debuglog') + +Return `util.debuglog`, if it exists, otherwise it will return an internal copy +of the implementation from node v0.11. + +## debuglog(section) + +* `section` {String} The section of the program to be debugged +* Returns: {Function} The logging function + +This is used to create a function which conditionally writes to stderr +based on the existence of a `NODE_DEBUG` environment variable. If the +`section` name appears in that environment variable, then the returned +function will be similar to `console.error()`. If not, then the +returned function is a no-op. + +For example: + +```javascript +var debuglog = util.debuglog('foo'); + +var bar = 123; +debuglog('hello from foo [%d]', bar); +``` + +If this program is run with `NODE_DEBUG=foo` in the environment, then +it will output something like: + + FOO 3245: hello from foo [123] + +where `3245` is the process id. If it is not run with that +environment variable set, then it will not print anything. + +You may separate multiple `NODE_DEBUG` environment variables with a +comma. For example, `NODE_DEBUG=fs,net,tls`. diff --git a/node_modules/read-installed/node_modules/debuglog/debuglog.js b/node_modules/read-installed/node_modules/debuglog/debuglog.js new file mode 100644 index 000000000..748fd72a1 --- /dev/null +++ b/node_modules/read-installed/node_modules/debuglog/debuglog.js @@ -0,0 +1,22 @@ +var util = require('util'); + +module.exports = (util && util.debuglog) || debuglog; + +var debugs = {}; +var debugEnviron = process.env.NODE_DEBUG || ''; + +function debuglog(set) { + set = set.toUpperCase(); + if (!debugs[set]) { + if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) { + var pid = process.pid; + debugs[set] = function() { + var msg = util.format.apply(exports, arguments); + console.error('%s %d: %s', set, pid, msg); + }; + } else { + debugs[set] = function() {}; + } + } + return debugs[set]; +}; diff --git a/node_modules/read-installed/node_modules/debuglog/package.json b/node_modules/read-installed/node_modules/debuglog/package.json new file mode 100644 index 000000000..396662562 --- /dev/null +++ b/node_modules/read-installed/node_modules/debuglog/package.json @@ -0,0 +1,45 @@ +{ + "name": "debuglog", + "version": "1.0.1", + "description": "backport of util.debuglog from node v0.11", + "license": "MIT", + "main": "debuglog.js", + "repository": { + "type": "git", + "url": "https://github.com/sam-github/node-debuglog.git" + }, + "author": { + "name": "Sam Roberts", + "email": "sam@strongloop.com" + }, + "engines": { + "node": "*" + }, + "browser": { + "util": false + }, + "bugs": { + "url": "https://github.com/sam-github/node-debuglog/issues" + }, + "homepage": "https://github.com/sam-github/node-debuglog", + "_id": "debuglog@1.0.1", + "dist": { + "shasum": "aa24ffb9ac3df9a2351837cfb2d279360cd78492", + "tarball": "http://registry.npmjs.org/debuglog/-/debuglog-1.0.1.tgz" + }, + "_from": "debuglog@>=1.0.1-0 <2.0.0-0", + "_npmVersion": "1.4.3", + "_npmUser": { + "name": "octet", + "email": "sam@strongloop.com" + }, + "maintainers": [ + { + "name": "octet", + "email": "sam@strongloop.com" + } + ], + "directories": {}, + "_shasum": "aa24ffb9ac3df9a2351837cfb2d279360cd78492", + "_resolved": "https://registry.npmjs.org/debuglog/-/debuglog-1.0.1.tgz" +} diff --git a/node_modules/read-installed/node_modules/util-extend/package.json b/node_modules/read-installed/node_modules/util-extend/package.json index cbcbed27f..0bab48d32 100644 --- a/node_modules/read-installed/node_modules/util-extend/package.json +++ b/node_modules/read-installed/node_modules/util-extend/package.json @@ -36,6 +36,5 @@ ], "directories": {}, "_shasum": "bb703b79480293ddcdcfb3c6a9fea20f483415bc", - "_resolved": "https://registry.npmjs.org/util-extend/-/util-extend-1.0.1.tgz", - "homepage": "https://github.com/isaacs/util-extend" + "_resolved": "https://registry.npmjs.org/util-extend/-/util-extend-1.0.1.tgz" } diff --git a/node_modules/read-installed/package.json b/node_modules/read-installed/package.json index dc869c6f6..4a311dd09 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.7", + "version": "3.0.0", "repository": { "type": "git", "url": "git://github.com/isaacs/read-installed" @@ -11,6 +11,7 @@ "test": "tap ./test/*.js" }, "dependencies": { + "debuglog": "^1.0.1", "read-package-json": "1", "semver": "2 || 3", "slide": "~1.1.3", @@ -27,16 +28,37 @@ }, "license": "ISC", "devDependencies": { + "mkdirp": "^0.5.0", + "rimraf": "^2.2.8", "tap": "~0.4.8" }, - "readme": "# read-installed\n\nRead all the installed packages in a folder, and return a tree\nstructure with all the data.\n\nnpm uses this.\n\n## 2.0.0\n\nBreaking changes in `2.0.0`:\n\nThe second argument is now an `Object` that contains the following keys:\n\n * `depth` optional, defaults to Infinity\n * `log` optional log Function\n * `dev` optional, default false, set to true to include devDependencies\n\n## Usage\n\n```javascript\nvar readInstalled = require(\"read-installed\")\n// optional options\nvar options = { dev: false, log: fn, depth: 2 }\nreadInstalled(folder, options, function (er, data) {\n ...\n})\n```\n", - "readmeFilename": "README.md", - "gitHead": "4b38f9ed81e9c533764241c2ee45fe96ef31e2f8", + "gitHead": "7d7aab10f63017271e48c44d382c01e73a04ba59", "bugs": { "url": "https://github.com/isaacs/read-installed/issues" }, "homepage": "https://github.com/isaacs/read-installed", - "_id": "read-installed@2.0.7", - "_shasum": "a82157a5e273576c57f230ecec3702ab215a6d6c", - "_from": "read-installed@latest" + "_id": "read-installed@3.0.0", + "_shasum": "a11326732b98e0aa7013ce25c0afcf18cd57b081", + "_from": "read-installed@latest", + "_npmVersion": "1.4.22", + "_npmUser": { + "name": "isaacs", + "email": "i@izs.me" + }, + "maintainers": [ + { + "name": "isaacs", + "email": "i@izs.me" + }, + { + "name": "othiym23", + "email": "ogd@aoaioxxysz.net" + } + ], + "dist": { + "shasum": "a11326732b98e0aa7013ce25c0afcf18cd57b081", + "tarball": "http://registry.npmjs.org/read-installed/-/read-installed-3.0.0.tgz" + }, + "directories": {}, + "_resolved": "https://registry.npmjs.org/read-installed/-/read-installed-3.0.0.tgz" } diff --git a/node_modules/read-installed/read-installed.js b/node_modules/read-installed/read-installed.js index 3574e6c2f..713d2633c 100644 --- a/node_modules/read-installed/read-installed.js +++ b/node_modules/read-installed/read-installed.js @@ -101,6 +101,8 @@ var url = require("url") var util = require("util") var extend = require("util-extend") +var debug = require("debuglog")("read-installed") + module.exports = readInstalled function readInstalled (folder, opts, cb) { @@ -120,23 +122,26 @@ function readInstalled (folder, opts, cb) { opts.log = function () {} opts.dev = !!opts.dev + opts.realpathSeen = {} + opts.findUnmetSeen = [] + readInstalled_(folder, null, null, null, 0, opts, function (er, obj) { if (er) return cb(er) // 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) + unmarkExtraneous(obj, opts) cb(null, obj) }) } -var rpSeen = {} function readInstalled_ (folder, parent, name, reqver, depth, opts, cb) { var installed , obj , real , link + , realpathSeen = opts.realpathSeen fs.readdir(path.resolve(folder, "node_modules"), function (er, i) { // error indicates that nothing is installed here @@ -161,7 +166,7 @@ function readInstalled_ (folder, parent, name, reqver, depth, opts, cb) { return next(er) } fs.realpath(folder, function (er, rp) { - //console.error("realpath(%j) = %j", folder, rp) + debug("realpath(%j) = %j", folder, rp) real = rp if (st.isSymbolicLink()) link = rp next(er) @@ -176,10 +181,10 @@ function readInstalled_ (folder, parent, name, reqver, depth, opts, cb) { errState = er return cb(null, []) } - //console.error('next', installed, obj && typeof obj, name, real) + debug('next', installed, obj && typeof obj, name, real) if (!installed || !obj || !real || called) return called = true - if (rpSeen[real]) return cb(null, rpSeen[real]) + if (realpathSeen[real]) return cb(null, realpathSeen[real]) if (obj === true) { obj = {dependencies:{}, path:folder} installed.forEach(function (i) { obj.dependencies[i] = "*" }) @@ -188,6 +193,9 @@ function readInstalled_ (folder, parent, name, reqver, depth, opts, cb) { obj.realName = name || obj.name obj.dependencies = obj.dependencies || {} + // At this point, figure out what dependencies we NEED to get met + obj._dependencies = copy(obj.dependencies) + // "foo":"http://blah" and "foo":"latest" are always presumed valid if (reqver && semver.validRange(reqver, true) @@ -195,21 +203,17 @@ function readInstalled_ (folder, parent, name, reqver, depth, opts, cb) { obj.invalid = true } - if (parent) { - var deps = parent.dependencies || {} - var inDeps = name in deps - var devDeps = parent.devDependencies || {} - var inDev = opts.dev && (name in devDeps) - if (!inDeps && !inDev) { - obj.extraneous = true - } - } + // Mark as extraneous at this point. + // This will be un-marked in unmarkExtraneous, where we mark as + // not-extraneous everything that is required in some way from + // the root object. + obj.extraneous = true obj.path = obj.path || folder obj.realPath = real obj.link = link if (parent && !obj.link) obj.parent = parent - rpSeen[real] = obj + realpathSeen[real] = obj obj.depth = depth //if (depth >= opts.depth) return cb(null, obj) asyncMap(installed, function (pkg, cb) { @@ -259,50 +263,45 @@ function resolveInheritance (obj, opts) { findUnmet(obj.dependencies[dep], opts) }) Object.keys(obj.dependencies).forEach(function (dep) { - resolveInheritance(obj.dependencies[dep], opts) + if (typeof obj.dependencies[dep] === "object") { + resolveInheritance(obj.dependencies[dep], opts) + } else { + debug("unmet dep! %s %s@%s", obj.name, dep, obj.dependencies[dep]) + } }) findUnmet(obj, opts) } // find unmet deps by walking up the tree object. // No I/O -var fuSeen = [] function findUnmet (obj, opts) { - if (fuSeen.indexOf(obj) !== -1) return - fuSeen.push(obj) - //console.error("find unmet", obj.name, obj.parent && obj.parent.name) + var findUnmetSeen = opts.findUnmetSeen + if (findUnmetSeen.indexOf(obj) !== -1) return + findUnmetSeen.push(obj) + debug("find unmet parent=%s obj=", obj.parent && obj.parent.name, obj.name || obj) var deps = obj.dependencies = obj.dependencies || {} - //console.error(deps) + debug(deps) Object.keys(deps) .filter(function (d) { return typeof deps[d] === "string" }) .forEach(function (d) { - //console.error("find unmet", obj.name, d, deps[d]) - var r = obj.parent - , found = null - while (r && !found && typeof deps[d] === "string") { - // if r is a valid choice, then use that. - found = r.dependencies[d] - if (!found && r.realName === d) found = r - - if (!found) { - r = r.link ? null : r.parent - continue - } - // "foo":"http://blah" and "foo":"latest" are always presumed valid - if ( typeof deps[d] === "string" - && semver.validRange(deps[d], true) - && !semver.satisfies(found.version, deps[d], true)) { - // the bad thing will happen - opts.log("unmet dependency", obj.path + " requires "+d+"@'"+deps[d] - +"' but will load\n" - +found.path+",\nwhich is version "+found.version - ) - found.invalid = true - } + var found = findDep(obj, d) + debug("finding dep %j", d, found && found.name || found) + // "foo":"http://blah" and "foo":"latest" are always presumed valid + if (typeof deps[d] === "string" && + semver.validRange(deps[d], true) && + found && + !semver.satisfies(found.version, deps[d], true)) { + // the bad thing will happen + opts.log( "unmet dependency" + , obj.path + " requires "+d+"@'"+deps[d] + + "' but will load\n" + + found.path+",\nwhich is version "+found.version ) + found.invalid = true + } + if (found) { deps[d] = found } - }) var peerDeps = obj.peerDependencies = obj.peerDependencies || {} @@ -329,34 +328,56 @@ function findUnmet (obj, opts) { obj.dependencies[d] = peerDeps[d] } else if (!semver.satisfies(dependency.version, peerDeps[d], true)) { dependency.peerInvalid = true - } else { - dependency.extraneous = dependency.extraneous || false } }) return obj } -function recursivelyMarkExtraneous (obj, extraneous) { - // stop recursion if we're not changing anything - if (obj.extraneous === extraneous) return +function unmarkExtraneous (obj, opts) { + // Mark all non-required deps as extraneous. + // 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 + + obj.extraneous = false + var deps = obj._dependencies + if (opts.dev && obj.devDependencies) { + Object.keys(obj.devDependencies).forEach(function (k) { + deps[k] = obj.devDependencies[k] + }) + } - obj.extraneous = extraneous - var deps = obj.dependencies = obj.dependencies || {} - Object.keys(deps).forEach(function(d){ - recursivelyMarkExtraneous(deps[d], extraneous) - }); + if (obj.peerDependencies) { + Object.keys(obj.peerDependencies).forEach(function (k) { + deps[k] = obj.peerDependencies[k] + }) + } + + Object.keys(deps).forEach(function (d) { + var dep = findDep(obj, d) + if (dep && dep.extraneous) { + unmarkExtraneous(dep, opts) + } + }) } -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); +// Find the one that will actually be loaded by require() +// so we can make sure it's valid etc. +function findDep (obj, d) { + var r = obj + , found = null + while (r && !found) { + // if r is a valid choice, then use that. + // kinda weird if a pkg depends on itself, but after the first + // iteration of this loop, it indicates a dep cycle. + if (typeof r.dependencies[d] === "object") { + found = r.dependencies[d] } - }); + if (!found && r.realName === d) found = r + r = r.link ? null : r.parent + } + return found } function copy (obj) { diff --git a/node_modules/read-installed/test/basic.js b/node_modules/read-installed/test/basic.js index 4d83cd0ca..f49784887 100644 --- a/node_modules/read-installed/test/basic.js +++ b/node_modules/read-installed/test/basic.js @@ -1,8 +1,9 @@ var readInstalled = require("../read-installed.js") -var json = require("./fixtures/package.json") -var known = [].concat(Object.keys(json.dependencies) - , Object.keys(json.optionalDependencies) - , Object.keys(json.devDependencies)).sort() +var json = require("../package.json") +var d = Object.keys(json.dependencies) +var dd = Object.keys(json.devDependencies) +var od = Object.keys(json.optionalDependencies) +var known = d.concat(dd).concat(od).sort() var test = require("tap").test var path = require("path") @@ -36,9 +37,7 @@ function cleanup (map) { default: delete map[i] } var dep = map.dependencies -// delete map.dependencies if (dep) { -// map.dependencies = dep for (var i in dep) if (typeof dep[i] === "object") { cleanup(dep[i]) } diff --git a/node_modules/read-installed/test/cyclic-extraneous-peer-deps.js b/node_modules/read-installed/test/cyclic-extraneous-peer-deps.js new file mode 100644 index 000000000..58bf6a649 --- /dev/null +++ b/node_modules/read-installed/test/cyclic-extraneous-peer-deps.js @@ -0,0 +1,81 @@ +var test = require("tap").test +var mkdirp = require("mkdirp") +var rimraf = require("rimraf") +var fs = require("fs") +var path = require("path") +var readInstalled = require("../read-installed.js") + +var parent = { + name: "parent", + version: "1.2.3", + dependencies: {}, + devDependencies: { + "child1":"*" + }, + readme:"." +} + +var child1 = { + name: "child1", + version: "1.2.3", + peerDependencies: { + child2: "*" + }, + readme:"." +} + +var child2 = { + name: "child2", + version: "1.2.3", + peerDependencies: { + child1: "*" + }, + readme:"." +} + + +var root = path.resolve(__dirname, "cyclic-extraneous-peer-deps") +var parentjson = path.resolve(root, "package.json") +var child1root = path.resolve(root, "node_modules/child1") +var child1json = path.resolve(child1root, "package.json") +var child2root = path.resolve(root, "node_modules/child2") +var child2json = path.resolve(child2root, "package.json") + +test("setup", function (t) { + rimraf.sync(root) + mkdirp.sync(child1root) + mkdirp.sync(child2root) + fs.writeFileSync(parentjson, JSON.stringify(parent, null, 2) + "\n", "utf8") + fs.writeFileSync(child1json, JSON.stringify(child1, null, 2) + "\n", "utf8") + fs.writeFileSync(child2json, JSON.stringify(child2, null, 2) + "\n", "utf8") + t.pass("setup done") + t.end() +}) + +test("dev mode", function (t) { + // peer dev deps should both be not extraneous. + readInstalled(root, { dev: true }, function (er, data) { + if (er) + throw er + t.notOk(data.dependencies.child1.extraneous, "c1 not extra") + t.notOk(data.dependencies.child2.extraneous, "c2 not extra") + t.end() + }) +}) + +test("prod mode", function (t) { + readInstalled(root, { dev: false }, function (er, data) { + if (er) + throw er + t.ok(data.dependencies.child1.extraneous, "c1 extra") + t.ok(data.dependencies.child2.extraneous, "c2 extra") + t.end() + }) +}) + + +test("cleanup", function (t) { + rimraf.sync(root) + t.pass("cleanup done") + t.end() +}) diff --git a/node_modules/read-installed/test/dev.js b/node_modules/read-installed/test/dev.js index f6f4857bb..48efe80b3 100644 --- a/node_modules/read-installed/test/dev.js +++ b/node_modules/read-installed/test/dev.js @@ -1,6 +1,6 @@ var readInstalled = require("../read-installed.js") var test = require("tap").test -var json = require("./fixtures/package.json") +var json = require("../package.json") var path = require("path") var known = [].concat(Object.keys(json.dependencies) , Object.keys(json.optionalDependencies) diff --git a/node_modules/read-installed/test/noargs.js b/node_modules/read-installed/test/noargs.js index a84a8f4cf..66fabeb74 100644 --- a/node_modules/read-installed/test/noargs.js +++ b/node_modules/read-installed/test/noargs.js @@ -1,6 +1,6 @@ var readInstalled = require("../read-installed.js") var test = require("tap").test -var json = require("./fixtures/package.json") +var json = require("../package.json") var path = require("path") var known = [].concat(Object.keys(json.dependencies) , Object.keys(json.optionalDependencies) |