auth0 / node-jsonwebtoken

JsonWebToken implementation for node.js http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html
MIT License
17.74k stars 1.23k forks source link

refactor: reduce library size by using lodash specific dependencies #933

Closed jakelacey2012 closed 1 year ago

jakelacey2012 commented 1 year ago

This is to reduce the size of the bundle users have to install.

By submitting a PR to this repository, you agree to the terms within the Auth0 Code of Conduct. Please see the contributing guidelines for how to create and submit a high-quality PR for this repo.

Description

In 9.0.0 we introduced a change which depended on lodash as a whole, which meant our bundle size increased. We need to ensure our bundle size is small enough so customers can depend on it at the edge for serverless functions.

References

Testing

Checklist

stefansundin commented 10 months ago

@jakelacey2012

Unfortunately this is bad for security as these packages are very old and some of these packages have open CVEs which are never going to be fixed. I haven't verified if these packages in particular have open CVEs, but every package depending on lodash.pick got a vulnerability a few days ago. Additionally, if there's ever a lodash v5, these packages will not be updated. https://lodash.com/per-method-packages

As that website explains, you should be able to use the main package and import e.g. lodash/includes.

You can also use lodash-es and get tree shaking if your build pipeline supports ESM. https://www.npmjs.com/package/lodash-es