File tree 1 file changed +22
-3
lines changed
packages/angular_devkit/core/src/workspace
1 file changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,11 @@ export class WorkspaceNotYetLoadedException extends BaseException {
49
49
constructor ( ) { super ( `Workspace needs to be loaded before it is used.` ) ; }
50
50
}
51
51
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
+ }
52
57
53
58
export class Workspace {
54
59
private readonly _workspaceSchemaPath = join ( normalize ( __dirname ) , 'workspace-schema.json' ) ;
@@ -175,11 +180,25 @@ export class Workspace {
175
180
// the sort is stable and the first declared project will win).
176
181
. sort ( ( a , b ) => b [ 0 ] . length - a [ 0 ] . length ) ;
177
182
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
+ }
180
199
}
181
200
182
- return null ;
201
+ return projects [ 0 ] [ 1 ] ;
183
202
}
184
203
185
204
getCli ( ) {
You can’t perform that action at this time.
0 commit comments