berry: [Bug] yarn add --peer after --dev doesn't add peer dependency
- I’d be willing to implement a fix
Describe the bug
I have a library that depends on rxjs
as a peer dependency, but it also has tests inside it.
If I add rxjs
as a normal dependency, tests run properly. If instead I run:
yarn add --peer --dev rxjs
My tests will complain about: Cannot find module 'rxjs' from '...'
Note that I’m also using typescript and ts-jest
.
Ideally, the dependency should be available to both peer and dev dependencies.
To Reproduce
const {promises: {readFile}} = require(`fs`);
await packageJsonAndInstall({
devDependencies: {},
});
await yarn(`add`, `--dev`, `rxjs`);
await yarn(`add`, `--peer`, `rxjs`);
const pkgJson = JSON.parse(await readFile(`package.json`, `utf8`));
expect(pkgJson).toHaveProperty(`peerDependencies`);
expect(pkgJson).toHaveProperty(`devDependencies`);
expect(pkgJson.peerDependencies).toHaveProperty(`rxjs`);
expect(pkgJson.devDependencies).toHaveProperty(`rxjs`);
Additional context
This is also a bug in yarn v1: https://github.com/yarnpkg/yarn/issues/5287
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15 (5 by maintainers)
Oh indeed - I think the problem comes from here, the two blocks should likely be inverted so that CLI flags take precedence over the detection heuristic:
https://github.com/yarnpkg/berry/blob/master/packages/plugin-essentials/sources/commands/add.ts#L249-L257