Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
install: scoped packages with peerDependencies
Browse files Browse the repository at this point in the history
Package scopes cause an additional level in the tree structure which
must be considered when resolving the target folders of a package's
peerDependencies.

Fixes #7454.
  • Loading branch information
ewie authored and othiym23 committed Apr 11, 2015
1 parent 15efe12 commit b027319
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,12 @@ function write (target, targetFolder, context, cb_) {
"in npm 3+. Your application will need to depend on it explicitly."
], pd+","+data.name)
})
var pdTargetFolder = path.resolve(targetFolder, "..", "..")

// Package scopes cause an addditional tree level which needs to be
// considered when resolving a peerDependency's target folder.
var pdTargetFolder = path.resolve(targetFolder,
(target.name[0] === "@" ? "../../.." : "../.."))

var pdContext = context
if (peerDeps.length > 0) {
actions.push(
Expand Down
32 changes: 32 additions & 0 deletions test/tap/install-scoped-with-peer-dependency.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var common = require("../common-tap.js")
var test = require("tap").test
var path = require("path")
var fs = require("fs")
var rimraf = require("rimraf")
var mkdirp = require("mkdirp")
var pkg = path.join(__dirname, "install-scoped-with-peer-dependency")

var EXEC_OPTS = { }

test("setup", function (t) {
mkdirp.sync(pkg)
mkdirp.sync(path.resolve(pkg, "node_modules"))
process.chdir(pkg)
t.end()
})

test("it should install peerDependencies in same tree level as the parent package", function(t) {
common.npm(["install", "./package"], EXEC_OPTS, function(err, code) {
var p = path.resolve(pkg, "node_modules/underscore/package.json")
t.ifError(err, "install local package successful")
t.equal(code, 0, "npm install exited with code")
t.ok(JSON.parse(fs.readFileSync(p, "utf8")))
t.end()
})
})

test("cleanup", function(t) {
process.chdir(__dirname)
rimraf.sync(path.resolve(pkg, "node_modules"))
t.end()
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@scope/package",
"version": "0.0.0",
"peerDependencies": {
"underscore": "*"
}
}

0 comments on commit b027319

Please sign in to comment.