/
update-tsconfig.ts
54 lines (49 loc) · 1.27 KB
/
update-tsconfig.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
import type { Tree } from '@nrwl/devkit';
import {
joinPathFragments,
readProjectConfiguration,
updateJson,
} from '@nrwl/devkit';
export function updateTsConfigs(tree: Tree, project: string): void {
const projectConfig = readProjectConfiguration(tree, project);
updateJson(
tree,
joinPathFragments(projectConfig.root, 'tsconfig.json'),
(json) => {
return {
...json,
references: [
...(json.references || []),
{
path: './tsconfig.spec.json',
},
],
};
}
);
let extraFiles: string[] = [];
if (
projectConfig.projectType == 'application' &&
projectConfig.targets.build?.options?.polyfills &&
typeof projectConfig.targets.build.options.polyfills === 'string'
) {
let polyfillsPath = projectConfig.targets.build.options.polyfills;
polyfillsPath = polyfillsPath.startsWith(projectConfig.root)
? polyfillsPath.replace(`${projectConfig.root}/`, '')
: polyfillsPath;
extraFiles = [polyfillsPath];
}
if (!extraFiles.length) {
return;
}
updateJson(
tree,
joinPathFragments(projectConfig.root, 'tsconfig.spec.json'),
(json) => {
return {
...json,
files: [...(json.files ?? []), ...extraFiles],
};
}
);
}