|
7 | 7 | */
|
8 | 8 | import { dirname, join, normalize } from '@angular-devkit/core';
|
9 | 9 | import { Rule, Tree } from '@angular-devkit/schematics';
|
10 |
| -import { findPropertyInAstObject, removePropertyInAstObject } from '../../utility/json-utils'; |
| 10 | +import { appendPropertyInAstObject, findPropertyInAstObject, removePropertyInAstObject } from '../../utility/json-utils'; |
11 | 11 | import { getWorkspace } from '../../utility/workspace';
|
12 | 12 | import { Builders } from '../../utility/workspace-models';
|
13 | 13 | import { readJsonFileAsAstObject } from '../update-9/utils';
|
@@ -68,6 +68,10 @@ export default function (): Rule {
|
68 | 68 | // This ensures that lazy-loaded works on the server.
|
69 | 69 | newModule: false,
|
70 | 70 | });
|
| 71 | + |
| 72 | + updateModuleAndTarget(host, p, { |
| 73 | + newTarget: 'es2016', |
| 74 | + }); |
71 | 75 | });
|
72 | 76 | break;
|
73 | 77 | case Builders.Karma:
|
@@ -102,7 +106,10 @@ function updateModuleAndTarget(host: Tree, tsConfigPath: string, replacements: M
|
102 | 106 | const recorder = host.beginUpdate(tsConfigPath);
|
103 | 107 | if (newTarget) {
|
104 | 108 | const targetAst = findPropertyInAstObject(compilerOptionsAst, 'target');
|
105 |
| - if (targetAst?.kind === 'string' && oldTarget === targetAst.value.toLowerCase()) { |
| 109 | + |
| 110 | + if (!targetAst && !oldTarget) { |
| 111 | + appendPropertyInAstObject(recorder, compilerOptionsAst, 'target', newTarget, 4); |
| 112 | + } else if (targetAst?.kind === 'string' && (!oldTarget || oldTarget === targetAst.value.toLowerCase())) { |
106 | 113 | const offset = targetAst.start.offset + 1;
|
107 | 114 | recorder.remove(offset, targetAst.value.length);
|
108 | 115 | recorder.insertLeft(offset, newTarget);
|
|
0 commit comments