Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Monorepo utils: add support for mismatched workspace dependencies
Browse files Browse the repository at this point in the history
kiwicom-source-id: ff372801acf839d7a05f76936312205f190a75c2
  • Loading branch information
Martin Zlámal authored and kiwicom-github-bot committed Jul 3, 2019
1 parent cd7a0d2 commit a225fe8
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 4 deletions.
75 changes: 75 additions & 0 deletions src/__tests__/findRelatedWorkspaces.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,78 @@ it("doesn't crash with circular dependencies - complex circle", () => {
}
`);
});

it('resolves mismatched workspace dependencies correctly', () => {
const circularWorkspaceDependencies = {
aaa: {
location: '',
workspaceDependencies: ['bbb'],
mismatchedWorkspaceDependencies: ['ccc'],
},
bbb: {
location: '',
workspaceDependencies: [],
mismatchedWorkspaceDependencies: [],
},
ccc: {
location: '',
workspaceDependencies: [],
mismatchedWorkspaceDependencies: [],
},
};

expect(findRelatedWorkspaces(circularWorkspaceDependencies, new Set(['aaa'])))
.toMatchInlineSnapshot(`
Set {
"aaa",
}
`);
expect(findRelatedWorkspaces(circularWorkspaceDependencies, new Set(['bbb'])))
.toMatchInlineSnapshot(`
Set {
"bbb",
"aaa",
}
`);
expect(findRelatedWorkspaces(circularWorkspaceDependencies, new Set(['ccc'])))
.toMatchInlineSnapshot(`
Set {
"ccc",
"aaa",
}
`);
expect(
findRelatedWorkspaces(
circularWorkspaceDependencies,
new Set(['aaa', 'ccc']),
),
).toMatchInlineSnapshot(`
Set {
"aaa",
"ccc",
}
`);
expect(
findRelatedWorkspaces(
circularWorkspaceDependencies,
new Set(['aaa', 'bbb']),
),
).toMatchInlineSnapshot(`
Set {
"aaa",
"bbb",
}
`);
expect(
findRelatedWorkspaces(
circularWorkspaceDependencies,
new Set(['aaa', 'bbb', 'ccc']),
),
).toMatchInlineSnapshot(`
Set {
"aaa",
"bbb",
"ccc",
}
`);
});
2 changes: 1 addition & 1 deletion src/findDirtyWorkspaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { type WorkspaceDependencies } from './Workspaces.flow';
export default function findDirtyWorkspaces(
workspaceDependencies: WorkspaceDependencies,
changedFiles: $ReadOnlyArray<string>,
) {
): $ReadOnlySet<string> {
const dirtyWorkspaces = new Set<string>();
Object.keys(workspaceDependencies).forEach(dependencyName => {
const value = workspaceDependencies[dependencyName];
Expand Down
2 changes: 1 addition & 1 deletion src/findPathsToTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { WorkspaceDependencies } from './Workspaces.flow';
export default function findPathsToTest(
workspaceDependencies: WorkspaceDependencies,
changedFiles: $ReadOnlyArray<string>,
) {
): $ReadOnlySet<string> {
const dirtyWorkspaces = findDirtyWorkspaces(
workspaceDependencies,
changedFiles,
Expand Down
15 changes: 13 additions & 2 deletions src/findRelatedWorkspaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { type WorkspaceDependencies } from './Workspaces.flow';
*/
export default function findRelatedWorkspaces(
workspaceDependencies: WorkspaceDependencies,
touchedWorkspaces: Set<string>,
) {
touchedWorkspaces: $ReadOnlySet<string>,
): $ReadOnlySet<string> {
const workspacesToTest = new Set<string>();

(function unwind(touchedWorkspaces) {
Expand All @@ -36,6 +36,17 @@ export default function findRelatedWorkspaces(
unwind([key]);
}
}

if (
workspaceDependencies[key].mismatchedWorkspaceDependencies.includes(
touchedWorkspace,
)
) {
if (!workspacesToTest.has(key)) {
workspacesToTest.add(key);
unwind([key]);
}
}
});
});
})(touchedWorkspaces);
Expand Down

0 comments on commit a225fe8

Please sign in to comment.