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 { 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,6 +17,11 @@ 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,
|
||||||
@ -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.');
|
||||||
|
}
|
||||||
|
}
|
||||||
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';
|
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;
|
||||||
|
|||||||
@ -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."
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user