diff --git a/lib/commands/link.js b/lib/commands/link.js index 0c0929115a557..cdc248569849c 100644 --- a/lib/commands/link.js +++ b/lib/commands/link.js @@ -109,13 +109,13 @@ class Link extends ArboristWorkspaceCmd { // using any of --save-dev or other types const save = Boolean( - this.npm.config.find('save') !== 'default' || + (this.npm.config.find('save') !== 'default' && + this.npm.config.get('save')) || this.npm.config.get('save-optional') || this.npm.config.get('save-peer') || this.npm.config.get('save-dev') || this.npm.config.get('save-prod') ) - // create a new arborist instance for the local prefix and // reify all the pending names as symlinks there const localArb = new Arborist({ diff --git a/test/lib/commands/link.js b/test/lib/commands/link.js index 65792fd141acb..85bada28d67b1 100644 --- a/test/lib/commands/link.js +++ b/test/lib/commands/link.js @@ -369,6 +369,40 @@ t.test('link pkg already in global space when prefix is a symlink', async t => { t.matchSnapshot(await printLinks(), 'should create a local symlink to global pkg') }) +t.test('should not save link to package file', async t => { + const { link, prefix } = await mockLink(t, { + globalPrefixDir: { + node_modules: { + '@myscope': { + linked: t.fixture('symlink', '../../../other/scoped-linked'), + }, + }, + }, + otherDirs: { + 'scoped-linked': { + 'package.json': JSON.stringify({ + name: '@myscope/linked', + version: '1.0.0', + }), + }, + }, + prefixDir: { + 'package.json': JSON.stringify({ + name: 'my-project', + version: '1.0.0', + }), + }, + config: { save: false }, + }) + + await link.exec(['@myscope/linked']) + t.match( + require(resolve(prefix, 'package.json')).dependencies, + undefined, + 'should not save to package.json upon linking' + ) +}) + t.test('should not prune dependencies when linking packages', async t => { const { link, prefix } = await mockLink(t, { globalPrefixDir: {