npm / cli

the package manager for JavaScript
https://docs.npmjs.com/cli/
Other
8.49k stars 3.17k forks source link

[DOCS] Question on `.npmignore` / `files` behavior for git dependencies in latest version #7335

Open cs-balazs opened 7 months ago

cs-balazs commented 7 months ago

Is there an existing issue for this?

This is a CLI Docs Enhancement, not another kind of Docs Enhancement.

Description of Problem

Considering a sample typescript project like this minimal example: https://github.com/cs-balazs/dummy-lib When this repo is used as a git dependency in an npm project, after npm install, the build folder is not included in node_modules/dummy-lib. With version 10.2.4, it does appear in the folder, but with 10.5.0 it doesn't

With either of these changes, it works with 10.5.0:

I wanted to understand the reason behind this, but couldn't find the relevant change in the changelog, nor found a reason in the docs. The documentation of the files field states, that:

Certain files are always included, regardless of settings:

  • package.json
  • README
  • LICENSE / LICENCE
  • The file in the "main" field
  • The file(s) in the "bin" field

Which to me means, that in this case at least build/src/index.js should be there

I don't know if this is indeed a problem with the docs, or just my misunderstanding, I'm submitting this issue to find that out, and a reason on why this git dependency behavior changed

Potential Solution

No response

Docs URL

No response

adamraine commented 7 months ago

I noticed this changed as well (https://github.com/nodejs/node/issues/52382). I assume it's intentional because the new behavior seems more inline with the syntax rules of .gitignore.

That being said, I think this change could break certain packages without warning.

cs-balazs commented 7 months ago

I noticed this changed as well (https://github.com/nodejs/node/issues/52382). I assume it's intentional because the new behavior seems more inline with the syntax rules of .gitignore.

Yeah, I guess this is indeed the reason. It seems like this might be the related dependency change (not sure): https://github.com/npm/ignore-walk/pull/118

bedrich-schindler commented 4 months ago

I might have similar issue.

In our package, I have .npmignore that contains:

# https://docs.npmjs.com/cli/v10/using-npm/developers#keeping-files-out-of-your-package
!.npmrc

Before this change, nom pack excluded .npmrc file. After this change when .npmignore exists, npm pack includes .npmrc file. However, we install this package as from git, not from npm registry and .npmrc is missing in installed module.

Why we need this? We have tooling repo containing our common files and .npmrc is one of them.

knolleary commented 4 months ago

This just broke our production system.

We had the following entry in .npmignore:

config/

Previously, this meant that /config/** would be ignored, but /forge/config/** would be included.

With this change, both are now ignored.

This is definitely related to the ignore-walk update which has changed its behaviour in a semvar patch updated.