Skip to content

Commit 5d73e9d

Browse files
clydinmgechev
authored andcommitted
refactor(@schematics/angular): use new JSON helpers in remove-tsickle migration
1 parent 9167122 commit 5d73e9d

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

packages/schematics/angular/migrations/update-9/remove-tsickle.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
*/
88
import { Rule } from '@angular-devkit/schematics';
99
import { removePackageJsonDependency } from '../../utility/dependencies';
10-
import { findPropertyInAstObject, removePropertyInAstObject } from '../../utility/json-utils';
10+
import { JSONFile } from '../../utility/json-file';
11+
import { findPropertyInAstObject } from '../../utility/json-utils';
1112
import { Builders } from '../../utility/workspace-models';
12-
import { getAllOptions, getTargets, getWorkspace, readJsonFileAsAstObject } from './utils';
13+
import { getAllOptions, getTargets, getWorkspace } from './utils';
1314

1415
/**
1516
* Remove tsickle from libraries
@@ -28,23 +29,17 @@ export function removeTsickle(): Rule {
2829
}
2930

3031
const tsConfigPath = tsConfigOption.value;
31-
const tsConfigAst = readJsonFileAsAstObject(tree, tsConfigPath);
32-
if (!tsConfigAst) {
32+
let tsConfigJson;
33+
try {
34+
tsConfigJson = new JSONFile(tree, tsConfigPath);
35+
} catch {
3336
logger.warn(`Cannot find file: ${tsConfigPath}`);
3437

3538
continue;
3639
}
3740

38-
const ngCompilerOptions = findPropertyInAstObject(tsConfigAst, 'angularCompilerOptions');
39-
if (ngCompilerOptions && ngCompilerOptions.kind === 'object') {
40-
// remove annotateForClosureCompiler option
41-
const recorder = tree.beginUpdate(tsConfigPath);
42-
removePropertyInAstObject(recorder, ngCompilerOptions, 'annotateForClosureCompiler');
43-
tree.commitUpdate(recorder);
44-
}
41+
tsConfigJson.remove(['angularCompilerOptions', 'annotateForClosureCompiler']);
4542
}
4643
}
47-
48-
return tree;
4944
};
5045
}

0 commit comments

Comments
 (0)