-
Notifications
You must be signed in to change notification settings - Fork 213
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
fix for including excluded and vice versa #1067
base: main
Are you sure you want to change the base?
Conversation
@microsoft-github-policy-service agree |
Thank you for looking into this. We try to follow the behaviour of npm packages to some degree and it's currently unclear to me if npm supports exclude patterns in their If we decide on taking this we will need to add more tests here. |
It was unclear to me too - all I saw in the documentation was that "File patterns follow a similar syntax to .gitignore, but reversed.", and unofficial sources like https://medium.com/trabe/control-what-you-publish-inside-your-npm-packages-e3ec911638b8 I assumed not supporting files and .vscodeignore together was a deliberate attempt to avoid confusion; and if they both have the same expressive power why do you need the .vscodeignore at all (other than for legacy reasons)? When you say 'we will need to add more tests' is the 'we' me or you? :) |
Just wanted to add, regardless of having exclude patterns in the files property, the real problem I was trying to fix was that I couldn't find a way to tell vsce that I wanted all the files in the 'assets' folder except the psds. In .vscodeignore:
because the excludes are processed before the includes, it becomes
so the psd clause is overridden |
@benibenj I added a file to the unit tests with explicit exclusion in the "files": [
"foo",
"!**/exclude.me", <-- I added
"foo2/bar2/include.me",
"*/bar3/**",
"package.json",
"LICENSE",
"README.md"
] Then I added this file that's implicitly included by the
With these changes the tests all pass. Are there any other tests you'd like to see on this feature? It definitely makes sense to be matching the
I was going to say the documentation is inconsistent, but it actually consistently says this. AI tools, Gemini specifically, seem to very much disagree, so I think it's a matter of time before the In the worst case we include this and we end up supporting something in vscode better than the actual tool, which is potentially misleading until the tool fixes it. On the other hand, it seems to me it's a matter of time until this is supported by npm, especially with Gemini being confused about it, and the ramifications of it becoming supported in npm and the vscode extension failing that is worse than the alternative. The docs say including an excludes with a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reviewed and then added the test. Considering the test is very little and I did the reformatting I was going to request, I'm approving.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I expanded the test to check if it works as expected. It does not.
If I exclude a folder and include files in that folder, the file will be included which it should not.
It should first consider all include patterns (do not start with !) and then based on the files which are included, should exclude all files matching the exclude patterns (start with !)
I don't know if there are definitive rules about how include/exclude rules work, especially in a situation where there are two lists working opposite to each other. My feeling was that the intuitive thing was to take the clauses in order, so I want A, but I don't want B, but I do want C, etc. It was the sorting of clauses that made 'everything in assets except psd's' impossible to express. |
I strongly believe that the order in which the patterns are added to the |
Using .vscodeIgnore in order to make it work like an include list I started with 'ignore everything' and then built up what I wanted; but the sorting prevented that from working. This change was initially just to fix that; adding '!' support for package.json's 'files' was secondary. The .gitignore manual says, 'An optional prefix "!" which negates the pattern; any matching file excluded by a previous pattern will become included again.'. I don't know how accurately that matches their implementation, but it certainly sounds like they're maintaining the order. Sorting precludes .vscodeIgnore from expressing 'everything in assets except psds'; the 'files' list could still do it, but not 'everything in assets except psds, but I do want icon.psd'. |
I reported this earlier today, but then thought I'd have a go fixing it, and... behold!
I won't be offended if you don't use this - I am not a javascript expert.