Skip to content

Commit

Permalink
refactor: make it easier to add an exception to same version rule (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
F3n67u authored May 6, 2022
1 parent d5a6863 commit 9093915
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions constraints.pro
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,23 @@ constraints_min_version(1).
% 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),
workspace_has_dependency(WorkspaceCwd, DependencyIdent, DependencyRange, DependencyType),
% Iterates over similarly-named dependencies from all workspaces (again)
workspace_has_dependency(OtherWorkspaceCwd, DependencyIdent, DependencyRange2, DependencyType2),
workspace_has_dependency(OtherWorkspaceCwd, DependencyIdent, DependencyRange2, DependencyType2),
% Ignore peer dependencies
DependencyType \= 'peerDependencies',
DependencyType2 \= 'peerDependencies',
DependencyType \= 'peerDependencies',
DependencyType2 \= 'peerDependencies',
% Ignore workspace:*: we use both `workspace:*` and real version such as `^28.0.0-alpha.8` to reference package in monorepo
% TODO: in the future we should make it consistent and remove this ignore
DependencyRange \= 'workspace:*',
DependencyRange2 \= 'workspace:*',
% Get the workspace name
workspace_ident(WorkspaceCwd, WorkspaceIdent),
workspace_ident(OtherWorkspaceCwd, OtherWorkspaceIdent),
% @types/node in the root need to stay on ~12.12.0
(
(WorkspaceIdent = '@jest/monorepo'; OtherWorkspaceIdent = '@jest/monorepo') ->
DependencyIdent \= '@types/node'
;
true
),
% 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
).
DependencyRange \= 'workspace:*',
DependencyRange2 \= 'workspace:*',
% A list of exception to same version rule
\+ member(DependencyIdent, [
% Allow enzyme example workspace use a older version react and react-dom, because enzyme don't support react 17
'react', 'react-dom',
% @types/node in the root need to stay on ~12.12.0
'@types/node'
]).

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

0 comments on commit 9093915

Please sign in to comment.