-
Notifications
You must be signed in to change notification settings - Fork 161
fix: mark webpack
dependencies as peer instead of optional
#517
fix: mark webpack
dependencies as peer instead of optional
#517
Conversation
@pgrzesik @medikoo would it be possible to get some eyes on this? I hate to ping out-of-the-blue, but this is preventing us from auditing our projects, and pulls in a lot of outdated and unneeded dependencies with no way to work around 😬 Happy to do the leg work, just would like to spur some movement on the review side to get this landed :) |
@tbarlow12 can you check that one? |
@medikoo @tbarlow12 any update on this? I hate to keep pinging, but as I've said it's pretty major for us. I'm happy to help if there's anything I can do :) |
@medikoo @tbarlow12 again any update? this is still a big problem for us - it's pretty much turned us off azure for now. |
@tbarlow12 let me know if you'd like me to rebase this so it can be landed. |
@tbarlow12 this needs rebasing because #537 changed the lockfile from v1 to v2 (meaning the author was using |
@medikoo would it be possible to get this reviewed & merged? I'm also open to helping maintain this package if you want. |
@medikoo @tbarlow12 bump - it would be really great if we could get this landed. Rebasing will be easy becuase it's just that the package lock needs to be regenerated |
@gligorkot I see that you're helping maintain this plugin now - would you be open to landing this if I rebased it? |
@G-Rath sure, just need to understand it a bit more. Are you saying that webpack is required for this package so it needs to be a peer dependency? Also, why also make serverless webpack a peer dependency in that case too? |
@gligorkot neither packages are required for this plugin, but if The version of I'm pretty sure that there isn't a need to also specify |
@G-Rath my plan is to work on updating all of the dependencies to their latest and then releasing a v3.0.0. However, regarding the discussion about whether or not webpack and serverless webpack are necessary to be peer or optional dependencies, if you use I'm still not clear how marking them as peer dependencies changes anything - if they're marked as peer dependencies then you wouldn't be able to install this plugin without installing those dependencies as well, right? (not sure if anyone uses this plugin without them as I'm new to the codebase and hadn't been involved in any discussions about it before) |
Technically yes, but it'll not install any optional dependencies which is not desirable - it also requires you to explicitly pass that whenever you run an
No - as I said, neither package is required for this plugin to work. Optional dependencies are for situations where a particular package is desirable to have but may not be able to be installed for external reasons such as incompatible OS - Peer dependencies on the other hand are for situations where a particular package is required but there should only be one version of it in the dependency tree, generally because of the nature of the work it does and the way the package is invoked, and because of how Node supports multiple versions of the same package. Consider for example if you have an app using Finally, we have optional peer dependencies - these are similar to the above, except that they don't require the peer dependency; they're for saying "this package supports enhanced behaviour if this package is installed, but it isn't required for the package to run". This plugin is an example of that: if You can also see this project as proof that this plugin can be used without these dependencies being configured. |
Yeah, I'm happy to bring in this change |
What did you implement:
When webpack was added as a dependency in #105 it was added as an "optional" dependency using
optionalDependencies
, when it should have been inpeerDependencies
.This is a common mistake, as
optionalDependencies
sounds like what you want when a dependency is optional, but those dependencies mean "if you error when installing this, that's fine, ignore it and continue" - they're used for packages likefsevents
which are only supported in some OSs (or other condition).peerDependencies
on the other hand mean "I support working with this version of this package , but require a single version of it to exist in the tree". Taking this even further,peerDependenciesMeta
lets you mark a package as really optional (aka "I support using this package within this version constraint, but I don't require it to function"); otherwise a peer dependency will be installed by default (maybe, depending on package manager - it use to be a thing innpm
then they removed that for 5 & 6 but added it back in 7).Doing this lets us not pull in the old version of webpack that has known vulnerabilities if we're not wanting to use webpack.
(Upgrading the version of webpack supported by this library is another thing of it's own 😬).
Currently this is pulling in an extra 155 packages (including at least 6 known vulnerabilities that cannot be patched due to webpack 3),
How did you implement it:
By adjusting the
package.json
.How can we verify it:
Do
npm i serverless-azure-functions && npm ls webpack
- you'll see its currently being installed in the tree, but there are no requires for it in code.If you do
npm i
on this branch, you'll see webpack not on the tree and ~150 packages are removed.Todos:
Note: Run
npm run test:ci
to run all validation checks on proposed changesValidate via
npm run lint
Note: Some reported issues can be automatically fixed by running
npm run lint:fix
Validate via
npm test
Is this ready for review?: YES
Is it a breaking change?: NO (sort of)
This is in the annoying grey area of "is this is a breaking change" - if people are relying on the fact that
serverless-webpack
is being installed viaserverless-azure-functions
then this will break their build, but they're relying on a subtle functionality of package management that shouldn't be relied on to begin with (as it can itself break without warning), and the fix is entirely just "runnpm i -D serverless-webpack webpack
.Users that have
serverless-webpack
in theirpackage.json
as a dependency won't be affected - things will just continue to work for them (they'll probably have their dependency tree shrink tbh).