Skip to content

Commit

Permalink
fix: Print build logs correctly (#14846)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Aug 13, 2022
1 parent 7e8d03f commit a32cf83
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 24 deletions.
22 changes: 11 additions & 11 deletions Gulpfile.mjs
Expand Up @@ -6,7 +6,6 @@ import { fileURLToPath } from "url";
import plumber from "gulp-plumber";
import through from "through2";
import chalk from "chalk";
import fancyLog from "fancy-log";
import filter from "gulp-filter";
import gulp from "gulp";
import { rollup } from "rollup";
Expand All @@ -24,6 +23,7 @@ import { resolve as importMetaResolve } from "import-meta-resolve";

import rollupBabelSource from "./scripts/rollup-plugin-babel-source.js";
import formatCode from "./scripts/utils/formatCode.js";
import { log } from "./scripts/utils/logger.cjs";

let USE_ESM = false;
try {
Expand Down Expand Up @@ -86,7 +86,7 @@ function getIndexFromPackage(name) {
function errorsLogger() {
return plumber({
errorHandler(err) {
fancyLog(err.stack);
log(err.stack);
},
});
}
Expand Down Expand Up @@ -116,7 +116,7 @@ function generateHelpers(generator, dest, filename, message) {
file.contents = Buffer.from(
formatCode(await generateCode(filename), dest + file.path)
);
fancyLog(`${chalk.green("✔")} Generated ${message}`);
log(`${chalk.green("✔")} Generated ${message}`);
callback(null, file);
})
)
Expand Down Expand Up @@ -176,7 +176,7 @@ function generateStandalone() {
.src(babelStandalonePluginConfigGlob, { base: monorepoRoot })
.pipe(
through.obj((file, enc, callback) => {
fancyLog("Generating @babel/standalone files");
log("Generating @babel/standalone files");
const pluginConfig = JSON.parse(file.contents);
let imports = "";
let list = "";
Expand Down Expand Up @@ -307,7 +307,7 @@ function buildRollup(packages, targetBrowsers) {
);

const input = getIndexFromPackage(src);
fancyLog(`Compiling '${chalk.cyan(input)}' with rollup ...`);
log(`Compiling '${chalk.cyan(input)}' with rollup ...`);
const bundle = await rollup({
input,
external,
Expand Down Expand Up @@ -413,7 +413,7 @@ function buildRollup(packages, targetBrowsers) {
});

if (!process.env.IS_PUBLISH) {
fancyLog(
log(
chalk.yellow(
`Skipped minification of '${chalk.cyan(
outputFile
Expand All @@ -422,7 +422,7 @@ function buildRollup(packages, targetBrowsers) {
);
return undefined;
}
fancyLog(`Minifying '${chalk.cyan(outputFile)}'...`);
log(`Minifying '${chalk.cyan(outputFile)}'...`);

await bundle.write({
file: outputFile.replace(/\.js$/, ".min.js"),
Expand Down Expand Up @@ -451,7 +451,7 @@ function buildRollupDts(packages) {
packages.map(async packageName => {
const input = `${mapToDts(packageName)}/src/index.d.ts`;
const output = `${packageName}/lib/index.d.ts`;
fancyLog(`Bundling '${chalk.cyan(output)}' with rollup ...`);
log(`Bundling '${chalk.cyan(output)}' with rollup ...`);

const bundle = await rollup({
input,
Expand Down Expand Up @@ -514,7 +514,7 @@ const standaloneBundle = [
];

gulp.task("generate-type-helpers", () => {
fancyLog("Generating @babel/types and @babel/traverse dynamic functions");
log("Generating @babel/types and @babel/traverse dynamic functions");

return Promise.all([
generateTypeHelpers("asserts"),
Expand All @@ -529,7 +529,7 @@ gulp.task("generate-type-helpers", () => {
});

gulp.task("generate-runtime-helpers", () => {
fancyLog("Generating @babel/helpers runtime helpers");
log("Generating @babel/helpers runtime helpers");

return generateRuntimeHelpers();
});
Expand Down Expand Up @@ -597,7 +597,7 @@ ${fs.readFileSync(path.join(path.dirname(input), "license"), "utf8")}*/

gulp.task("build-cjs-bundles", () => {
if (!USE_ESM) {
fancyLog(
log(
chalk.yellow(
"Skipping CJS-compat bundles for ESM-based builds, because not compiling to ESM"
)
Expand Down
4 changes: 2 additions & 2 deletions babel-worker.cjs
@@ -1,7 +1,7 @@
const { transformSync } = require("@babel/core");
const { mkdirSync, statSync, readFileSync, writeFileSync } = require("fs");
const { dirname } = require("path");
const fancyLog = require("fancy-log");
const { log } = require("./scripts/utils/logger.cjs");

let chalk;
const chalkP = import("chalk").then(ns => {
Expand Down Expand Up @@ -30,7 +30,7 @@ exports.transform = async function transform(src, dest) {
if (!needCompile(src, dest)) {
return;
}
fancyLog(`Compiling '${chalk.cyan(src)}'...`);
log(`Compiling '${chalk.cyan(src)}'...`);
const content = readFileSync(src, { encoding: "utf8" });
const { code } = transformSync(content, {
filename: src,
Expand Down
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -52,7 +52,6 @@
"eslint-plugin-jest": "^26.6.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.2.1",
"fancy-log": "^2.0.0",
"glob": "^7.2.0",
"gulp": "^4.0.2",
"gulp-filter": "^7.0.0",
Expand Down
4 changes: 4 additions & 0 deletions scripts/utils/logger.cjs
@@ -0,0 +1,4 @@
exports.log = function (msg, ...args) {
const time = new Date().toLocaleTimeString("en-US", { hour12: false });
console.log(`[${time}] ${msg}`, ...args);
};
10 changes: 0 additions & 10 deletions yarn.lock
Expand Up @@ -5926,7 +5926,6 @@ __metadata:
eslint-plugin-jest: ^26.6.0
eslint-plugin-node: ^11.1.0
eslint-plugin-prettier: ^4.2.1
fancy-log: ^2.0.0
glob: ^7.2.0
gulp: ^4.0.2
gulp-filter: ^7.0.0
Expand Down Expand Up @@ -8394,15 +8393,6 @@ __metadata:
languageName: node
linkType: hard

"fancy-log@npm:^2.0.0":
version: 2.0.0
resolution: "fancy-log@npm:2.0.0"
dependencies:
color-support: ^1.1.3
checksum: 5652bf35e6a0be68bc011cf38706c78c7724808311e88905a3e4623d0e86168f084a9f38109dce2b2f78078ae704e4b55095effda743b4795c37f30ddb70497e
languageName: node
linkType: hard

"fast-deep-equal@npm:^3.1.1, fast-deep-equal@npm:^3.1.3":
version: 3.1.3
resolution: "fast-deep-equal@npm:3.1.3"
Expand Down

0 comments on commit a32cf83

Please sign in to comment.