Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/commands/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { resolve } = require('node:path')
const npa = require('npm-package-arg')
const pkgJson = require('@npmcli/package-json')
const semver = require('semver')
const { output } = require('proc-log')
const reifyFinish = require('../utils/reify-finish.js')
const resolveAllowScripts = require('../utils/resolve-allow-scripts.js')
const strictAllowScriptsPreflight = require('../utils/strict-allow-scripts-preflight.js')
Expand Down Expand Up @@ -169,6 +170,11 @@ class Link extends ArboristWorkspaceCmd {
await arb.reify({
add,
})
if (!this.npm.config.get('json')) {
for (const { to } of arb.explicitRequests) {
output.standard(`${to.path} -> ${to.realpath}`)
}
}
await reifyFinish(this.npm, arb)
}

Expand Down
22 changes: 21 additions & 1 deletion test/lib/commands/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const mockLink = async (t, { globalPrefixDir, ...opts } = {}) => {
}

t.test('link to globalDir when in current working dir of pkg and no args', async t => {
const { link, printLinks } = await mockLink(t, {
const { link, printLinks, joinedOutput, npm, prefix } = await mockLink(t, {
globalPrefixDir: {
node_modules: {
a: {
Expand All @@ -63,6 +63,26 @@ t.test('link to globalDir when in current working dir of pkg and no args', async

await link.exec()
t.matchSnapshot(await printLinks({ global: true }), 'should create a global link to current pkg')
t.equal(
joinedOutput(),
`${join(npm.globalDir, 'test-pkg-link')} -> ${fs.realpathSync(prefix)}`,
'should output the created link'
)
})

t.test('link to globalDir with --json does not output plain link', async t => {
const { link, joinedOutput } = await mockLink(t, {
prefixDir: {
'package.json': JSON.stringify({
name: 'test-pkg-link',
version: '1.0.0',
}),
},
config: { json: true },
})

await link.exec()
t.equal(joinedOutput(), '', 'should not output the created link')
})

t.test('link ws to globalDir when workspace specified and no args', async t => {
Expand Down