Skip to content

feat: add a global npmignore file#9351

Open
ljharb wants to merge 1 commit into
npm:latestfrom
ljharb:feat/global-npmignore
Open

feat: add a global npmignore file#9351
ljharb wants to merge 1 commit into
npm:latestfrom
ljharb:feat/global-npmignore

Conversation

@ljharb
Copy link
Copy Markdown
Contributor

@ljharb ljharb commented May 12, 2026

The purpose of this is to allow users to specify files that should never be published that are not project-specific, and should remain on their local machine and NOT committed to every project they happen to work with. This could include IDE files (nobody else should know or care which IDE i'm using), LLM output (.claude directories, things like that), anything that is unique to me, my environment, or my machine, that i never want published.

The intention is for this global file to be configured in a user's npmrc, and then that separate file (~/.npmignore, for example, like how most people's global gitignore is set to ~/.gitignore) is respected.

Whether a package is using files, or .npmignore (or neither), the global npmignore is respected: with files, anything listed is published as normal; with .npmignore or neither, anything listed (except things npm always publishes like package.json and the readme etc) will be removed from the packed file list.

@ljharb ljharb requested review from a team as code owners May 12, 2026 22:58
Defines a new path typed config, `global-ignore-file`, with a default of `${prefix}/etc/npmignore`.
The default is computed via a getter on the defaults object so it follows `--prefix` overrides, mirroring the existing `globalconfig` setup.
The default flatten function camelCases the key to `globalIgnoreFile`, which is the option name the pack and publish call chain will look for once `npm-packlist` and `pacote` ship matching support.

The intent is that a user can keep a single ignore list (for editor metadata, scratch directories, and similar artifacts that should never ship) instead of copying the same patterns into every package's `.npmignore`.
The patches that actually consume `globalIgnoreFile` live in `npm-packlist` and `pacote` and will land via separate releases of those packages.
Reserving the config name in cli now means once those releases land here, the value flows through without further changes.

Includes definitions tests (type, default, description, flattening), index tests (computed default from `--prefix`, explicit cli override), and updated snapshots for the type description, the config command output, and the docs generator.
@ljharb ljharb force-pushed the feat/global-npmignore branch from e559d3e to 41a0eef Compare May 12, 2026 23:37
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

Successfully merging this pull request may close these issues.

1 participant