-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Allow prerelease versions when checking peer deps #3361
Conversation
Uses lower-level APIs in node-semver to allow prerelease versions when checking peer deps. This honors the intent of library authors e.g. when they write a React component that asks for `"react": ">=15.0.0"` they're saying OK with `react@16.0.0` (partly because the React team specifically has said that if you don't have any warnings in version N, then version N+1 should work for you). By extension and modulo bugs, `react@16.0.0-alpha` works too (if the user explicitly installs it). Test Plan: Added unit tests for the new semver utility. Tested in a real project that uses React 16.0.0-alpha.11 and verified I didn't get any peer dep warnings that usually appear from libraries that ask for `"react": ">=15.0.0"`. Downgraded React to 0.14.0 (too low) and saw peer dep warnings come back as expected.
Thanks, @ide. |
node-semver converts ~ and ^ ranges into pairs of >= and < ranges but the upper bounds don't properly exclude prerelease versions. For example, "^1.0.0" is converted to ">=1.0.0 <2.0.0", which includes "2.0.0-pre" since prerelease versions are lower than their non-prerelease counterparts. As a practical workaround we make upper-bound ranges exclude prereleases and convert "<2.0.0" to "<2.0.0-0", for example. Added unit tests as well.
Can this be made to work with yarn/src/package-compatibility.js Lines 58 to 88 in fe34bb0
$ node --version
v8.2.0-rc.1
$ yarn
yarn install v0.24.6
[1/4] 🔍 Resolving packages...
[2/4] 🚚 Fetching packages...
error ansi-styles@3.0.0: The engine "node" is incompatible with this module. Expected version ">=4".
error Found incompatible module
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command. EDIT: Workaround: |
@SimenB I think it is a good idea, would you send a PR? |
Summary
Uses lower-level APIs in node-semver to allow prerelease versions when checking peer deps. This honors the intent of library authors e.g. when they write a React component that asks for
"react": ">=15.0.0"
they're saying OK toreact@16.0.0
(partly because the React team specifically has said that if you don't have any warnings in version N, then version N+1 should work for you). By extension and modulo bugs,react@16.0.0-alpha
works too if the user explicitly installs it.Fixes #2760
Test plan
Added unit tests for the new semver utility.
Tested in a real project that uses React 16.0.0-alpha.11 and verified I didn't get any peer dep warnings that usually appear from libraries that ask for
"react": ">=15.0.0"
. Downgraded React to 0.14.0 (too low) and saw peer dep warnings come back as expected.