feat(rspack): add typecheck (#338)
* feat(rspack): add typecheck * Reusing the type-check existing on the @nx/js
This commit is contained in:
parent
dd060a8d00
commit
c4667924d8
@ -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.');
|
||||
}
|
||||
}
|
||||
1
src/executors/rspack/schema.d.ts
vendored
1
src/executors/rspack/schema.d.ts
vendored
@ -3,6 +3,7 @@ export interface RspackExecutorSchema {
|
||||
target: 'web' | 'node';
|
||||
main: string;
|
||||
tsConfig: string;
|
||||
typeCheck?: boolean;
|
||||
outputPath: string;
|
||||
indexHtml?: string;
|
||||
mode?: Mode;
|
||||
|
||||
@ -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."
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user