Do you want to request a feature or report a bug?
Feature
What is the expected behavior?
"dependencies": {
"fabric --ignore-optional": "1.1.0",
}
I have a installation problem with optional dependencies of fabric module on mac. When I install package as yarn add fabric -D --ignore-optional then it install fine. But if I add another package then it install all packages with default optional and my installation just broken.
It'd make more sense to use something like this.
"dependencies": {
"fabric": {
"version": "1.1.0",
"ignore-optional": true
}
}
Can you please write an RFC? Cf https://github.com/yarnpkg/rfcs/
Indeed it makes sense to persist --flat, --ignore-optional etc on .yarnrc level.
Oh wait, we already have this feature https://yarnpkg.com/en/docs/yarnrc#toc-cli-args
@bestander this looks more like a dupe of https://github.com/yarnpkg/yarn/issues/2666
You are right they are related but this one raised an issue of persisting CLI arguments.
@bestander : Hmm, I don't think either of the referenced issues match the original feature request. The CLI arguments only works globally, which is often undesirable. Here's an example:
If I have package A with optional deps (A1, A2) and package B with optional deps (B1, B2)... and I actually want to install A along with A1, and A2, as well as B, but WITHOUT B1 and B2, I can run: yarn add A and then yarn add B --ignore-optional. My node_modules/ will have A, A1, A2, B as desired... but this is not captured in package.json or yarn.lock: yarn.lock will have A, A1, A2, B, B1, B2. This means that if I rm -r node_modules, I have no automatic way of restoring my modules to the way they were before. In particular, my two automated options are:
yarn install which will result in A, A1, A2, B, B1, B2
yarn install --ignore-optional which will result in A, B (with the fix from #2666)
The particular case where I am affected by this issue is using fabric.js only in the browser environment, but it has optionalDependencies for it to work in the node environment, which I simply don't care for. In our CI, installing these optional dependencies has to compile natively, which sometimes errors. This issue is concisely stated here: https://github.com/kangax/fabric.js/issues/2775#issuecomment-274643765
I think a better solution than the proposed one would be to allow declaring a blacklist of modules you don't want to be installed. One could add "blacklistedDependencies": ["B1", "B2"] in package.json. And then running, yarn add B would install only B, and print a warning saying that some optional deps were skipped because they were blacklisted. If it is an actual dependency of the module (not optional), then yarn check should error. If it is an optional dependency, yarn check should emit nothing.
I'd be happy to submit an an RFC if this approach has some merit.
@saifelse, you are right.
We have a few flags in Yarn that indicate some installation mode: --ignore-optional, --production etc.
If you use this flag in add/remove/upgrade command Yarn would execute the command but it will apply the flag to whole node_modules and all dependencies.
This is not intuitive because people assume that yarn add with a flag would make this flag stick to the dependency but it actually applies to the whole node_modules generation.
Give it a thought how Yarn could make those flags stick maybe so that users don't have to list all flags every time.
As for your particular case and solution, I am not sold yet, IMHO optionalDependencies is a bad hack that is wrongly used in many places, I would rather spend time looking for a more robust solution that does not add features around handling optional dependencies.
IMHO --ignore-optional should be the default. If you want an "optional dependency" then yarn add it separately yourself. Yarn could maybe list the optional dependencies for you at yarn add time, but that should be the only time yarn cares about optional dependencies.
Most helpful comment
IMHO
--ignore-optionalshould be the default. If you want an "optional dependency" thenyarn addit separately yourself. Yarn could maybe list the optional dependencies for you atyarn addtime, but that should be the only time yarn cares about optional dependencies.