feat(cli): Enhance type checking in CLI by adding default file pattern handling
This commit is contained in:
@ -190,11 +190,66 @@ export const runCli = async () => {
|
||||
tsbuildCli.addCommand('check').subscribe(async (argvArg) => {
|
||||
const patterns = argvArg._.slice(1); // Remove the first element which is 'check'
|
||||
|
||||
// If no patterns provided, default to checking ts/**/* and then test/**/*
|
||||
if (patterns.length === 0) {
|
||||
console.error('\n❌ Error: Please provide at least one TypeScript file path or glob pattern');
|
||||
console.error(' Usage: tsbuild check <file_or_glob_pattern> [additional_patterns ...]\n');
|
||||
console.error(' Example: tsbuild check "src/**/*.ts" "test/**/*.ts"\n');
|
||||
process.exit(1);
|
||||
console.log('\n🔬 Running default type checking sequence...\n');
|
||||
|
||||
// First check ts/**/* without skiplibcheck
|
||||
console.log('📂 Checking ts/**/* files...');
|
||||
const tsFiles = await plugins.smartfile.fs.listFileTree(process.cwd(), 'ts/**/*.ts');
|
||||
const tsTsFiles = Array.isArray(tsFiles)
|
||||
? tsFiles.filter((item): item is string => typeof item === 'string')
|
||||
: [];
|
||||
|
||||
if (tsTsFiles.length > 0) {
|
||||
console.log(` Found ${tsTsFiles.length} TypeScript files in ts/`);
|
||||
const tsAbsoluteFiles = plugins.smartpath.transform.toAbsolute(
|
||||
tsTsFiles,
|
||||
process.cwd()
|
||||
) as string[];
|
||||
|
||||
const tsCompilerOptions = tsbuild.mergeCompilerOptions({}, argvArg);
|
||||
const tsSuccess = await tsbuild.checkTypes(tsAbsoluteFiles, tsCompilerOptions, argvArg);
|
||||
|
||||
if (!tsSuccess) {
|
||||
console.error('❌ Type checking failed for ts/**/*');
|
||||
process.exit(1);
|
||||
}
|
||||
console.log('✅ Type checking passed for ts/**/*\n');
|
||||
} else {
|
||||
console.log(' No TypeScript files found in ts/\n');
|
||||
}
|
||||
|
||||
// Then check test/**/* with skiplibcheck
|
||||
console.log('📂 Checking test/**/* files with --skiplibcheck...');
|
||||
const testFiles = await plugins.smartfile.fs.listFileTree(process.cwd(), 'test/**/*.ts');
|
||||
const testTsFiles = Array.isArray(testFiles)
|
||||
? testFiles.filter((item): item is string => typeof item === 'string')
|
||||
: [];
|
||||
|
||||
if (testTsFiles.length > 0) {
|
||||
console.log(` Found ${testTsFiles.length} TypeScript files in test/`);
|
||||
const testAbsoluteFiles = plugins.smartpath.transform.toAbsolute(
|
||||
testTsFiles,
|
||||
process.cwd()
|
||||
) as string[];
|
||||
|
||||
// Create new argvArg with skiplibcheck for test files
|
||||
const testArgvArg = { ...argvArg, skiplibcheck: true };
|
||||
const testCompilerOptions = tsbuild.mergeCompilerOptions({}, testArgvArg);
|
||||
const testSuccess = await tsbuild.checkTypes(testAbsoluteFiles, testCompilerOptions, testArgvArg);
|
||||
|
||||
if (!testSuccess) {
|
||||
console.error('❌ Type checking failed for test/**/*');
|
||||
process.exit(1);
|
||||
}
|
||||
console.log('✅ Type checking passed for test/**/*\n');
|
||||
} else {
|
||||
console.log(' No TypeScript files found in test/\n');
|
||||
}
|
||||
|
||||
console.log('✅ All default type checks passed!\n');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const cwd = process.cwd();
|
||||
|
Reference in New Issue
Block a user