-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
update-editor-tsconfig.ts
53 lines (46 loc) · 1.28 KB
/
update-editor-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
import type { Tree } from '@nrwl/devkit';
import type { NormalizedSchema } from './normalized-schema';
import { joinPathFragments, readJson, updateJson } from '@nrwl/devkit';
interface TsConfig {
compilerOptions: { types: string[] };
}
function getCompilerOptionsTypes(tsConfig: TsConfig): string[] {
return tsConfig?.compilerOptions?.types ?? [];
}
export function updateEditorTsConfig(tree: Tree, options: NormalizedSchema) {
const types = getCompilerOptionsTypes(
readJson<TsConfig>(
tree,
joinPathFragments(options.appProjectRoot, 'tsconfig.app.json')
)
);
if (options.unitTestRunner !== 'none') {
types.push(
...getCompilerOptionsTypes(
readJson<TsConfig>(
tree,
joinPathFragments(options.appProjectRoot, 'tsconfig.spec.json')
)
)
);
}
updateJson(
tree,
joinPathFragments(options.appProjectRoot, 'tsconfig.editor.json'),
(json) => {
json.compilerOptions.types = types;
return json;
}
);
// This should be the last tsconfig references so it's not in the template
updateJson(
tree,
joinPathFragments(options.appProjectRoot, 'tsconfig.json'),
(json) => {
json.references.push({
path: './tsconfig.editor.json',
});
return json;
}
);
}