Local package's `files` field is not respected

cli

(Ahn Heejong) #1

What I Wanted to Do

So, I have folder structure somewhat like below:

root
β”œβ”€β”€ common
└── services
    └── a

common is a npm package, and services/a also is. I want to import common from services/a without publishing common to npm, so I added following field to the package.json of services/a:

{
  ...,
   "devDependencies": {
    "common": "file:../../common",
    ...
  },
  ...
}

Also, as I want to only expose build output of common as a module, I have sth like below in the package.json of common.

{
  ...
  "files": [
    "dist"
  ],
  ...
}

What I’ve expected was, when I run npm install in services/a folder, only dist folder of common gets installed.

What Happened Instead

Instead, entire folder (including source files and all) got copied to services/a/node_modules/common.

Reproduction Steps

As mentioned above

Details

https://docs.npmjs.com/files/package.json#files says,

The optional files field is an array of file patterns that describes the entries to be included when your package is installed as a dependency.

My current suspicion is that files field is only respected in the publishing process. However, I think common still β€œis installed as a dependency” in services/a's perspective, so I think files field should be respected in this case too. Am I doing anything wrong? Or is there any workaround for this? (My main pain point is that as @types/react of common is included in common/node_modules, services/a's compile process breaks due to duplicate declaration file)

Platform Info

$ npm --versions
6.3.0
$ node -p process.platform
darwin

(Kat MarchΓ‘n) #2

files won’t work for file: dependencies because they get symlinked.


(Ahn Heejong) #3

Thanks for the answer. If you don’t mind, I’ve created a PR stating that on the official doc’s files field: https://github.com/npm/cli/pull/63


(system) #4

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.