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
@ljharb ljharb force-pushed the feat/global-npmignore branch from e559d3e to 41a0eef Compare May 12, 2026 23:37
@owlstronaut
Copy link
Copy Markdown
Contributor

@ljharb I like the idea, not sure I want to merge it without the accompanying/supporting code as it will silently do nothing but still be a config option

@ljharb ljharb force-pushed the feat/global-npmignore branch from 41a0eef to b19803e Compare May 13, 2026 17:05
@ljharb
Copy link
Copy Markdown
Contributor Author

ljharb commented May 13, 2026

whoops, sorry! i meant to push 4 commits (which is all the supporting code). pushed.

@owlstronaut
Copy link
Copy Markdown
Contributor

whoops, sorry! i meant to push 4 commits (which is all the supporting code). pushed.

Ha, no worries - but the pacote and packlist changes will have to be in their respective repositories

@ljharb
Copy link
Copy Markdown
Contributor Author

ljharb commented May 13, 2026

ha, also my bad :-) i'll make those PRs and then update this one.

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 that `pacote` and `npm-packlist` will read off the flat options bag once their matching support is released.

The motivation is letting a user 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`.

This is the cli side of a multi repo feature.
The matching changes live on branches in the corresponding repos and need releases before the option has any effect:
  - ljharb/npm-packlist branch feat/global-ignore-file
  - ljharb/pacote      branch feat/global-ignore-file
After both ship, a follow up commit in cli will bump the `npm-packlist` and `pacote` dependency versions; no other cli source changes are required since the value already flows through `flatOptions` via `lib/commands/pack.js`, `lib/commands/publish.js`, and `libnpmpack`.

Includes definitions tests (type, default, description, flattening) and index tests (computed default from `--prefix`, explicit cli override), plus regenerated snapshots for the type description, the `npm config list` output, and the docs generator.
@ljharb ljharb force-pushed the feat/global-npmignore branch from b19803e to 2b8da71 Compare May 13, 2026 19:44
@ljharb
Copy link
Copy Markdown
Contributor Author

ljharb commented May 13, 2026

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.

2 participants