csstools / postcss-normalize

Use the parts of normalize.css (or sanitize.css) you need from your browserslist
Creative Commons Zero v1.0 Universal
816 stars 40 forks source link

Add browserslist to peerDependencies #45

Closed joshwilsonvu closed 4 years ago

joshwilsonvu commented 4 years ago

Hello,

When installing a dependent of this package with Yarn 2, I got log output pointing out that this package has a missing peer dependency browserslist, because postcss-browser-comments has a peer dependency on it. More info here.

➤ YN0000: ┌ Resolution step
➤ YN0002: │ postcss-normalize@npm:9.0.0 doesn't provide browserslist@^4 requested by postcss-browser-comments@npm:3.0.0
➤ YN0000: └ Completed in 0.32s
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed in 2.58s
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed in 2.92s
➤ YN0000: Done with warnings in 6s

Unfortunately, this isn't just a warning; Yarn 2 Plug 'n Play throws an error when postcss-browser-comments attempts to require browserslist, even if the top-level project has browserslist installed.

UnhandledPromiseRejectionWarning: Error: postcss-browser-comments tried to access browserslist (a peer dependency) but it isn't provided by its ancestors; this makes the require call ambiguous and unsound.

Adding browserslist to peerDependencies makes the intended behavior here explicit and resolves the installation warning and runtime exception. It will not be a breaking change as npm and Yarn 1 already surface a peer dependency warning from postcss-browser-comments.

jonathantneal commented 4 years ago

Thank you for explaining the issue so clearly and even presenting me with a solution.

I’m merging this because it resolve an important issue and it is non-breaking.

However, I’m surprised to discover that browserslist is a peerDependencies since it explicitly uses it. Do you suppose that package should change browserslist to a dependency?

joshwilsonvu commented 4 years ago

They certainly could, but a peer dependency lets their package work with whatever version the end user or a dependent package decides to install. Just a matter of taste I suppose.