-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
executor-utils.ts
57 lines (51 loc) · 1.58 KB
/
executor-utils.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 { printDiagnostics, runTypeCheck } from '@nx/js';
import { join, resolve } from 'path';
import { ViteBuildExecutorOptions } from '../executors/build/schema';
import { ExecutorContext } from '@nx/devkit';
import { ViteDevServerExecutorOptions } from '../executors/dev-server/schema';
import {
calculateProjectDependencies,
createTmpTsConfig,
} from '@nx/js/src/utils/buildable-libs-utils';
import { registerTsConfigPaths } from '@nx/js/src/internal';
export async function validateTypes(opts: {
workspaceRoot: string;
projectRoot: string;
tsconfig: string;
}): Promise<void> {
const result = await runTypeCheck({
workspaceRoot: opts.workspaceRoot,
tsConfigPath: join(opts.workspaceRoot, opts.tsconfig),
mode: 'noEmit',
});
await printDiagnostics(result.errors, result.warnings);
if (result.errors.length > 0) {
throw new Error('Found type errors. See above.');
}
}
export function registerPaths(
projectRoot: string,
options: ViteBuildExecutorOptions | ViteDevServerExecutorOptions,
context: ExecutorContext
) {
const tsConfig = resolve(projectRoot, 'tsconfig.json');
options.buildLibsFromSource ??= true;
if (!options.buildLibsFromSource) {
const { dependencies } = calculateProjectDependencies(
context.projectGraph,
context.root,
context.projectName,
context.targetName,
context.configurationName
);
const tmpTsConfig = createTmpTsConfig(
tsConfig,
context.root,
projectRoot,
dependencies
);
registerTsConfigPaths(tmpTsConfig);
} else {
registerTsConfigPaths(tsConfig);
}
}