/
update-swcrc.ts
39 lines (31 loc) · 1 KB
/
update-swcrc.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
import {
formatFiles,
getProjects,
readJson,
Tree,
updateJson,
} from '@nrwl/devkit';
import { join } from 'path';
import { defaultExclude } from '../../utils/swc/add-swc-config';
export default async function update(host: Tree) {
const projects = getProjects(host);
for (const config of projects.values()) {
if (config?.targets?.build?.executor !== '@nrwl/js:swc') continue;
const swcrcPath = join(config.root, '.swcrc');
if (!host.exists(swcrcPath)) continue;
// rename
const libSwcrcPath = join(config.root, '.lib.swcrc');
host.rename(swcrcPath, libSwcrcPath);
const swcrcContent = readJson(host, libSwcrcPath);
// skip if swcrc already has "exclude" field
if (swcrcContent['exclude']) continue;
// check swcExclude build options
const exclude =
config?.targets?.build?.options['swcExclude'] || defaultExclude;
updateJson(host, libSwcrcPath, (swcrc) => {
swcrc['exclude'] = exclude;
return swcrc;
});
}
await formatFiles(host);
}