Skip to content

Commit

Permalink
fix: make npm link respect --no-save (#6910)
Browse files Browse the repository at this point in the history
  • Loading branch information
Santoshraj2 committed Oct 31, 2023
1 parent 11e3c41 commit 8ed6d28
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/commands/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
34 changes: 34 additions & 0 deletions test/lib/commands/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 8ed6d28

Please sign in to comment.