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

Rename .gitignore to .npmignore in package if no .npmignore found #1862

Closed
isaacs opened this issue Dec 9, 2011 · 16 comments
Closed

Rename .gitignore to .npmignore in package if no .npmignore found #1862

isaacs opened this issue Dec 9, 2011 · 16 comments

Comments

@isaacs
Copy link
Contributor

isaacs commented Dec 9, 2011

When packaging up a folder, if there's a gitignore file and no .npmignore file, add it to the tarball as .npmignore.

Always exclude .gitignore files from packages.

This is to better support the "check node_modules into git" approach.

@glenjamin
Copy link
Contributor

+100 on this.

I've lost count of the number of times I've managed to check in a dependency without realising that its dependencies are missing!

@isaacs isaacs closed this as completed in 2212118 Dec 14, 2011
@cespare
Copy link

cespare commented Apr 11, 2012

This "feature" threw me off for a long time when trying to package my first node library.

I am generating the code from coffeescript, so while my package.json contains this:

"directories": {
  "lib": "./lib/coffee-scope"
}

my .gitignore has a /lib/ entry (because I don't want the generated code checked in). The result is that the packaged library is missing /lib/ and is therefore completely broken.

Regardless of whether my approach is ideal, the behavior is very confusing. I wouldn't expect that my .gitignore would have an effect on how npm behaves.

I would suggest one or more of the following changes:

  • Don't automatically rename .gitignore to .npmignore.
  • If you do rename .gitignore to .npmignore, remove entries which would exclude files and directories specifically required in package.json.
  • Document this feature in npm help json. I read that help file thoroughly and explicitly chose not to include a .npmignore file for my project, and only realized that this .gitignore magic was happening after I found this github ticket.

@philc
Copy link

philc commented Apr 11, 2012

+1 @cespare . Please reopen for consideration.

@isaacs
Copy link
Contributor Author

isaacs commented Apr 11, 2012

The directories.lib field is completely for human consumption. npm does not do anything interesting with it.

.gitignore files are only renamed to .npmignore when they're treated as such. If a .npmignore file is already present, then .gitignore files are excluded. This is to make it easier to check node_modules folders into source control for deployed apps.

Doc patches are always welcome, but the behavior is not going to change.

@cespare
Copy link

cespare commented Apr 12, 2012

Thanks for clarifying, @isaacs.

I made a pull request for a tweak to the docs that would have helped me out, at least.

I can see why removing .gitignore might be desirable, assuming you want to encourage people to check in their node_modules folder, but this

.gitignore files are only renamed to .npmignore when they're treated as such.

doesn't really make sense to me. How can you assume that the files that people want git to ignore are the same that they don't want included in their package?

@isaacs
Copy link
Contributor Author

isaacs commented Apr 12, 2012

Given the number of complaints I'd received from people who accidentally published stuff that's .gitignore'd, vs the number of complaints from people who accidentally didn't publish stuff that's .gitignore'd once the change was made, yes, the data is overwhelmingly not in your favor here. There's no way to not confuse anyone. Even that sentence is sort of confusing.

@JaysonRaymond
Copy link

This design really becomes a bit draconian when creating yo modules to setup new projects - particularly where you want to include a .gitignore file - this hidden 'feature' breaks my yo generator that has a .gitignore (by renaming it to .npmignore).

Besides, I don't want node_modules checked in - I want to force developers to define explicit versions in their package.json and require an 'npm install' upon code checkout to assure packages are explicitly listed or the build fails (particularly on the build server). We have a private repo and caching proxy to assure these dependencies aren't lost and our more frequent installs don't impact the public npm repo.

kethinov added a commit to rooseveltframework/roosevelt that referenced this issue May 4, 2014
Closes #10

npm calls it a feature. I call it a bug.
npm/npm#1862
kaelzhang pushed a commit to cortexjs-legacy/cortex-playground that referenced this issue Jun 9, 2014
kaelzhang pushed a commit to cortexjs-legacy/cortex-playground that referenced this issue Jun 9, 2014
npm calls it a feature, while I call it a bug. npm/npm#1862;
sorrycc added a commit to spmjs/spm that referenced this issue Jun 15, 2014
kaelzhang pushed a commit to cortexjs-legacy/cortex-scaffold-generator that referenced this issue Jun 17, 2014
@callumacrae
Copy link

This is breaking my yeoman generator, as well: Lostmyname/generator-component#1

Is there any reason to completely remove the .gitignore? It only saves a few bytes, but it messes up Yeoman and ember generators (see some of the issues above).

@kosz
Copy link

kosz commented Jan 8, 2015

Yepp also breaking my generator. I have a templates/.gitignore file, which in fact is just a template file. I guess I should just rename it to gitignore in it's template form. Either way, a bit annoying to have third party code screw with your files.

@UltCombo
Copy link

UltCombo commented Feb 1, 2015

@JaysonRaymond @callumacrae @kosz Can we center the generators discussion at #7252? It would be nice if we could come up with a solution that solves both use cases.
Thanks!

brodycj pushed a commit to brodycj/cordova-create that referenced this issue May 10, 2017
NOTE: This implementation is a workaround for the
npm .gitignore/.npmignore behavior discussed in:
- npm/npm#1862
- npm/npm#3763
- npm/npm#7252
brodycj pushed a commit to brodycj/cordova-create that referenced this issue May 15, 2017
NOTE: This implementation is a workaround for the
npm .gitignore/.npmignore behavior discussed in:
- npm/npm#1862
- npm/npm#3763
- npm/npm#7252
suzuki-shunsuke added a commit to suzuki-shunsuke/generator-ss-ansible-playbook that referenced this issue Aug 27, 2017
The package is broken because `npm publish` has renamed `gitignore` to `.npmignore`.

* npm/npm#1862
* npm/npm#7252
jimf added a commit to jimf/gen-new-project that referenced this issue Nov 10, 2017
npm renames .gitignore to .npmignore in the event that a .npmignore file
doesn't exist. This is indented behavior on npm's part. Add special
handling for this case.

See npm/npm#1862
ZauberNerd added a commit to xing/hops that referenced this issue Nov 22, 2017
Because npm never publishes a `.gitignore` file, we need to rename
our `.gitignore` files in our templates to `_gitignore` and have the
`hops-local-cli` `init()` method rename it again, after unpacking.

Read more about it: npm/npm#1862

Related to: #275
dmbch pushed a commit to xing/hops that referenced this issue Nov 22, 2017
Because npm never publishes a `.gitignore` file, we need to rename
our `.gitignore` files in our templates to `_gitignore` and have the
`hops-local-cli` `init()` method rename it again, after unpacking.

Read more about it: npm/npm#1862

Related to: #275
sgratzl added a commit to phovea/generator-phovea that referenced this issue Dec 22, 2017
brodycj pushed a commit to brodycj/cordova-create that referenced this issue May 30, 2018
NOTE: This implementation is a workaround for the
npm .gitignore/.npmignore behavior discussed in:
- npm/npm#1862
- npm/npm#3763
- npm/npm#7252
brodycj pushed a commit to brodycj/cordova-create that referenced this issue May 30, 2018
XXX TODO: USE fs-extra function instead,
XXX WAITING FOR apache#14 to be merged

NOTE: This implementation is a workaround for the
npm .gitignore/.npmignore behavior discussed in:
- npm/npm#1862
- npm/npm#3763
- npm/npm#7252
ghoullier added a commit to zetapush/zetapush that referenced this issue Jun 4, 2018
affects: @zetapush/create
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests