Skip to content

Commit 86e4201

Browse files
clydinfilipesilva
authored andcommitted
refactor(@schematics/angular): use new workspace helpers in update-server-main-file migration
1 parent c859fcb commit 86e4201

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

packages/schematics/angular/migrations/update-9/update-server-main-file.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,28 @@
88
import { Rule } from '@angular-devkit/schematics';
99
import * as ts from '../../third_party/github.com/Microsoft/TypeScript/lib/typescript';
1010
import { findNodes } from '../../utility/ast-utils';
11-
import { findPropertyInAstObject } from '../../utility/json-utils';
11+
import { allWorkspaceTargets, getWorkspace } from '../../utility/workspace';
1212
import { Builders } from '../../utility/workspace-models';
13-
import { getTargets, getWorkspace } from './utils';
1413

1514
/**
1615
* Update the `main.server.ts` file by adding exports to `renderModule` and `renderModuleFactory` which are
1716
* now required for Universal and App-Shell for Ivy and `bundleDependencies`.
1817
*/
1918
export function updateServerMainFile(): Rule {
20-
return tree => {
21-
const workspace = getWorkspace(tree);
19+
return async tree => {
20+
const workspace = await getWorkspace(tree);
2221

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) {
2624
continue;
2725
}
2826

2927
// 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') {
3230
continue;
3331
}
3432

35-
const mainFilePath = mainFile.value;
36-
3733
const content = tree.read(mainFilePath);
3834
if (!content) {
3935
continue;
@@ -137,7 +133,5 @@ export function updateServerMainFile(): Rule {
137133

138134
tree.commitUpdate(recorder);
139135
}
140-
141-
return tree;
142136
};
143137
}

0 commit comments

Comments
 (0)