Skip to content

Commit

Permalink
feat(rspack): add typecheck (#338)
Browse files Browse the repository at this point in the history
* feat(rspack): add typecheck

* Reusing the type-check existing on the @nx/js
  • Loading branch information
dgmachado authored Sep 14, 2023
1 parent 5afa9da commit 805d18c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
28 changes: 27 additions & 1 deletion packages/rspack/src/executors/rspack/rspack.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<{
Expand Down Expand Up @@ -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.');
}
}
1 change: 1 addition & 0 deletions packages/rspack/src/executors/rspack/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export interface RspackExecutorSchema {
target: 'web' | 'node';
main: string;
tsConfig: string;
typeCheck?: boolean;
outputPath: string;
indexHtml?: string;
mode?: Mode;
Expand Down
4 changes: 4 additions & 0 deletions packages/rspack/src/executors/rspack/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down

0 comments on commit 805d18c

Please sign in to comment.