Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make brotli-size optional #214

Merged
merged 8 commits into from
May 2, 2018

Conversation

styfle
Copy link

@styfle styfle commented Apr 13, 2018

Description

  1. Remove brotli-size from dependencies
  2. Add try-catch around require('brotli-size')
  3. Warn if using brotli option but missing brotli-size

Motivation and Context

It turns out the brotli-size (#194) is quite big and doesn't install very nicely on Windows.

See the following issues:

Fixes #202
Fixes #213

@styfle
Copy link
Author

styfle commented Apr 13, 2018

@siddharthkp Does travis need to install optional dependencies to run tests?

package.json Outdated
@@ -49,6 +48,9 @@
"prettycli": "^1.4.3",
"read-pkg-up": "^3.0.0"
},
"optionalDependencies": {
"brotli-size": "0.0.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be updated to 0.0.2 at the same time? :-)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey that sounds like a good idea considering the size of the package decreased significantly https://packagephobia.now.sh/[email protected]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@siddharthkp What do you think?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any difference in size because of that?

Copy link
Author

@styfle styfle Apr 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

I will bump the version to 0.0.2

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done ✅

@styfle styfle changed the title Make Brotli and optional dependency Make Brotli an optional dependency Apr 13, 2018
const brotli = require('brotli-size')
size = brotli.sync(data)
} catch (e) {
console.warn('Missing optional dependency: brotli-size')
Copy link
Owner

@siddharthkp siddharthkp Apr 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make this slightly more instructional + use prettycli (already declared as dependency), that will let you add nice multiline warnings.

WARN Missing optional dependency. Install it with:

npm install brotli-size

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done ✅

@styfle
Copy link
Author

styfle commented Apr 21, 2018

@siddharthkp @edmorley Any other changes requested?

package.json Outdated
@@ -49,6 +48,9 @@
"prettycli": "^1.4.3",
"read-pkg-up": "^3.0.0"
},
"optionalDependencies": {
"brotli-size": "0.0.2"
Copy link
Contributor

@edmorley edmorley Apr 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure that both npm and yarn install optionalDependencies by default (they just don't exit with a non-zero exit code, if it wasn't able to be installed).

As such with default npm yarn options (which is what most users will use), this PR will solve the installation errors issue, however there will still be install time and size impact from brotli-size. Perhaps instead brotli-size should be removed from package.json entirely - and then users will install manually instead? (Which is what the error message added to src/compressed-size.js says to do anyway; though perhaps it would be good to also have a README.md mention?)

Many thanks for looking into this!

Copy link
Author

@styfle styfle Apr 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@edmorley You're right! I changed to peerDependency since this will give a hint to a developer looking at package.json

I also added a note to the README 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately having in peerDependencies will result in warnings being shown when installing with yarn/npm, if it's not installed. Some users fail CI if these warnings are generated. I think the best plan is to omit it from package.json entirely.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@edmorley Yes I can see how that would be misleading for the users who only want to use gzip. I removed it completely now, thanks! 👍

@styfle
Copy link
Author

styfle commented Apr 24, 2018

@siddharthkp @edmorley I think I got it right this time 😄

@styfle styfle changed the title Make Brotli an optional dependency Make brotli-size an optional dependency Apr 28, 2018
@styfle styfle changed the title Make brotli-size an optional dependency Make brotli-size optional Apr 28, 2018
@styfle
Copy link
Author

styfle commented Apr 28, 2018

I updated the title and description to reflect the changes requested

@XhmikosR
Copy link
Contributor

@siddharthkp: this is an issue even more with node.js 10.x and bundle-size depending on iltorb which doesn't have the bindings yet.

const brotli = require('brotli-size')
size = brotli.sync(data)
} catch (e) {
warn(`Missing optional dependency. Install it with:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If something else can throw too in brotli.sync, then the message would be misleading, wouldn't it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@XhmikosR Good point. I fixed this 🔧

@@ -50,6 +50,8 @@ npx bundlesize
#### 1) Add the path and maxSize in your `package.json`.
By default the gzipped size is tested. You can use the `compression` option to change this. (`gzip`, `brotli`, or `none`).

To use the `brotli` compression option, you must install the peer dependency: `npm install --save brotli-size`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"the brotli-size peer dependency" maybe?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is pretty clear already since it has the exact command to run. This is how it looks rendered:
image

@XhmikosR
Copy link
Contributor

XhmikosR commented May 2, 2018

Ping @siddharthkp

@siddharthkp
Copy link
Owner

@XhmikosR Hey! Sorry I was on a laptop less vacation.

Will test this out soon

@siddharthkp siddharthkp changed the base branch from master to brotli-optional May 2, 2018 11:21
@siddharthkp siddharthkp merged commit 1294f58 into siddharthkp:brotli-optional May 2, 2018
@siddharthkp
Copy link
Owner

siddharthkp commented May 2, 2018

Merged into local branch so that CI tests can run. New PR: #220

@XhmikosR
Copy link
Contributor

XhmikosR commented May 2, 2018

@siddharthkp: thanks! I was going to downgrade bundle-size to be honest if it took more time because this fails for node 10.x.

@styfle
Copy link
Author

styfle commented May 2, 2018

@siddharthkp Thanks, anything else I need to do?

@styfle styfle deleted the brotli-optional branch June 6, 2018 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants