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

fix: don't trash optional dependencies that fail to install due to incompatible platform #8127

Open
wants to merge 3 commits into
base: latest
Choose a base branch
from

Conversation

paulrutter
Copy link

@paulrutter paulrutter commented Feb 23, 2025

This PR is a proposed solution for multiple reported issues regarding failed optional dependencies that are platform specific.
See #4828, #7961 and possibly related PR #8077.

It can be reproduced as follows:

  • mkdir test && cd test
  • npm init -y
  • npm i -D rollup
  • Read package-lock.json - observe 18 OS/CPU@rollup/* package variants are listed
  • rm package-lock.json
  • npm i
  • Read package-lock.json - observe only 1 OS/CPU @rollup/* package variant is now listed for the current platform

With this PR, the package-lock.json will remain to contain the initial 18 rollup related dependencies, as any optional failure due to incompatible platform (EBADPLATFORM) will not lead to trashing the node.

The side-effect of this is that all platform specific dependencies will be present on all platforms (just an empty directory where the platform doesn't match). But it does solve the issue at hand.

I would need help writing a proper unit test for this scenario though. With the steps below, i did manage to test my PR and see that it has the desired effect:

  • node . i -D rollup
  • Read package-lock.json - observe 18 OS/CPU@rollup/* package variants are listed
  • rm package-lock.json
  • node . i
  • Read package-lock.json - observe 18 OS/CPU@rollup/* package variants are listed still

…n incompatible platform, to prevent issues when either the lockfile is removed
@paulrutter paulrutter changed the title fix for #4828: don't trash optional dependencies that fail to install due to incompatible platform fix: don't trash optional dependencies that fail to install due to incompatible platform Feb 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant