Skip to content

Commit e52e0e1

Browse files
hanslfilipesilva
authored andcommitted
fix(@angular-devkit/core): when two projects are the same, pick the first declared
The comparator function for project names was invalid; sort() expect to be consistent and in this case was returning 1 for a set of arguments, and 0 if arguments were reversed, leading inconsistencies in the sort result.
1 parent df406f9 commit e52e0e1

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

packages/angular_devkit/core/src/workspace/workspace.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,10 @@ export class Workspace {
170170
const projects = this.listProjectNames()
171171
.map(name => [this.getProject(name).root, name] as [Path, string])
172172
.filter(tuple => isInside(tuple[0], path))
173-
// Sort tuples by depth, with the deeper ones first.
174-
.sort((a, b) => isInside(a[0], b[0]) ? 1 : 0);
173+
// Sort tuples by depth, with the deeper ones first. Since the first member is a path and
174+
// we filtered all invalid paths, the longest will be the deepest (and in case of equality
175+
// the sort is stable and the first declared project will win).
176+
.sort((a, b) => b[0].length - a[0].length);
175177

176178
if (projects[0]) {
177179
return projects[0][1];

0 commit comments

Comments
 (0)