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

further simplify adding new deps to the root #49

Merged
merged 4 commits into from
Feb 26, 2020
Merged

Conversation

isaacs
Copy link
Contributor

@isaacs isaacs commented Feb 24, 2020

The previous revision of the buildIdealTree/reify add option converted
the package.json-esque data structure into instead passing a list of
specs for each location in the package, since the name couldn't be known
100% of the time up front.

However, that still puts too much of the burden of placing deps onto the
caller.

When you run npm install foo, if foo is already a devDependency,
then the updated save spec gets added there, unless specified otherwise.
Since we aren't guaranteed to know the name of the dep until we've
resolved it, how is the caller (ie, the npm CLI) supposed to know where
to put it in the objecet?

At the expense of a slight amount of flexibility, this changes things
further so that the add option mirrors exactly the positional
arguments passed to the npm install command: it's just a list of
specs, that's it.

Two more options were added:

  • saveType
  • saveBundle

If the saveType is not set, then added deps are added wherever they
already exist, or to dependencies if they're not already present.
Otherwise, it should be set to one of the edge type values:

  • 'prod'
  • 'dev'
  • 'optional'
  • 'peer'
  • 'peerOptional'

If saveBundle is true, then newly added deps are added to the
bundleDependencies list as well.

The previous revision of the buildIdealTree/reify `add` option converted
the package.json-esque data structure into instead passing a list of
specs for each location in the package, since the name couldn't be known
100% of the time up front.

However, that still puts too much of the burden of placing deps onto the
caller.

When you run `npm install foo`, if `foo` is already a devDependency,
then the updated save spec gets added there, unless specified otherwise.
Since we aren't guaranteed to know the _name_ of the dep until we've
resolved it, how is the caller (ie, the npm CLI) supposed to know where
to put it in the objecet?

At the expense of a slight amount of flexibility, this changes things
further so that the `add` option mirrors exactly the positional
arguments passed to the `npm install` command: it's just a list of
specs, that's it.

Two more options were added:

- saveType
- saveBundle

If the saveType is not set, then added deps are added wherever they
already exist, or to `dependencies` if they're not already present.
Otherwise, it should be set to one of the edge type values:

- 'prod'
- 'dev'
- 'optional'
- 'peer'
- 'peerOptional'

If `saveBundle` is true, then newly added deps are added to the
`bundleDependencies` list as well.
Considering that maybe that Node.package setter is more of a footgun
than it's worth.  It's nice to know that the deps will always be kept
up to date, but throwing away and reloading edges just because you
pulled in something tangential feels like it's bad-clever.
isaacs added a commit to npm/cli that referenced this pull request Feb 24, 2020
isaacs added a commit to npm/cli that referenced this pull request Feb 24, 2020
isaacs added a commit to npm/cli that referenced this pull request Feb 24, 2020
@mikemimik mikemimik added this to the OSS - Sprint 5 milestone Feb 25, 2020
@mikemimik mikemimik mentioned this pull request Feb 25, 2020
10 tasks
No longer sending 'Referer: undefined' on registry requests.
@isaacs isaacs merged commit b3a311e into master Feb 26, 2020
@ruyadorno ruyadorno deleted the isaacs/easier-add branch May 25, 2020 14:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants