-
Notifications
You must be signed in to change notification settings - Fork 0
/
constraints.pro
48 lines (41 loc) · 2.42 KB
/
constraints.pro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
constraints_min_version(1).
% This file is written in Prolog
% It contains rules that the project must respect.
% In order to see them in action, run `yarn constraints source`
% 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 devDependencies on other workspaces
(
(DependencyType = 'devDependencies'; DependencyType2 = 'devDependencies') ->
\+ workspace_ident(DependencyCwd, DependencyIdent)
;
true
).
% This rule will prevent workspaces from depending on non-workspace versions of available workspaces
gen_enforced_dependency(WorkspaceCwd, DependencyIdent, 'workspace:^', DependencyType) :-
% Iterates over all dependencies from all workspaces
workspace_has_dependency(WorkspaceCwd, DependencyIdent, DependencyRange, DependencyType),
% Only consider those that target something that could be a workspace
workspace_ident(DependencyCwd, DependencyIdent).
% This rule will enforce that all packages must have an correct engines.node field
% Keep in sync with the range inside packages/yarnpkg-cli/sources/main.ts
gen_enforced_field(WorkspaceCwd, 'engines.node', '16.x || 18.x || 20.x').
% Required to make the package work with the GitHub Package Registry
gen_enforced_field(WorkspaceCwd, 'repository.type', 'git').
gen_enforced_field(WorkspaceCwd, 'repository.url', 'ssh://git@github.com/lukeshay/npm.git').
gen_enforced_field(WorkspaceCwd, 'repository.directory', WorkspaceCwd).
% Require scripts for all apps and packages
% gen_enforced_field(WorkspaceCwd, 'scripts.build', _).
% gen_enforced_field(WorkspaceCwd, 'scripts.test', _).
% gen_enforced_field(WorkspaceCwd, 'scripts.clean', _).
% Validate other fields
gen_enforced_field(WorkspaceCwd, 'license', 'MIT').
% gen_enforced_field(WorkspaceCwd, 'devDependencies.prettier', _).
% gen_enforced_field(WorkspaceCwd, 'devDependencies.eslint', _).