/
update-typescript-target.ts
57 lines (49 loc) · 1.62 KB
/
update-typescript-target.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import type { Tree } from '@nrwl/devkit';
import { formatFiles, getProjects, updateJson } from '@nrwl/devkit';
import { Builders } from '@schematics/angular/utility/workspace-models';
function updateTarget(tree: Tree, tsconfigPath: string) {
updateJson(tree, tsconfigPath, (json) => ({
...json,
compilerOptions: {
...(json.compilerOptions ?? {}),
target: 'ES2022',
useDefineForClassFields: false,
},
}));
}
export default async function updateTypescriptTarget(tree: Tree) {
const projects = getProjects(tree);
for (const [, project] of projects) {
if (!project.targets) continue;
for (const [, target] of Object.entries(project.targets)) {
// Update all other known CLI builders that use a tsconfig
const tsConfigs = [
target.options || {},
...Object.values(target.configurations || {}),
]
.filter((opt) => typeof opt?.tsConfig === 'string')
.map((opt) => (opt as { tsConfig: string }).tsConfig);
const uniqueTsConfigs = [...new Set(tsConfigs)];
if (uniqueTsConfigs.length < 1) {
continue;
}
const supportedExecutors = new Set([
Builders.Server,
Builders.Karma,
Builders.Browser,
Builders.NgPackagr,
'@nrwl/angular:webpack-browser',
'@nrwl/angular:ng-packagr-lite',
'@nrwl/angular:package',
'@nrwl/angular:delegate-build',
'@nrwl/jest:jest',
]);
if (supportedExecutors.has(target.executor)) {
for (const tsConfig of uniqueTsConfigs) {
updateTarget(tree, tsConfig);
}
}
}
}
await formatFiles(tree);
}