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

Commit

Permalink
fix: path resolution for global linking filepaths
Browse files Browse the repository at this point in the history
related to: npm/cli#1786

Co-authored-by: isaacs <i@izs.me>
  • Loading branch information
ruyadorno and isaacs committed Sep 10, 2020
1 parent 5492920 commit e8bcfc7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/add-rm-pkg-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const addSingle = ({pkg, spec, saveBundle, saveType, path}) => {
pkg[type] = pkg[type] || {}
if (rawSpec !== '' || pkg[type][name] === undefined) {
// if we're in global mode, file specs are based on cwd, not arb path
pkg[type][name] = specType === 'file' ? `file:${relpath(path, fetchSpec)}`
pkg[type][name] = specType === 'file' || specType === 'directory' ? `file:${relpath(path, fetchSpec)}`
: (rawSpec || '*')
}

Expand Down
22 changes: 22 additions & 0 deletions test/arborist/build-ideal-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,28 @@ t.test('resolve files from cwd in global mode, Arb path in local mode', t => {
})
})

t.only('resolve links in global mode', t => {
const cwd = process.cwd()
t.teardown(() => process.chdir(cwd))
const path = t.testdir({
global: {}
})
const fixturedir = resolve(fixtures, 'root-bundler')
process.chdir(fixturedir)
const arb = new Arborist({
global: true,
path: resolve(path, 'global'),
...OPT,
})
return arb.buildIdealTree({
add: ['file:../sax'],
global: true,
}).then(tree => {
const resolved = 'file:../../../../fixtures/sax'
t.equal(tree.children.get('sax').resolved, resolved)
})
})

t.test('dont get confused if root matches duped metadep', async t => {
const path = resolve(fixtures, 'test-root-matches-metadep')
const arb = new Arborist({ path, ...OPT })
Expand Down

0 comments on commit e8bcfc7

Please sign in to comment.