Skip to content

Commit d88905d

Browse files
committed
fix(cli): Redirect messages to stderr
1 parent eca4f6b commit d88905d

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

packages/cli/src/swc/dir.ts

+15-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { existsSync, promises } from "fs";
22
import { dirname, resolve } from "path";
33
import Piscina from "piscina";
4+
import { stderr } from "process";
5+
import { format } from "util";
46
import { CompileStatus } from "./constants";
57
import { Callbacks, CliOptions } from "./options";
68
import { exists, getDest } from "./util";
@@ -208,22 +210,22 @@ async function initialCompilation(
208210
if (copied) {
209211
message += `copied ${copied} ${copied > 1 ? "files" : "file"}`;
210212
}
211-
message += ` with swc (%dms)`;
213+
message += format(" with swc (%dms)\n", duration.toFixed(2));
212214

213215
if (callbacks?.onSuccess) {
214216
if (!failed) {
215217
callbacks.onSuccess({ duration, compiled, copied });
216218
}
217219
} else if (!quiet) {
218-
console.log(message, duration.toFixed(2));
220+
stderr.write(message);
219221
}
220222
}
221223

222224
if (failed) {
223225
if (callbacks?.onFail) {
224226
callbacks.onFail({ duration, reasons });
225227
} else {
226-
console.log(
228+
console.error(
227229
`Failed to compile ${failed} ${
228230
failed !== 1 ? "files" : "file"
229231
} with swc.`
@@ -316,9 +318,11 @@ async function watchCompilation(
316318
filename,
317319
});
318320
} 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+
)
322326
);
323327
}
324328
}
@@ -353,9 +357,11 @@ async function watchCompilation(
353357
filename,
354358
});
355359
} 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+
)
359365
);
360366
}
361367
}

packages/cli/src/swc/util.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as swc from "@swc/core";
22
import slash from "slash";
33
import { mkdirSync, writeFileSync, promises } from "fs";
44
import { dirname, join, relative } from "path";
5+
import { stderr } from "process";
56

67
export async function exists(path: string): Promise<boolean> {
78
let pathExists = true;
@@ -113,10 +114,10 @@ export function assertCompilationResult<T>(
113114
}
114115
if (!quiet && compiled + copied > 0) {
115116
const copyResult = copied === 0 ? " " : ` (copied ${copied}) `;
116-
console.info(
117+
stderr.write(
117118
`Successfully compiled ${compiled} ${
118119
compiled !== 1 ? "files" : "file"
119-
}${copyResult}with swc.`
120+
}${copyResult}with swc.\n`
120121
);
121122
}
122123

0 commit comments

Comments
 (0)