Skip to content

Commit c638af2

Browse files
committed
fix(@angular-devkit/core): detect ambiguous projects with path discover
1 parent bb21592 commit c638af2

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

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

+22-3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ export class WorkspaceNotYetLoadedException extends BaseException {
4949
constructor() { super(`Workspace needs to be loaded before it is used.`); }
5050
}
5151

52+
export class AmbiguousProjectPathException extends BaseException {
53+
constructor(public readonly path: Path, public readonly projects: ReadonlyArray<string>) {
54+
super(`Current active project is ambiguous (${projects.join(',')}) using path: '${path}'`);
55+
}
56+
}
5257

5358
export class Workspace {
5459
private readonly _workspaceSchemaPath = join(normalize(__dirname), 'workspace-schema.json');
@@ -175,11 +180,25 @@ export class Workspace {
175180
// the sort is stable and the first declared project will win).
176181
.sort((a, b) => b[0].length - a[0].length);
177182

178-
if (projects[0]) {
179-
return projects[0][1];
183+
if (projects.length === 0) {
184+
return null;
185+
} else if (projects.length > 1) {
186+
const found = new Set<Path>();
187+
const sameRoots = projects.filter(v => {
188+
if (!found.has(v[0])) {
189+
found.add(v[0]);
190+
191+
return false;
192+
}
193+
194+
return true;
195+
});
196+
if (sameRoots.length > 0) {
197+
throw new AmbiguousProjectPathException(path, sameRoots.map(v => v[1]));
198+
}
180199
}
181200

182-
return null;
201+
return projects[0][1];
183202
}
184203

185204
getCli() {

0 commit comments

Comments
 (0)