duniul / clean-modules

๐Ÿงน Clean up/prune unnecessary files and reduce the size of your node_modules directory.
ISC License
107 stars 6 forks source link

.yarnclean compatibility #3

Closed shellscape closed 3 years ago

shellscape commented 3 years ago

Hey there :wave: Great project, I'm glad that someone else has done this legwork. I would like to know if you'd be willing to add the ability to read globs from a resource/config file, just like .yarnclean. Our ecosystem was setup to use yarn, but we're slowly migrating to pnpm, and our shared .yarnclean file is significant in size - it wouldn't be easy to add each line as a command line flag. What are your thoughts about supporting globs from a file like that?

duniul commented 3 years ago

Glad you like it! ๐Ÿ™ Yeah, I initially considered this myself but decided against it then as I wanted to require as little config as possible and didn't have a real need for it myself at the time. That said I definitely agree that it would be a useful thing for people who want a more controlled cleanup.

It shouldn't be too hard to add as an optional feature (or read e.g. a .cleanmodules file if it's present). In order to make it compatible with .yarnclean's syntax I'd have to make some changes, as picomatch and .yarnclean don't use the same glob syntax.

I'll have a look as soon as I have time ๐Ÿ‘

shellscape commented 3 years ago

No worries about 1:1 compatibility. Having a .cleanmodules config would be worth switching away from .yarnclean even if that comes with a glob conversion.

shellscape commented 3 years ago

For the time being I've implemented a solution where I have a a file (.cleanlist) in which I have newline-separated globs. I run the following script to create a .cleanmodules file of sorts:

"prebuild": "echo \"**/@(`paste -sd '|' .cleanlist`)\" > .cleanmodules",

That generates a file that contains a single line, wrapped in globstar containing all of my globs. And then I call the bin using:

$ pnpx clean-modules -i "$(<.cleanmodules)" -y

Which pipes the contents of the generated .cleanmodules as an inline arg for the command. It works fairly nicely. One big caveat is that extra line breaks and any kind of config-file comment will break it. It'd still be far nicer to be able to specify this, or have the package pick up that there's a file there automatically, but this gets the job done in the mean time.

duniul commented 3 years ago

@shellscape Hey! #5 should solve this in a nice way I think.

It accepts almost exactly the same syntax as .yarnclean, with the exception that directory patterns have to be suffixed with /, /* or /**. This is necessary in order to prevent some file patterns from matching with directories (for example, including *.ts in .yarnclean deletes the whole microevent.ts directory).

To completely control what patterns to include you can also pass --no-defaults, then it will only use what's in .cleanmodules and/or passed with --include/--exclude.

If you have time, please have a look at updated documentation and see if it solves your needs! I'll most likely be merging it and release a new version next week after having a last look ๐Ÿ‘

duniul commented 3 years ago

:tada: This issue has been resolved in version 2.0.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

shellscape commented 2 years ago

Wanted to stop in and say thanks for --glob-file. Was able to eliminate a step of compiling a file into something that -i would accept. Much appreciated.