|
8 | 8 | import { Rule } from '@angular-devkit/schematics';
|
9 | 9 | import * as ts from '../../third_party/github.com/Microsoft/TypeScript/lib/typescript';
|
10 | 10 | import { findNodes } from '../../utility/ast-utils';
|
11 |
| -import { findPropertyInAstObject } from '../../utility/json-utils'; |
| 11 | +import { allWorkspaceTargets, getWorkspace } from '../../utility/workspace'; |
12 | 12 | import { Builders } from '../../utility/workspace-models';
|
13 |
| -import { getTargets, getWorkspace } from './utils'; |
14 | 13 |
|
15 | 14 | /**
|
16 | 15 | * Update the `main.server.ts` file by adding exports to `renderModule` and `renderModuleFactory` which are
|
17 | 16 | * now required for Universal and App-Shell for Ivy and `bundleDependencies`.
|
18 | 17 | */
|
19 | 18 | export function updateServerMainFile(): Rule {
|
20 |
| - return tree => { |
21 |
| - const workspace = getWorkspace(tree); |
| 19 | + return async tree => { |
| 20 | + const workspace = await getWorkspace(tree); |
22 | 21 |
|
23 |
| - for (const { target } of getTargets(workspace, 'server', Builders.Server)) { |
24 |
| - const options = findPropertyInAstObject(target, 'options'); |
25 |
| - if (!options || options.kind !== 'object') { |
| 22 | + for (const [targetName, target] of allWorkspaceTargets(workspace)) { |
| 23 | + if (targetName !== 'server' || target.builder !== Builders.Server) { |
26 | 24 | continue;
|
27 | 25 | }
|
28 | 26 |
|
29 | 27 | // find the main server file
|
30 |
| - const mainFile = findPropertyInAstObject(options, 'main'); |
31 |
| - if (!mainFile || typeof mainFile.value !== 'string') { |
| 28 | + const mainFilePath = target.options?.main; |
| 29 | + if (!mainFilePath || typeof mainFilePath !== 'string') { |
32 | 30 | continue;
|
33 | 31 | }
|
34 | 32 |
|
35 |
| - const mainFilePath = mainFile.value; |
36 |
| - |
37 | 33 | const content = tree.read(mainFilePath);
|
38 | 34 | if (!content) {
|
39 | 35 | continue;
|
@@ -137,7 +133,5 @@ export function updateServerMainFile(): Rule {
|
137 | 133 |
|
138 | 134 | tree.commitUpdate(recorder);
|
139 | 135 | }
|
140 |
| - |
141 |
| - return tree; |
142 | 136 | };
|
143 | 137 | }
|
0 commit comments