/
update-tsconfig.ts
85 lines (77 loc) · 2.05 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import {
getWorkspaceLayout,
joinPathFragments,
Tree,
updateJson,
} from '@nrwl/devkit';
import { getRootTsConfigPathInTree } from '@nrwl/workspace/src/utilities/typescript';
import { NormalizedSchema } from './normalized-schema';
function updateRootConfig(
host: Tree,
options: NormalizedSchema['libraryOptions']
) {
updateJson(host, getRootTsConfigPathInTree(host), (json) => {
const c = json.compilerOptions;
c.paths = c.paths || {};
delete c.paths[options.name];
if (c.paths[options.importPath]) {
throw new Error(
`You already have a library using the import path "${options.importPath}". Make sure to specify a unique one.`
);
}
c.paths[options.importPath] = [
joinPathFragments(
getWorkspaceLayout(host).libsDir,
options.projectDirectory,
'/src/index.ts'
),
];
return json;
});
}
function updateProjectConfig(
host: Tree,
options: NormalizedSchema['libraryOptions']
) {
updateJson(host, `${options.projectRoot}/tsconfig.lib.json`, (json) => {
json.include = ['**/*.ts'];
json.exclude = [
...new Set([
...(json.exclude || []),
'jest.config.ts',
'**/*.test.ts',
'**/*.spec.ts',
]),
];
return json;
});
// tsconfig.json
updateJson(host, `${options.projectRoot}/tsconfig.json`, (json) => ({
...json,
compilerOptions: { ...json.compilerOptions, target: 'es2022' },
}));
}
function updateProjectIvyConfig(
host: Tree,
options: NormalizedSchema['libraryOptions']
) {
if (options.buildable || options.publishable) {
return updateJson(
host,
`${options.projectRoot}/tsconfig.lib.prod.json`,
(json) => {
json.angularCompilerOptions['compilationMode'] =
options.compilationMode === 'full' ? undefined : 'partial';
return json;
}
);
}
}
export function updateTsConfig(
host: Tree,
options: NormalizedSchema['libraryOptions']
) {
updateRootConfig(host, options);
updateProjectConfig(host, options);
updateProjectIvyConfig(host, options);
}