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

Huge 27.4 MB install size #100

Closed
jaydenseric opened this issue Nov 3, 2021 · 2 comments
Closed

Huge 27.4 MB install size #100

jaydenseric opened this issue Nov 3, 2021 · 2 comments
Assignees
Labels

Comments

@jaydenseric
Copy link

@trivago/prettier-plugin-sort-imports (currently v3) has a huge 27.4 MB install size:

https://packagephobia.com/result?p=@trivago/[email protected]

This is unnecessarily inefficient. Personally, introducing this complexity and all the risks it entails to my projects outweighs the benefits and others might feel the same.

The first thing that jumps out is that all of lodash is being installed:

"lodash": "4.17.21"

lodash being used at all is a smell; almost always there is a native way to do the same simple things without introducing a complicated dependency. Any of the more complicated things lodash might genuinely help with, like deep comparison and cloning, are also a smell. Almost always there is a more elegant way to write the code to avoid deep comparisons and cloning. If there really is no way around doing those complicated operations, then never install the full lodash package to use just a few exports. Install separate lodash packages for each utility used to avoid installing all the unused stuff. Do these things right, and > 1 MB can be shaved off the install size and potentially runtime memory usage could be reduced.

It doesn't appear right to have the @types/lodash TypeScript types for lodash installed as a production dependency:

"@types/lodash": "4.14.168",

839 kB could be shaved of the install size by moving it to dev dependencies:

https://packagephobia.com/result?p=@types/[email protected]

A low hanging fruit (which you have already identified in #96) is to prevent all the junk like tests, docs, examples, markdown files, etc. from being published:

https://unpkg.com/browse/@trivago/[email protected]/

Can any of these Babel dependencies be avoided or substituted for lighter options?

"@babel/core": "7.13.10",
"@babel/generator": "7.13.9",
"@babel/parser": "7.14.6",
"@babel/traverse": "7.13.0",
"@babel/types": "7.13.0",

I haven't written a Prettier plugin before so I'm assuming there is no way to use the AST Prettier already generated? Does Prettier not accept an AST and do the string generation itself?

@ayusharma ayusharma self-assigned this Nov 3, 2021
@ayusharma
Copy link
Collaborator

Hi @jaydenseric , First of all, thanks for the investigation. ❤️

It doesn't appear right to have the @types/lodash TypeScript types for lodash installed as a production dependency:

yes, we will move it to the devDependencies.

Can any of these Babel dependencies be avoided or substituted for lighter options?

We already thought about removing babel and use swc when we will have more time.

About lodash,

As the project is the development tool, I think it does not hurt much. We will look for other alternatives.

@ayusharma
Copy link
Collaborator

ayusharma commented Nov 3, 2021

I'm assuming there is no way to use the AST Prettier already generated.

As far as I know, prettier is an opinionated code formatter, it does not allow writing a plugin which is already built in the prettier. So we can only write pre-processors to the prettier.

Does Prettier not accept an AST and do the string generation itself?

It does not accept an AST and it accepts the generated code as a string.

ayusharma added a commit that referenced this issue Nov 3, 2021
@ayusharma ayusharma added v3 and removed investigation labels Nov 4, 2021
ayusharma added a commit that referenced this issue Nov 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants