Skip to content

Commit 805d18c

Browse files
author
Douglas Machado
authored
feat(rspack): add typecheck (#338)
* feat(rspack): add typecheck * Reusing the type-check existing on the @nx/js
1 parent 5afa9da commit 805d18c

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

packages/rspack/src/executors/rspack/rspack.impl.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as path from 'path';
66
import { createCompiler } from '../../utils/create-compiler';
77
import { isMode } from '../../utils/mode-utils';
88
import { RspackExecutorSchema } from './schema';
9+
import { printDiagnostics, runTypeCheck } from '@nx/js';
910

1011
export default async function* runExecutor(
1112
options: RspackExecutorSchema,
@@ -16,12 +17,17 @@ export default async function* runExecutor(
1617
if (isMode(process.env.NODE_ENV)) {
1718
options.mode = process.env.NODE_ENV;
1819
}
20+
21+
if (options.typeCheck) {
22+
await executeTypeCheck(options, context);
23+
}
24+
1925
// Mimic --clean from webpack.
2026
rmSync(path.join(context.root, options.outputPath), {
2127
force: true,
2228
recursive: true,
2329
});
24-
30+
2531
const compiler = await createCompiler(options, context);
2632

2733
const iterable = createAsyncIterable<{
@@ -111,3 +117,23 @@ function registerCleanupCallback(callback: () => void) {
111117
process.on('SIGTERM', wrapped);
112118
process.on('exit', wrapped);
113119
}
120+
121+
122+
async function executeTypeCheck(
123+
options: RspackExecutorSchema,
124+
context: ExecutorContext
125+
) {
126+
const projectConfiguration =
127+
context.projectsConfigurations!.projects[context.projectName!];
128+
const result = await runTypeCheck({
129+
workspaceRoot: path.resolve(projectConfiguration.root),
130+
tsConfigPath: options.tsConfig,
131+
mode: 'noEmit',
132+
});
133+
134+
await printDiagnostics(result.errors, result.warnings);
135+
136+
if (result.errors.length > 0) {
137+
throw new Error('Found type errors. See above.');
138+
}
139+
}

packages/rspack/src/executors/rspack/schema.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export interface RspackExecutorSchema {
33
target: 'web' | 'node';
44
main: string;
55
tsConfig: string;
6+
typeCheck?: boolean;
67
outputPath: string;
78
indexHtml?: string;
89
mode?: Mode;

packages/rspack/src/executors/rspack/schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
"type": "string",
2323
"description": "The tsconfig file to build the project."
2424
},
25+
"typeCheck": {
26+
"type": "boolean",
27+
"description": "Skip the type checking."
28+
},
2529
"indexHtml": {
2630
"type": "string",
2731
"description": "The path to the index.html file."

0 commit comments

Comments
 (0)