Skip to content

Commit

Permalink
Move try/catch around require
Browse files Browse the repository at this point in the history
  • Loading branch information
styfle authored Apr 30, 2018
1 parent 088e8f7 commit eecc3f9
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/compressed-size.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { warn } = require('prettycli')
const gzip = require('gzip-size')
let brotli

const getCompressedSize = (data, compression = 'gzip') => {
let size
Expand All @@ -9,12 +10,12 @@ const getCompressedSize = (data, compression = 'gzip') => {
break
case 'brotli':
try {
const brotli = require('brotli-size')
size = brotli.sync(data)
brotli = require('brotli-size')
} catch (e) {
warn(`Missing optional dependency. Install it with:
npm install --save brotli-size`)
}
size = brotli ? brotli.sync(data) : 0
break
case 'none':
default:
Expand Down

0 comments on commit eecc3f9

Please sign in to comment.