Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

fix: package.json saving optional deps #221

Merged

Conversation

isaacs
Copy link
Contributor

@isaacs isaacs commented Feb 4, 2021

Reify currently duplicates entries listed as optionalDependencies in the
users' package.json files. While it's working as expected this is
unexpected to a number of users and it also contradicts our own docs on
it:

Entries in optionalDependencies will override entries of the same
name in dependencies, so it's usually best to only put in one place.

This patches this UX problem by adding an extra check that will avoid
adding a dependency to the package.json dependencies object in case
that package is already listed under optionalDependencies.

Fixes: npm/cli#2203
Fixes: npm/cli#1886
Fixes: npm/cli#724

EDIT(isaacs): Moved this into updateRootPackageJson in pairing session

Alternative approach for #219

References

ruyadorno added a commit to ruyadorno/init-package-json that referenced this pull request Feb 4, 2021
When saving over existing files that contains optionalDependencies it
should avoid also saving that dep to dependencies, respecting our docs
recommendation on it:

    Entries in optionalDependencies will override entries of the same
    name in dependencies, so it's usually best to only put in one place.

This patches this UX problem by adding an extra check that will avoid
adding a dependency to the package.json `dependencies` object in case
that package is already listed under `optionalDependencies`.

Relates to: npm/arborist#221
Fixes: npm/cli#724
ruyadorno added a commit to ruyadorno/init-package-json that referenced this pull request Feb 4, 2021
When saving over existing files that contains optionalDependencies it
should avoid also saving that dep to dependencies, respecting our docs
recommendation on it:

    Entries in optionalDependencies will override entries of the same
    name in dependencies, so it's usually best to only put in one place.

This patches this UX problem by adding an extra check that will avoid
adding a dependency to the package.json `dependencies` object in case
that package is already listed under `optionalDependencies`.

Relates to: npm/arborist#221
Fixes: npm/cli#724
ruyadorno added a commit to ruyadorno/init-package-json that referenced this pull request Feb 4, 2021
When saving over existing files that contains optionalDependencies it
should avoid also saving that dep to dependencies, respecting our docs
recommendation on it:

    Entries in optionalDependencies will override entries of the same
    name in dependencies, so it's usually best to only put in one place.

This patches this UX problem by adding an extra check that will avoid
adding a dependency to the package.json `dependencies` object in case
that package is already listed under `optionalDependencies`.

Relates to: npm/arborist#221
Fixes: npm/cli#724

PR-URL: npm#109
Credit: @ruyadorno
Close: npm#109
Reviewed-by: @nlf, @wraithgar
Reify currently duplicates entries listed as optionalDependencies in the
users' package.json files. While it's working as expected this is
unexpected to a number of users and it also contradicts our own docs on
it:

    Entries in optionalDependencies will override entries of the same
    name in dependencies, so it's usually best to only put in one place.

This patches this UX problem by adding an extra check that will avoid
adding a dependency to the package.json `dependencies` object in case
that package is already listed under `optionalDependencies`.

Fixes: npm/cli#2203
Fixes: npm/cli#1886
Fixes: npm/cli#724

EDIT(isaacs): Moved this into updateRootPackageJson in pairing session

PR-URL: #221
Credit: @isaacs
Close: #221
Reviewed-by: @ruyadorno
@ruyadorno ruyadorno force-pushed the isaacs-and-ruyadorno/do-not-repeat-optional-dependencies branch from 7624528 to 03d453c Compare February 4, 2021 22:23
@ruyadorno ruyadorno merged commit 03d453c into main Feb 4, 2021
@isaacs isaacs deleted the isaacs-and-ruyadorno/do-not-repeat-optional-dependencies branch February 4, 2021 23:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.