Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: npm link should override --install-links #5633

Merged
merged 1 commit into from Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/commands/link.js
Expand Up @@ -51,6 +51,8 @@ class Link extends ArboristWorkspaceCmd {
{ code: 'ELINKGLOBAL' }
)
}
// install-links is implicitely false when running `npm link`
this.npm.config.set('install-links', false)

// link with no args: symlink the folder to the global location
// link with package arg: symlink the global to the local
Expand Down
5 changes: 5 additions & 0 deletions tap-snapshots/test/lib/commands/link.js.test.cjs
Expand Up @@ -48,3 +48,8 @@ exports[`test/lib/commands/link.js TAP link ws to globalDir when workspace speci
{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

`

exports[`test/lib/commands/link.js TAP test linked installed as symlinks > linked package should not be installed 1`] = `
{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

`
36 changes: 33 additions & 3 deletions test/lib/commands/link.js
@@ -1,9 +1,9 @@
const t = require('tap')
const { resolve } = require('path')
const { resolve, join } = require('path')
const fs = require('fs')

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

const redactCwd = (path) => {
const normalizePath = p => p
Expand Down Expand Up @@ -72,7 +72,6 @@ t.test('link to globalDir when in current working dir of pkg and no args', async
path: resolve(npm.globalDir, '..'),
global: true,
})

t.matchSnapshot(links, 'should create a global link to current pkg')
})

Expand Down Expand Up @@ -550,3 +549,34 @@ t.test('hash character in working directory path', async t => {

t.matchSnapshot(links, 'should create a global link to current pkg, even within path with hash')
})

t.test('test linked installed as symlinks', async t => {
// fakeMock is insufficient due to lack of flatOptions
const { npm } = await fullMockNpm(t, {
otherDirs: {
mylink: {
'package.json': JSON.stringify({
name: 'mylink',
version: '1.0.0',
}),
},
},
})

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

await npm.exec('link', [
join('file:../other/mylink'),
])
process.chdir(_cwd)
const links = await printLinks({
path: npm.prefix,
})

t.ok(fs.lstatSync(join(npm.prefix, 'node_modules', 'mylink')).isSymbolicLink(),
'linked path should by symbolic link'
)

t.matchSnapshot(links, 'linked package should not be installed')
})