-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Caches the Yarn resolution for faster installs #5270
Conversation
0252d84
to
676ad4e
Compare
Small note: I recommend to use Yarn 1.12+ to generate this file. It will be easier for users to then transition to the 2.0 later on (because of the |
Can you describe what happens when new |
It's the third case:
Yarn will use as much as possible from the cached lockfile (so if both |
How often should we run |
Would be best, yes, to ensure it's always up-to-date with the latest |
Can you add it to our release instructions in Contributing.md? |
There seems to be a problem in the md formatting, investigating. |
I recently turned on |
Oh ok! Should be fine then 👍 |
Awesome. We've wanted to do this for a long time but I wasn't sure how. This makes sense. |
@AviVahl It shouldn't matter - Yarn will simply resolve the custom package passed as parameter against what's on the registry, then use it to bootstrap the app (and use the cache if they match the transitive dependencies of your custom package). Worst case: there will be no identical dependency between the custom package and the cache, in which case the install will just be slower (it won't be able to take advantage of the cache and will need to resolve everything as before). Unless you've noticed something awry in practice? |
@arcanis It works, yes, but the behavior has changed. If any semver request matches by accident, it will be locked to the cached version. While I think the approach is flawed, because it also means you guys will have to release a new |
I'm not sure I understand what you mean. Let's take scenarios:
That said, while I'm not sure I see the problem in having |
My use case matches third-scenario, no forced upgrade from first-level (although it uses ^ for second-level, and that one also uses carets). I'm creating In my Without this PR, every time a new user comes to try out my scripts, he'll get both 1st-level and every-other-level resolved "fresh" (according to semver requests). Yarn might optimize it one way or another, but resolution still happens, so there's a chance a fixed upstream 10th-level dependency gets updated. With this PR, my 1st-level deps are resolved "fresh", as I use carets while the original Regarding "nothing guarantees that Yarn won't pick up the vulnerable version (even if there's a newer one)" - you are correct. But with this PR, it is guaranteed that it will pick up the exact same vulnerable version unless the semver request changes (in 2nd-level+ deps) or create-react-app releases a new version (with a new cached I understand the user can always go and delete his lock file and regenerate it from scratch, but the behavioral change is regarding the first install. Meaning usage of Is my understanding of the works here correct? Are my assumptions? |
I think your understanding is correct. One remark though:
I think this is the crux of the problem here. But at the same time, I wonder if it's really one - the use case you mention is: "a vulnerable dependency won't be upgraded to a safe one". Couldn't that be reworded as "a safe dependency won't be upgraded to a vulnerable one"? Or, more likely: "a dependency we're sure is compatible won't be upgraded to something potentially breaking" (as sometimes happens when semver isn't entirely respected, or when a bug creeps in). So I agree with your assessment, but I'm not entirely sure whether this behavior should be considered as being positive or negative 🤔 |
Yes, it works both ways. That's probably why my first instinct was to change this just for custom scripts, where one may find a different, yet overlapping, dep tree. If we had the exact same dependencies, I might have preferred this approach. My experience has taught me that the same version can be good for one dep tree, and broken in another (where different features are used). I find forcing an initial lockfile from a completely different package problematic. Am I going to find myself making a PR updating just the cached lockfile of |
FWIW I don't mind limiting the lockfile thing only for the default package. Want to send a PR? |
@gaearon done. |
What about the case where a user has a custom registry set for yarn? I suggest that in this case they should be excluded from getting the cached file. In my organisation users can't get to |
Related: yarnpkg/yarn#5892 I guess the lockfile could be disabled through an option, like |
What about |
When running
create-react-app
, a good chunk of the time is spent resolving the dependency tree to satisfying versions. Sincereact-scripts
uses pinned dependencies anyway (suggesting that you always want to use precise versions), this looks a bit unnecessary.This PR adds a new script,
compile:lockfile
, meant to be ran manually every now and then. It will update theyarn.lock.cached
file located in thecreate-react-app
package, which will be copied into the app directory before runningyarn add react-scripts
(only if Yarn is being used, of course). Three cases then:create-react-app
is up-to-date with the latestreact-scripts
, the resolution will be mostly instantaneous.create-react-app
is completely desynchronized with thereact-scripts
being used, the resolution will be like now (the cached resolution will simply be ignored by Yarn).create-react-app
is old-but-not-that-much compared toreact-scripts
, Yarn will be able to reuse at least some of the cached resolution, which will still give a perf boost.