-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Self-service
- I'd be willing to implement a fix
Describe the bug
Hi, this is a follow-up to #4359. I'm looking to migrate a mono-repo from yarn classic to yarn 3, and am trying to get around a design pattern we've relied upon. There's multiple instances of a "meta-package" of dependencies. From the docs, it sounds like the preferred solution is to add the dependencies as a direct and peer. However if I try directly adding the dependency as a peer, it will throw an error:
Package "typescript" is already listed as a regular dependency - remove the -D,-P flags or remove it from your dependencies first·
$ yarn add [--json] [-F,--fixed] [-E,--exact] [-T,--tilde] [-C,--caret] [-D,--dev] [-P,--peer] [-O,--optional] [--prefer-dev] [-i,--interactive] [--cached] [--mode #0] ...
The particular docs I'm looking at is under https://yarnpkg.com/advanced/rulebook#packages-should-only-ever-require-what-they-formally-list-in-their-dependencies
The preferred one is to list the dependency (in Next.js's case, webpack) as both a regular dependency and a peer dependency. Yarn will interpret this pattern as "peer dependency with a default", meaning that your users will be able to take ownership of the Webpack package if they need to, while still giving the package manager the ability to emit a warning if the provided version is incompatible with the one your package expects.
How do you go about achieving this? At the moment it is possible to add a dependency as a peer and dev, but not as peer and direct.
To reproduce
await packageJson({
name: 'parent',
workspaces: [
'packages/*'
]
});
await packageJson({
name: 'meta-package',
dependencies: {
"typescript": "4.6.3",
}
}, { cwd: './packages/meta-package' });
await packageJson({
name: 'child',
devDependencies: {
"meta-package": "workspace:*"
},
scripts: {
"build": "tsc --help"
}
}, { cwd: './packages/child' });
await yarn('config', 'set', 'nodeLinker', 'node-modules');
await yarn('install');
await expect(yarn('workspace', 'meta-package', 'add', '-P', '[email protected]')).resolves.toBeTruthy();
await yarn('workspace', 'child', 'add', '-D', '[email protected]');
await expect(yarn('workspace', 'child', 'run', 'build')).resolves.toBeTruthy();Environment
System:
OS: macOS 12.3.1
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Binaries:
Node: 12.13.0 - /private/var/folders/4x/pqh5fq0x3mx_b1drhv0s2r900000gp/T/xfs-eb8ded8c/node
Yarn: 3.2.0 - /private/var/folders/4x/pqh5fq0x3mx_b1drhv0s2r900000gp/T/xfs-eb8ded8c/yarn
npm: 6.12.0 - ~/.nvm/versions/node/v12.13.0/bin/npmAdditional context
No response