Skip to content

Commit ccecdae

Browse files
authored
Enforce same version of a dependency (#12668)
1 parent 7f484cb commit ccecdae

File tree

50 files changed

+464
-310
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+464
-310
lines changed

.github/workflows/nodejs.yml

+15-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
run: yarn verify-old-ts
6060

6161
lint:
62-
name: Running ESLint
62+
name: Running Lint
6363
runs-on: ubuntu-latest
6464
needs: prepare-yarn-cache
6565

@@ -82,6 +82,20 @@ jobs:
8282
- name: check copyright headers
8383
run: yarn check-copyright-headers
8484

85+
yarn-validate:
86+
name: Validate Yarn constraints
87+
runs-on: ubuntu-latest
88+
needs: prepare-yarn-cache
89+
steps:
90+
- uses: actions/checkout@v3
91+
- uses: actions/setup-node@v3
92+
with:
93+
node-version: lts/*
94+
cache: yarn
95+
- name: 'Check for unmet constraints (fix w/ "yarn constraints --fix")'
96+
run: |
97+
yarn constraints
98+
8599
test:
86100
name: Node v${{ matrix.node-version }} on ${{ matrix.os }} (${{ matrix.shard }})
87101
strategy:

.yarn/plugins/@yarnpkg/plugin-constraints.cjs

+52
Large diffs are not rendered by default.

.yarnrc.yml

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ packageExtensions:
2727
"@babel/preset-env": ^7.1.6
2828

2929
plugins:
30+
- path: .yarn/plugins/@yarnpkg/plugin-constraints.cjs
31+
spec: "@yarnpkg/plugin-constraints"
3032
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
3133
spec: "@yarnpkg/plugin-interactive-tools"
3234
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs

CONTRIBUTING.md

+12
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,18 @@ Time: 0.232 s, estimated 1 s
129129
Ran all test suites.
130130
```
131131

132+
## Checking Constraints
133+
134+
We use [Yarn Constraints](https://yarnpkg.com/features/constraints) to enforce various rules across the repository. They are declared inside the [`constraints.pro` file](https://github.com/facebook/jest/blob/main/constraints.pro) and their purposes are documented with comments.
135+
136+
Constraints can be checked with `yarn constraints`, and fixed with `yarn constraints --fix`. Generally speaking:
137+
138+
- Workspaces must not depend on conflicting ranges of dependencies. Use the `-i,--interactive` flag and select "Reuse" when installing dependencies and you shouldn't ever have to deal with this rule.
139+
140+
- A dependency doesn't appear in both `dependencies` and `devDependencies` of the same workspace.
141+
142+
- Workspaces must point our repository through the `repository` field.
143+
132144
##### Using jest-circus
133145

134146
There may be cases where you want to run jest using `jest-circus` instead of `jest-jasmine2` (which is the default runner) for integration testing. In situations like this, set the environment variable `JEST_CIRCUS` to 1. That will configure jest to use `jest-circus`. So something like this.

constraints.pro

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
constraints_min_version(1).
2+
3+
% This file is written in Prolog
4+
% It contains rules that the project must respect.
5+
% Check with "yarn constraints" (fix w/ "yarn constraints --fix")
6+
% Yarn Constraints https://yarnpkg.com/features/constraints
7+
% Reference for other constraints:
8+
% https://github.com/babel/babel/blob/main/constraints.pro
9+
% https://github.com/yarnpkg/berry/blob/master/constraints.pro
10+
11+
% This rule will enforce that a workspace MUST depend on the same version of a dependency as the one used by the other workspaces
12+
gen_enforced_dependency(WorkspaceCwd, DependencyIdent, DependencyRange2, DependencyType) :-
13+
% Iterates over all dependencies from all workspaces
14+
workspace_has_dependency(WorkspaceCwd, DependencyIdent, DependencyRange, DependencyType),
15+
% Iterates over similarly-named dependencies from all workspaces (again)
16+
workspace_has_dependency(OtherWorkspaceCwd, DependencyIdent, DependencyRange2, DependencyType2),
17+
% Ignore peer dependencies
18+
DependencyType \= 'peerDependencies',
19+
DependencyType2 \= 'peerDependencies',
20+
% Ignore workspace:*: we use both `workspace:*` and real version such as `^28.0.0-alpha.8` to reference package in monorepo
21+
% TODO: in the future we should make it consistent and remove this ignore
22+
DependencyRange \= 'workspace:*',
23+
DependencyRange2 \= 'workspace:*',
24+
% Get the workspace name
25+
workspace_ident(WorkspaceCwd, WorkspaceIdent),
26+
workspace_ident(OtherWorkspaceCwd, OtherWorkspaceIdent),
27+
% @types/node in the root need to stay on ~12.12.0
28+
(
29+
(WorkspaceIdent = '@jest/monorepo'; OtherWorkspaceIdent = '@jest/monorepo') ->
30+
DependencyIdent \= '@types/node'
31+
;
32+
true
33+
),
34+
% Allow enzyme example workspace use a older version react and react-dom, because enzyme don't support react 17
35+
(
36+
(WorkspaceIdent = 'example-enzyme'; OtherWorkspaceIdent = 'example-enzyme') ->
37+
\+ member(DependencyIdent, ['react', 'react-dom'])
38+
;
39+
true
40+
).
41+
42+
% Enforces that a dependency doesn't appear in both `dependencies` and `devDependencies`
43+
gen_enforced_dependency(WorkspaceCwd, DependencyIdent, null, 'devDependencies') :-
44+
workspace_has_dependency(WorkspaceCwd, DependencyIdent, _, 'devDependencies'),
45+
workspace_has_dependency(WorkspaceCwd, DependencyIdent, _, 'dependencies').
46+
47+
% Enforces the license in all public workspaces while removing it from private workspaces
48+
gen_enforced_field(WorkspaceCwd, 'license', 'MIT') :-
49+
\+ workspace_field(WorkspaceCwd, 'private', true).
50+
gen_enforced_field(WorkspaceCwd, 'license', null) :-
51+
workspace_field(WorkspaceCwd, 'private', true).
52+
53+
% Enforces the repository field for all public workspaces while removing it from private workspaces
54+
gen_enforced_field(WorkspaceCwd, 'repository.type', 'git') :-
55+
\+ workspace_field(WorkspaceCwd, 'private', true).
56+
gen_enforced_field(WorkspaceCwd, 'repository.url', 'https://github.com/facebook/jest.git') :-
57+
\+ workspace_field(WorkspaceCwd, 'private', true).
58+
gen_enforced_field(WorkspaceCwd, 'repository.directory', WorkspaceCwd) :-
59+
\+ workspace_field(WorkspaceCwd, 'private', true).
60+
gen_enforced_field(WorkspaceCwd, 'repository', null) :-
61+
workspace_field(WorkspaceCwd, 'private', true).
62+
63+
% Enforces 'publishConfig.access' is set to public for public workspaces while removing it from private workspaces
64+
gen_enforced_field(WorkspaceCwd, 'publishConfig.access', 'public') :-
65+
\+ workspace_field(WorkspaceCwd, 'private', true).
66+
gen_enforced_field(WorkspaceCwd, 'publishConfig.access', null) :-
67+
workspace_field(WorkspaceCwd, 'private', true).
68+
69+
% Enforces the engines.node field for public workspace
70+
gen_enforced_field(WorkspaceCwd, 'engines.node', '^12.13.0 || ^14.15.0 || ^16.13.0 || >=17.0.0') :-
71+
\+ workspace_field(WorkspaceCwd, 'private', true).
72+
73+
% Enforces the main and types field to start with ./
74+
gen_enforced_field(WorkspaceCwd, FieldName, ExpectedValue) :-
75+
% Fields the rule applies to
76+
member(FieldName, ['main', 'types']),
77+
% Get current value
78+
workspace_field(WorkspaceCwd, FieldName, CurrentValue),
79+
% Must not start with ./ already
80+
\+ atom_concat('./', _, CurrentValue),
81+
% Store './' + CurrentValue in ExpectedValue
82+
atom_concat('./', CurrentValue, ExpectedValue).

e2e/__tests__/__snapshots__/stackTraceSourceMapsWithCoverage.test.ts.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ exports[`processes stack traces and code frames with source maps with coverage 1
1515
15 | }
1616
16 |
1717
18-
at Object.error (lib.ts:14:9)
19-
at Object.<anonymous> (__tests__/fails.ts:10:3)"
18+
at error (lib.ts:14:9)
19+
at Object.<anonymous> (__tests__/fails.ts:10:8)"
2020
`;

e2e/babel-plugin-jest-hoist/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"@babel/preset-env": "^7.0.0",
44
"@babel/preset-flow": "^7.0.0",
55
"@babel/preset-typescript": "^7.0.0",
6-
"react": "*"
6+
"react": "17.0.2"
77
},
88
"jest": {
99
"automock": true,

e2e/babel-plugin-jest-hoist/yarn.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -1596,7 +1596,7 @@ __metadata:
15961596
languageName: node
15971597
linkType: hard
15981598

1599-
"react@npm:*":
1599+
"react@npm:17.0.2":
16001600
version: 17.0.2
16011601
resolution: "react@npm:17.0.2"
16021602
dependencies:
@@ -1703,7 +1703,7 @@ __metadata:
17031703
"@babel/preset-env": ^7.0.0
17041704
"@babel/preset-flow": ^7.0.0
17051705
"@babel/preset-typescript": ^7.0.0
1706-
react: "*"
1706+
react: 17.0.2
17071707
languageName: unknown
17081708
linkType: soft
17091709

e2e/coverage-remapping/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
"testEnvironment": "node"
88
},
99
"dependencies": {
10-
"typescript": "^3.7.4"
10+
"typescript": "^4.6.2"
1111
}
1212
}

e2e/coverage-remapping/yarn.lock

+9-9
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@ __metadata:
99
version: 0.0.0-use.local
1010
resolution: "root-workspace-0b6124@workspace:."
1111
dependencies:
12-
typescript: ^3.7.4
12+
typescript: ^4.6.2
1313
languageName: unknown
1414
linkType: soft
1515

16-
"typescript@npm:^3.7.4":
17-
version: 3.9.10
18-
resolution: "typescript@npm:3.9.10"
16+
"typescript@npm:^4.6.2":
17+
version: 4.6.3
18+
resolution: "typescript@npm:4.6.3"
1919
bin:
2020
tsc: bin/tsc
2121
tsserver: bin/tsserver
22-
checksum: 46c842e2cd4797b88b66ef06c9c41dd21da48b95787072ccf39d5f2aa3124361bc4c966aa1c7f709fae0509614d76751455b5231b12dbb72eb97a31369e1ff92
22+
checksum: 255bb26c8cb846ca689dd1c3a56587af4f69055907aa2c154796ea28ee0dea871535b1c78f85a6212c77f2657843a269c3a742d09d81495b97b914bf7920415b
2323
languageName: node
2424
linkType: hard
2525

26-
"typescript@patch:typescript@^3.7.4#~builtin<compat/typescript>":
27-
version: 3.9.10
28-
resolution: "typescript@patch:typescript@npm%3A3.9.10#~builtin<compat/typescript>::version=3.9.10&hash=bda367"
26+
"typescript@patch:typescript@^4.6.2#~builtin<compat/typescript>":
27+
version: 4.6.3
28+
resolution: "typescript@patch:typescript@npm%3A4.6.3#~builtin<compat/typescript>::version=4.6.3&hash=bda367"
2929
bin:
3030
tsc: bin/tsc
3131
tsserver: bin/tsserver
32-
checksum: dc7141ab555b23a8650a6787f98845fc11692063d02b75ff49433091b3af2fe3d773650dea18389d7c21f47d620fb3b110ea363dab4ab039417a6ccbbaf96fc2
32+
checksum: 6bf45caf847062420592e711bc9c28bf5f9a9a7fa8245343b81493e4ededae33f1774009d1234d911422d1646a2c839f44e1a23ecb111b40a60ac2ea4c1482a8
3333
languageName: node
3434
linkType: hard

e2e/stack-trace-source-maps-with-coverage/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"testRegex": "fails"
99
},
1010
"dependencies": {
11-
"typescript": "^3.7.4"
11+
"typescript": "^4.6.2"
1212
}
1313
}

e2e/stack-trace-source-maps-with-coverage/yarn.lock

+9-9
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@ __metadata:
99
version: 0.0.0-use.local
1010
resolution: "root-workspace-0b6124@workspace:."
1111
dependencies:
12-
typescript: ^3.7.4
12+
typescript: ^4.6.2
1313
languageName: unknown
1414
linkType: soft
1515

16-
"typescript@npm:^3.7.4":
17-
version: 3.9.10
18-
resolution: "typescript@npm:3.9.10"
16+
"typescript@npm:^4.6.2":
17+
version: 4.6.3
18+
resolution: "typescript@npm:4.6.3"
1919
bin:
2020
tsc: bin/tsc
2121
tsserver: bin/tsserver
22-
checksum: 46c842e2cd4797b88b66ef06c9c41dd21da48b95787072ccf39d5f2aa3124361bc4c966aa1c7f709fae0509614d76751455b5231b12dbb72eb97a31369e1ff92
22+
checksum: 255bb26c8cb846ca689dd1c3a56587af4f69055907aa2c154796ea28ee0dea871535b1c78f85a6212c77f2657843a269c3a742d09d81495b97b914bf7920415b
2323
languageName: node
2424
linkType: hard
2525

26-
"typescript@patch:typescript@^3.7.4#~builtin<compat/typescript>":
27-
version: 3.9.10
28-
resolution: "typescript@patch:typescript@npm%3A3.9.10#~builtin<compat/typescript>::version=3.9.10&hash=bda367"
26+
"typescript@patch:typescript@^4.6.2#~builtin<compat/typescript>":
27+
version: 4.6.3
28+
resolution: "typescript@patch:typescript@npm%3A4.6.3#~builtin<compat/typescript>::version=4.6.3&hash=bda367"
2929
bin:
3030
tsc: bin/tsc
3131
tsserver: bin/tsserver
32-
checksum: dc7141ab555b23a8650a6787f98845fc11692063d02b75ff49433091b3af2fe3d773650dea18389d7c21f47d620fb3b110ea363dab4ab039417a6ccbbaf96fc2
32+
checksum: 6bf45caf847062420592e711bc9c28bf5f9a9a7fa8245343b81493e4ededae33f1774009d1234d911422d1646a2c839f44e1a23ecb111b40a60ac2ea4c1482a8
3333
languageName: node
3434
linkType: hard

e2e/stack-trace-source-maps/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"testRegex": "fails"
99
},
1010
"dependencies": {
11-
"typescript": "^3.7.4"
11+
"typescript": "^4.6.2"
1212
}
1313
}

e2e/stack-trace-source-maps/yarn.lock

+9-9
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@ __metadata:
99
version: 0.0.0-use.local
1010
resolution: "root-workspace-0b6124@workspace:."
1111
dependencies:
12-
typescript: ^3.7.4
12+
typescript: ^4.6.2
1313
languageName: unknown
1414
linkType: soft
1515

16-
"typescript@npm:^3.7.4":
17-
version: 3.9.10
18-
resolution: "typescript@npm:3.9.10"
16+
"typescript@npm:^4.6.2":
17+
version: 4.6.3
18+
resolution: "typescript@npm:4.6.3"
1919
bin:
2020
tsc: bin/tsc
2121
tsserver: bin/tsserver
22-
checksum: 46c842e2cd4797b88b66ef06c9c41dd21da48b95787072ccf39d5f2aa3124361bc4c966aa1c7f709fae0509614d76751455b5231b12dbb72eb97a31369e1ff92
22+
checksum: 255bb26c8cb846ca689dd1c3a56587af4f69055907aa2c154796ea28ee0dea871535b1c78f85a6212c77f2657843a269c3a742d09d81495b97b914bf7920415b
2323
languageName: node
2424
linkType: hard
2525

26-
"typescript@patch:typescript@^3.7.4#~builtin<compat/typescript>":
27-
version: 3.9.10
28-
resolution: "typescript@patch:typescript@npm%3A3.9.10#~builtin<compat/typescript>::version=3.9.10&hash=bda367"
26+
"typescript@patch:typescript@^4.6.2#~builtin<compat/typescript>":
27+
version: 4.6.3
28+
resolution: "typescript@patch:typescript@npm%3A4.6.3#~builtin<compat/typescript>::version=4.6.3&hash=bda367"
2929
bin:
3030
tsc: bin/tsc
3131
tsserver: bin/tsserver
32-
checksum: dc7141ab555b23a8650a6787f98845fc11692063d02b75ff49433091b3af2fe3d773650dea18389d7c21f47d620fb3b110ea363dab4ab039417a6ccbbaf96fc2
32+
checksum: 6bf45caf847062420592e711bc9c28bf5f9a9a7fa8245343b81493e4ededae33f1774009d1234d911422d1646a2c839f44e1a23ecb111b40a60ac2ea4c1482a8
3333
languageName: node
3434
linkType: hard

e2e/transform/multiple-transformers/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"@babel/core": "^7.0.0",
1818
"@babel/preset-env": "^7.0.0",
1919
"@babel/preset-react": "^7.0.0",
20-
"react": "*",
21-
"react-dom": "*",
22-
"react-test-renderer": "*"
20+
"react": "17.0.2",
21+
"react-dom": "^17.0.1",
22+
"react-test-renderer": "17.0.2"
2323
}
2424
}

e2e/transform/multiple-transformers/yarn.lock

+6-6
Original file line numberDiff line numberDiff line change
@@ -1700,7 +1700,7 @@ __metadata:
17001700
languageName: node
17011701
linkType: hard
17021702

1703-
"react-dom@npm:*":
1703+
"react-dom@npm:^17.0.1":
17041704
version: 17.0.2
17051705
resolution: "react-dom@npm:17.0.2"
17061706
dependencies:
@@ -1732,7 +1732,7 @@ __metadata:
17321732
languageName: node
17331733
linkType: hard
17341734

1735-
"react-test-renderer@npm:*":
1735+
"react-test-renderer@npm:17.0.2":
17361736
version: 17.0.2
17371737
resolution: "react-test-renderer@npm:17.0.2"
17381738
dependencies:
@@ -1746,7 +1746,7 @@ __metadata:
17461746
languageName: node
17471747
linkType: hard
17481748

1749-
"react@npm:*":
1749+
"react@npm:17.0.2":
17501750
version: 17.0.2
17511751
resolution: "react@npm:17.0.2"
17521752
dependencies:
@@ -1853,9 +1853,9 @@ __metadata:
18531853
"@babel/core": ^7.0.0
18541854
"@babel/preset-env": ^7.0.0
18551855
"@babel/preset-react": ^7.0.0
1856-
react: "*"
1857-
react-dom: "*"
1858-
react-test-renderer: "*"
1856+
react: 17.0.2
1857+
react-dom: ^17.0.1
1858+
react-test-renderer: 17.0.2
18591859
languageName: unknown
18601860
linkType: soft
18611861

e2e/typescript-coverage/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
"testEnvironment": "node"
88
},
99
"dependencies": {
10-
"typescript": "^3.3.1"
10+
"typescript": "^4.6.2"
1111
}
1212
}

0 commit comments

Comments
 (0)