Skip to content

Commit f0a6abe

Browse files
committed
fix: npm link should override --install-links
1 parent 9609e9e commit f0a6abe

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

lib/commands/link.js

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class Link extends ArboristWorkspaceCmd {
5151
{ code: 'ELINKGLOBAL' }
5252
)
5353
}
54+
// install-links is implicitely false when running `npm link`
55+
this.npm.config.set('install-links', false)
5456

5557
// link with no args: symlink the folder to the global location
5658
// link with package arg: symlink the global to the local

tap-snapshots/test/lib/commands/link.js.test.cjs

+5
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,8 @@ exports[`test/lib/commands/link.js TAP link ws to globalDir when workspace speci
4848
{CWD}/test/lib/commands/tap-testdir-link-link-ws-to-globalDir-when-workspace-specified-and-no-args/global-prefix/lib/node_modules/a -> {CWD}/test/lib/commands/tap-testdir-link-link-ws-to-globalDir-when-workspace-specified-and-no-args/test-pkg-link/packages/a
4949
5050
`
51+
52+
exports[`test/lib/commands/link.js TAP test linked installed as symlinks > linked package should not be installed 1`] = `
53+
{CWD}/test/lib/commands/tap-testdir-link-test-linked-installed-as-symlinks/prefix/node_modules/mylink -> {CWD}/test/lib/commands/tap-testdir-link-test-linked-installed-as-symlinks/other/mylink
54+
55+
`

test/lib/commands/link.js

+34-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const t = require('tap')
2-
const { resolve } = require('path')
2+
const { resolve, join } = require('path')
33
const fs = require('fs')
44

55
const Arborist = require('@npmcli/arborist')
6-
const { fake: mockNpm } = require('../../fixtures/mock-npm')
6+
const { fake: mockNpm, load: fullMockNpm } = require('../../fixtures/mock-npm')
77

88
const redactCwd = (path) => {
99
const normalizePath = p => p
@@ -72,7 +72,6 @@ t.test('link to globalDir when in current working dir of pkg and no args', async
7272
path: resolve(npm.globalDir, '..'),
7373
global: true,
7474
})
75-
7675
t.matchSnapshot(links, 'should create a global link to current pkg')
7776
})
7877

@@ -550,3 +549,35 @@ t.test('hash character in working directory path', async t => {
550549

551550
t.matchSnapshot(links, 'should create a global link to current pkg, even within path with hash')
552551
})
552+
553+
t.test('test linked installed as symlinks', async t => {
554+
// fakeMock is insufficient due to lack of flatOptions
555+
const { npm } = await fullMockNpm(t, {
556+
otherDirs: {
557+
mylink: {
558+
'package.json': JSON.stringify({
559+
name: 'mylink',
560+
version: '1.0.0',
561+
}),
562+
},
563+
},
564+
})
565+
const link = new Link(npm)
566+
567+
const _cwd = process.cwd()
568+
process.chdir(npm.prefix)
569+
570+
await npm.exec('link', [
571+
join('file:../other/mylink'),
572+
])
573+
process.chdir(_cwd)
574+
const links = await printLinks({
575+
path: npm.prefix,
576+
})
577+
578+
t.ok(fs.lstatSync(join(npm.prefix, 'node_modules', 'mylink')).isSymbolicLink(),
579+
'linked path should by symbolic link'
580+
)
581+
582+
t.matchSnapshot(links, 'linked package should not be installed')
583+
})

0 commit comments

Comments
 (0)