Skip to content

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

@ljharb

Description

@ljharb

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions