-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Self-service
- I'd be willing to implement a fix
Describe the bug
hi!
First of all thanks for all your great work!
I found that after converting few projects to yarn workspaces the behavior of peerDependencies has changed: it's no longer guaranteed that used peer dependency in some workspace is exactly the same as in another workspace that consumes the 1st workspace. While docs say that they should be the same.
I've tried to add reproduction but messed up with filesystem somewhere. Though I assume it's clear what behavior I expect (if not, please, let me know, I'll do smth about it).
Would be very thankful for any advice.
The final aim: to be able to have different versions of react in a and b workspaces and make pkg workspace use exactly the same version of react depending on which workspace (a or b) it's executed.
To reproduce
const { promises: fs } = require('fs');
await fs.appendFile('.yarnrc.yml', '\nnodeLinker: node-modules\n')
// initializing workspaces
await Promise.all([fs.mkdir('a'), fs.mkdir('b'), fs.mkdir('pkg')]);
await Promise.all([
fs.writeFile('package.json', JSON.stringify({ workspaces: ['a', 'b', 'pkg'] }, null, 2)),
fs.writeFile(
'pkg/package.json',
JSON.stringify(
{
name: 'pkg',
version: '0.0.0',
peerDependencies: {
react: '>16.0.0',
},
},
null,
2,
),
),
fs.writeFile(
'a/package.json',
JSON.stringify(
{
name: 'a',
dependencies: {
pkg: '0.0.0',
react: '16.8.0',
},
},
null,
2,
),
),
fs.writeFile(
'b/package.json',
JSON.stringify(
{
name: 'b',
dependencies: {
pkg: '0.0.0',
react: '17.0.0',
},
},
null,
2,
),
),
]);
await yarn('install');
// initializing files
await Promise.all([
fs.writeFile(
'pkg/index.js',
'module.exports = { reactVersion: require("react").version }',
),
fs.writeFile(
'a/get-react-version-from-package.js',
`const fs = require('fs');
fs.writeFileSync(__dirname + "/react-version.txt", require("pkg").reactVersion)`,
),
fs.writeFile(
'b/get-react-version-from-package.js',
`const fs = require('fs');
fs.writeFileSync(__dirname + "/react-version.txt", require("pkg").reactVersion)`,
),
]);
// running the files
await Promise.all([
yarn('node', 'a/get-react-version-from-package.js'),
yarn('node', 'b/get-react-version-from-package.js'),
]);
// one of these is failing
await expect(fs.readFile('a/react-version.txt', `utf8`)).resolves.toBe('16.8.0');
await expect(fs.readFile('b/react-version.txt', `utf8`)).resolves.toBe('17.0.0');Environment
System:
OS: macOS 11.4
CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Binaries:
Node: 15.14.0 - /private/var/folders/bt/6t9rw3zs4gj58yc8xsp8xfbr0000gn/T/xfs-09a94538/node
Yarn: 2.4.2 - /private/var/folders/bt/6t9rw3zs4gj58yc8xsp8xfbr0000gn/T/xfs-09a94538/yarn
npm: 7.7.6 - ~/.nvm/versions/node/v15.14.0/bin/npm
Additional context
No response