Skip to content

Commit

Permalink
fix: do not require a log option
Browse files Browse the repository at this point in the history
Just use a no-op 'logger' if there isn't one in the options.
  • Loading branch information
isaacs committed Jan 6, 2020
1 parent 3fa88fa commit 2c6fb91
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
15 changes: 15 additions & 0 deletions index.js
Expand Up @@ -16,6 +16,15 @@ const normalize = require('npm-normalize-package-bin')

module.exports = binLinks

// don't blow up trying to log stuff if we weren't given a logger
const log = {
clearProgress () {},
info () {},
showProgress () {},
silly () {},
verbose () {}
}

function binLinks (pkg, folder, global, opts) {
pkg = normalize(pkg)
folder = path.resolve(folder)
Expand All @@ -27,6 +36,12 @@ function binLinks (pkg, folder, global, opts) {
var gnm = global && opts.globalDir
var gtop = parent === gnm

// use the no-op logger if one is not provided
opts = {
log,
...opts
}

opts.log.info('linkStuff', opts.pkgId)
opts.log.silly('linkStuff', opts.pkgId, 'has', parent, 'as its parent node_modules')
if (global) opts.log.silly('linkStuff', opts.pkgId, 'is part of a global install')
Expand Down
14 changes: 0 additions & 14 deletions test/link-bins.js
Expand Up @@ -15,14 +15,6 @@ mkdirp(me)
const globalDir = resolve(me, 'node_modules')
t.teardown(() => rimraf(me))

const log = {
clearProgress () {},
info () {},
showProgress () {},
silly () {},
verbose () {}
}

// create some stuff that's already in the bin/man folders
const globalBin = resolve(me, 'bin')
mkdirp(globalBin)
Expand Down Expand Up @@ -63,7 +55,6 @@ t.test('foo package cannot link, pre-existing stuff there', t => {
global: true,
globalBin,
globalDir,
log,
pkgId: `${pkg.name}@${pkg.version}`,
name: pkg.name,
_FAKE_PLATFORM_,
Expand Down Expand Up @@ -96,7 +87,6 @@ t.test('foo package can link with --force link', t => {
global: true,
globalBin,
globalDir,
log,
pkgId: `${pkg.name}@${pkg.version}`,
name: pkg.name,
_FAKE_PLATFORM_,
Expand Down Expand Up @@ -130,7 +120,6 @@ t.test('bar package can update, links are ours', t => {
global: true,
globalBin,
globalDir,
log,
pkgId: `${pkg.name}@${pkg.version}`,
name: pkg.name,
_FAKE_PLATFORM_,
Expand Down Expand Up @@ -160,7 +149,6 @@ t.test('cannot overwrite with another package with the same bin', t => {
prefix: me,
globalBin,
globalDir,
log,
pkgId: `${pkg.name}@${pkg.version}`,
_FAKE_PLATFORM_,
name: pkg.name,
Expand All @@ -185,7 +173,6 @@ t.test('nothing to link', t => {
prefix: me,
globalBin,
globalDir,
log,
pkgId: `${pkg.name}@${pkg.version}`,
_FAKE_PLATFORM_,
name: pkg.name,
Expand All @@ -209,7 +196,6 @@ t.test('invalid man page name', t => {
prefix: me,
globalBin,
globalDir,
log,
pkgId: `${pkg.name}@${pkg.version}`,
_FAKE_PLATFORM_,
name: pkg.name,
Expand Down

0 comments on commit 2c6fb91

Please sign in to comment.