diff --git a/lib/commands/link.js b/lib/commands/link.js index cd6782a1f9836..0e9f18afb80a5 100644 --- a/lib/commands/link.js +++ b/lib/commands/link.js @@ -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') @@ -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) } diff --git a/test/lib/commands/link.js b/test/lib/commands/link.js index 11ed182edd94b..6541ecaff9e8e 100644 --- a/test/lib/commands/link.js +++ b/test/lib/commands/link.js @@ -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: { @@ -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 => {