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

feat(update): add mechanism to allow updating/writing back to package.json #324

Closed
darcyclarke opened this issue Apr 9, 2021 · 2 comments
Assignees
Labels

Comments

@darcyclarke
Copy link
Contributor

Problem Statement

We've experience significant feedback from users that they were using the npm update command to reflect changes in package.json; Rightly or wrongly, this seems to be a pattern which is useful for some & we should facilitate a mechanism for them to achieve this in v7

@darcyclarke
Copy link
Contributor Author

darcyclarke commented Jan 4, 2022

References:

Example of what we could do... as a feature

  • Have npm update support --save which indicates that you want to save the latest spec back to package.json
npm update foo --save

Current Status/Expectations/Potential

  • package-lock=true & save=false are the defaults
  • package-lock=true + save=true = package.json is updated / package-lock.json is updated
  • package-lock=false + save=true = package.json is updated / package-lock.json isn't updated
  • package-lock=false + save=false = package.json isn't updated / package-lock.json isn't updated

ruyadorno added a commit to ruyadorno/config that referenced this issue Jan 10, 2022
Add a new method `isDefault(key)` that enables a way to know if the
value to be returned by a `config.get(key)` call is coming from the
default definitions or any other different source. In case it's coming
from the default values this method returns `true`, it returns `false`
otherwise.

This addition is going to allow for effectively managing different
default values in the npm cli on a command-basis, e.g:

The `save` config default value in the npm cli is `true`, so that in
`npm install` and other commands that value is always going to default
to true if no user config is provided. Now let's say we want to use a
different value in `npm update`, for example `save=false`. This change
enables us to have a conditional check to see if the `save` config value
is coming from the default source, thus providing a way to use a
different value instead of the default:

    const save = config.isDefault('save') ? false : config.get('save')

Relates to: npm/cli#4223
Relates to: npm/statusboard#324
ruyadorno added a commit to npm/config that referenced this issue Jan 10, 2022
Add a new method `isDefault(key)` that enables a way to know if the
value to be returned by a `config.get(key)` call is coming from the
default definitions or any other different source. In case it's coming
from the default values this method returns `true`, it returns `false`
otherwise.

This addition is going to allow for effectively managing different
default values in the npm cli on a command-basis, e.g:

The `save` config default value in the npm cli is `true`, so that in
`npm install` and other commands that value is always going to default
to true if no user config is provided. Now let's say we want to use a
different value in `npm update`, for example `save=false`. This change
enables us to have a conditional check to see if the `save` config value
is coming from the default source, thus providing a way to use a
different value instead of the default:

    const save = config.isDefault('save') ? false : config.get('save')

Relates to: npm/cli#4223
Relates to: npm/statusboard#324
@ruyadorno
Copy link

Landed in npm/cli#4223

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants