-
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
Adds versioning to the cache path #2768
Conversation
What kind of tests could we implement here? |
Not sure; testing it would require changing the constant value, which means that yarn would have to be rebuilt while running the tests :/ |
I think we could mock it with jest easily.
|
Some more ideas:
|
I digged a bit
I can check that the path ends with the expected version number without issue.
Now things start to get a bit hairy. Deleting the cache with |
It is ok to run the test in sequence (not .concurrent) so that it does not run with other tests in parallel. |
Yep, I'm already doing this - the issue is that the two affected tests somehow need the Thinking of it, I found a way to make it work. Running |
I've just push my test - note that there's still a failure because Flow fails to find the |
1 test got broken. BTW, jest got just updated to 19.0.0 in master, you may want to rebase |
Just rebased. Unfortunately, neither |
Should be ok! 👍 I also had to change the file to manually add |
Just noticed that I'm still using |
|
||
await mockConstants({CACHE_VERSION: 42}, async (config): Promise<void> => { | ||
await cache(config, reporter, {}, ['dir']); | ||
assert.ok(!!(JSON.parse(String(inOut.read())) : any).data.match(/\/v42\/?$/)); |
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.
I think you should add a more high level check that verifies connection between current CACHE_VERSION and what gets installed in node_modules.
E.g.
- Install package-a
- add an empty file MARKER to the cache folder of package-a
- install package-a (with --skip-integrity-check flag) and verify that MARKER was copied
- set CACHE_VERSION=42
- install package-a (with --skip-integrity-check flag) and verify that MARKER was removed in node_modules
- set CACHE_VERSION=1
- install package-a (with --skip-integrity-check flag) and verify that MARKER was copied
Awesome job! |
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.
I think there should be only one cacheFolder in config. The fact that it is versioned is implementation detail that should not leak to other classes
src/config.js
Outdated
@@ -232,10 +236,16 @@ export default class Config { | |||
networkConcurrency: this.networkConcurrency, | |||
}); | |||
|
|||
this.cacheFolder = String( |
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.
After thinking about this I think this.cacheFolder should contain the folder with version.
Otherwise you will have to modify every command that reads cacheFolder from config
invariant(this.config.cacheFolder, 'expected packages root'); | ||
const cacheFolder = path.join(this.config.cacheFolder, scope ? 'npm-' + scope : ''); | ||
invariant(this.config.versionedCacheFolder, 'expected packages root'); | ||
const cacheFolder = path.join(this.config.versionedCacheFolder, scope ? 'npm-' + scope : ''); |
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 will work for npm dependencies but not for other resolvers: git etc
assert.ok(await fs.exists(path.join(config.cwd, 'node_modules', 'is-array', 'yarn.test'))); | ||
|
||
await mockConstants({CACHE_VERSION: 42}, async (config): Promise<void> => { | ||
const firstReinstall = new Install({}, config, reporter, lockfile); |
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.
nit: it is secondReinstall then?
I've just pushed a commit that changes On a similar note, I feel like |
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.
Great!
Let's see the CI to be green and merge it then
I am not sure when we have the next major release :)
|
@bestander Should be fine now :) There's an error with Node 4, but I doubt it comes from this PR:
|
cc @bestander
Summary
Cf #2035 - sometimes the cache structure changes, and things break.
This commit adds an additional part in the cache path that allows to invalidate previous caches. These old caches will not get removed until after running
yarn cache clean
, which allows for some easy rollback, just in case.It should not conflict with the current structure (old cache files will stay in the root cache directory until the next cache clean, but that shouldn't cause any other issue).
Test plan
The main effect is that the cache directory will change a bit:
Note that this variable will also be appended to custom paths: