Skip to content

Commit 2c6fb91

Browse files
committed
fix: do not require a log option
Just use a no-op 'logger' if there isn't one in the options.
1 parent 3fa88fa commit 2c6fb91

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

index.js

+15
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ const normalize = require('npm-normalize-package-bin')
1616

1717
module.exports = binLinks
1818

19+
// don't blow up trying to log stuff if we weren't given a logger
20+
const log = {
21+
clearProgress () {},
22+
info () {},
23+
showProgress () {},
24+
silly () {},
25+
verbose () {}
26+
}
27+
1928
function binLinks (pkg, folder, global, opts) {
2029
pkg = normalize(pkg)
2130
folder = path.resolve(folder)
@@ -27,6 +36,12 @@ function binLinks (pkg, folder, global, opts) {
2736
var gnm = global && opts.globalDir
2837
var gtop = parent === gnm
2938

39+
// use the no-op logger if one is not provided
40+
opts = {
41+
log,
42+
...opts
43+
}
44+
3045
opts.log.info('linkStuff', opts.pkgId)
3146
opts.log.silly('linkStuff', opts.pkgId, 'has', parent, 'as its parent node_modules')
3247
if (global) opts.log.silly('linkStuff', opts.pkgId, 'is part of a global install')

test/link-bins.js

-14
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@ mkdirp(me)
1515
const globalDir = resolve(me, 'node_modules')
1616
t.teardown(() => rimraf(me))
1717

18-
const log = {
19-
clearProgress () {},
20-
info () {},
21-
showProgress () {},
22-
silly () {},
23-
verbose () {}
24-
}
25-
2618
// create some stuff that's already in the bin/man folders
2719
const globalBin = resolve(me, 'bin')
2820
mkdirp(globalBin)
@@ -63,7 +55,6 @@ t.test('foo package cannot link, pre-existing stuff there', t => {
6355
global: true,
6456
globalBin,
6557
globalDir,
66-
log,
6758
pkgId: `${pkg.name}@${pkg.version}`,
6859
name: pkg.name,
6960
_FAKE_PLATFORM_,
@@ -96,7 +87,6 @@ t.test('foo package can link with --force link', t => {
9687
global: true,
9788
globalBin,
9889
globalDir,
99-
log,
10090
pkgId: `${pkg.name}@${pkg.version}`,
10191
name: pkg.name,
10292
_FAKE_PLATFORM_,
@@ -130,7 +120,6 @@ t.test('bar package can update, links are ours', t => {
130120
global: true,
131121
globalBin,
132122
globalDir,
133-
log,
134123
pkgId: `${pkg.name}@${pkg.version}`,
135124
name: pkg.name,
136125
_FAKE_PLATFORM_,
@@ -160,7 +149,6 @@ t.test('cannot overwrite with another package with the same bin', t => {
160149
prefix: me,
161150
globalBin,
162151
globalDir,
163-
log,
164152
pkgId: `${pkg.name}@${pkg.version}`,
165153
_FAKE_PLATFORM_,
166154
name: pkg.name,
@@ -185,7 +173,6 @@ t.test('nothing to link', t => {
185173
prefix: me,
186174
globalBin,
187175
globalDir,
188-
log,
189176
pkgId: `${pkg.name}@${pkg.version}`,
190177
_FAKE_PLATFORM_,
191178
name: pkg.name,
@@ -209,7 +196,6 @@ t.test('invalid man page name', t => {
209196
prefix: me,
210197
globalBin,
211198
globalDir,
212-
log,
213199
pkgId: `${pkg.name}@${pkg.version}`,
214200
_FAKE_PLATFORM_,
215201
name: pkg.name,

0 commit comments

Comments
 (0)