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

Refactor to lodash-es #5294

Closed
Tracked by #5205
jeddy3 opened this issue May 12, 2021 · 8 comments
Closed
Tracked by #5205

Refactor to lodash-es #5294

jeddy3 opened this issue May 12, 2021 · 8 comments
Labels
status: ready to implement is ready to be worked on by someone type: refactor an improvement to the code structure
Milestone

Comments

@jeddy3
Copy link
Member

jeddy3 commented May 12, 2021

Using https://webuild.envato.com/blog/automating-the-migration-of-lodash-to-lodash-es-in-a-large-codebase-with-jscodeshift/

@jeddy3 jeddy3 added status: ready to implement is ready to be worked on by someone type: refactor an improvement to the code structure labels May 12, 2021
@jeddy3 jeddy3 added this to the future-major milestone May 12, 2021
@jeddy3 jeddy3 mentioned this issue May 12, 2021
30 tasks
@stephenwade
Copy link
Contributor

stephenwade commented May 21, 2021

I'll be happy to take this on. I think this is blocked on #5291 – I tried to do this now but found errors like this one when running the test suite:

    Details:

    /Users/stephen/git/stylelint/node_modules/lodash-es/lodash.js:10
    export { default as add } from './add.js';
    ^^^^^^

    SyntaxError: Unexpected token 'export'

By the way, just switching to importing individual files from Lodash reduces the bundle size from 855 KB to 822 KB (I used the instructions in #5291 (comment) to compare bundle sizes):

-const _ = require('lodash');
+const get = require('lodash/get');
+const isEmpty = require('lodash/isEmpty');
+const last = require('lodash/last');

https://github.com/stylelint/stylelint/compare/v14...stephenwade:lodash-slash?expand=1

Screenshot of Bundle Buddy. On the left is the v14 branch. On the right is my lodash-slash branch.

@m-allanson
Copy link
Member

@stephenwade I have some unfinished work (from last year) with stylelint and lodash. Maybe there’s something you can borrow from it? https://github.com/m-allanson/codemod-lodash-requires

@jeddy3
Copy link
Member Author

jeddy3 commented May 21, 2021

I'll be happy to take this on.

Fantastic.

I think this is blocked on #5291

Yes, that's right. Migrating to lodash-es will likely be one of the last things we do before releasing 14.0.0.

I have some unfinished work (from last year) with stylelint and lodash. Maybe there’s something you can borrow from it? https://github.com/m-allanson/codemod-lodash-requires

I used your codemod yesterday while conducting my own tests 😄. Worked like a charm.

I can't find a definitive answer for which module formats is best. It looks to be either:

  • import get from "lodash/get"
  • import { get } from "lodash-es"

The latter seems to result in a leaner bundle in benchmarks.

Does anyone know the definitive answer?

@ybiquitous
Copy link
Member

Related to #4412?

@jeddy3
Copy link
Member Author

jeddy3 commented May 21, 2021

Yes, once we've migrated we can pick up that issue to see if any lodash functions can be replaced with native ones.

I suspect once 14.0.0 is out, there'll be quite a few issues in the backlog that are either fixed, unblocked and no longer relevant. We should do a run-through at some point after release.

@stephenwade
Copy link
Contributor

I just landed eslint/eslint#14287 to remove Lodash from ESLint. I'd be happy to work on the same for Stylelint.

@stephenwade
Copy link
Contributor

I can't find a definitive answer for which module formats is best. It looks to be either:

import get from "lodash/get"
import { get } from "lodash-es"
The latter seems to result in a leaner bundle in benchmarks.

Does anyone know the definitive answer?

I searched for a while yesterday but found conflicting opinions online. When we finish #5291, we can see what the module sizes look like for this project.

@jeddy3
Copy link
Member Author

jeddy3 commented May 24, 2021

I just landed eslint/eslint#14287 to remove Lodash from ESLint.

@stephenwade That's a fantastic piece of work.

If you'd like to work on #4412, then that would be fabulous.

I don't think it's blocked by anything and will either:

  • reduce the amount of lodash we eventually move to either lodash-es or individual modules (e.g. lodash/get)
  • remove the need to do it entirely

Please branch off v14 (targeting "node": "^12.20.0 || ^14.13.1 || >=16.0.0"), which will let you know which native features are available to you (and linted by ESLint). It's probably best to do separate pull requests for each lodash function you replace, to make reviewing a bit easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready to implement is ready to be worked on by someone type: refactor an improvement to the code structure
Development

No branches or pull requests

4 participants