Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(build-tools): Replace chalk with picocolors #23034

Merged
merged 3 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build-tools/packages/build-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
"@rushstack/node-core-library": "^5.9.0",
"async": "^3.2.6",
"azure-devops-node-api": "^11.2.0",
"chalk": "^5.3.0",
"change-case": "^3.1.0",
"cosmiconfig": "^8.3.6",
"danger": "^12.3.3",
Expand All @@ -119,6 +118,7 @@
"minimatch": "^7.4.6",
"npm-check-updates": "^16.14.20",
"oclif": "^4.15.16",
"picocolors": "^1.1.1",
"prettier": "~3.2.5",
"prompts": "^2.4.2",
"read-pkg-up": "^7.0.1",
Expand Down
2 changes: 1 addition & 1 deletion build-tools/packages/build-cli/src/commands/bump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { strict as assert } from "node:assert";

import { confirm } from "@inquirer/prompts";
import { Flags } from "@oclif/core";
import chalk from "chalk";
import chalk from "picocolors";
import * as semver from "semver";

import { FluidRepo, MonoRepo, Package } from "@fluidframework/build-tools";
Expand Down
2 changes: 1 addition & 1 deletion build-tools/packages/build-cli/src/commands/bump/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { Flags } from "@oclif/core";
import chalk from "chalk";
import chalk from "picocolors";
import prompts from "prompts";
import stripAnsi from "strip-ansi";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { Flags } from "@oclif/core";
import chalk from "chalk";
import chalk from "picocolors";
import { sortPackageJson as sortJson } from "sort-package-json";

import { BaseCommand, Repository } from "../../library/index.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { VersionBumpType } from "@fluid-tools/version-tools";
import { Package } from "@fluidframework/build-tools";
import { Flags, ux } from "@oclif/core";
import { PackageName } from "@rushstack/node-core-library";
import chalk from "chalk";
import { humanId } from "human-id";
import chalk from "picocolors";
import prompts from "prompts";

