Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/install/inflate-shrinkwrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ function makeFakeChild (name, topPath, tree, sw, requested) {
realpath: requested.type === 'directory' ? requested.fetchSpec : childPath(tree.realpath, pkg),
location: (tree.location === '/' ? '' : tree.location + '/') + pkg.name,
isLink: requested.type === 'directory',
isInLink: tree.isLink,
isInLink: tree.isLink || tree.isInLink,
swRequires: sw.requires
})
tree.children.push(child)
Expand Down
7 changes: 5 additions & 2 deletions lib/shrinkwrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,13 @@ function shrinkwrapDeps (deps, top, tree, seen) {
var childIsOnlyDev = isOnlyDev(child)
var pkginfo = deps[moduleName(child)] = {}
var requested = getRequested(child) || child.package._requested || {}
var linked = child.isLink || child.isInLink
var linkedFromHere = linked && path.relative(top.realpath, child.realpath)[0] !== '.'
pkginfo.version = childVersion(top, child, requested)
if (requested.type === 'git' && child.package._from) {
pkginfo.from = child.package._from
}
if (child.fromBundle || child.isInLink) {
if (child.fromBundle && !linked) {
pkginfo.bundled = true
} else {
if (isRegistry(requested)) {
Expand All @@ -139,7 +141,8 @@ function shrinkwrapDeps (deps, top, tree, seen) {
pkginfo.requires[moduleName(required)] = childRequested(top, required, requested)
})
}
if (child.children.length) {
// iterate into children on non-links and links contained within the top level package
if (child.children.length && (!child.isLink || linkedFromHere)) {
pkginfo.dependencies = {}
shrinkwrapDeps(pkginfo.dependencies, top, child, seen)
}
Expand Down
69 changes: 69 additions & 0 deletions test/tap/install-at-sub-path-locally.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
var fs = require('graceful-fs')
var path = require('path')

var mkdirp = require('mkdirp')
var osenv = require('osenv')
var rimraf = require('rimraf')
var test = require('tap').test

var common = require('../common-tap.js')

var pkg = path.join(__dirname, 'install-at-sub-path-locally')

var EXEC_OPTS = { cwd: pkg, stdio: [0, 1, 2] }

var json = {
name: 'install-at-sub-path-locally-mock',
version: '0.0.0'
}

var target = '../[email protected]'

test('setup', function (t) {
cleanup()
t.end()
})

test('\'npm install ../[email protected]\' should install local pkg from sub path', function (t) {
setup()
common.npm(['install', '--loglevel=silent', target], EXEC_OPTS, function (err, code) {
if (err) throw err
var p = path.resolve(pkg, 'node_modules/install-at-sub-path-locally-mock/package.json')
t.equal(code, 0, 'npm install exited with code')
t.ok(JSON.parse(fs.readFileSync(p, 'utf8')))
t.end()
})
})

test('\'running npm install ../[email protected]\' should not break on sub path re-install', function (t) {
common.npm(['install', '--loglevel=silent', target], EXEC_OPTS, function (err, code) {
if (err) throw err
var p = path.resolve(pkg, 'node_modules/install-at-sub-path-locally-mock/package.json')
t.equal(code, 0, 'npm install exited with code')
t.ok(JSON.parse(fs.readFileSync(p, 'utf8')))
t.end()
})
})

test('cleanup', function (t) {
cleanup()
t.end()
})

function cleanup () {
process.chdir(osenv.tmpdir())
rimraf.sync(pkg)
rimraf.sync(path.resolve(pkg, target))
}

function setup () {
cleanup()
var root = path.resolve(pkg, target)
mkdirp.sync(root)
fs.writeFileSync(
path.join(root, 'package.json'),
JSON.stringify(json, null, 2)
)
mkdirp.sync(path.resolve(pkg, 'node_modules'))
process.chdir(pkg)
}
3 changes: 1 addition & 2 deletions test/tap/shrinkwrap-local-dependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ var shrinkwrap = {
version: 'file:' + unixFormatPath(path.join('mods', 'mod2')),
dependencies: {
mod1: {
version: 'file:' + unixFormatPath(path.join('mods', 'mod1')),
bundled: true
version: 'file:' + unixFormatPath(path.join('mods', 'mod1'))
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions test/tap/spec-local-specifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,7 @@ test('save behavior', function (t) {
var deps = pjson.dependencies || {}
t.is(deps['sb-transitive'], 'file:../sb-transitive', 'package.json')
var sdep = shrinkwrap.dependencies['sb-transitive'] || {}
var tdep = sdep.dependencies.sbta
t.like(tdep, {bundled: true, version: 'file:../sb-transitive/sbta'}, 'npm-shrinkwrap.json transitive dep')
t.like(sdep, {bundled: null, version: 'file:../sb-transitive'}, 'npm-shrinkwrap.json direct dep')
t.like(sdep, {bundled: null, dependencies: null, version: 'file:../sb-transitive'}, 'npm-shrinkwrap.json direct dep')
t.done()
})
})
Expand Down