From d88905d87ed0c8b7f1745cddbfd618fc3b48cdb8 Mon Sep 17 00:00:00 2001 From: magic-akari Date: Fri, 30 Aug 2024 20:08:22 +0800 Subject: [PATCH 1/2] fix(cli): Redirect messages to stderr --- packages/cli/src/swc/dir.ts | 24 +++++++++++++++--------- packages/cli/src/swc/util.ts | 5 +++-- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/packages/cli/src/swc/dir.ts b/packages/cli/src/swc/dir.ts index 03c4c8d..9e2ec89 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 { Callbacks, CliOptions } from "./options"; import { exists, getDest } from "./util"; @@ -208,14 +210,14 @@ async function initialCompilation( if (copied) { message += `copied ${copied} ${copied > 1 ? "files" : "file"}`; } - message += ` with swc (%dms)`; + message += format(" with swc (%dms)\n", duration.toFixed(2)); if (callbacks?.onSuccess) { if (!failed) { callbacks.onSuccess({ duration, compiled, copied }); } } else if (!quiet) { - console.log(message, duration.toFixed(2)); + stderr.write(message); } } @@ -223,7 +225,7 @@ async function initialCompilation( if (callbacks?.onFail) { callbacks.onFail({ duration, reasons }); } else { - console.log( + console.error( `Failed to compile ${failed} ${ failed !== 1 ? "files" : "file" } with swc.` @@ -316,9 +318,11 @@ async function watchCompilation( filename, }); } else if (!quiet) { - console.log( - `Successfully compiled ${filename} with swc (%dms)`, - duration.toFixed(2) + stderr.write( + format( + `Successfully compiled ${filename} with swc (%dms)\n`, + duration.toFixed(2) + ) ); } } @@ -353,9 +357,11 @@ async function watchCompilation( filename, }); } else if (!quiet) { - console.log( - `Successfully copied ${filename} with swc (%dms)`, - duration.toFixed(2) + stderr.write( + format( + `Successfully copied ${filename} with swc (%dms)\n`, + duration.toFixed(2) + ) ); } } 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` ); } From d4865bf80ae05ac301b332df1c9db811494dbe8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Tue, 29 Oct 2024 09:51:54 +0900 Subject: [PATCH 2/2] Create famous-actors-glow.md --- .changeset/famous-actors-glow.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/famous-actors-glow.md diff --git a/.changeset/famous-actors-glow.md b/.changeset/famous-actors-glow.md new file mode 100644 index 0000000..7cdc9aa --- /dev/null +++ b/.changeset/famous-actors-glow.md @@ -0,0 +1,5 @@ +--- +"@swc/cli": patch +--- + +fix(cli): Redirect messages to stderr