Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does yarn ignore .npmignore?

I'm creating a npm package for self-learning purpose and published it on Github repo. The idea is that I want to install the package from one of the branch github repo rather. My folder contains:

a/
b/
c/
.gitignore
.npmignore
package.json

I want to ignore certain file so I put them in .npmignore:

a
c

When I npm install git://github.com/USER/REPO.git#MY_AWESOME_BRANCH and look into node_modules

node_modules
└── MY_PACKAGE_NAME
   ├── b/
   ├── .gitignore
   ├── .npmignore
   └── package.json

But when I yarn add git://github.com/USER/REPO.git#MY_AWESOME_BRANCH

node_modules
└── MY_PACKAGE_NAME
   ├── a/
   ├── b/
   ├── c/
   ├── .gitignore
   ├── .npmignore
   └── package.json

Somehow, yarn add is ignoring .npmignore file. Is there a way to exclude certain files for both npm install and yarn add ?

like image 911
Thein Htut Avatar asked Feb 06 '20 06:02

Thein Htut


People also ask

Should .yarn be ignored?

. yarn/unplugged should likely always be ignored since they typically hold machine-specific build artifacts. Ignoring it might however prevent Zero-Installs from working (to prevent this, set enableScripts to false ).

Is Yarn deprecated?

⚠️ Deprecation Notice (2022-02-20) ⚠️yvm has been deprecated in favour of corepack which is distributed by default with NodeJS v14, and is available in older versions by installing the corepack npm package globally.

What is Npmignore file?

.npmignore works similarly to .gitignore , it is used to specify which files should be omitted when publishing the package to NPM.


1 Answers

TLDR: .npmignore has no impact on yarn install or yarn add.

There's a bit of confusion here on the purpose of the .npmignore file. It is not a configuration used when installing a package. It is used when publishing the package. By using a GitHub repository (as opposed to GitHub Packages), you are essentially publishing everything recognized by Git.

You can use the .gitignore file to alter the files that are committed and pushed to your GitHub repository. The .gitignore file is also respected as a default when the .npmignore is not present in case you choose to publish to a package repository like NPM or GItHub Packages at a later date.

Reference: https://npm.github.io/publishing-pkgs-docs/publishing/the-npmignore-file.html

like image 181
David R. Avatar answered Sep 21 '22 22:09

David R.