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

Optional Non-installed Dependencies #1085

Closed
fishcharlie opened this issue Mar 31, 2020 · 5 comments
Closed

Optional Non-installed Dependencies #1085

fishcharlie opened this issue Mar 31, 2020 · 5 comments

Comments

@fishcharlie
Copy link

What / Why

It would be great instead of optionalDependencies in the package.json options, if there was an option just like optionalDependencies but that the package wouldn't be installed by default. This would be especially useful for things like the debug npm package. An example of this would be, I want users to be able to use debug and get information provided by it from my NPM package, but not all users will need to take advantage of that debug functionality, so it shouldn't be installed by default, and should be completely optional.

When

  • n/a

Where

  • npm/cli

How

Current Behavior

  • optionalDependencies installs automatically

Expected Behavior

  • Option to mark optionalDependency as not installed automatically, it'd be great if the CLI alerted users that these are additional packages that can be installed manually for more functionality.

Who

  • n/a

References

  • n/a
@ljharb
Copy link
Contributor

ljharb commented Mar 31, 2020

I believe you can already do this with peer deps + peerDependenciesMeta?

@fishcharlie
Copy link
Author

@ljharb Any documentation on that? All I see is info for peerDependencies under the package.json docs. Looks more like for use with plugins, I'm not sure if that is the same use case as what I'm trying to do. But maybe adding peerDependenciesMeta gives more flexibility? But never heard of the peerDependenciesMeta option before.

@abdonrd
Copy link

abdonrd commented Sep 4, 2020

I have created an issue about document the peerDependenciesMeta property: #1247

@remyrylan
Copy link

For anyone stumbling on this same problem, peerDependencies + marking as optional using peerDependenciesMeta still automatically installs and is not currently a solution.

I've opened an issue here to discuss: npm/rfcs#221

@remyrylan
Copy link

@fishcharlie fyi, this was implemented here: npm/arborist@e13ba3b and I presume it will be in the next npm v7 beta, but that's up to the npm team.

It relies on using the peerDependenciesMeta field, paired with { "optional": true }.

Example package.json:

{
  "peerDependencies": {
     "react": "^16.0.0"
  },
  "peerDependenciesMeta": {
     "react": {
        "optional": true
     }
  }

In this case, react will not be automatically installed.

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

No branches or pull requests

5 participants