fix(tsbuild): Avoid process.exit in library, add confirmskiplibcheck flag, improve CLI exit handling and JSON/quiet modes, update test script
This commit is contained in:
@@ -309,10 +309,17 @@ export class TsBuild {
|
||||
*/
|
||||
public async compileWithErrorTracking(): Promise<{ emittedFiles: any[], errorSummary: IErrorSummary }> {
|
||||
if (this.options.skipLibCheck) {
|
||||
console.log('\n⚠️ WARNING ⚠️');
|
||||
console.log('You are skipping libcheck... Is that really wanted?');
|
||||
console.log('Continuing in 5 seconds...\n');
|
||||
await plugins.smartdelay.delayFor(5000);
|
||||
if (this.argvArg?.confirmskiplibcheck) {
|
||||
console.log('\n⚠️ WARNING ⚠️');
|
||||
console.log('You are skipping libcheck... Is that really wanted?');
|
||||
console.log('Continuing in 5 seconds...\n');
|
||||
await plugins.smartdelay.delayFor(5000);
|
||||
} else {
|
||||
// No delay by default; keep a short note unless in quiet/json modes
|
||||
if (!this.argvArg?.quiet && !this.argvArg?.json) {
|
||||
console.log('⚠️ skipLibCheck enabled; use --confirmskiplibcheck to pause with warning.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Enhanced logging with task info
|
||||
@@ -382,7 +389,9 @@ export class TsBuild {
|
||||
this.displayErrorSummary(combinedErrorSummary);
|
||||
console.error('\n❌ TypeScript emit failed. Please investigate the errors listed above!');
|
||||
console.error(' No output files have been generated.\n');
|
||||
process.exit(exitCode);
|
||||
// Do not exit here; return error summary so caller can decide
|
||||
done.resolve({ emittedFiles: [], errorSummary: combinedErrorSummary });
|
||||
return done.promise;
|
||||
}
|
||||
|
||||
return done.promise;
|
||||
@@ -393,10 +402,16 @@ export class TsBuild {
|
||||
*/
|
||||
public async compile(): Promise<any[]> {
|
||||
if (this.options.skipLibCheck) {
|
||||
console.log('\n⚠️ WARNING ⚠️');
|
||||
console.log('You are skipping libcheck... Is that really wanted?');
|
||||
console.log('Continuing in 5 seconds...\n');
|
||||
await plugins.smartdelay.delayFor(5000);
|
||||
if (this.argvArg?.confirmskiplibcheck) {
|
||||
console.log('\n⚠️ WARNING ⚠️');
|
||||
console.log('You are skipping libcheck... Is that really wanted?');
|
||||
console.log('Continuing in 5 seconds...\n');
|
||||
await plugins.smartdelay.delayFor(5000);
|
||||
} else {
|
||||
if (!this.argvArg?.quiet && !this.argvArg?.json) {
|
||||
console.log('⚠️ skipLibCheck enabled; use --confirmskiplibcheck to pause with warning.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`🔨 Compiling ${this.fileNames.length} files...`);
|
||||
@@ -412,7 +427,8 @@ export class TsBuild {
|
||||
this.displayErrorSummary(preEmitErrorSummary);
|
||||
console.error('\n❌ TypeScript pre-emit checks failed. Please fix the issues listed above before proceeding.');
|
||||
console.error(' Type errors must be resolved before the compiler can emit output files.\n');
|
||||
process.exit(1);
|
||||
// Throw instead of exiting to keep library pure
|
||||
throw new Error('TypeScript pre-emit checks failed.');
|
||||
}
|
||||
|
||||
// If no pre-emit errors, proceed with emit
|
||||
@@ -438,7 +454,8 @@ export class TsBuild {
|
||||
this.displayErrorSummary(emitErrorSummary);
|
||||
console.error('\n❌ TypeScript emit failed. Please investigate the errors listed above!');
|
||||
console.error(' No output files have been generated.\n');
|
||||
process.exit(exitCode);
|
||||
// Throw instead of exiting to keep library pure
|
||||
throw new Error('TypeScript emit failed.');
|
||||
}
|
||||
|
||||
return done.promise;
|
||||
@@ -565,4 +582,4 @@ export const checkTypes = async (
|
||||
): Promise<boolean> => {
|
||||
const tsBuild = new TsBuild(fileNames, options, argvArg);
|
||||
return tsBuild.checkTypes();
|
||||
};
|
||||
};
|
||||
|
Reference in New Issue
Block a user