diff --git a/packages/cli/src/swc/dir.ts b/packages/cli/src/swc/dir.ts index 24390c8..1d6951b 100644 --- a/packages/cli/src/swc/dir.ts +++ b/packages/cli/src/swc/dir.ts @@ -1,6 +1,8 @@ import { existsSync, promises } from "fs"; import { dirname, resolve } from "path"; import Piscina from "piscina"; +import { stderr } from "process"; +import { format } from "util"; import { CompileStatus } from "./constants"; import { CliOptions } from "./options"; import { exists, getDest } from "./util"; @@ -196,13 +198,14 @@ async function initialCompilation(cliOptions: CliOptions, swcOptions: Options) { if (copied) { message += `copied ${copied} ${copied > 1 ? "files" : "file"}`; } - message += ` with swc (%dms)`; + message += ` with swc (%dms)\n`; + message = format(message, (end[1] / 1000000).toFixed(2)); - console.log(message, (end[1] / 1000000).toFixed(2)); + stderr.write(message); } if (failed) { - console.log( + console.error( `Failed to compile ${failed} ${ failed !== 1 ? "files" : "file" } with swc.` @@ -276,9 +279,11 @@ async function watchCompilation(cliOptions: CliOptions, swcOptions: Options) { }); if (!quiet && result === CompileStatus.Compiled) { const end = process.hrtime(start); - console.log( - `Successfully compiled ${filename} with swc (%dms)`, - (end[1] / 1000000).toFixed(2) + stderr.write( + format( + `Successfully compiled ${filename} with swc (%dms)\n`, + (end[1] / 1000000).toFixed(2) + ) ); } } catch (err: any) { @@ -294,9 +299,11 @@ async function watchCompilation(cliOptions: CliOptions, swcOptions: Options) { ); if (!quiet && result === CompileStatus.Copied) { const end = process.hrtime(start); - console.log( - `Successfully copied ${filename} with swc (%dms)`, - (end[1] / 1000000).toFixed(2) + stderr.write( + format( + `Successfully copied ${filename} with swc (%dms)\n`, + (end[1] / 1000000).toFixed(2) + ) ); } } catch (err: any) { diff --git a/packages/cli/src/swc/util.ts b/packages/cli/src/swc/util.ts index 221fdfe..f65a58e 100644 --- a/packages/cli/src/swc/util.ts +++ b/packages/cli/src/swc/util.ts @@ -2,6 +2,7 @@ import * as swc from "@swc/core"; import slash from "slash"; import { mkdirSync, writeFileSync, promises } from "fs"; import { dirname, join, relative } from "path"; +import { stderr } from "process"; export async function exists(path: string): Promise { let pathExists = true; @@ -113,10 +114,10 @@ export function assertCompilationResult( } if (!quiet && compiled + copied > 0) { const copyResult = copied === 0 ? " " : ` (copied ${copied}) `; - console.info( + stderr.write( `Successfully compiled ${compiled} ${ compiled !== 1 ? "files" : "file" - }${copyResult}with swc.` + }${copyResult}with swc.\n` ); }