feat(rspack): add typecheck (#338)

* feat(rspack): add typecheck

* Reusing the type-check existing on the @nx/js
This commit is contained in:
Douglas Machado 2023-09-14 15:33:31 -03:00 committed by GitHub
parent dd060a8d00
commit c4667924d8
3 changed files with 32 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import * as path from 'path';
import { createCompiler } from '../../utils/create-compiler'; import { createCompiler } from '../../utils/create-compiler';
import { isMode } from '../../utils/mode-utils'; import { isMode } from '../../utils/mode-utils';
import { RspackExecutorSchema } from './schema'; import { RspackExecutorSchema } from './schema';
import { printDiagnostics, runTypeCheck } from '@nx/js';
export default async function* runExecutor( export default async function* runExecutor(
options: RspackExecutorSchema, options: RspackExecutorSchema,
@ -16,12 +17,17 @@ export default async function* runExecutor(
if (isMode(process.env.NODE_ENV)) { if (isMode(process.env.NODE_ENV)) {
options.mode = process.env.NODE_ENV; options.mode = process.env.NODE_ENV;
} }
if (options.typeCheck) {
await executeTypeCheck(options, context);
}
// Mimic --clean from webpack. // Mimic --clean from webpack.
rmSync(path.join(context.root, options.outputPath), { rmSync(path.join(context.root, options.outputPath), {
force: true, force: true,
recursive: true, recursive: true,
}); });
const compiler = await createCompiler(options, context); const compiler = await createCompiler(options, context);
const iterable = createAsyncIterable<{ const iterable = createAsyncIterable<{
@ -111,3 +117,23 @@ function registerCleanupCallback(callback: () => void) {
process.on('SIGTERM', wrapped); process.on('SIGTERM', wrapped);
process.on('exit', 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.');
}
}

View File

@ -3,6 +3,7 @@ export interface RspackExecutorSchema {
target: 'web' | 'node'; target: 'web' | 'node';
main: string; main: string;
tsConfig: string; tsConfig: string;
typeCheck?: boolean;
outputPath: string; outputPath: string;
indexHtml?: string; indexHtml?: string;
mode?: Mode; mode?: Mode;

View File

@ -22,6 +22,10 @@
"type": "string", "type": "string",
"description": "The tsconfig file to build the project." "description": "The tsconfig file to build the project."
}, },
"typeCheck": {
"type": "boolean",
"description": "Skip the type checking."
},
"indexHtml": { "indexHtml": {
"type": "string", "type": "string",
"description": "The path to the index.html file." "description": "The path to the index.html file."