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

[RRFC] .npmignore pragma to include .gitignore #363

Open
ljharb opened this issue Apr 7, 2021 · 4 comments
Open

[RRFC] .npmignore pragma to include .gitignore #363

ljharb opened this issue Apr 7, 2021 · 4 comments

Comments

@ljharb
Copy link
Contributor

ljharb commented Apr 7, 2021

Motivation ("The Why")

While opinions differ, I consider "files" to be dangerous, since I have zero concern for accidental publishing but I have infinite concern for accidental breakage. (Let's avoid debating this)

When using .npmignore, one has to remember to start by cp .gitignore .npmignore, and then later, to keep those in sync, since unfortunately npm ignores .gitignore when .npmignore is present. This is a maintenance burden and is error-prone over time.

Example/How/Desired Behavior

These examples show a hypothetical where "coverage data" is ignored by both git and npm, but the "dist" folder (build output) is ignored by git but included in npm.

Current:

.gitignore

coverage/ # coverage data
dist/ # build output

.npmignore

coverage/ # coverage data
Potential:

.gitignore

coverage/ # coverage data
dist/ # build output

.npmignore

<include gitignore> # ideally something that would make the npm CLI crash prior to supporting this feature
!dist/ # unignore build output

The advantage would be that additions to .gitignore no longer need to be propagated to .npmignore. The disadvantage would be that removals from .gitignore now do need to be propagated, but the explicit opt-in would mean that's expected.

Thoughts?

@isaacs
Copy link
Contributor

isaacs commented Apr 12, 2021

I think this is pretty useful. The challenge will be to find a syntax that would indeed make the npm CLI crash prior to supporting this feature. Globs are very accommodating, unfortunately, since filenames on posix systems can contain almost any character. I don't see anything offhand that will make ignore-walk throw an error. Anything that doesn't parse as a glob is just treated as part of the filename being matched.

@ljharb
Copy link
Contributor Author

ljharb commented Apr 13, 2021

Another alternative would be to make a new filename, that when present causes npmignore to be ignored - but i have no brilliant suggestions for a name for it :-/

@darcyclarke darcyclarke added the Agenda will be discussed at the Open RFC call label Apr 14, 2021
@isaacs
Copy link
Contributor

isaacs commented May 5, 2021

Another alternative would be to make a new filename, that when present causes npmignore to be ignored - but i have no brilliant suggestions for a name for it :-/

Hm, not seeing how that would fix the make-work of adding something to both .gitignore and .npmignore. I'm reminded somewhat of https://xkcd.com/927/ 😂

@ljharb
Copy link
Contributor Author

ljharb commented May 5, 2021

Yeah, fair point - for npm back compat i'd still need to maintain an npmignore in that case, so that's probably not a viable solution.

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

No branches or pull requests

3 participants