Skip to content

Commit 51c2bf8

Browse files
authored
fix: don't print the funding message for global installs (#9864)
## What / Why A global install prints "N packages are looking for funding / run `npm fund` for details", but nothing can be done with it. `npm fund -g` fails with `EFUNDGLOBAL`, and a bare `npm fund` loads the tree at the local prefix, so outside a project it prints the directory name and nothing else. `packagesFundingMessage` in `lib/utils/reify-output.js` never looked at `npm.global`, so the hint went out for global installs too. It now returns early in that case. Making `npm fund -g` work is a separate feature request; #3112 already splits it out that way. ## Testing New case in `test/lib/utils/reify-output.js`, mirroring the existing `fund: false` one: with `global: true` the output no longer mentions funding. It fails without the change. ## References Fixes #9863 Fixes #3112
1 parent 4cdccea commit 51c2bf8

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

‎lib/utils/reify-output.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ const packagesChangedMessage = (npm, { added, removed, changed, audited }) => {
221221
}
222222

223223
const packagesFundingMessage = (npm, { funding }) => {
224-
if (!funding) {
224+
if (!funding || npm.global) {
225225
return
226226
}
227227

‎test/lib/utils/reify-output.js‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,35 @@ t.test('no message when funding config is false', async t => {
128128
t.notMatch(out, 'looking for funding', 'should not print funding info')
129129
})
130130

131+
t.test('no message when installing globally', async t => {
132+
const out = await mockReify(t, {
133+
actualTree: {
134+
name: 'foo',
135+
package: {
136+
name: 'foo',
137+
version: '1.0.0',
138+
},
139+
edgesOut: new Map([
140+
['bar', {
141+
to: {
142+
name: 'bar',
143+
package: {
144+
name: 'bar',
145+
version: '1.0.0',
146+
funding: { type: 'foo', url: 'http://example.com' },
147+
},
148+
},
149+
}],
150+
]),
151+
},
152+
diff: {
153+
children: [],
154+
},
155+
}, { global: true })
156+
157+
t.notMatch(out, 'looking for funding', 'should not print funding info')
158+
})
159+
131160
t.test('print appropriate message for many packages', async t => {
132161
const out = await mockReify(t, {
133162
actualTree: {

0 commit comments

Comments
 (0)