diff --git a/tools/tsp-client/src/index.ts b/tools/tsp-client/src/index.ts index 3fbb55f7f34..f9fe419f93a 100644 --- a/tools/tsp-client/src/index.ts +++ b/tools/tsp-client/src/index.ts @@ -219,7 +219,7 @@ async function generate({ args.push("--force"); } await npmCommand(srcDir, args); - await compileTsp({ emitterPackage: emitter, outputPath: rootUrl, resolvedMainFilePath, saveInputs: noCleanup, additionalEmitterOptions }); + const succeeded = await compileTsp({ emitterPackage: emitter, outputPath: rootUrl, resolvedMainFilePath, saveInputs: noCleanup, additionalEmitterOptions }); if (noCleanup) { Logger.debug(`Skipping cleanup of temp directory: ${tempRoot}`); @@ -227,6 +227,9 @@ async function generate({ Logger.debug("Cleaning up temp directory"); await removeDirectory(tempRoot); } + if (!succeeded) { + process.exit(1); + } } diff --git a/tools/tsp-client/src/typespec.ts b/tools/tsp-client/src/typespec.ts index 8138fa5f9aa..3557ff459ef 100644 --- a/tools/tsp-client/src/typespec.ts +++ b/tools/tsp-client/src/typespec.ts @@ -64,7 +64,7 @@ export async function compileTsp({ resolvedMainFilePath: string; additionalEmitterOptions?: string; saveInputs?: boolean; -}) { +}): Promise { const parsedEntrypoint = getDirectoryPath(resolvedMainFilePath); const { compile, NodeHost, resolveCompilerOptions } = await importTsp(parsedEntrypoint); @@ -100,19 +100,21 @@ export async function compileTsp({ Logger.debug(`Compiler options: ${JSON.stringify(options)}`); if (diagnostics.length > 0) { // This should not happen, but if it does, we should log it. - Logger.debug(`Compiler options diagnostic information: ${JSON.stringify(diagnostics)}`); + Logger.error("Diagnostics were reported while resolving compiler options...") + diagnostics.forEach((diagnostic) => { Logger.error(formatDiagnostic(diagnostic)); }); + return false; } const program = await compile(NodeHost, resolvedMainFilePath, options); if (program.diagnostics.length > 0) { - for (const diagnostic of program.diagnostics) { - Logger.error(formatDiagnostic(diagnostic)); - } - process.exit(1); + Logger.error("Diagnostics were reported during compilation..."); + program.diagnostics.forEach((diagnostic) => { Logger.error(formatDiagnostic(diagnostic)); }); + return false; } else { Logger.success("generation complete"); } + return true; } export async function importTsp(baseDir: string): Promise {