cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] In monorepositories `npm publish` and `npm pack` take into account `.gitignore` and ignore `.npmignore`

Open KostyaTretyak opened this issue 2 years ago • 2 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

This issue exists in the latest npm version

  • [X] I am using the latest npm

Current Behavior

In monorepositories (with workspaces in package.json), npm publish and npm pack take into account .gitignore and ignore .npmignore.

Expected Behavior

If .npmignore is present, npm publish and npm pack should take that file into account and ignore .gitignore.

Steps To Reproduce

git clone [email protected]:KostyaTretyak/npm-bug-with-monorepo.git
cd npm-bug-with-monorepo
npm i
cd packages/pkg1
npm pack

Now you can see that the packages/pkg1/pkg1-1.0.0.tgz archive does not contain a dist directory.

Environment

  • npm: 10.1 (and tested with v9.6.7);
  • Node.js: v18.17.1;
  • OS Name: Ubuntu 22.04;
  • System Model Name: HP Notebook
  • npm config:
; "user" config from /home/me/.npmrc

//registry.npmjs.org/:_authToken = (protected) 

; node bin location = /home/me/.nvm/versions/node/v18.17.1/bin/node
; node version = v18.17.1
; npm local prefix = /srv/git/npm-bug-with-monorepo
; npm version = 10.1.0
; cwd = /srv/git/npm-bug-with-monorepo
; HOME = /home/me
; Run `npm config ls -l` to show all defaults.

KostyaTretyak avatar Sep 15 '23 10:09 KostyaTretyak

When both the files .gitignore and .npmignore kept at the same level on root or subdirectory, as expected .npmignore is preferred.

When both the files are at different level .gitignore is at root and .npmignore is at subdirectory level in that case .gitignore is prefered which is not expected behaviour. We need to rule out all the rules defined, when .npmignore is present in workspace.

Santoshraj2 avatar Dec 01 '23 16:12 Santoshraj2