diff --git a/packages/rspack/src/executors/rspack/rspack.impl.ts b/packages/rspack/src/executors/rspack/rspack.impl.ts index a008d465a..a30c7e401 100644 --- a/packages/rspack/src/executors/rspack/rspack.impl.ts +++ b/packages/rspack/src/executors/rspack/rspack.impl.ts @@ -6,6 +6,7 @@ import * as path from 'path'; import { createCompiler } from '../../utils/create-compiler'; import { isMode } from '../../utils/mode-utils'; import { RspackExecutorSchema } from './schema'; +import { printDiagnostics, runTypeCheck } from '@nx/js'; export default async function* runExecutor( options: RspackExecutorSchema, @@ -16,12 +17,17 @@ export default async function* runExecutor( if (isMode(process.env.NODE_ENV)) { options.mode = process.env.NODE_ENV; } + + if (options.typeCheck) { + await executeTypeCheck(options, context); + } + // Mimic --clean from webpack. rmSync(path.join(context.root, options.outputPath), { force: true, recursive: true, }); - + const compiler = await createCompiler(options, context); const iterable = createAsyncIterable<{ @@ -111,3 +117,23 @@ function registerCleanupCallback(callback: () => void) { process.on('SIGTERM', wrapped); process.on('exit', wrapped); } + + +async function executeTypeCheck( + options: RspackExecutorSchema, + context: ExecutorContext +) { + const projectConfiguration = + context.projectsConfigurations!.projects[context.projectName!]; + const result = await runTypeCheck({ + workspaceRoot: path.resolve(projectConfiguration.root), + tsConfigPath: options.tsConfig, + mode: 'noEmit', + }); + + await printDiagnostics(result.errors, result.warnings); + + if (result.errors.length > 0) { + throw new Error('Found type errors. See above.'); + } +} \ No newline at end of file diff --git a/packages/rspack/src/executors/rspack/schema.d.ts b/packages/rspack/src/executors/rspack/schema.d.ts index 027036e43..0c6455746 100644 --- a/packages/rspack/src/executors/rspack/schema.d.ts +++ b/packages/rspack/src/executors/rspack/schema.d.ts @@ -3,6 +3,7 @@ export interface RspackExecutorSchema { target: 'web' | 'node'; main: string; tsConfig: string; + typeCheck?: boolean; outputPath: string; indexHtml?: string; mode?: Mode; diff --git a/packages/rspack/src/executors/rspack/schema.json b/packages/rspack/src/executors/rspack/schema.json index 0a66e1940..85d4a5da3 100644 --- a/packages/rspack/src/executors/rspack/schema.json +++ b/packages/rspack/src/executors/rspack/schema.json @@ -22,6 +22,10 @@ "type": "string", "description": "The tsconfig file to build the project." }, + "typeCheck": { + "type": "boolean", + "description": "Skip the type checking." + }, "indexHtml": { "type": "string", "description": "The path to the index.html file."