Skip to content
This repository was archived by the owner on Jan 20, 2022. It is now read-only.

Commit e8bcfc7

Browse files
ruyadornoisaacs
andcommitted
fix: path resolution for global linking filepaths
related to: npm/cli#1786 Co-authored-by: isaacs <[email protected]>
1 parent 5492920 commit e8bcfc7

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/add-rm-pkg-deps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const addSingle = ({pkg, spec, saveBundle, saveType, path}) => {
5555
pkg[type] = pkg[type] || {}
5656
if (rawSpec !== '' || pkg[type][name] === undefined) {
5757
// if we're in global mode, file specs are based on cwd, not arb path
58-
pkg[type][name] = specType === 'file' ? `file:${relpath(path, fetchSpec)}`
58+
pkg[type][name] = specType === 'file' || specType === 'directory' ? `file:${relpath(path, fetchSpec)}`
5959
: (rawSpec || '*')
6060
}
6161

test/arborist/build-ideal-tree.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,28 @@ t.test('resolve files from cwd in global mode, Arb path in local mode', t => {
13481348
})
13491349
})
13501350

1351+
t.only('resolve links in global mode', t => {
1352+
const cwd = process.cwd()
1353+
t.teardown(() => process.chdir(cwd))
1354+
const path = t.testdir({
1355+
global: {}
1356+
})
1357+
const fixturedir = resolve(fixtures, 'root-bundler')
1358+
process.chdir(fixturedir)
1359+
const arb = new Arborist({
1360+
global: true,
1361+
path: resolve(path, 'global'),
1362+
...OPT,
1363+
})
1364+
return arb.buildIdealTree({
1365+
add: ['file:../sax'],
1366+
global: true,
1367+
}).then(tree => {
1368+
const resolved = 'file:../../../../fixtures/sax'
1369+
t.equal(tree.children.get('sax').resolved, resolved)
1370+
})
1371+
})
1372+
13511373
t.test('dont get confused if root matches duped metadep', async t => {
13521374
const path = resolve(fixtures, 'test-root-matches-metadep')
13531375
const arb = new Arborist({ path, ...OPT })

0 commit comments

Comments
 (0)