ai / size-limit

Calculate the real cost to run your JS app or lib to keep good performance. Show error in pull request if the cost exceeds the limit.
MIT License
6.48k stars 1.82k forks source link

Global installation with plugin support #329

Closed zavodnyuk closed 1 year ago

zavodnyuk commented 1 year ago

I am encountering an issue while trying to use the @size-limit/file plugin locally without installing all the dependencies in my project. Currently, I am utilizing the size-limit library in conjunction with a file plugin. In my project's Gitlab CI/CD configuration, I have a job that verifies if the built bundle size is under a specified threshold. However, I would like to have a separate job where I can pass the bundle as an artifact, and then run size-limit using that dedicated job.

The problem I am facing is that I do not want to pass the entire node_modules directory as cache nor install all the dependencies from scratch in the dedicated job. When I attempt to install both size-limit and @size-limit/file globally and run size-limit inside the project folder, it returns an error stating that it could not find the file plugin locally. I noticed a screenshot in the README that suggests I might be able to use size-limit through npx, but unfortunately, it does not work for me.

I would appreciate any suggestions or guidance on how I can avoid running npm install in this job and installing all the dependencies while still being able to utilize the @size-limit/file plugin successfully. Imagine I have bundle files and only thing I want is to fail the job if file size if above the limits.

Thank you for your assistance!

ai commented 1 year ago

I think global install is antipattern. What reasons do you have for that in your case?

zavodnyuk commented 1 year ago

I want to have separate gitlab jobs in pipeline like Build -> Check bundle size . Each job is isolated, so to be able to run size-limit I need whether install all dependencies (which takes around 5 minutes in my project) or cache node_modules and pass to the next job (takes around 3 minutes), though I only want to check file size. So eventually I want to have separate jobs and optimize dependency installation by limiting installation only specific packages. It should improve overall job time and resources. Btw, why it's antipattern?

ai commented 1 year ago

How do you use lock file for global install?

zavodnyuk commented 1 year ago

How do you use lock file for global install?

I don't really think I need any kind of lock file, that's why I was thinking about global installation. I just want to check file size with size-limit lib config file and output experience

ai commented 1 year ago

Without lock file the Size Limit results can be different (esbuild update can change size changes). Also, we are not talking about security risks.

I still think it is a bad practice.

For your case, you can install Size Limit locally for size task:

npm install --save-dev @size-limit/file size-limit
npx size-limit