Skip to content

Commit 8676429

Browse files
larsgwMichael Perrotte
authored and
Michael Perrotte
committed
fix(packageRelativePath): fix 'where' for file deps
Fix 'where' for file deps. It makes more sense for the 'where' to be the directory the file is in (and was possibly built in) than it being the file itself, having no use whatsoever. See https://npm.community/t/3364 PR-URL: #142 Credit: @larsgw Close: #142 Reviewed-by: @mikemimik
1 parent d480f2c commit 8676429

File tree

3 files changed

+136
-16
lines changed

3 files changed

+136
-16
lines changed

lib/install/deps.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,15 @@ function removeObsoleteDep (child, log) {
203203
function packageRelativePath (tree) {
204204
if (!tree) return ''
205205
var requested = tree.package._requested || {}
206-
var isLocal = requested.type === 'directory' || requested.type === 'file'
207-
return isLocal ? requested.fetchSpec
208-
: (tree.isLink || tree.isInLink) && !preserveSymlinks() ? tree.realpath
209-
: tree.path
206+
if (requested.type === 'directory') {
207+
return requested.fetchSpec
208+
} else if (requested.type === 'file') {
209+
return path.dirname(requested.fetchSpec)
210+
} else if ((tree.isLink || tree.isInLink) && !preserveSymlinks()) {
211+
return tree.realpath
212+
} else {
213+
return tree.path
214+
}
210215
}
211216

212217
function matchingDep (tree, name) {

test/tap/install-dep-classification.js

+33-12
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,39 @@ const env = common.newEnv().extend({
2323
npm_config_loglevel: 'error'
2424
})
2525

26+
/**
27+
* NOTE: Tarball Fixtures
28+
* They contain package.json files with dependencies like the following:
29+
* a-1.0.0.tgz: package/package.json
30+
* {
31+
* "name":"a",
32+
* "version":"1.0.0",
33+
* "dependencies":{
34+
* "b":"./b-1.0.0.tgz"
35+
* }
36+
* }
37+
* example-1.0.0.tgz: package/package.json
38+
* {
39+
* "name":"example",
40+
* "version":"1.0.0",
41+
* "dependencies":{
42+
* "a":"./a-1.0.0.tgz",
43+
* "b":"./b-1.0.0.tgz"
44+
* }
45+
* }
46+
*/
2647
const fixture = new Tacks(Dir({
2748
cache: Dir(),
2849
global: Dir(),
2950
tmp: Dir(),
3051
testdir: Dir({
3152
'a-1.0.0.tgz': File(Buffer.from(
32-
'1f8b0800000000000003edcfc10e82300c0660ce3ec5d2b38e4eb71d789b' +
33-
'010d41e358187890f0ee56493c71319218937d977feb9aa50daebab886f2' +
34-
'b0a43cc7ce671b4344abb558ab3f2934223b198b4a598bdcc707a38f9c5b' +
35-
'0fb2668c83eb79946fff597611effc131378772528c0c11e6ed4c7b6f37c' +
36-
'53122572a5a640be265fb514a198a0e43729f3f2f06a9043738779defd7a' +
37-
'89244992e4630fd69e456800080000',
53+
'1f8b0800000000000003edcfc10a83300c06e09df71492f35653567bf06d' +
54+
'a2067163b558b7c3c4775f54f0e4654c18837e973f4da0249eca1bd59cfa' +
55+
'25d535b4eeb03344b4c6245bfd8946995d328b5a5b3bd55264464beebdc8' +
56+
'9647e8a99355befd67b92559f34f0ce0e8ce9003c1099edc85a675f2d20a' +
57+
'154aa762cfae6257361c201fa090994a8bf33c577dfd82713cfefa86288a' +
58+
'a2e8736f68a0ff4400080000',
3859
'hex'
3960
)),
4061
'b-1.0.0.tgz': File(Buffer.from(
@@ -55,12 +76,12 @@ const fixture = new Tacks(Dir({
5576
})
5677
}),
5778
'example-1.0.0.tgz': File(Buffer.from(
58-
'1f8b0800000000000003ed8fc10ac2300c8677f62946cedaa5d8f5e0db64' +
59-
'5b1853d795758a38f6ee4607e261370722f4bbfce5cb4f493c9527aa39f3' +
60-
'73aa63e85cb23288688d4997fc136d304df6b945adad45e9c923375a72ed' +
61-
'4596b884817a59e5db7fe65bd277fe0923386a190ec0376afd99610b57ee' +
62-
'43d339715aa14231157b7615bbb2e100871148664a65b47b15d450dfa554' +
63-
'ccb2f890d3b4f9f57d9148241259e60112d8208a00080000',
79+
'1f8b0800000000000003ed8fc10a83300c863def2924e7ada6587bf06daa' +
80+
'06719bb55837c6c4775fa6307670a70963d0ef92f02584fcce94275353e2' +
81+
'962a8ebeb3d1c620a2562a5ef34f64aae328cd344aa935f21e379962875b' +
82+
'3fb2c6c50fa6e757bebdb364895ff54f18c19a962007ba99d69d09f670a5' +
83+
'de379d6527050a645391235b912d1bf2908f607826127398e762a8efbc53' +
84+
'ccae7873d3b4fb75ba402010087ce2014747c9d500080000',
6485
'hex'
6586
)),
6687
optional: Dir({

test/tap/install-local-from-local.js

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
'use strict'
2+
var path = require('path')
3+
var fs = require('graceful-fs')
4+
var test = require('tap').test
5+
var common = require('../common-tap.js')
6+
var Tacks = require('tacks')
7+
var Dir = Tacks.Dir
8+
var File = Tacks.File
9+
10+
var testdir = path.join(__dirname, path.basename(__filename, '.js'))
11+
var cwd = path.join(testdir, '3')
12+
13+
/**
14+
* NOTE: Tarball Fixtures
15+
* They contain package.json files with dependencies like the following:
16+
* 1-1.0.0.tgz: package/package.json
17+
* {
18+
* "name":"1",
19+
* "version":"1.0.0"
20+
* }
21+
* 2-1.0.0.tgz: package/package.json
22+
* {
23+
* "name":"2",
24+
* "version":"1.0.0",
25+
* "dependencies":{
26+
* "1":"file:../1/1-1.0.0.tgz"
27+
* }
28+
* }
29+
*/
30+
var fixture = new Tacks(Dir({
31+
'1': Dir({
32+
'1-1.0.0.tgz': File(Buffer.from(
33+
'1f8b08000000000000032b484cce4e4c4fd52f80d07a59c5f9790c540606' +
34+
'06066626260ad8c4c1c0d85c81c1d8d4ccc0d0d0cccc00a80ec830353103' +
35+
'd2d4760836505a5c925804740aa5e640bca200a78708a856ca4bcc4d55b2' +
36+
'523254d2512a4b2d2acecccf03f1f40cf40c946ab906da79a360148c8251' +
37+
'300a6804007849dfdf00080000',
38+
'hex'
39+
))
40+
}),
41+
'2': Dir({
42+
'2-1.0.0.tgz': File(Buffer.from(
43+
'1f8b0800000000000003ed8f3d0e83300c8599394594b90d36840cdc2602' +
44+
'17d19f80087468c5ddeb14a9135b91aa4af996e73c3f47f660eb8b6d291b' +
45+
'565567dfbb646700c0682db6fc00ea5c24456900d118e01c17a52e58f75e' +
46+
'648bd94f76e455befd67bd457cf44f78a64248676f242b21737908cf3b8d' +
47+
'beeb5d70508182d56d6820d790ab3bf2dc0a83ec62489dba2b554a6598e1' +
48+
'f13da1a6f62139b0a44bfaeb0b23914824b2c50b8b5b623100080000',
49+
'hex'
50+
))
51+
}),
52+
'3': Dir({
53+
'package.json': File({
54+
name: '3',
55+
version: '1.0.0',
56+
dependencies: {
57+
'2': '../2/2-1.0.0.tgz'
58+
}
59+
})
60+
})
61+
}))
62+
63+
function setup () {
64+
fixture.create(testdir)
65+
}
66+
67+
function cleanup () {
68+
fixture.remove(testdir)
69+
}
70+
71+
test('setup', function (t) {
72+
cleanup()
73+
setup()
74+
t.end()
75+
})
76+
77+
test('installing local package with local dependency', function (t) {
78+
common.npm(
79+
['install'],
80+
{cwd: cwd},
81+
function (er, code, stdout, stderr) {
82+
t.is(code, 0, 'no error code')
83+
t.is(stderr, '', 'no error output')
84+
t.ok(fs.existsSync(path.join(cwd, 'node_modules', '2')), 'installed direct dep')
85+
t.ok(fs.existsSync(path.join(cwd, 'node_modules', '1')), 'installed indirect dep')
86+
t.end()
87+
}
88+
)
89+
})
90+
91+
test('cleanup', function (t) {
92+
cleanup()
93+
t.end()
94+
})

0 commit comments

Comments
 (0)