Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

npm doesn't respect .gitignore if ignored folder has an index.js in it. #3968

Closed
jdalton opened this issue Oct 4, 2013 · 10 comments
Closed
Labels

Comments

@jdalton
Copy link
Contributor

jdalton commented Oct 4, 2013

I noticed this behavior.
If my .gitignore looks like:

.DS_Store
legacy
node_modules
mobile

and I run npm pack

the package will contain the folders mobile and legacy if there is an index.js file in them. If I remove the index.js file it will ignore them.

The workaround atm is to include mobile and legacy in the .npmignore file as well.

@robertkowalski
Copy link
Contributor

is anyone able to reproduce this? here is what i am doing:

mkdir bla && cd bla
npm init
echo "ente" >> .gitignore
mkdir ente
touch index.js
touch ente/index.js
cd ..
npm pack ./bla/
tar xvfz bla-0.0.0.tgz

@jdalton
Copy link
Contributor Author

jdalton commented Nov 3, 2013

also do touch .npmignore. then try npm pack again.

@othiym23 othiym23 added the bug label Oct 10, 2014
@peter-mouland
Copy link

old issue, but as it's still open, i'll try to help close it.

What you describe is now the desired behaviour as mentioned in the docs, keeping-files-out-of-your-package:

If you want to include something that is excluded by your .gitignore file, you can create an empty .npmignore file to override it.

@jdalton
Copy link
Contributor Author

jdalton commented Apr 8, 2016

@peter-mouland This is the opposite of that.
These folders should be ignored by npm as per the .gitignore file but are not.

@jdalton
Copy link
Contributor Author

jdalton commented Apr 12, 2016

\cc @zkat

@zkat zkat added this to the Files and Ignores milestone Apr 12, 2016
@zkat
Copy link
Contributor

zkat commented Apr 12, 2016

@jdalton Added to the milestone! Thanks a ton for the ping :)

@zkat
Copy link
Contributor

zkat commented Apr 13, 2016

@jdalton Hey so, I looked at this a little closer. I can't reproduce the behavior you described, for a couple of expected reasons:

  • .npmignore completely overrides .gitignore. There is no merging involved.
  • I assume when you say "it'll ignore mobile", you mean that there's files in there other than index.js. Empty directories are not included.
  • It's possible that mobile was still going to be ignored if there were non-index.js contents, sometime in the past, but I can't see that being a problem with the way npm pack works now. I'll note you opened the issue back in 2013 originally, so I wouldn't be surprised :)

Based on that, and unless I'm misunderstanding your report, this seems to be working as intended. Is that the case?

@jdalton
Copy link
Contributor Author

jdalton commented Apr 13, 2016

.npmignore completely overrides .gitignore. There is no merging involved.

That would explain why an empty .npmignore lets things through that .gitignore is ignoring.
If that's the case, and it's by design, then this issue can be closed.

@zkat
Copy link
Contributor

zkat commented Apr 13, 2016

Indeed. I think you already know about it, but there's a nice wiki page now that goes into detail about how this stuff works.

Since things seem to be working as expected, I'm closing this. There's a couple of issues/PRs that might affect this behavior, too, if you want to keep an eye on them or put in your 2c, specifically #12331 and #11669.

Cheers 💃

@zkat zkat closed this as completed Apr 13, 2016
@jdalton
Copy link
Contributor Author

jdalton commented Apr 13, 2016

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants