Skip to content

Enforce same version of a dependency #12668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
594bfcb
enforce same version of a dependency
F3n67u Apr 12, 2022
43d50fd
add workflow
F3n67u Apr 12, 2022
82dbc04
fix pass 2
F3n67u Apr 12, 2022
5273ba8
react
F3n67u Apr 12, 2022
2fbef57
jest-environment-node
F3n67u Apr 12, 2022
8b92faa
update lock
F3n67u Apr 12, 2022
324418d
downgrade react of example-enzyme
F3n67u Apr 13, 2022
e4fe317
update yarn lock
F3n67u Apr 13, 2022
7bbbcb4
@types/node
F3n67u Apr 13, 2022
3d6e667
ignore prolog file
F3n67u Apr 13, 2022
4b21550
update lock
F3n67u Apr 13, 2022
f0e4aa8
prettier
F3n67u Apr 13, 2022
f389910
update root package.json
F3n67u Apr 13, 2022
dddf349
update example
F3n67u Apr 13, 2022
9ab23c5
update lock
F3n67u Apr 13, 2022
2d37018
check dev deps
F3n67u Apr 13, 2022
46a140e
ignore example enzyme
F3n67u Apr 13, 2022
09b7105
duplicated deps
F3n67u Apr 13, 2022
60851d7
fix contriants error
F3n67u Apr 13, 2022
dfcf657
update constriants
F3n67u Apr 13, 2022
f77e418
eslint to lint
F3n67u Apr 13, 2022
4ffbdec
update
F3n67u Apr 13, 2022
4dd6a3b
refactor: use member
F3n67u Apr 13, 2022
33f09e5
make typescript version consistent
F3n67u Apr 13, 2022
0120a79
update workflow and contributing.md
F3n67u Apr 13, 2022
280f346
update snapshot
F3n67u Apr 13, 2022
029c4e4
Update CONTRIBUTING.md
F3n67u Apr 13, 2022
1588faa
reorder
F3n67u Apr 18, 2022
5983579
example dir use *
F3n67u Apr 19, 2022
121fe50
update lock
F3n67u Apr 19, 2022
c628e7b
use node 12 in root
F3n67u Apr 19, 2022
801c01b
update lock
F3n67u Apr 19, 2022
bf3ae23
alphabetical
SimenB Apr 19, 2022
9eedd17
update verion on examples to workspace:*
F3n67u Apr 19, 2022
1fdef1e
workspace:*
F3n67u Apr 19, 2022
c4b11aa
workspace:*
F3n67u Apr 19, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
run: yarn verify-old-ts

lint:
name: Running ESLint
name: Running Lint
runs-on: ubuntu-latest
needs: prepare-yarn-cache

Expand All @@ -82,6 +82,20 @@ jobs:
- name: check copyright headers
run: yarn check-copyright-headers

yarn-validate:
name: Validate Yarn constraints
runs-on: ubuntu-latest
needs: prepare-yarn-cache
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: lts/*
cache: yarn
- name: 'Check for unmet constraints (fix w/ "yarn constraints --fix")'
run: |
yarn constraints

test:
name: Node v${{ matrix.node-version }} on ${{ matrix.os }} (${{ matrix.shard }})
strategy:
Expand Down
52 changes: 52 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-constraints.cjs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ packageExtensions:
"@babel/preset-env": ^7.1.6

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-constraints.cjs
spec: "@yarnpkg/plugin-constraints"
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: "@yarnpkg/plugin-interactive-tools"
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
Expand Down
12 changes: 12 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ Time: 0.232 s, estimated 1 s
Ran all test suites.
```

## Checking Constraints

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.

Constraints can be checked with `yarn constraints`, and fixed with `yarn constraints --fix`. Generally speaking:

- 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.

- A dependency doesn't appear in both `dependencies` and `devDependencies` of the same workspace.

- Workspaces must point our repository through the `repository` field.

##### Using jest-circus

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.
Expand Down
74 changes: 74 additions & 0 deletions constraints.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
constraints_min_version(1).

% This file is written in Prolog
% It contains rules that the project must respect.
% Check with "yarn constraints" (fix w/ "yarn constraints --fix")
% Yarn Constraints https://yarnpkg.com/features/constraints
% Reference for other constraints:
% https://github.com/babel/babel/blob/main/constraints.pro
% https://github.com/yarnpkg/berry/blob/master/constraints.pro

% This rule will enforce that a workspace MUST depend on the same version of a dependency as the one used by the other workspaces
gen_enforced_dependency(WorkspaceCwd, DependencyIdent, DependencyRange2, DependencyType) :-
% Iterates over all dependencies from all workspaces
workspace_has_dependency(WorkspaceCwd, DependencyIdent, DependencyRange, DependencyType),
% Iterates over similarly-named dependencies from all workspaces (again)
workspace_has_dependency(OtherWorkspaceCwd, DependencyIdent, DependencyRange2, DependencyType2),
% Ignore peer dependencies
DependencyType \= 'peerDependencies',
DependencyType2 \= 'peerDependencies',
% Ignore *
DependencyRange \= '*',
DependencyRange2 \= '*',
% Get the workspace name
workspace_ident(WorkspaceCwd, WorkspaceIdent),
workspace_ident(OtherWorkspaceCwd, OtherWorkspaceIdent),
% Allow enzyme example workspace use a older version react and react-dom, because enzyme don't support react 17
(
(WorkspaceIdent = 'example-enzyme'; OtherWorkspaceIdent = 'example-enzyme') ->
\+ member(DependencyIdent, ['react', 'react-dom'])
;
true
).

% Enforces that a dependency doesn't appear in both `dependencies` and `devDependencies`
gen_enforced_dependency(WorkspaceCwd, DependencyIdent, null, 'devDependencies') :-
workspace_has_dependency(WorkspaceCwd, DependencyIdent, _, 'devDependencies'),
workspace_has_dependency(WorkspaceCwd, DependencyIdent, _, 'dependencies').

% Enforces the license in all public workspaces while removing it from private workspaces
gen_enforced_field(WorkspaceCwd, 'license', 'MIT') :-
\+ workspace_field(WorkspaceCwd, 'private', true).
gen_enforced_field(WorkspaceCwd, 'license', null) :-
workspace_field(WorkspaceCwd, 'private', true).

% Enforces the repository field for all public workspaces while removing it from private workspaces
gen_enforced_field(WorkspaceCwd, 'repository.type', 'git') :-
\+ workspace_field(WorkspaceCwd, 'private', true).
gen_enforced_field(WorkspaceCwd, 'repository.url', 'https://github.com/facebook/jest.git') :-
\+ workspace_field(WorkspaceCwd, 'private', true).
gen_enforced_field(WorkspaceCwd, 'repository.directory', WorkspaceCwd) :-
\+ workspace_field(WorkspaceCwd, 'private', true).
gen_enforced_field(WorkspaceCwd, 'repository', null) :-
workspace_field(WorkspaceCwd, 'private', true).

% Enforces 'publishConfig.access' is set to public for public workspaces while removing it from private workspaces
gen_enforced_field(WorkspaceCwd, 'publishConfig.access', 'public') :-
\+ workspace_field(WorkspaceCwd, 'private', true).
gen_enforced_field(WorkspaceCwd, 'publishConfig.access', null) :-
workspace_field(WorkspaceCwd, 'private', true).

% Enforces the engines.node field for public workspace
gen_enforced_field(WorkspaceCwd, 'engines.node', '^12.13.0 || ^14.15.0 || ^16.13.0 || >=17.0.0') :-
\+ workspace_field(WorkspaceCwd, 'private', true).

% Enforces the main and types field to start with ./
gen_enforced_field(WorkspaceCwd, FieldName, ExpectedValue) :-
% Fields the rule applies to
member(FieldName, ['main', 'types']),
% Get current value
workspace_field(WorkspaceCwd, FieldName, CurrentValue),
% Must not start with ./ already
\+ atom_concat('./', _, CurrentValue),
% Store './' + CurrentValue in ExpectedValue
atom_concat('./', CurrentValue, ExpectedValue).
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ exports[`processes stack traces and code frames with source maps with coverage 1
15 | }
16 |

at Object.error (lib.ts:14:9)
at Object.<anonymous> (__tests__/fails.ts:10:3)"
at error (lib.ts:14:9)
at Object.<anonymous> (__tests__/fails.ts:10:8)"
`;
2 changes: 1 addition & 1 deletion e2e/babel-plugin-jest-hoist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"@babel/preset-env": "^7.0.0",
"@babel/preset-flow": "^7.0.0",
"@babel/preset-typescript": "^7.0.0",
"react": "*"
"react": "17.0.2"
},
"jest": {
"automock": true,
Expand Down
4 changes: 2 additions & 2 deletions e2e/babel-plugin-jest-hoist/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1596,7 +1596,7 @@ __metadata:
languageName: node
linkType: hard

"react@npm:*":
"react@npm:17.0.2":
version: 17.0.2
resolution: "react@npm:17.0.2"
dependencies:
Expand Down Expand Up @@ -1703,7 +1703,7 @@ __metadata:
"@babel/preset-env": ^7.0.0
"@babel/preset-flow": ^7.0.0
"@babel/preset-typescript": ^7.0.0
react: "*"
react: 17.0.2
languageName: unknown
linkType: soft

Expand Down
2 changes: 1 addition & 1 deletion e2e/coverage-remapping/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"testEnvironment": "node"
},
"dependencies": {
"typescript": "^3.7.4"
"typescript": "^4.6.2"
}
}
18 changes: 9 additions & 9 deletions e2e/coverage-remapping/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ __metadata:
version: 0.0.0-use.local
resolution: "root-workspace-0b6124@workspace:."
dependencies:
typescript: ^3.7.4
typescript: ^4.6.2
languageName: unknown
linkType: soft

"typescript@npm:^3.7.4":
version: 3.9.10
resolution: "typescript@npm:3.9.10"
"typescript@npm:^4.6.2":
version: 4.6.3
resolution: "typescript@npm:4.6.3"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 46c842e2cd4797b88b66ef06c9c41dd21da48b95787072ccf39d5f2aa3124361bc4c966aa1c7f709fae0509614d76751455b5231b12dbb72eb97a31369e1ff92
checksum: 255bb26c8cb846ca689dd1c3a56587af4f69055907aa2c154796ea28ee0dea871535b1c78f85a6212c77f2657843a269c3a742d09d81495b97b914bf7920415b
languageName: node
linkType: hard

"typescript@patch:typescript@^3.7.4#~builtin<compat/typescript>":
version: 3.9.10
resolution: "typescript@patch:typescript@npm%3A3.9.10#~builtin<compat/typescript>::version=3.9.10&hash=bda367"
"typescript@patch:typescript@^4.6.2#~builtin<compat/typescript>":
version: 4.6.3
resolution: "typescript@patch:typescript@npm%3A4.6.3#~builtin<compat/typescript>::version=4.6.3&hash=bda367"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: dc7141ab555b23a8650a6787f98845fc11692063d02b75ff49433091b3af2fe3d773650dea18389d7c21f47d620fb3b110ea363dab4ab039417a6ccbbaf96fc2
checksum: 6bf45caf847062420592e711bc9c28bf5f9a9a7fa8245343b81493e4ededae33f1774009d1234d911422d1646a2c839f44e1a23ecb111b40a60ac2ea4c1482a8
languageName: node
linkType: hard
2 changes: 1 addition & 1 deletion e2e/stack-trace-source-maps-with-coverage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"testRegex": "fails"
},
"dependencies": {
"typescript": "^3.7.4"
"typescript": "^4.6.2"
}
}
18 changes: 9 additions & 9 deletions e2e/stack-trace-source-maps-with-coverage/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ __metadata:
version: 0.0.0-use.local
resolution: "root-workspace-0b6124@workspace:."
dependencies:
typescript: ^3.7.4
typescript: ^4.6.2
languageName: unknown
linkType: soft

"typescript@npm:^3.7.4":
version: 3.9.10
resolution: "typescript@npm:3.9.10"
"typescript@npm:^4.6.2":
version: 4.6.3
resolution: "typescript@npm:4.6.3"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 46c842e2cd4797b88b66ef06c9c41dd21da48b95787072ccf39d5f2aa3124361bc4c966aa1c7f709fae0509614d76751455b5231b12dbb72eb97a31369e1ff92
checksum: 255bb26c8cb846ca689dd1c3a56587af4f69055907aa2c154796ea28ee0dea871535b1c78f85a6212c77f2657843a269c3a742d09d81495b97b914bf7920415b
languageName: node
linkType: hard

"typescript@patch:typescript@^3.7.4#~builtin<compat/typescript>":
version: 3.9.10
resolution: "typescript@patch:typescript@npm%3A3.9.10#~builtin<compat/typescript>::version=3.9.10&hash=bda367"
"typescript@patch:typescript@^4.6.2#~builtin<compat/typescript>":
version: 4.6.3
resolution: "typescript@patch:typescript@npm%3A4.6.3#~builtin<compat/typescript>::version=4.6.3&hash=bda367"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: dc7141ab555b23a8650a6787f98845fc11692063d02b75ff49433091b3af2fe3d773650dea18389d7c21f47d620fb3b110ea363dab4ab039417a6ccbbaf96fc2
checksum: 6bf45caf847062420592e711bc9c28bf5f9a9a7fa8245343b81493e4ededae33f1774009d1234d911422d1646a2c839f44e1a23ecb111b40a60ac2ea4c1482a8
languageName: node
linkType: hard
2 changes: 1 addition & 1 deletion e2e/stack-trace-source-maps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"testRegex": "fails"
},
"dependencies": {
"typescript": "^3.7.4"
"typescript": "^4.6.2"
}
}
18 changes: 9 additions & 9 deletions e2e/stack-trace-source-maps/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ __metadata:
version: 0.0.0-use.local
resolution: "root-workspace-0b6124@workspace:."
dependencies:
typescript: ^3.7.4
typescript: ^4.6.2
languageName: unknown
linkType: soft

"typescript@npm:^3.7.4":
version: 3.9.10
resolution: "typescript@npm:3.9.10"
"typescript@npm:^4.6.2":
version: 4.6.3
resolution: "typescript@npm:4.6.3"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 46c842e2cd4797b88b66ef06c9c41dd21da48b95787072ccf39d5f2aa3124361bc4c966aa1c7f709fae0509614d76751455b5231b12dbb72eb97a31369e1ff92
checksum: 255bb26c8cb846ca689dd1c3a56587af4f69055907aa2c154796ea28ee0dea871535b1c78f85a6212c77f2657843a269c3a742d09d81495b97b914bf7920415b
languageName: node
linkType: hard

"typescript@patch:typescript@^3.7.4#~builtin<compat/typescript>":
version: 3.9.10
resolution: "typescript@patch:typescript@npm%3A3.9.10#~builtin<compat/typescript>::version=3.9.10&hash=bda367"
"typescript@patch:typescript@^4.6.2#~builtin<compat/typescript>":
version: 4.6.3
resolution: "typescript@patch:typescript@npm%3A4.6.3#~builtin<compat/typescript>::version=4.6.3&hash=bda367"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: dc7141ab555b23a8650a6787f98845fc11692063d02b75ff49433091b3af2fe3d773650dea18389d7c21f47d620fb3b110ea363dab4ab039417a6ccbbaf96fc2
checksum: 6bf45caf847062420592e711bc9c28bf5f9a9a7fa8245343b81493e4ededae33f1774009d1234d911422d1646a2c839f44e1a23ecb111b40a60ac2ea4c1482a8
languageName: node
linkType: hard
6 changes: 3 additions & 3 deletions e2e/transform/multiple-transformers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"@babel/core": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"react": "*",
"react-dom": "*",
"react-test-renderer": "*"
"react": "17.0.2",
"react-dom": "^17.0.1",
"react-test-renderer": "17.0.2"
}
}
12 changes: 6 additions & 6 deletions e2e/transform/multiple-transformers/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1700,7 +1700,7 @@ __metadata:
languageName: node
linkType: hard

"react-dom@npm:*":
"react-dom@npm:^17.0.1":
version: 17.0.2
resolution: "react-dom@npm:17.0.2"
dependencies:
Expand Down Expand Up @@ -1732,7 +1732,7 @@ __metadata:
languageName: node
linkType: hard

"react-test-renderer@npm:*":
"react-test-renderer@npm:17.0.2":
version: 17.0.2
resolution: "react-test-renderer@npm:17.0.2"
dependencies:
Expand All @@ -1746,7 +1746,7 @@ __metadata:
languageName: node
linkType: hard

"react@npm:*":
"react@npm:17.0.2":
version: 17.0.2
resolution: "react@npm:17.0.2"
dependencies:
Expand Down Expand Up @@ -1853,9 +1853,9 @@ __metadata:
"@babel/core": ^7.0.0
"@babel/preset-env": ^7.0.0
"@babel/preset-react": ^7.0.0
react: "*"
react-dom: "*"
react-test-renderer: "*"
react: 17.0.2
react-dom: ^17.0.1
react-test-renderer: 17.0.2
languageName: unknown
linkType: soft

Expand Down
2 changes: 1 addition & 1 deletion e2e/typescript-coverage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"testEnvironment": "node"
},
"dependencies": {
"typescript": "^3.3.1"
"typescript": "^4.6.2"
}
}
18 changes: 9 additions & 9 deletions e2e/typescript-coverage/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ __metadata:
version: 0.0.0-use.local
resolution: "root-workspace-0b6124@workspace:."
dependencies:
typescript: ^3.3.1
typescript: ^4.6.2
languageName: unknown
linkType: soft

"typescript@npm:^3.3.1":
version: 3.9.10
resolution: "typescript@npm:3.9.10"
"typescript@npm:^4.6.2":
version: 4.6.3
resolution: "typescript@npm:4.6.3"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 46c842e2cd4797b88b66ef06c9c41dd21da48b95787072ccf39d5f2aa3124361bc4c966aa1c7f709fae0509614d76751455b5231b12dbb72eb97a31369e1ff92
checksum: 255bb26c8cb846ca689dd1c3a56587af4f69055907aa2c154796ea28ee0dea871535b1c78f85a6212c77f2657843a269c3a742d09d81495b97b914bf7920415b
languageName: node
linkType: hard

"typescript@patch:typescript@^3.3.1#~builtin<compat/typescript>":
version: 3.9.10
resolution: "typescript@patch:typescript@npm%3A3.9.10#~builtin<compat/typescript>::version=3.9.10&hash=bda367"
"typescript@patch:typescript@^4.6.2#~builtin<compat/typescript>":
version: 4.6.3
resolution: "typescript@patch:typescript@npm%3A4.6.3#~builtin<compat/typescript>::version=4.6.3&hash=bda367"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: dc7141ab555b23a8650a6787f98845fc11692063d02b75ff49433091b3af2fe3d773650dea18389d7c21f47d620fb3b110ea363dab4ab039417a6ccbbaf96fc2
checksum: 6bf45caf847062420592e711bc9c28bf5f9a9a7fa8245343b81493e4ededae33f1774009d1234d911422d1646a2c839f44e1a23ecb111b40a60ac2ea4c1482a8
languageName: node
linkType: hard
Loading