Skip to content

Commit

Permalink
refactor: use colors from consola/utils
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jul 2, 2024
1 parent 027fdf6 commit 6a8f36d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 37 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^5.0.7",
"@rollup/pluginutils": "^5.1.0",
"chalk": "^5.3.0",
"citty": "^0.1.6",
"consola": "^3.2.3",
"defu": "^6.1.4",
Expand Down
9 changes: 0 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/auto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { BuildEntry, BuildPreset, MkdistBuildEntry } from "./types";
import { existsSync } from "node:fs";
import { normalize, join, resolve } from "pathe";
import { consola } from "consola";
import chalk from "chalk";
import { colors } from "consola/utils";
import { definePreset } from "./types";
import { extractExportFilenames, listRecursively, warn } from "./utils";

Expand Down Expand Up @@ -38,18 +38,18 @@ export const autoPreset: BuildPreset = definePreset(() => {
}
consola.info(
"Automatically detected entries:",
chalk.cyan(
colors.cyan(
ctx.options.entries
.map((e) =>
chalk.bold(
colors.bold(
e.input
.replace(ctx.options.rootDir + "/", "")
.replace(/\/$/, "/*"),
),
)
.join(", "),
),
chalk.gray(
colors.gray(
["esm", res.cjs && "cjs", res.dts && "dts"]
.filter(Boolean)
.map((tag) => `[${tag}]`)
Expand Down
30 changes: 15 additions & 15 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { promises as fsp } from "node:fs";
import { resolve, relative, isAbsolute, normalize } from "pathe";
import { withTrailingSlash } from "ufo";
import type { PackageJson } from "pkg-types";
import chalk from "chalk";
import { colors } from "consola/utils";
import { consola } from "consola";
import { defu } from "defu";
import { createHooks } from "hookable";
Expand Down Expand Up @@ -228,11 +228,11 @@ async function _build(

// Start info
consola.info(
chalk.cyan(`${options.stub ? "Stubbing" : "Building"} ${options.name}`),
colors.cyan(`${options.stub ? "Stubbing" : "Building"} ${options.name}`),
);
if (process.env.DEBUG) {
consola.info(`${chalk.bold("Root dir:")} ${options.rootDir}
${chalk.bold("Entries:")}
consola.info(`${colors.bold("Root dir:")} ${options.rootDir}
${colors.bold("Entries:")}
${options.entries.map((entry) => " " + dumpObject(entry)).join("\n ")}
`);
}
Expand Down Expand Up @@ -286,7 +286,7 @@ async function _build(
}

// Done info
consola.success(chalk.green("Build succeeded for " + options.name));
consola.success(colors.green("Build succeeded for " + options.name));

// Find all dist files and add missing entries as chunks
const outFiles = await globby("**", { cwd: options.outDir });
Expand All @@ -313,12 +313,12 @@ async function _build(
totalBytes += ctx.buildEntries.find((e) => e.path === chunk)?.bytes || 0;
}
let line =
` ${chalk.bold(rPath(entry.path))} (` +
` ${colors.bold(rPath(entry.path))} (` +
[
totalBytes && `total size: ${chalk.cyan(prettyBytes(totalBytes))}`,
entry.bytes && `chunk size: ${chalk.cyan(prettyBytes(entry.bytes))}`,
totalBytes && `total size: ${colors.cyan(prettyBytes(totalBytes))}`,
entry.bytes && `chunk size: ${colors.cyan(prettyBytes(entry.bytes))}`,
entry.exports?.length &&
`exports: ${chalk.gray(entry.exports.join(", "))}`,
`exports: ${colors.gray(entry.exports.join(", "))}`,
]
.filter(Boolean)
.join(", ") +
Expand All @@ -330,10 +330,10 @@ async function _build(
.map((p) => {
const chunk =
ctx.buildEntries.find((e) => e.path === p) || ({} as any);
return chalk.gray(
return colors.gray(
" └─ " +
rPath(p) +
chalk.bold(
colors.bold(
chunk.bytes ? ` (${prettyBytes(chunk?.bytes)})` : "",
),
);
Expand All @@ -347,19 +347,19 @@ async function _build(
.filter((m) => m.id.includes("node_modules"))
.sort((a, b) => (b.bytes || 0) - (a.bytes || 0))
.map((m) => {
return chalk.gray(
return colors.gray(
" 📦 " +
rPath(m.id) +
chalk.bold(m.bytes ? ` (${prettyBytes(m.bytes)})` : ""),
colors.bold(m.bytes ? ` (${prettyBytes(m.bytes)})` : ""),
);
})
.join("\n");
}
consola.log(entry.chunk ? chalk.gray(line) : line);
consola.log(entry.chunk ? colors.gray(line) : line);
}
console.log(
"Σ Total dist size (byte size):",
chalk.cyan(
colors.cyan(
prettyBytes(ctx.buildEntries.reduce((a, e) => a + (e.bytes || 0), 0)),
),
);
Expand Down
8 changes: 4 additions & 4 deletions src/builders/rollup/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { relative } from "pathe";
import { watch as _rollupWatch } from "rollup";
import type { RollupOptions } from "../../types";
import consola from "consola";
import chalk from "chalk";
import { colors } from "consola/utils";

export function rollupWatch(rollupOptions: RollupOptions): void {
const watcher = _rollupWatch(rollupOptions);
Expand All @@ -24,16 +24,16 @@ export function rollupWatch(rollupOptions: RollupOptions): void {
);

watcher.on("change", (id, { event }) => {
consola.info(`${chalk.cyan(relative(".", id))} was ${event}d`);
consola.info(`${colors.cyan(relative(".", id))} was ${event}d`);
});

watcher.on("restart", () => {
consola.info(chalk.gray("[unbuild] [rollup] Rebuilding bundle"));
consola.info(colors.gray("[unbuild] [rollup] Rebuilding bundle"));
});

watcher.on("event", (event) => {
if (event.code === "END") {
consola.success(chalk.green("[unbuild] [rollup] Rebuild finished\n"));
consola.success(colors.green("[unbuild] [rollup] Rebuild finished\n"));
}
});
}
8 changes: 4 additions & 4 deletions src/validate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { PackageJson } from "pkg-types";
import type { BuildContext } from "./types";
import { existsSync } from "node:fs";
import chalk from "chalk";
import { colors } from "consola/utils";
import { resolve } from "pathe";
import { arrayIncludes, extractExportFilenames, getpkg, warn } from "./utils";

Expand Down Expand Up @@ -34,14 +34,14 @@ export function validateDependencies(ctx: BuildContext): void {
warn(
ctx,
"Potential unused dependencies found: " +
[...unusedDependencies].map((id) => chalk.cyan(id)).join(", "),
[...unusedDependencies].map((id) => colors.cyan(id)).join(", "),
);
}
if (implicitDependencies.size > 0 && !ctx.options.rollup.inlineDependencies) {
warn(
ctx,
"Potential implicit dependencies found: " +
[...implicitDependencies].map((id) => chalk.cyan(id)).join(", "),
[...implicitDependencies].map((id) => colors.cyan(id)).join(", "),
);
}
}
Expand Down Expand Up @@ -79,7 +79,7 @@ export function validatePackage(
warn(
ctx,
`Potential missing package.json files: ${missingOutputs
.map((o) => chalk.cyan(o))
.map((o) => colors.cyan(o))
.join(", ")}`,
);
}
Expand Down

0 comments on commit 6a8f36d

Please sign in to comment.