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

Replace keypather with lodash.get #1155

Merged
merged 2 commits into from
Nov 24, 2021
Merged

Replace keypather with lodash.get #1155

merged 2 commits into from
Nov 24, 2021

Conversation

lfdebrux
Copy link
Member

keypather is a bit unloved and Dependabot complains about it. We can replace it with the _.get function from lodash [1]. This also saves a little bit of disk space, as we have to install lodash loads anyway.

This PR checks that everything is a-okay by adding some small tests for checked, which uses keypather, and then doing the switch.

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-prototype-kit-pr-1155 November 11, 2021 14:41 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-prototype-kit-pr-1155 November 11, 2021 14:41 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-prototype-kit-pr-1155 November 11, 2021 14:47 Inactive
@domoscargin
Copy link
Contributor

This looks great and seems hunky dory on my machine.

Do we think this could break some existing prototypes where users have made use of keypather elsewhere?

@lfdebrux
Copy link
Member Author

Do we think this could break some existing prototypes where users have made use of keypather elsewhere?

Hmm, possibly... it would be nice if we could find if there were any such prototypes on GitHub 🤔

@domoscargin
Copy link
Contributor

Do we think this could break some existing prototypes where users have made use of keypather elsewhere?

Hmm, possibly... it would be nice if we could find if there were any such prototypes on GitHub 🤔

Only 1500ish results to check... https://github.com/search?l=JavaScript&q=%22keypather%22&type=Code

@joelanman
Copy link
Contributor

we've never documented keypather or told people to use it/aware of people using it, in which case we don't normally consider it part of our 'api' to be included in 'breaking changes'

Copy link
Contributor

@domoscargin domoscargin left a comment

Choose a reason for hiding this comment

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

Given @joelanman's comment that we don't consider this a breaking change, I think this is ready to go with a fix entry in the CHANGELOG. dependabot is going to be so pleased.

keypather is a bit unloved and Dependabot complains about it. We can
replace it with the `_.get` function from lodash [[1]]. This also saves
a little bit of disk space, as we have to install lodash loads anyway.

[1]: https://lodash.com/docs/4.17.15#get
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-prototype-kit-pr-1155 November 24, 2021 09:50 Inactive
@lfdebrux
Copy link
Member Author

lfdebrux commented Nov 24, 2021

I've update the CHANGELOG👍 When do we want to merge this?

@domoscargin
Copy link
Contributor

There shouldn't be any harm in merging straight away?

We could potentially do a 11.0.1 release with this so anybody who's upgrading now doesn't get the Big Scary Security Warning?

@joelanman
Copy link
Contributor

@domoscargin sounds good to me on both counts

@lfdebrux lfdebrux merged commit 266226c into main Nov 24, 2021
@lfdebrux lfdebrux deleted the ldeb-replace-keypather branch November 24, 2021 13:07
@domoscargin domoscargin changed the title Replace keypather with lodash.get Replace keypather with lodash.get Nov 29, 2021
@domoscargin domoscargin added this to the v12.0 milestone Dec 2, 2021
@fofr
Copy link
Contributor

fofr commented Dec 14, 2021

As a prototype developer that's re-used keypather in the kit, I'd like to know a bit more about this change.

I like that this fixes the security issue, and lodash looks like a good replacement - is the API similar, and is it pretty much a straight swap?

@domoscargin
Copy link
Contributor

Hi @fofr - we haven't gone into much detail on this in the release notes, since we only used keypather to help out in a utility function and don't promote it for users:

const { get: getKeypath } = require('lodash')

We were specifically interested in get for our case, and we were able to simply swap out keypather for lodash.get with no code changes, but with two bonuses: we got rid of the security vulnerability, and we were able to add lodash to our package.json - it was already a sub-dependency multiple times, and it's a useful library that some of our users make use of.

If you're making use of other keypather functions, or using it in a more advanced way, it'd definitely be worth checking.

At a glance:

lodash doesn't provide the options argument, but otherwise get, set, unset (it's version of del) are largely compatible.

For immutable actions, looks like the lodash/fp module might help.

has and hasIn would be the lodash analogues for keypather's has and in.

For flatten and expand, looks like a bit more work is involved.

@domoscargin domoscargin mentioned this pull request Dec 16, 2021
frankieroberto added a commit to nhsuk/nhsuk-prototype-kit that referenced this pull request Jun 6, 2024
keypather is quite old and has some security issues with one of its dependencies. This replaces it with a function from lodash, which is already installed anyway.

Re-applies same update from the GOV.UK Prototype Kit here: alphagov/govuk-prototype-kit#1155
frankieroberto added a commit to nhsuk/nhsuk-prototype-kit that referenced this pull request Jun 6, 2024
keypather is quite old and has some security issues with one of its dependencies. This replaces it with a function from lodash, which is already installed anyway.

Re-applies same update from the GOV.UK Prototype Kit here: alphagov/govuk-prototype-kit#1155
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.

5 participants