Properly skip installation of packages that do not need to be installed (incompatible optionalDependencies for example)#1997
Conversation
Set the ignore flag using ENVIRONMENT_IGNORE visiblity. Add the compatbility check as a step of the install hydrate, and call hydrate from install check.
Only set it on the directly affected package, and then ignore those packages in the hoister
bestander
left a comment
There was a problem hiding this comment.
@mvestergaard would you please add some tests as in your test plan?
We need to make sure that this feature does not break in the future and it is easy to break.
We have platform specific tests for install operation already.
|
|
||
| // get patterns that are installed when running `yarn install` | ||
| const [, rawPatterns] = await install.hydrate(); | ||
| const [, rawPatterns] = await install.hydrate(true); |
There was a problem hiding this comment.
Why is fetch true for a check operation?
There was a problem hiding this comment.
It's for this bit:
await this.fetcher.init();
await this.compatibility.init();It seems that if the fetcher is not run beforehand, the compatibility check does not have the os and cpu data for each package to properly do the check.
There was a problem hiding this comment.
Would this work offline?
I am afraid that initing fetcher may cause a longer check
There was a problem hiding this comment.
That's a good question. I mean if the package is in the cache, it doesn't actually fetch anything, right?
There was a problem hiding this comment.
This happens if the fetch is not a part of the check:
yarn check v0.18.0-0
error chokidar#fsevents not installed
error fsevents#nan not installed
error fsevents#node-pre-gyp not installed
error node-pre-gyp#npmlog not installed
error node-pre-gyp#rc not installed
error node-pre-gyp#tar-pack not installed
error rc#deep-extend not installed
error tar-pack#fstream-ignore not installed
error rc#minimist not installed
error tar-pack#once not installed
error tar-pack#uid-number not installed
error Found 11 errors.
Because the check does not exclude those package due to incompatibility, it expects them to be there, which it shouldn't.
There was a problem hiding this comment.
Ah, it makes sense.
For cross platform modules - they are installed in node_modules and could be verified in place but the missing ones could be either "missing" or not installed because they are "optional".
Adding "optional" property to lockfile makes more sense but this needs a discussion involving more people, maybe an RFC?
There was a problem hiding this comment.
As a matter of fact, I think there should be a third mode for check - #1934.
I would rather rely on that and the integrity check than the default one
There was a problem hiding this comment.
I don't think adding whether a package is optional to the lock file is enough alone.
You still want it to be installed on an OS where it is supported, but skipped on an OS where it isn't.
There was a problem hiding this comment.
I wonder, if package is optional but it failed to install because you don't have a compiler, is it an error or is it ok?
There was a problem hiding this comment.
That should be an error.
In my opinion, if it is determined by the OS and CPU requirements of the package that your system is compatible, then any installation error that occurs, are out of the scope of what yarn should handle.
|
@bestander I'll look into adding some tests tonight. |
You could depend on a fake optional dependency that does not work on any OS. |
|
@bestander How does one go about correctly generating one of those .tgz files found in the |
It is a bit involved. |
|
@bestander I added two tests. |
|
Great job, @mvestergaard, I'll have a look |
|
@bestander Any ETA on next release? |
|
Saturday-Sunday this week |
|
Several years later, this worked for me (just adding the "*" to fsEvent in optional packages), I was trying to do CI in aws and the problem was that package :D |
Summary
This is a different approach to #1438
It should make sure that packages incompatible with the current environment are not installed.
See #1954 for further motivation
With this change, any
optionalDependenciesthat is incompatible with the environment will be skipped entirely in the install.Installing a package.json like this on windows or linux:
{ "optionalDependencies": { "fsevents": "*" } }Will result in an empty node_modules folder, which is the same behavior as using
npm.Test plan
The current test 'root install with optional deps' should test the scenario on anything other than OSX. It uses
fseventswhich is only compatible with OSX.To test on OSX you need to modify
__tests__/fixtures/install/root-install-with-optional-dependency/package.jsonto use an optional package that is not compatible with OSX.CI servers are running linux, so they should be fine.
After running install on a package with a single optional incompatible dependency, node_modules should be empty.
Fixes #1059 #1435