Skip to content

Replace all lodash.* packages - #612

Merged
valscion merged 9 commits into
webpack:masterfrom
SukkaW:replace-loadsh-usage
Sep 13, 2023
Merged

valscion merged 9 commits into
webpack:masterfrom
SukkaW:replace-loadsh-usage

Conversation

@SukkaW

@SukkaW SukkaW commented Sep 12, 2023 •

Copy link
Copy Markdown
Contributor

The PR replaces all lodash.* packages.

  • lodash.escape -> html-escaper
  • lodash.flatten -> a modified version of arr-flatten
  • lodash.debounce -> debounce
  • lodash.pullall -> Array.prototype.filter
  • lodash.uniqby -> Set + Array.prototype.filter
  • lodash.invokemap -> Object.values

Comparison

Running npm i --omit=dev --omit=optional against webpack-contrib/webpack-bundle-analyzer:master:

image

Running npm i --omit=dev --omit=optional against sukkaw/webpack-bundle-analyzer:repalce-lodash-usage:

image

The installation size becomes even smaller!

@SukkaW SukkaW mentioned this pull request Sep 12, 2023
@SukkaW
SukkaW force-pushed the replace-loadsh-usage branch from ed911d0 to 609b4d5 Compare September 12, 2023 15:15
@stof

stof commented Sep 12, 2023

Copy link
Copy Markdown

For throttle and debounce, I'm using https://www.npmjs.com/package/@github/mini-throttle personally. It is small, efficient and maintained.

@SukkaW

SukkaW commented Sep 12, 2023 •

Copy link
Copy Markdown
Contributor Author

For throttle and debounce, I'm using https://www.npmjs.com/package/@github/mini-throttle personally. It is small, efficient and maintained.

I was thinking about using perfect-debounce from the unjs community (https://www.npmjs.com/package/perfect-debounce). However, webpack-bundle-analyzer still targets Node.js 10.13.0+ and I was afraid of breaking it. So I chose the debounce package instead. Once the Node.js 10 support has been dropped, we can switch to a more modern package.

@SukkaW
SukkaW marked this pull request as ready for review September 12, 2023 16:14
@SukkaW SukkaW changed the title (WIP) Drop all lodash.* packages Replace all lodash.* packages Sep 12, 2023
@stof

stof commented Sep 13, 2023

Copy link
Copy Markdown

Do you also want to replace the packages used as dev dependencies ?

@valscion

Copy link
Copy Markdown
Collaborator

Do you also want to replace the packages used as dev dependencies ?

Hmm, I don't know about that. If we do decide to go that route, let's at least split that work to its own PR to make this diff smaller.

@valscion valscion left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This looks good to me!

Any changes you want to add or is this ready to go?

EDIT: Oh right, I forgot about that packageManager comment I had pending. That would need to be resolved first.

Comment thread package.json
"engines": {
"node": ">= 10.13.0"
},
"packageManager": "[email protected]",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hmm if I've understood the corepack docs correctly, having a packageManager with npm in it is of no use.

Is this needed for some purpose other than that?

@SukkaW SukkaW Sep 13, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@valscion

By default npm is already shipped with Node.js, so you don't need corepack to install npm, that's why the docs said something of "no use". But, the field still helps when corepack is enabled and a specific version of npm is needed.

I have been using the latest version of npm (which uses the lockfile v2/v3) for a while. However, the webpack-bundle-analyzer still uses the v1 version of package-lock.json and I need to use an older version of npm.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Okay cool! I didn't know that this allowed corepack to use an older version of npm. This is useful!

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@SukkaW SukkaW Sep 13, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

based on https://nodejs.org/api/corepack.html#how-does-corepack-interact-with-npm, I don't think corepack will install an older npm version

But for some reason, it does work for me though. I am able to use the 6.x version of npm to generate the correct package-lock.json that won't bloat the change.

And if I cd into other projects the npm automatically reverted back to the latest version.

@SukkaW SukkaW Sep 13, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@stof I might have found out why corepack works for me. It might have something to do with my special setup:

  • I use fnm, a tool like nvm, to manage my Node.js versions
  • Though not recommended, I've manually specified NPM_CONFIG_PREFIX so npm will install global packages to my specific location (instead of the default location)
  • I've upgraded my npm version with npm i npm -g, so my npm is located inside NPM_CONFIG_PREFIX instead of the default location.
  • In my $PATH, I add the Node.js path before the NPM_CONFIG_PREFIX, so the shell will choose npm from corepack when available.
image

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Okay, so a special setup is the reason.

I don't think having the packageManager line hurts in any way, though. Or do you think it's a bad idea to have in the repository?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Okay, so a special setup is the reason.

I don't think having the packageManager line hurts in any way, though. Or do you think it's a bad idea to have in the repository?

Yes, it doesn't hurt.

This packageManager field has no effect on the package's users. Maintainers/contributors who don't have corepack won't be affected either. Maintainers/contributors who have enabled corepack without a specific setup will have an extra copy of corepack's npm installed, it just won't be chosen by the shell (The shell will prefer the original npm without the setup).

@valscion
valscion merged commit f01056a into webpack:master Sep 13, 2023
@valscion

Copy link
Copy Markdown
Collaborator

Released in v4.10.0! ☺️

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.

3 participants