cli icon indicating copy to clipboard operation
cli copied to clipboard

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

Open cs-balazs opened this issue 10 months ago • 4 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

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

  • [X] This is a CLI 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:

  • Adding a files: ["./build/**/*"] in package.json
  • Removing src from .npmignore

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

cs-balazs avatar Apr 03 '24 13:04 cs-balazs

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.

adamraine avatar Apr 08 '24 16:04 adamraine

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

cs-balazs avatar Apr 09 '24 07:04 cs-balazs

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.

bedrich-schindler avatar Jun 23 '24 20:06 bedrich-schindler

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.

knolleary avatar Jul 06 '24 08:07 knolleary