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

Commit

Permalink
use the idealtree target path if it exists
Browse files Browse the repository at this point in the history
This ensures relpaths are from the correct root

PR-URL: #224
Credit: @nlf
Close: #224
Reviewed-by: @wraithgar, @ruyadorno
  • Loading branch information
nlf authored and isaacs committed Feb 12, 2021
1 parent 4f2c028 commit 3724d2a
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/arborist/build-ideal-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,8 @@ module.exports = cls => class IdealTreeBuilder extends cls {
/* istanbul ignore else - should also be covered by realpath failure */
if (filepath) {
const { name } = spec
spec = npa(`file:${relpath(this.path, filepath)}`, this.path)
const tree = this.idealTree.target || this.idealTree
spec = npa(`file:${relpath(tree.path, filepath)}`, tree.path)
spec.name = name
}
return spec
Expand Down
40 changes: 40 additions & 0 deletions tap-snapshots/test-arborist-build-ideal-tree.js-TAP.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,46 @@ ArboristNode {
}
`

exports[`test/arborist/build-ideal-tree.js TAP adding tarball to global prefix that is a symlink at a different path depth > must match snapshot 1`] = `
ArboristLink {
"location": "../another-path/global-root",
"name": "global-root",
"path": "{CWD}/test/arborist/build-ideal-tree-adding-tarball-to-global-prefix-that-is-a-symlink-at-a-different-path-depth/another-path/global-root",
"realpath": "{CWD}/test/arborist/build-ideal-tree-adding-tarball-to-global-prefix-that-is-a-symlink-at-a-different-path-depth/real-root",
"resolved": "file:../real-root",
"target": ArboristNode {
"children": Map {
"mkdirp" => ArboristNode {
"edgesIn": Set {
EdgeIn {
"from": "",
"name": "mkdirp",
"spec": "file:../../../fixtures/registry-mocks/content/mkdirp/-/mkdirp-1.0.2.tgz",
"type": "prod",
},
},
"location": "node_modules/mkdirp",
"name": "mkdirp",
"path": "{CWD}/test/arborist/build-ideal-tree-adding-tarball-to-global-prefix-that-is-a-symlink-at-a-different-path-depth/real-root/node_modules/mkdirp",
"resolved": "file:{CWD}/test/fixtures/registry-mocks/content/mkdirp/-/mkdirp-1.0.2.tgz",
"version": "1.0.2",
},
},
"edgesOut": Map {
"mkdirp" => EdgeOut {
"name": "mkdirp",
"spec": "file:../../../fixtures/registry-mocks/content/mkdirp/-/mkdirp-1.0.2.tgz",
"to": "node_modules/mkdirp",
"type": "prod",
},
},
"location": "",
"name": "real-root",
"path": "{CWD}/test/arborist/build-ideal-tree-adding-tarball-to-global-prefix-that-is-a-symlink-at-a-different-path-depth/real-root",
},
}
`

exports[`test/arborist/build-ideal-tree.js TAP allow updating when peer outside of explicit update set conflict, but resolves appropriately with --force > succeed if force applied 1`] = `
ArboristNode {
"children": Map {
Expand Down
28 changes: 27 additions & 1 deletion test/arborist/build-ideal-tree.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {basename, resolve} = require('path')
const {basename, resolve, relative} = require('path')
const t = require('tap')
const Arborist = require('../..')
const fixtures = resolve(__dirname, '../fixtures')
Expand Down Expand Up @@ -1236,6 +1236,32 @@ t.test('workspaces', t => {
t.end()
})

t.test('adding tarball to global prefix that is a symlink at a different path depth', async t => {
const fixt = t.testdir({
'real-root': {},
'another-path': {
'global-root': t.fixture('symlink', '../real-root'),
},
})
const path = resolve(fixt, 'another-path/global-root')
const arb = new Arborist({
path,
global: true,
...OPT,
})

const tarballpath = resolve(__dirname, '../fixtures/registry-mocks/content/mkdirp/-/mkdirp-1.0.2.tgz')
const tree = await arb.buildIdealTree({
path,
global: true,
add: [
// this will be a relative path to the tarball above
relative(process.cwd(), tarballpath),
],
})
t.matchSnapshot(printTree(tree))
})

t.test('add symlink that points to a symlink', t => {
const fixt = t.testdir({
'global-prefix': {
Expand Down

0 comments on commit 3724d2a

Please sign in to comment.