Skip to content

Commit

Permalink
fix: npm link <pkg> should not save package.json
Browse files Browse the repository at this point in the history
When running `npm link <pkg>` it should not save the new item to the
currrent dependencies of that package.json file.

Fixes: #2034
  • Loading branch information
ruyadorno committed Nov 27, 2020
1 parent 27a4c19 commit 719f7ef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,13 @@ const linkInstall = async args => {
const localArb = new Arborist({
...npm.flatOptions,
path: npm.prefix,
save: false,
})
await localArb.reify({
...npm.flatOptions,
path: npm.prefix,
add: names.map(l => `file:${resolve(globalTop, 'node_modules', l)}`),
save: false,
})

await reifyFinish(localArb)
Expand Down
8 changes: 7 additions & 1 deletion test/lib/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ 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)
t.plan(3)

const testdir = t.testdir({
'global-prefix': {
Expand Down Expand Up @@ -235,6 +235,12 @@ t.test('link pkg already in global space', (t) => {
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')
}

Expand Down

0 comments on commit 719f7ef

Please sign in to comment.