-
Notifications
You must be signed in to change notification settings - Fork 239
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
Add check-installed-peers rfc #386
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Add `check-installed` option to `peerDependenciesMeta` | ||
|
||
## Summary | ||
|
||
Currently `peerDependenciesMeta` (as far as I know) only adds the ability to basically turn off peer dependency warnings for your peer. I would like to add the ability to mark a dependency that may or not be installed (`optional` but that terminology is already used) but who's version should be checked if it is installed. | ||
|
||
## Motivation | ||
|
||
I have encountered several situations where a package can have optional peers depending on the use case of the package. If the peer is installed though it will be important to have the correct version. Examples include: | ||
|
||
* A config package that contains configs for various libraries. If the `eslint` config is used by the consuming package then the `eslint` peer needs to be installed but must be a minimum version for the config. | ||
* An async package that provides promise based and observable based versions of it's functions. If the PRomise based versions are used `rxjs` is not required. If the observable versions are used then the `rxjs` peer should be installed and the version should be within the specified range. | ||
|
||
## Detailed Explanation | ||
|
||
I expect that an additional config option would be added to `peerDependenciesMeta`: | ||
|
||
```json | ||
{ | ||
"peerDependencies": { | ||
"rxjs": "^6.0.0" | ||
}, | ||
"peerDependenciesMeta": { | ||
"rxjs": { | ||
"check-installed": true | ||
} | ||
} | ||
} | ||
``` | ||
(I am now married to the `check-installed` name but can't currently think of anything better) | ||
|
||
If `check-installed` is specified then no warning would be printed if the peer is not installed. If it is installed warnings about incompatible versions would be printed. | ||
|
||
## Rationale and Alternatives | ||
|
||
* **do not specify a peer** - Means that documentation must be relied on and if a new version of the dependency is installed that needs a different version of the peer there will be no warnings and the app will break. | ||
* **specify the peer normally** - means that all consumers of your package will have to install a dependency that they don't need to get rid of the peer warning | ||
* **specify an optional peer** - as far as I can see this is little different than the first option. | ||
|
||
## Implementation | ||
|
||
To be completed | ||
|
||
## Prior Art | ||
|
||
The only prior art I can think of is the existing `peerDependenciesMeta` configuration option that has already been discussed. | ||
|
||
## Unresolved Questions and Bikeshedding | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to me like it should be the default behavior. An optional peer dep will likely be try/catch required. If the wrong version exists, the program will happily use it, and perhaps break in terrifyingly silent ways.
I can't think of any use case where the package exists, the version is incompatible, and that's desirable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I completely agree. It would be much easier and better to modify existing behaviour but I was trying to avoid breaking what has already been implemented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fwiw what this RFC describes is how Yarn implements it. That npm has a slightly different behavior wasn't intended and mostly just an oversight when I ported it. Seems a good idea to align.