Skip to content

Loading…

Add peerDependencies. #3003

Closed
wants to merge 2 commits into from

4 participants

@domenic
npm member

See #1400.

@dignifiedquire dignifiedquire referenced this pull request in karma-runner/karma
Closed

Reorganize Testacular #158

@isaacs
npm member

Landed on master. Will go out with node 0.8.17, very shortly.

@isaacs isaacs closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 16, 2012
  1. @domenic

    Install peerDependencies.

    domenic committed
  2. @domenic

    Add peerInvalid to npm ls.

    domenic committed
View
84 lib/install.js
@@ -896,39 +896,65 @@ function write (target, targetFolder, context, cb_) {
// before continuing to installing dependencies, check for a shrinkwrap.
var opt = { dev: npm.config.get("dev") }
readDependencies(context, targetFolder, opt, function (er, data, wrap) {
- var deps = Object.keys(data.dependencies || {})
-
- // don't install bundleDependencies, unless they're missing.
- if (data.bundleDependencies) {
- deps = deps.filter(function (d) {
- return data.bundleDependencies.indexOf(d) === -1 ||
- bundled.indexOf(d) === -1
- })
- }
-
- var newcontext = { family: family
+ var deps = prepareForInstallMany(data, "dependencies", bundled, wrap,
+ family)
+ var depsTargetFolder = targetFolder
+ var depsContext = { family: family
, ancestors: context.ancestors
, parent: target
, explicit: false
, wrap: wrap }
- installMany(deps.filter(function (d) {
- // prefer to not install things that are satisfied by
- // something in the "family" list, unless we're installing
- // from a shrinkwrap.
- return wrap || !semver.satisfies(family[d], data.dependencies[d])
- }).map(function (d) {
- var t = data.dependencies[d]
- , parsed = url.parse(t.replace(/^git\+/, "git"))
- t = d + "@" + t
- return t
- }), targetFolder, newcontext, function (er, d) {
- log.verbose("about to build", targetFolder)
- if (er) return cb(er)
- npm.commands.build( [targetFolder]
- , npm.config.get("global")
- , true
- , function (er) { return cb(er, d) })
- })
+
+ var peerDeps = prepareForInstallMany(data, "peerDependencies", bundled,
+ wrap, family)
+ var pdTargetFolder = path.resolve(targetFolder, "..", "..")
+ var pdContext = context
+
+ var actions =
+ [ [ installManyAndBuild, deps, depsTargetFolder, depsContext ] ]
+
+ if (peerDeps.length > 0) {
+ actions.push(
+ [ installManyAndBuild, peerDeps, pdTargetFolder, pdContext ]
+ )
+ }
+
+ chain(actions, cb)
})
})
}
+
+function installManyAndBuild (deps, targetFolder, context, cb) {
+ installMany(deps, targetFolder, context, function (er, d) {
+ log.verbose("about to build", targetFolder)
+ if (er) return cb(er)
+ npm.commands.build( [targetFolder]
+ , npm.config.get("global")
+ , true
+ , function (er) { return cb(er, d) })
+ })
+}
+
+function prepareForInstallMany (packageData, depsKey, bundled, wrap, family) {
+ var deps = Object.keys(packageData[depsKey] || {})
+
+ // don't install bundleDependencies, unless they're missing.
+ if (packageData.bundleDependencies) {
+ deps = deps.filter(function (d) {
+ return packageData.bundleDependencies.indexOf(d) === -1 ||
+ bundled.indexOf(d) === -1
+ })
+ }
+
+ return deps.filter(function (d) {
+ // prefer to not install things that are satisfied by
+ // something in the "family" list, unless we're installing
+ // from a shrinkwrap.
+ return wrap || !semver.satisfies(family[d], packageData[depsKey][d])
+ }).map(function (d) {
+ var t = packageData[depsKey][d]
+ , parsed = url.parse(t.replace(/^git\+/, "git"))
+ t = d + "@" + t
+ return t
+ })
+}
View
17 lib/ls.js
@@ -68,7 +68,7 @@ function ls (args, silent, cb) {
})
}
-// only include
+// only include
function filter (data, args) {
}
@@ -112,6 +112,14 @@ function getLite (data, noname) {
+ " " + (data.path || "") )
}
+ if (data.peerInvalid) {
+ lite.peerInvalid = true
+ lite.problems = lite.problems || []
+ lite.problems.push( "peer invalid: "
+ + data.name + "@" + data.version
+ + " " + (data.path || "") )
+ }
+
if (data.dependencies) {
var deps = Object.keys(data.dependencies)
if (deps.length) lite.dependencies = deps.map(function (d) {
@@ -244,6 +252,12 @@ function makeArchy_ (data, long, dir, depth, parent, d) {
+ (color ? "\033[0m" : "")
}
+ if (data.peerInvalid) {
+ out.label += " " + (color ? "\033[31;40m" : "")
+ + "peer invalid"
+ + (color ? "\033[0m" : "")
+ }
+
if (data.extraneous && data.path !== dir) {
out.label += " " + (color ? "\033[32;40m" : "")
+ "extraneous"
@@ -331,4 +345,5 @@ function makeParseable_ (data, long, dir, depth, parent, d) {
+ ":" + (data.realPath !== data.path ? data.realPath : "")
+ (data.extraneous ? ":EXTRANEOUS" : "")
+ (data.invalid ? ":INVALID" : "")
+ + (data.peerInvalid ? ":PEERINVALID" : "")
}
View
1 test/packages/npm-test-peer-deps-invalid/README
@@ -0,0 +1 @@
+just an npm test
View
23 test/packages/npm-test-peer-deps-invalid/npm-ls.json
@@ -0,0 +1,23 @@
+{
+ "name": "npm-test-peer-deps-invalid",
+ "version": "0.0.0",
+ "dependencies": {
+ "npm-test-peer-deps-file": {
+ "version": "1.2.3",
+ "from": "https://raw.github.com/gist/3971128/3f6aa37b4fa1186c2f47da9b77dcc4ec496e3483/index.js",
+ "dependencies": {
+ "opener": {
+ "version": "1.3.0"
+ }
+ }
+ },
+ "npm-test-peer-deps-file-invalid": {
+ "version": "1.2.3",
+ "from": "https://gist.github.com/raw/4303335/861f8d3213061826ab31591840c3cb0ac737f4fc/index.js"
+ },
+ "dict": {
+ "version": "1.0.0",
+ "peerInvalid": true
+ }
+ }
+}
View
12 test/packages/npm-test-peer-deps-invalid/package.json
@@ -0,0 +1,12 @@
+{
+ "author": "Domenic Denicola <domenic@domenicdenicola.com> (http://domenicdenicola.com/)",
+ "name": "npm-test-peer-deps-invalid",
+ "version": "0.0.0",
+ "dependencies": {
+ "npm-test-peer-deps-file": "https://raw.github.com/gist/3971128/3f6aa37b4fa1186c2f47da9b77dcc4ec496e3483/index.js",
+ "npm-test-peer-deps-file-invalid": "https://gist.github.com/raw/4303335/861f8d3213061826ab31591840c3cb0ac737f4fc/index.js"
+ },
+ "scripts": {
+ "test": "node test.js"
+ }
+}
View
26 test/packages/npm-test-peer-deps-invalid/test.js
@@ -0,0 +1,26 @@
+var path = require("path")
+var assert = require("assert")
+
+process.env.npm_config_prefix = process.cwd()
+delete process.env.npm_config_global
+delete process.env.npm_config_depth
+
+var npm = path.resolve(process.env.npm_config_prefix, "../../npm")
+
+require("child_process").exec(npm + " ls --json", {
+ env: process.env, cwd: process.cwd() },
+ function (err, stdout, stderr) {
+
+ var actual = JSON.parse(stdout).dependencies
+ var expected = require("./npm-ls.json").dependencies
+
+ // Delete the "problems" entry because it contains system-specific path info,
+ // so we can't compare it accurately and thus have deleted it from
+ // ./npm-ls.json.
+ delete actual.dict.problems
+
+ assert.deepEqual(actual, expected)
+
+ assert.ok(err)
+ assert(/peer invalid/.test(err.message))
+})
View
1 test/packages/npm-test-peer-deps/README
@@ -0,0 +1 @@
+just an npm test
View
18 test/packages/npm-test-peer-deps/npm-ls.json
@@ -0,0 +1,18 @@
+{
+ "name": "npm-test-peer-deps",
+ "version": "0.0.0",
+ "dependencies": {
+ "npm-test-peer-deps-file": {
+ "version": "1.2.3",
+ "from": "https://raw.github.com/gist/3971128/3f6aa37b4fa1186c2f47da9b77dcc4ec496e3483/index.js",
+ "dependencies": {
+ "opener": {
+ "version": "1.3.0"
+ }
+ }
+ },
+ "dict": {
+ "version": "1.1.0"
+ }
+ }
+}
View
11 test/packages/npm-test-peer-deps/package.json
@@ -0,0 +1,11 @@
+{
+ "author": "Domenic Denicola <domenic@domenicdenicola.com> (http://domenicdenicola.com/)",
+ "name": "npm-test-peer-deps",
+ "version": "0.0.0",
+ "dependencies": {
+ "npm-test-peer-deps-file": "https://raw.github.com/gist/3971128/3f6aa37b4fa1186c2f47da9b77dcc4ec496e3483/index.js"
+ },
+ "scripts": {
+ "test": "node test.js"
+ }
+}
View
20 test/packages/npm-test-peer-deps/test.js
@@ -0,0 +1,20 @@
+var path = require("path")
+var assert = require("assert")
+
+process.env.npm_config_prefix = process.cwd()
+delete process.env.npm_config_global
+delete process.env.npm_config_depth
+
+var npm = path.resolve(process.env.npm_config_prefix, "../../npm")
+
+require("child_process").exec(npm + " ls --json", {
+ env: process.env, cwd: process.cwd() },
+ function (err, stdout, stderr) {
+
+ if (err) throw err
+
+ var actual = JSON.parse(stdout).dependencies
+ var expected = require("./npm-ls.json").dependencies
+
+ assert.deepEqual(actual, expected)
+})
Something went wrong with that request. Please try again.