yarn probably shouldn't cache packages resolved with a file path
Do you want to request a feature or report a bug?
I guess a bug.
What is the current behavior? If the current behavior is a bug, please provide the steps to reproduce.
Say you have the following project structure:
component-foo/
└── package.json
└── index.js
yarn-test/
└── package.json
With the following files:
component-foo/package.json:
{
"name": "component-foo",
"version": "1.0.0",
"private": true,
"main": "index.js"
}
component-foo/index.js:
console.log('foo');
yarn-test/package.json:
{
"name": "yarn-test",
"version": "1.0.0",
"private": true,
"dependencies": {
"component-foo": "file:../component-foo"
}
}
Now you run $ yarn install inside yarn-test/ and yarn-test/node_modules/component-foo/index.js is:
console.log('foo');
Now remove yarn-test/node_modules/ and yarn-test/yarn.lock and change component-foo/index.js to this:
console.log('bar');
Now you run $ yarn install inside yarn-test/ again and yarn-test/node_modules/component-foo/index.js will be:
console.log('foo');
It uses the cached version of component-foo, but component-foo/index.js has changed.
What is the expected behavior?
I'd expect that yarn-test/node_modules/component-foo/index.js should be this at the end:
console.log('bar');
Maybe packages installed with local paths like file:../ shouldn't be cached at all, if we can't figure out, if they have changed.
(FYI: It looks like npm doesn't cache them.)
Please mention your node.js, yarn and operating system version.
$ node -v
v6.9.1
$ yarn -V
0.18.0
macOS 10.12.1
This fooled me as well. There must be a way to get around this without clearing all the cache.
I think there could the three ways to make yarn usable for this case:
- @donaldpipowitch 's suggestion of ignoring all local dependencies.
- Reinstalling local dependencies if a file in there is modified later than when it's cached. This would require us to keep this metadata. For local dependencies we may insert lines like this to "Resolved" column:
file://<path>@<cache_timestamp> - Ignoring packages by package names with commands such as
yarn cache rm <package>andyarn cache add <package>. For all dependencies.
I'd like to see the second suggestion to be implemented. Unless, the third option could be useful for other cases as well. For instance, yarn cache add <package> can be used to refresh the cache for already cached dependencies in case something could go wrong while downloading a dependency.
@hantuzun why cache local dependencies at all? they are local anyways, so it will be fast regardless cached or not.
@satya164 you're right. Although, I'm more inclined to the third approach would help if a dependency from network is modified intentionally.
Something like yarn cache ignore <package> will be useful. But I think they don't have to be mutually exclusive. Ignoring a package is useful, but it requires manual work. File dependencies could be made to work without any additional effort if they were ignored by default.
Can someone explain me the internal logic?
My understanding:
When a dependency with file: is encountered the file-resolver.js kicks in. It says the dependency should be copied and is not hashed. Doesn't no hash mean it should not be cached already...? But the copy-fetcher.js seems to set the hash to an empty string instead of keeping null... Is this problem?
@bestander or @kittens Maybe you could explain this a little bit more...? Would love to get a little help to create a PR ♥
Hash means the md5 hash that is used for tarball-fetcher, for example. This hash is then added to yarn.lock file for future verifications and also appended to folder name when saving the unzipped folder in cache. You are digging in the right direction, thanks for looking into this, a PR is very much welcome. You can probably start with a PR that adds a broken unit tests
You can probably start with a PR that adds a broken unit tests
Okay, thank you for your response. Should I ping you as a reviewer in the PR or should I ping someone else (or no one)...?
Yeah, ping me
@bestander probably this issue shouldn't be closed since it's not fixed yet?
Yes, it should be re-opened. It was closed because I wrote " fixes #2165" in the title of my PR. In the beginning I thought it would be an ongoing PR, but to fix this bug we want two PRs: the first one added a unit test (the assertion which would fail is not really active, so CI doesn't blow up) and the second one will actually fix it.
Sorry, github closes issues when PR is merged
so obviously this is still a problem? it's quite annoying to develop with, to be honest. it's causing a bit of a disruption for me on a personal level at work, where i'm making use of file: to create a modular development environment. the sucky part is that every local package that I edit (using the file: path in package.json), requires doing this, in order to pull down the refreshed contents:
editing the contents of my eslint-config-base-eslint package
yarn cache clean && rm -rf node_modules/eslint-config-base-eslint && yarn install --force && yarn lint
Everyone is welcome to contribute to the project. It could be anything - submitting a broken integration test for this case, a fix or convincing someone to work on the fix. If you want to chat about the best way to approach that, you can find help on the discord channel.
I actually think that the fix should be 10-15 lines of code, it will probably save a lot of time fixing it sooner
FYI: It could be that this issue is also relevant for slow linking dependencies steps. See my comment here: https://github.com/yarnpkg/yarn/issues/1496#issuecomment-282688818.
Sorry. I couldn't found the time to create another PR for this issue :( I was (and still am) very busy.
@bestander This is a pretty big blocker for me, working on a multi-module project. If I'm reading @donaldpipowitch 's code links and comments correctly, could we have the file-resolver create a new hash (instead of null) every time it tries to resolve so it forces a reinstall? Say a UUID or current timestamp? Forgive me if I'm missing something, I'm not familiar with the way the code works.
A new cache with a time stamp and uuid sounds like a reasonable hack. Ideally we should copy the files directly without the cache but it may be a more complex change. Go ahead send a PR
On Tue, 7 Mar 2017 at 03:38, Matt Traynham [email protected] wrote:
@bestander https://github.com/bestander This is a pretty big blocker for me, working on a multi-module project. If I'm reading @donaldpipowitch https://github.com/donaldpipowitch 's code links and comments correctly, could we have the file-resolver create a new hash (instead of null) every time it tries to resolve so it forces a reinstall? Say a UUID or current timestamp? Forgive me if I'm missing something, I'm not familiar with the way the code works.
— You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub https://github.com/yarnpkg/yarn/issues/2165#issuecomment-284612526, or mute the thread https://github.com/notifications/unsubscribe-auth/ACBdWDS3xSr8KNu1o9Zn8sA9xdO8pyHOks5rjNEmgaJpZM4LFbmf .
@bestander Regarding your last comment: Wouldn't it make even more sense to symlink it, instead of copying the files? Or is there any reason not to do that?
@danrot windows seems to require admin to symlink. also it messes up recursing down to find node modules