import { releaseGroupFlag } from "../../flags.js";
Expand Down Expand Up @@ -236,7 +236,7 @@ export default class GenerateChangesetCommand extends BaseCommand<
.map((pkg) => {
const changed = changedPackages.some((cp) => cp.name === pkg.name);
return {
title: changed ? `${pkg.name} ${chalk.red.bold("(changed)")}` : pkg.name,
title: changed ? `${pkg.name} ${chalk.red(chalk.bold("(changed)"))}` : pkg.name,
value: pkg,
selected: changed,
};
Expand All @@ -251,7 +251,7 @@ export default class GenerateChangesetCommand extends BaseCommand<
}
const changed = changedPackages.some((cp) => cp.name === pkg.name);
packageChoices.push({
title: changed ? `${pkg.name} ${chalk.red.bold("(changed)")}` : pkg.name,
title: changed ? `${pkg.name} ${chalk.red(chalk.bold("(changed)"))}` : pkg.name,
value: pkg,
selected: changed,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { strict as assert } from "node:assert";
import { Logger } from "@fluidframework/build-tools";
import { Flags } from "@oclif/core";
import chalk from "chalk";
import chalk from "picocolors";

import {
BaseCommand,
Expand Down
4 changes: 2 additions & 2 deletions build-tools/packages/build-cli/src/commands/merge/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { Flags } from "@oclif/core";
import chalk from "chalk";
import chalk from "picocolors";

import { BaseCommand, Repository } from "../../library/index.js";

Expand Down Expand Up @@ -100,7 +100,7 @@ export default class MergeInfoCommand extends BaseCommand<typeof MergeInfoComman

const revs = rawRevs.split(/\r?\n/);

const [b1Log, b2Log] = [chalk.bold.blue(branch1), chalk.bold.blue(branch2)];
const [b1Log, b2Log] = [chalk.bold(chalk.blue(branch1)), chalk.bold(chalk.blue(branch2))];

this.logHr();
this.log(
Expand Down
2 changes: 1 addition & 1 deletion build-tools/packages/build-cli/src/commands/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from "@fluid-tools/version-tools";
import { rawlist } from "@inquirer/prompts";
import { Config } from "@oclif/core";
import chalk from "chalk";
import chalk from "picocolors";

import { findPackageOrReleaseGroup } from "../args.js";
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { Flags } from "@oclif/core";
import chalk from "chalk";
import chalk from "picocolors";
import { table } from "table";

import {
Expand Down Expand Up @@ -137,7 +137,7 @@ export default class ReleaseHistoryCommand extends ReleaseReportBaseCommand<
const bumpType = detectBumpType(displayPreviousVersion, ver.version);
const displayBumpType = highlight(`${bumpType}`);

const displayVersionSection = chalk.grey(
const displayVersionSection = chalk.gray(
`${highlight(ver.version)} <-- ${displayPreviousVersion}`,
);

Expand Down
10 changes: 6 additions & 4 deletions build-tools/packages/build-cli/src/commands/release/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

import chalk from "chalk";
import chalk from "picocolors";

import { findPackageOrReleaseGroup, packageOrReleaseGroupArg } from "../../args.js";
import { BaseCommand } from "../../library/index.js";
Expand Down Expand Up @@ -71,14 +71,16 @@ export class ReleasePrepareCommand extends BaseCommand<typeof ReleasePrepareComm
// eslint-disable-next-line no-await-in-loop -- the checks are supposed to run serially
const checkResult = await check(context, pkgOrReleaseGroup);
const checkPassed = checkResult === undefined;
const icon = checkPassed ? chalk.bgGreen.black(" ✔︎ ") : chalk.bgRed.white(" ✖︎ ");
const icon = checkPassed
? chalk.bgGreen(chalk.black(" ✔︎ "))
: chalk.bgRed(chalk.white(" ✖︎ "));

this.log(`${icon} ${checkPassed ? name : chalk.red(checkResult.message)}`);
if (!checkPassed) {
if (checkResult.fixCommand !== undefined) {
this.logIndent(
`${chalk.yellow(`Possible fix command:`)} ${chalk.yellow.bold(
checkResult.fixCommand,
`${chalk.yellow(`Possible fix command:`)} ${chalk.yellow(
chalk.bold(checkResult.fixCommand),
)}`,
6,
);
Expand Down
20 changes: 10 additions & 10 deletions build-tools/packages/build-cli/src/commands/release/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import {
} from "@fluid-tools/version-tools";
import { rawlist } from "@inquirer/prompts";
import { Command, Flags, ux } from "@oclif/core";
import chalk from "chalk";
import { differenceInBusinessDays, formatDistanceToNow } from "date-fns";
import { writeJson } from "fs-extra/esm";
import chalk from "picocolors";
import sortJson from "sort-json";
import { table } from "table";

Expand Down Expand Up @@ -430,26 +430,26 @@ export default class ReleaseReportCommand extends ReleaseReportBaseCommand<
this.log(chalk.underline(chalk.bold(`Release Report`)));
if (mode === "inRepo" && flags.releaseGroup !== undefined) {
this.log(
`${chalk.yellow.bold("\nIMPORTANT")}: This report only includes the ${chalk.blue(
`${chalk.yellow(chalk.bold("\nIMPORTANT"))}: This report only includes the ${chalk.blue(
flags.releaseGroup,
)} release group (version ${chalk.blue(
context.getVersion(flags.releaseGroup),
)}) and its ${chalk.bold("direct Fluid dependencies")}.`,
);
this.log(
`${chalk.yellow.bold(
"IMPORTANT",
`${chalk.yellow(
chalk.bold("IMPORTANT"),
)}: The release version was determined by the in-repo version of the release group.`,
);
} else if (flags.releaseGroup === undefined) {
this.log(
`${chalk.yellow.bold("\nIMPORTANT")}: This report includes ${chalk.blue(
`${chalk.yellow(chalk.bold("\nIMPORTANT"))}: This report includes ${chalk.blue(
"all packages and release groups",
)} in the repo.`,
);
} else if (flags.releaseGroup !== undefined) {
this.log(
`${chalk.yellow.bold("\nIMPORTANT")}: This report only includes the ${chalk.blue(
`${chalk.yellow(chalk.bold("\nIMPORTANT"))}: This report only includes the ${chalk.blue(
flags.releaseGroup,
)} release group! ${chalk.bold("None of its dependencies are included.")}`,
);
Expand All @@ -458,7 +458,7 @@ export default class ReleaseReportCommand extends ReleaseReportBaseCommand<
switch (mode) {
case "interactive": {
this.log(
`${chalk.yellow.bold("IMPORTANT")}: Release versions were selected ${chalk.bold(
`${chalk.yellow(chalk.bold("IMPORTANT"))}: Release versions were selected ${chalk.bold(
"interactively",
)}.`,
);
Expand All @@ -467,7 +467,7 @@ export default class ReleaseReportCommand extends ReleaseReportBaseCommand<
}
case "date": {
this.log(
`${chalk.yellow.bold("IMPORTANT")}: The latest release version ${chalk.bold(
`${chalk.yellow(chalk.bold("IMPORTANT"))}: The latest release version ${chalk.bold(
"by date",
)} was selected.`,
);
Expand All @@ -476,7 +476,7 @@ export default class ReleaseReportCommand extends ReleaseReportBaseCommand<
}
case "version": {
this.log(
`${chalk.yellow.bold("IMPORTANT")}: The ${chalk.bold(
`${chalk.yellow(chalk.bold("IMPORTANT"))}: The ${chalk.bold(
"highest semver",
)} version was selected.`,
);
Expand Down Expand Up @@ -635,7 +635,7 @@ export default class ReleaseReportCommand extends ReleaseReportBaseCommand<
const bumpType = detectBumpType(prevVer ?? DEFAULT_MIN_VERSION, latestVer);
const displayBumpType = highlight(`${bumpType}`);

const displayVersionSection = chalk.grey(
const displayVersionSection = chalk.gray(
`${highlight(latestVer)} <-- ${displayPreviousVersion}`,
);

Expand Down
2 changes: 1 addition & 1 deletion build-tools/packages/build-cli/src/handlers/doFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*/

import { strict as assert } from "node:assert";
import chalk from "chalk";
import { Machine } from "jssm";
import chalk from "picocolors";

import { FluidRepo, MonoRepo } from "@fluidframework/build-tools";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*/

import { Command } from "@oclif/core";
import chalk from "chalk";
import { Machine } from "jssm";
import chalk from "picocolors";

import { Context } from "../library/index.js";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Licensed under the MIT License.
*/

import chalk from "chalk";
import { Machine } from "jssm";
import chalk from "picocolors";

import { type InstructionalPrompt, mapADOLinks } from "../instructionalPromptWriter.js";
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { StringBuilder } from "@rushstack/node-core-library";
import chalk from "chalk";
import chalk from "picocolors";

// eslint-disable-next-line import/no-deprecated
import { MonoRepoKind, indentString } from "./library/index.js";
Expand Down
4 changes: 2 additions & 2 deletions build-tools/packages/build-cli/src/library/commands/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { Command, Flags, Interfaces } from "@oclif/core";
// eslint-disable-next-line import/no-internal-modules
import type { PrettyPrintableError } from "@oclif/core/errors";
import chalk from "chalk";
import chalk from "picocolors";

import { GitRepo, getResolvedFluidRoot } from "@fluidframework/build-tools";
import { CommandLogger } from "../../logging.js";
Expand Down Expand Up @@ -279,7 +279,7 @@ export abstract class BaseCommand<T extends typeof Command>
*/
public verbose(message: string | Error | undefined): void {
if (this.flags.verbose === true) {
const color = typeof message === "string" ? chalk.grey : chalk.red;
const color = typeof message === "string" ? chalk.gray : chalk.red;
this.log(color(`VERBOSE: ${message}`));
}
}
Expand Down
2 changes: 1 addition & 1 deletion build-tools/packages/build-cli/src/stateMachineCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*/

import { Command, Flags } from "@oclif/core";
import chalk from "chalk";
import { Machine } from "jssm";
import chalk from "picocolors";

import { testModeFlag } from "./flags.js";
import { StateHandler } from "./handlers/index.js";
Expand Down
2 changes: 1 addition & 1 deletion build-tools/packages/build-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"@fluid-tools/version-tools": "workspace:~",
"@manypkg/get-packages": "^2.2.2",
"async": "^3.2.6",
"chalk": "^2.4.2",
"cosmiconfig": "^8.3.6",
"date-fns": "^2.30.0",
"debug": "^4.3.7",
Expand All @@ -56,6 +55,7 @@
"lodash": "^4.17.21",
"lodash.isequal": "^4.5.0",
"multimatch": "^5.0.0",
"picocolors": "^1.1.1",
"picomatch": "^2.3.1",
"rimraf": "^4.4.1",
"semver": "^7.6.3",
Expand Down
2 changes: 1 addition & 1 deletion build-tools/packages/build-tools/src/common/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

import chalk from "chalk";
import chalk from "picocolors";

import { commonOptions } from "../fluidBuild/commonOptions";

Expand Down
32 changes: 16 additions & 16 deletions build-tools/packages/build-tools/src/common/npmPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import { existsSync, readFileSync, readdirSync } from "node:fs";
import * as path from "node:path";
import { queue } from "async";
import * as chalk from "chalk";
import detectIndent from "detect-indent";
import { readJsonSync, writeJson, writeJsonSync } from "fs-extra";
import chalk from "picocolors";
import sortPackageJson from "sort-package-json";

import type { SetRequired, PackageJson as StandardPackageJson } from "type-fest";
Expand Down Expand Up @@ -75,21 +75,21 @@ interface PackageDependency {
export class Package {
private static packageCount: number = 0;
private static readonly chalkColor = [
chalk.default.red,
chalk.default.green,
chalk.default.yellow,
chalk.default.blue,
chalk.default.magenta,
chalk.default.cyan,
chalk.default.white,
chalk.default.grey,
chalk.default.redBright,
chalk.default.greenBright,
chalk.default.yellowBright,
chalk.default.blueBright,
chalk.default.magentaBright,
chalk.default.cyanBright,
chalk.default.whiteBright,
chalk.red,
chalk.green,
chalk.yellow,
chalk.blue,
chalk.magenta,
chalk.cyan,
chalk.white,
chalk.gray,
chalk.redBright,
chalk.greenBright,
chalk.yellowBright,
chalk.blueBright,
chalk.magentaBright,
chalk.cyanBright,
chalk.whiteBright,
];

private _packageJson: PackageJson;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { AsyncPriorityQueue } from "async";
import chalk from "chalk";
import chalk from "picocolors";
import * as semver from "semver";

import * as assert from "assert";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

import chalk from "chalk";
import chalk from "picocolors";

import { GitRepo } from "../common/gitRepo";
import { defaultLogger } from "../common/logging";
Expand Down
Loading
Loading