antoine-coulon / skott

All-in-one devtool to automatically analyze, search and visualize project modules and dependencies from JavaScript, TypeScript (JSX/TSX) and Node.js (ES6, CommonJS)
MIT License
669 stars 25 forks source link

Multiple Ignore Patterns #79

Closed rypete closed 4 months ago

rypete commented 1 year ago

I have a few different patterns I want to ignore via --ignorePatterns but it seems this can only accept one pattern? It would be great if this could accept an array similar to --fileExtensions

jakebiesinger commented 1 year ago

I also happened to need this today... it's hacky, but you skott is using https://www.npmjs.com/package/minimatch under the hood, so you can use {} with comma-separated lists, e.g.,

--ignorePattern '{src/file1.ts,src/path/to/file2.ts,src/api/**/*.ts}'

Note the surrounding ' since your shell may try to interpolate otherwise.

jakebiesinger commented 1 year ago

I'm now using a silly command to grab this from a file if it exists:

npx skott --fileExtensions=.ts,.tsx --showCircularDependencies --ignorePattern '{'$([[ -e .skottSkips ]] && cat .skottSkips)'}' --displayMode raw

you shove your list into a file .skottSkips and it'll be pulled in

rypete commented 1 year ago

The above are very helpful, thanks. What I ended up doing was temporarily putting the paths I wanted to ignore into my .gitignore file before running skott.

antoine-coulon commented 1 year ago

Hello folks and thanks for opening that issue @rypete!

"ignorePattern" is a pretty new feature for skott so I wanted to collect few feedbacks about the ability of ignoring specific set of files before going further as there is currently the "ignorePattern" option, the "fileExtensions" option that can be also considered as a filter even though it does not really allow fine grained file filtering and also the ".gitignore" support.

If you guys are facing some use cases where you would want multiple patterns to be provided at once I can definitely work on that to make skott support it.

Are you both @jakebiesinger @rypete using skott via the API? For the CLI it would probably require a skott config file as I'm afraid for the CLI itself it would be too verbose and error prone to allow multiple ignore patterns.

FYI I'm currently on vacation till the end of the next week so don't expect quick replies until there but I will catch up asap :)

jakebiesinger commented 1 year ago

I'm using skott via the CLI and would love it if there were a config file I could set and forget.

For the large typescript codebase I'm working in now, we prevent PRs containing circular imports everywhere except in a set of "context" files, where we set up helper methods that dynamically import at method call time via await import ('./some/file').doSomeThing().

Skott has found literally hundreds of circular imports that madge missed due to some shortcomings in how they're parsing extended tsconfig files (https://github.com/pahen/madge/issues/322) so we're cutting over to use skott everywhere.

antoine-coulon commented 1 year ago

Glad to hear that it helps you out!

I'll work asap on introducing a skott config file that will enable support for all API options when using the CLI (+ multiple ignore patterns that will be available both from the CLI using the config file or directly through the API).

If you ever think of other feature suggestions that could be useful for you or if you ever encounter any issues let me know, I'm trying hard to make skott a tiny tool that fits developers needs and expectations (it's only the beginning) so I'm happy when I get feedbacks and feature requests like this :)

rypete commented 1 year ago

I'm using the CLI but not the config file. My use case is a lot simpler than @jakebiesinger and I only needed it for a showcase demo.

antoine-coulon commented 1 year ago

Thanks for the input, by the way the config file is not yet available, we were just discussing about the possibility of implementing it.

Without that config file I hardly see how we could easily provide multiple ignore patterns using the CLI

rypete commented 1 year ago

One way might be, and what I also tried, was to use the --ignorePatterns flag multiple times. I noticed the underlying system turned it into an array. This might be useful but I will of course use whatever you come up with.

Something like skott --ignorePatterns="**/*.test.ts" --ignorePatterns="**/*.js" etc

antoine-coulon commented 1 year ago

Could actually be one way to do it, didn't think about that actually, thanks!

I'm back from vacation so you'll get updates pretty soon, stay tuned!

eppisapiafsl commented 1 year ago

You need to use brackets { } to ignore multiple files

This worked for me

--ignorePattern='{commons/Store/{Redux/types/StateMachineContext.ts,ExerciseTherapySessionState/actions/transition.ts},commons/Utils/TestMocks/Provider.tsx}'
antoine-coulon commented 1 year ago

Thanks for the tip @eppisapiafsl

This is what can be used until I investigate in providing a way to stack multiple patterns without losing too much DX. Hopefully we'll find a middle ground between easy configuration and nice DX still.

antoine-coulon commented 4 months ago

Hello guys,

I was finally able to land support for multiple ignore patterns. It will be released in the next version, that is skott@0.35.0.

Multiple patterns are supported through the CLI by having multiple occurrences of the --ignorePattern parameter e.g. skott --ignorePattern=X --ignorePattern=Y or supported within the API using a simple array skott({ ignorePatterns: ["test/**/*.js", "examples/**/*.js" })

Feel free to re-open the issue if you're still encountering issues after the release