Skip to content

Commit

Permalink
fix: should not reify if no args
Browse files Browse the repository at this point in the history
  • Loading branch information
ruyadorno committed Sep 12, 2020
1 parent c7eb066 commit b12d9db
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@ const linkInstall = async args => {
// any extra arg that is missing from the current
// global space should be reified there first
const missing = missingArgsFromTree(globals, args)
await globalArb.reify({
...globalOpts,
add: missing
})
if (missing.length) {
await globalArb.reify({
...globalOpts,
add: missing
})
}

// get a list of module names that should be linked in the local prefix
const names = []
Expand Down
5 changes: 5 additions & 0 deletions tap-snapshots/test-lib-link.js-TAP.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ exports[`test/lib/link.js TAP link global linked pkg to local nm when using args
`

exports[`test/lib/link.js TAP link pkg already in global space > should create a local symlink to global pkg 1`] = `
{CWD}/test/lib/link-link-pkg-already-in-global-space/my-project/node_modules/@myscope/linked -> {CWD}/test/lib/link-link-pkg-already-in-global-space/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
54 changes: 54 additions & 0 deletions test/lib/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,60 @@ t.test('link global linked pkg to local nm when using args', (t) => {
})
})

t.test('link pkg already in global space', (t) => {
t.plan(2)

const testdir = t.testdir({
'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')

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

reifyOutput = async () => {
reifyOutput = undefined
process.chdir(_cwd)

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

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

// installs examples for:
// - test-pkg-link: pkg linked to globalDir from local fs
// - @myscope/linked: scoped pkg linked to globalDir from local fs
// - @myscope/bar: prev installed scoped package available in globalDir
// - a: prev installed package available in globalDir
// - file:./link-me-too: pkg that needs to be reified in globalDir first
link(['@myscope/linked'], (err) => {
t.ifError(err, 'should not error out')
})
})

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

0 comments on commit b12d9db

Please sign in to comment.