Skip to content

Commit cbb493e

Browse files
clydinalexeagle
authored andcommitted
refactor(@angular-devkit/architect): support stable workspaces API
1 parent 5b3ee07 commit cbb493e

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

‎packages/angular_devkit/architect/node/node-modules-architect-host.ts

+30-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { experimental, json } from '@angular-devkit/core';
8+
import { experimental, json, workspaces } from '@angular-devkit/core';
99
import { resolve } from '@angular-devkit/core/node';
1010
import * as path from 'path';
1111
import { BuilderInfo } from '../src';
@@ -21,13 +21,26 @@ export type NodeModulesBuilderInfo = BuilderInfo & {
2121

2222
// TODO: create a base class for all workspace related hosts.
2323
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+
2432
constructor(
25-
protected _workspace: experimental.workspace.Workspace,
33+
protected _workspace: experimental.workspace.Workspace | workspaces.WorkspaceDefinition,
2634
protected _root: string,
2735
) {}
2836

2937
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;
3144
}
3245

3346
/**
@@ -87,7 +100,7 @@ export class WorkspaceNodeModulesArchitectHost implements ArchitectHost<NodeModu
87100
}
88101

89102
async getOptionsForTarget(target: Target): Promise<json.JsonObject | null> {
90-
const targetSpec = this._workspace.getProjectTargets(target.project)[target.target];
103+
const targetSpec = this.findProjectTarget(target);
91104
if (targetSpec === undefined) {
92105
return null;
93106
}
@@ -109,4 +122,17 @@ export class WorkspaceNodeModulesArchitectHost implements ArchitectHost<NodeModu
109122

110123
throw new Error('Builder is not a builder');
111124
}
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+
}
112138
}

0 commit comments

Comments
 (0)