Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Production prune removes peerDeps that are also devDeps #7296

Open
2 tasks done
kf6kjg opened this issue Mar 18, 2024 · 1 comment
Open
2 tasks done

[BUG] Production prune removes peerDeps that are also devDeps #7296

kf6kjg opened this issue Mar 18, 2024 · 1 comment
Labels
Bug thing that needs fixing Priority 2 secondary priority issue

Comments

@kf6kjg
Copy link

kf6kjg commented Mar 18, 2024

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

The packages that are both peer and development packages are removed when pruning due to the omit=dev option being applied to all development dependencies.

I.E. the below script emits Expected dev and peer package not found was pruned when it was not supposd to be.

Expected Behavior

The packages that are both peer and development packages are kept due to the include=peer option overriding the omit=dev option.

I.E. the below script emits Test passed.

Steps To Reproduce

Here's a shell script that reproduces the problem:

#!/bin/sh

set -e

rm -rf node_modules package.json package-lock.json

npm -v # 10.2.4


# Part 1: Set up a package for demonstration.

npm init --init-author-name bugdemo --init-license UNLICENSED --init-module index.js --init-version 0.0.0 --yes

## Install a package as a development dependency.
npm i -D --package-lock-only @slidewave/gitignore-include@2 c8

## Add the one package as peer dependency.
jq '. + {peerDependencies:{"@slidewave/gitignore-include": ">=2", "chai": ">=1"}}' package.json > t && mv t package.json

## Update the package-lock to include the peer dependency data.
npm i -D --package-lock-only @slidewave/gitignore-include


# Part 2: Demonstrate the bug.

## Install all the packages.
ENV_NAME=build npm ci --unsafe-perm --no-fund --no-audit

## Verify existence of the expected packages.
if [ ! -e 'node_modules/c8/package.json' ]; then
    echo "Expected dev-only package not found." >&2
    exit 1
fi
if [ ! -e 'node_modules/@slidewave/gitignore-include' ]; then
    echo "Expected dev and peer package not found." >&2
    exit 1
fi
if [ ! -e 'node_modules/chai' ]; then
    echo "Expected peer-only package not found." >&2
    exit 1
fi

## Remove the dev packages, but leave the peer packages.
ENV_NAME= npm prune --omit=dev --include=peer --no-fund --no-audit

hadError=
if [ -e 'node_modules/c8/package.json' ]; then
    echo "Expected dev-only package found when it should have been pruned." >&2
    hadError=1
fi
if [ ! -e 'node_modules/chai/package.json' ]; then
    echo "Expected peer-only package was pruned when it was not supposd to be." >&2
    hadError=1
fi
if [ ! -e 'node_modules/@slidewave/gitignore-include/package.json' ]; then
    echo "Expected dev and peer package not found was pruned when it was not supposd to be." >&2
    hadError=1
fi

if [ ! "$hadError" ]; then
    echo "Test passed."
fi

Environment

  • npm: 10.2.4
  • Node.js: v20.11.1
  • OS Name: macOS 14.1.1
  • System Model Name: Apple M1 Pro
  • npm config:
; "user" config from /root/.npmrc

//npm.pkg.github.com/:_authToken = (protected) 
//registry.npmjs.org/:_authToken = (protected) 

; node bin location = /usr/local/share/nvm/versions/node/v20.11.1/bin/node
; node version = v20.11.1
; npm local prefix = /npmbug
; npm version = 10.2.4
; cwd = /npmbug
; HOME = /root
; Run `npm config ls -l` to show all defaults.
@kf6kjg kf6kjg added Bug thing that needs fixing Needs Triage needs review for next steps Release 10.x labels Mar 18, 2024
@kf6kjg
Copy link
Author

kf6kjg commented Mar 18, 2024

According to the docs:

If a package type appears in both the --include and --omit lists, then it will be included.

and

Dependency types specified in --include will not be omitted, regardless of the order in which omit/include are specified on the command-line.

Thus I'd figured that a devdep that was also a peerdep would be retained after a prune that omits dev, but includes peer.

@milaninfy milaninfy added Priority 2 secondary priority issue and removed Needs Triage needs review for next steps labels May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Priority 2 secondary priority issue
Projects
None yet
Development

No branches or pull requests

3 participants