npm / npm/cli

[BUG] globally installed package from src does not include all files

Open
#4,147 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Needs Triage Release 8.x
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

Description

Is there an existing issue for this?
  • I have searched the existing issues
This issue exists in the latest npm version
  • I am using the latest npm
Current Behavior

in a fresh container
docker run --rm -t -i -v $(dirname $SSH_AUTH_SOCK):$(dirname $SSH_AUTH_SOCK) -e SSH_AUTH_SOCK=$SSH_AUTH_SOCK node:16 /bin/bash

given the package foo with package.json

{
  "name": "@user/foo",
  "version": "21.12.8-5f6d932",
  "bin": {
    "foo": "./bin/run"
  },
  "main": "lib/index.js",
  "types": "lib/index.d.ts",
  "engines": {
    "node": "16.13.1",
    "npm": "8.1.2"
  },
  "files": [
    "bin/",
    "lib/",
    "src/",
    "types/",
    "package-lock.json",
    "package.json",
    "README.md",
    "tsconfig.json"
  ],
  "scripts": {
    "postinstall": "npm run build",
    "build": "tsc"
  }
}

Installing the package in a custom dir npm i --ignore-scripts --prefix ./foo github:User/foo gives us the tree

README.md  bin	package.json  src  tsconfig.json  types

whereas npm i -g --ignore-scripts github:User/foo gives us

src

It looks like files field in package.json is not used while installing package from source globaly

same behaviour in our CI (github actions)

Expected Behavior

installing package from source globaly should behave the same way as locally

Steps To Reproduce

No response

Environment
  • npm: 8.2
  • Node: 16.13.1
  • OS: ubuntu 20.04
  • platform:
  • npm config:
; node bin location = /usr/local/bin/node
; cwd = /root/.npm/_cacache/tmp/git-clonepBND4z
; HOME = /root
; Run `npm config ls -l` to show all defaults.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the difference between npm i --ignore-scripts --prefix ./foo github:User/foo and npm i -g --ignore-scripts github:User/foo using the provided package.json and files list. Compare the resulting package trees, then trace npm CLI handling of globally installed GitHub source packages and the files field. Done means both installation modes include the same expected files.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
cli, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.