Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correctly identify already linked packages when global prefix is a symlink #2486

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/link.js
Expand Up @@ -45,6 +45,9 @@ const link = async args => {
// Returns a list of items that can't be fulfilled by
// things found in the current arborist inventory
const missingArgsFromTree = (tree, args) => {
if (tree.isLink)
return missingArgsFromTree(tree.target, args)

const foundNodes = []
const missing = args.filter(a => {
const arg = npa(a)
Expand Down
5 changes: 5 additions & 0 deletions tap-snapshots/test-lib-link.js-TAP.test.js
Expand Up @@ -19,6 +19,11 @@ exports[`test/lib/link.js TAP link pkg already in global space > should create a

`

exports[`test/lib/link.js TAP link pkg already in global space when prefix is a symlink > should create a local symlink to global pkg 1`] = `
{CWD}/test/lib/link-link-pkg-already-in-global-space-when-prefix-is-a-symlink/my-project/node_modules/@myscope/linked -> {CWD}/test/lib/link-link-pkg-already-in-global-space-when-prefix-is-a-symlink/scoped-linked

`

exports[`test/lib/link.js TAP link to globalDir when in current working dir of pkg and no args > should create a global link to current pkg 1`] = `
{CWD}/test/lib/link-link-to-globalDir-when-in-current-working-dir-of-pkg-and-no-args/global-prefix/lib/node_modules/test-pkg-link -> {CWD}/test/lib/link-link-to-globalDir-when-in-current-working-dir-of-pkg-and-no-args/test-pkg-link

Expand Down
58 changes: 58 additions & 0 deletions test/lib/link.js
Expand Up @@ -259,6 +259,64 @@ t.test('link pkg already in global space', (t) => {
})
})

t.test('link pkg already in global space when prefix is a symlink', (t) => {
t.plan(3)

const testdir = t.testdir({
'global-prefix': t.fixture('symlink', './real-global-prefix'),
'real-global-prefix': {
lib: {
node_modules: {
'@myscope': {
linked: t.fixture('symlink', '../../../../scoped-linked'),
},
},
},
},
'scoped-linked': {
'package.json': JSON.stringify({
name: '@myscope/linked',
version: '1.0.0',
}),
},
'my-project': {
'package.json': JSON.stringify({
name: 'my-project',
version: '1.0.0',
}),
},
})
npm.globalDir = resolve(testdir, 'global-prefix', 'lib', 'node_modules')
npm.prefix = resolve(testdir, 'my-project')

npm.config.find = () => 'default'

const _cwd = process.cwd()
process.chdir(npm.prefix)

reifyOutput = async () => {
reifyOutput = undefined
process.chdir(_cwd)
npm.config.find = () => null

const links = await printLinks({
path: npm.prefix,
})

t.equal(
require(resolve(testdir, 'my-project', 'package.json')).dependencies,
undefined,
'should not save to package.json upon linking'
)

t.matchSnapshot(links, 'should create a local symlink to global pkg')
}

link(['@myscope/linked'], (err) => {
t.ifError(err, 'should not error out')
})
})

t.test('completion', (t) => {
const testdir = t.testdir({
'global-prefix': {
Expand Down