5
5
* Use of this source code is governed by an MIT-style license that can be
6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
- import { experimental , json } from '@angular-devkit/core' ;
8
+ import { experimental , json , workspaces } from '@angular-devkit/core' ;
9
9
import { resolve } from '@angular-devkit/core/node' ;
10
10
import * as path from 'path' ;
11
11
import { BuilderInfo } from '../src' ;
@@ -21,13 +21,26 @@ export type NodeModulesBuilderInfo = BuilderInfo & {
21
21
22
22
// TODO: create a base class for all workspace related hosts.
23
23
export class WorkspaceNodeModulesArchitectHost implements ArchitectHost < NodeModulesBuilderInfo > {
24
+
25
+ /**
26
+ * @deprecated
27
+ */
28
+ constructor ( _workspace : experimental . workspace . Workspace , _root : string )
29
+
30
+ constructor ( _workspace : workspaces . WorkspaceDefinition , _root : string )
31
+
24
32
constructor (
25
- protected _workspace : experimental . workspace . Workspace ,
33
+ protected _workspace : experimental . workspace . Workspace | workspaces . WorkspaceDefinition ,
26
34
protected _root : string ,
27
35
) { }
28
36
29
37
async getBuilderNameForTarget ( target : Target ) {
30
- return this . _workspace . getProjectTargets ( target . project ) [ target . target ] [ 'builder' ] ;
38
+ const targetDefinition = this . findProjectTarget ( target ) ;
39
+ if ( ! targetDefinition ) {
40
+ throw new Error ( 'Project target does not exist.' ) ;
41
+ }
42
+
43
+ return targetDefinition . builder ;
31
44
}
32
45
33
46
/**
@@ -87,7 +100,7 @@ export class WorkspaceNodeModulesArchitectHost implements ArchitectHost<NodeModu
87
100
}
88
101
89
102
async getOptionsForTarget ( target : Target ) : Promise < json . JsonObject | null > {
90
- const targetSpec = this . _workspace . getProjectTargets ( target . project ) [ target . target ] ;
103
+ const targetSpec = this . findProjectTarget ( target ) ;
91
104
if ( targetSpec === undefined ) {
92
105
return null ;
93
106
}
@@ -109,4 +122,17 @@ export class WorkspaceNodeModulesArchitectHost implements ArchitectHost<NodeModu
109
122
110
123
throw new Error ( 'Builder is not a builder' ) ;
111
124
}
125
+
126
+ private findProjectTarget ( target : Target ) {
127
+ if ( 'getProjectTargets' in this . _workspace ) {
128
+ return this . _workspace . getProjectTargets ( target . project ) [ target . target ] ;
129
+ } else {
130
+ const projectDefinition = this . _workspace . projects . get ( target . project ) ;
131
+ if ( ! projectDefinition ) {
132
+ throw new Error ( 'Project does not exist.' ) ;
133
+ }
134
+
135
+ return projectDefinition . targets . get ( target . target ) ;
136
+ }
137
+ }
112
138
}
0 commit comments