|
1 | 1 | import { existsSync, promises } from "fs";
|
2 | 2 | import { dirname, resolve } from "path";
|
3 | 3 | import Piscina from "piscina";
|
| 4 | +import { stderr } from "process"; |
| 5 | +import { format } from "util"; |
4 | 6 | import { CompileStatus } from "./constants";
|
5 | 7 | import { Callbacks, CliOptions } from "./options";
|
6 | 8 | import { exists, getDest } from "./util";
|
@@ -208,22 +210,22 @@ async function initialCompilation(
|
208 | 210 | if (copied) {
|
209 | 211 | message += `copied ${copied} ${copied > 1 ? "files" : "file"}`;
|
210 | 212 | }
|
211 |
| - message += ` with swc (%dms)`; |
| 213 | + message += format(" with swc (%dms)\n", duration.toFixed(2)); |
212 | 214 |
|
213 | 215 | if (callbacks?.onSuccess) {
|
214 | 216 | if (!failed) {
|
215 | 217 | callbacks.onSuccess({ duration, compiled, copied });
|
216 | 218 | }
|
217 | 219 | } else if (!quiet) {
|
218 |
| - console.log(message, duration.toFixed(2)); |
| 220 | + stderr.write(message); |
219 | 221 | }
|
220 | 222 | }
|
221 | 223 |
|
222 | 224 | if (failed) {
|
223 | 225 | if (callbacks?.onFail) {
|
224 | 226 | callbacks.onFail({ duration, reasons });
|
225 | 227 | } else {
|
226 |
| - console.log( |
| 228 | + console.error( |
227 | 229 | `Failed to compile ${failed} ${
|
228 | 230 | failed !== 1 ? "files" : "file"
|
229 | 231 | } with swc.`
|
@@ -316,9 +318,11 @@ async function watchCompilation(
|
316 | 318 | filename,
|
317 | 319 | });
|
318 | 320 | } else if (!quiet) {
|
319 |
| - console.log( |
320 |
| - `Successfully compiled ${filename} with swc (%dms)`, |
321 |
| - duration.toFixed(2) |
| 321 | + stderr.write( |
| 322 | + format( |
| 323 | + `Successfully compiled ${filename} with swc (%dms)\n`, |
| 324 | + duration.toFixed(2) |
| 325 | + ) |
322 | 326 | );
|
323 | 327 | }
|
324 | 328 | }
|
@@ -353,9 +357,11 @@ async function watchCompilation(
|
353 | 357 | filename,
|
354 | 358 | });
|
355 | 359 | } else if (!quiet) {
|
356 |
| - console.log( |
357 |
| - `Successfully copied ${filename} with swc (%dms)`, |
358 |
| - duration.toFixed(2) |
| 360 | + stderr.write( |
| 361 | + format( |
| 362 | + `Successfully copied ${filename} with swc (%dms)\n`, |
| 363 | + duration.toFixed(2) |
| 364 | + ) |
359 | 365 | );
|
360 | 366 | }
|
361 | 367 | }
|
|
0 commit comments