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

fix for including excluded and vice versa #1067

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

adrianstephens
Copy link

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.

@adrianstephens
Copy link
Author

@microsoft-github-policy-service agree

@benibenj
Copy link
Contributor

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 files property. If they do, then we should add support for this. If they don't we need to make sure to think this through. It might still make sure to support this as we do not support combining "files" and ".vscodeignore" which npm does.

If we decide on taking this we will need to add more tests here.

@adrianstephens
Copy link
Author

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? :)

@adrianstephens
Copy link
Author

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:

*
!dist/**/*.js
!assets/*
assets/*.psd

because the excludes are processed before the includes, it becomes

*
assets/*.psd
!dist/**/*.js
!assets/*

so the psd clause is overridden

@AshtonStephens
Copy link

@benibenj I added a file to the unit tests with explicit exclusion in the package.json file.

	"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 foo path but is excluded based on the global filename match.

manifestFiles
├── LICENSE
├── README.md
├── foo
│   └── bar
│       ├── exclude.me <-- I added and is excluded
│       └── hello.txt
├── foo2
│   └── bar2
│       ├── ignore.me
│       └── include.me
├── foo3
│   └── bar3
│       └── hello.txt
├── logger.log
└── package.json

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 npm behavior and I'm looking at their documentation and I see specifically the last bullet here states that doing exclusions with ! with the files parameter is undefined.

  • "The consequences are undefined" if you try to negate any of the files entries (that is, "!foo.js"). Please don't. Use .npmignore.

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 npm team gets bug reports on this.

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 ! is undefined, and therefore exclusion falls into valid behavior when the behavior is undefined. So, future proofing the extension, I think it makes the most sense to consider merging it.

Copy link

@AshtonStephens AshtonStephens left a 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.

Copy link

@wileyj wileyj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@benibenj benibenj added this to the November 2024 milestone Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants