-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[Bug?]: .npmignore is not processed like gitignore; **
doesn't match files at the root, order not respected
#5872
Comments
I'll check that - I think Git is sometimes weird with
Yes, that's a bug in npm (and pnpm, since it shells out to npm for packing); they don't actually behave like a gitignore:
git status (it doesn't see
npm pack --dry-run (it sees
We try to follow the npm behaviour when possible, but since it doesn't even follow its own documentation it's quite difficult to be sure that there's 100% parity 😅 |
For now I added some tests and a couple of TODOs in #5873. |
**What's the problem this PR addresses?** #5872 made me notice that we have few tests covering how the `*` / `**` patterns are interpreted. **How did you fix it?** This diff fixes that by adding a couple of tests, along with comments on the few places where we seem to diverge from npm. It doesn't try to change the pack list generation, just to increase its coverage and make it easier to add more tests in the future. **Checklist** <!--- Don't worry if you miss something, chores are automatically tested. --> <!--- This checklist exists to help you remember doing the chores when you submit a PR. --> <!--- Put an `x` in all the boxes that apply. --> - [x] I have read the [Contributing Guide](https://yarnpkg.com/advanced/contributing). <!-- See https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released for more details. --> <!-- Check with `yarn version check` and fix with `yarn version check -i` --> - [x] I have set the packages that need to be released for my changes to be effective. <!-- The "Testing chores" workflow validates that your PR follows our guidelines. --> <!-- If it doesn't pass, click on it to see details as to what your PR might be missing. --> - [x] I will check that all automated PR checks pass before the PR gets reviewed.
Apologies, I know it's bad timing, we just so happened to do the big DT migration and are working on the small stuff.
Hm, in my testing using an npmignore similar to my repro, all package managers behaved as expected except yarn on this front. I'll have to retest and make sure that I'm actually observing all of the files I'm intending to include in all of these cases. FWIW this isn't blocking or anything; the DT publisher copies files of its choosing out of the DT checkout into a tempdir for publishing, so we can always publish exactly what we want. But, a soft goal with the new "we actually have |
Ah, I see what you mean in that example. I guess this is a case where the "directories cannot be added back" is not being followed by npm, since The best real-world example I have is https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/ember-data with: *
!**/*.d.ts
!**/*.d.cts
!**/*.d.mts
!**/*.d.*.ts
/v2/
/v3/ Giving me tar contents of:
npm 6-10 and pnpm agree, but yarn 1-4 don't exclude the dirs. |
Self-service
Describe the bug
.npmignore
is theoretically supposed to have identical semantics togitignore
. However, in testing stuff out for DefinitelyTyped (so that packing works for any package manager people may run on the repo), I noticed that yarn's implementation doesn't match other package managers and git. https://git-scm.com/docs/gitignore#_pattern_formatFirst,
**/*.d.ts
should be able to match a.d.ts
file at the root, but only matchesd.ts
files within other packages.**
is documented as allowing "no match at all" per the gitignore docs.Secondly, the order isn't respected; if I exclude something, it should be possible to re-include things (with some exceptions). See https://stackoverflow.com/a/24678813 and the docs:
On DefinitelyTyped, we want to have ignored files something like this:
Which is to say for a package, include only dts files (there is also cts/mts/etc but I am omitting them for brevity), but not their child version packages. The above works for npm and pnpm, but not yarn at any version.
Skimming, I think the latter case comes down to the include/exclude just being two lists, but I'm no expert.
berry/packages/plugin-pack/sources/packUtils.ts
Line 204 in ab2e845
To reproduce
Here is a repo that shows things: https://github.com/jakebailey/yarn-npmignore-ordering
Environment
Additional context
No response
The text was updated successfully, but these errors were encountered: