-
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
Ref #2165 - file-resolver should invalidate cache with a new hash #2860
Conversation
@bestander I know little to nothing about Jest and haven't used async/await much. The failing test is checking for a package in the cache with the path You can use node-glob to find it and get the first occurence, but maybe you have a better recommendation? glob(`${path.join(config.cacheFolder, 'npm-dummy-0.0.0')}*`, (error, files) => files[0]) |
That particular test is fixed, but now getting a bunch of failures caused by 500's
|
Thanks for sending this PR. |
@bestander I've modified the existing test that was added in #2443, i.e. when not using On top of this, I had to correct the first test that broke ("properly find and save build artifacts") as it was failing intermittently. It initially broke because npm's install script would run and the new hash logic doubles the package in the cache. This is likely another reason to not cache local packages, but that is beyond this PR. Instead, I rewrote it so glob would find the correct cached build with the correct Let me know if there's anything else I need to do. Thanks! |
I've rebased this to resolve any conflicts. The failures look like 502 Bad Gateway responses which seem unrelated. Any chance this is going to make the next release? Wondering if I need an alternate route for the time being. |
Thanks, @mtraynham we are in an unstable CI phase right now, too many requests are getting timed out. There is an RFC yarnpkg/rfcs#34 related to this feature. |
I understand that npm developers seem to be unhappy about the copy behavior that npm@2 was doing |
@bestander I believe this is definitely related, but I'm probably not the one to ask if Per #2165, it seems like there is a lot of interest in just linking local dependencies with symlinks. Honestly, I don't have a use case for caching local dependencies at all. As it stands today, the Is there a use case where you want to cache a local package and not have it updated? I'm probably not the one to make that justification, but if it were me, I'd say no. There are other mechanisms for getting a local dependency back to a different state, such as source control and it's local, so a copy is probably slower than a symlink. And if that's a no, |
Hey, @mtraynham, sorry for taking that long. |
@bestander I've rebased, let me know if you need anything else. Thanks! |
Looks like cache test got broken FAIL tests/commands/cache.js (5.2s)
|
So this looks like a new test since the rebase. A count of 3 is expected and I'm going to increment that within the test and provide a comment. Some clarification on the reason it is now 3, this test uses the file: protocol fixture and now that we've changed the hash scheme, it may not just be one local package, but 2 in the cache; 3 including the |
Thanks! |
Summary
When using a
file:
resolution for dependencies, the dependency is always being pulled from yarn's cache; the first time being the exception, which puts it into the cache.Currently the cached package will only have the name and version, like the following:
This change ensures that the compared dependency always generates a new hashed name which will invalidate the cache. The new hash name looks like:
`npm-${package.name}-${package.version}-${uuid.v4()}-${(new Date()).getTime()}`
I've found two small caveats which are worth noting.
node_modules
directory, the hash comparison doesn't have any effect when runningyarn install
is called again. Only package.jsonversion
differences will have an effect, which are represented with differences in theyarn.lock
file. This can be circumvented withyarn install --force
, which invalidates the local package and replaces it with a new copy, even if it is the same version.Personally, I think this is correct functionality.
node_modules
or using theinstall --force
option, will add a duplicate entry to the yarn cache. The takeaway here is that we shouldn't cache the dependency at all as suggested here, but I'm probably not the right person to make that change.Test plan
file:
reference.bar
packagecat node_modules/foo/index.js # console.log('test');