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

Replace chalk by picocolors #8390

Merged
merged 17 commits into from
Jul 12, 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
38 changes: 15 additions & 23 deletions packages/create-turbo/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from "node:path";
import childProcess from "node:child_process";
import chalk from "chalk";
import { bold, cyan, green, red } from "picocolors";
import { setupTestFixtures, spyConsole, spyExit } from "@turbo/test-utils";
import { logger } from "@turbo/utils";
import type { PackageManager } from "@turbo/utils";
Expand Down Expand Up @@ -92,28 +92,24 @@ describe("create-turbo", () => {
telemetry,
});

const expected = `${chalk.bold(
const expected = `${bold(
logger.turboGradient(">>> Success!")
)} Created your Turborepo at ${chalk.green(
)} Created your Turborepo at ${green(
path.relative(process.cwd(), root)
)}`;
expect(mockConsole.log).toHaveBeenCalledWith(expected);
expect(mockConsole.log).toHaveBeenCalledWith();
expect(mockConsole.log).toHaveBeenCalledWith(
chalk.bold("To get started:")
);
expect(mockConsole.log).toHaveBeenCalledWith(bold("To get started:"));

expect(mockConsole.log).toHaveBeenCalledWith(
chalk.cyan("Library packages")
);
expect(mockConsole.log).toHaveBeenCalledWith(cyan("Library packages"));

expect(mockConsole.log).toHaveBeenCalledWith(
"- Run commands with Turborepo:"
);

availableScripts.forEach((script) => {
expect(mockConsole.log).toHaveBeenCalledWith(
expect.stringContaining(chalk.cyan(`${packageManager} run ${script}`))
expect.stringContaining(cyan(`${packageManager} run ${script}`))
);
});

Expand Down Expand Up @@ -179,28 +175,24 @@ describe("create-turbo", () => {
telemetry,
});

const expected = `${chalk.bold(
const expected = `${bold(
logger.turboGradient(">>> Success!")
)} Created your Turborepo at ${chalk.green(
)} Created your Turborepo at ${green(
path.relative(process.cwd(), root)
)}`;
expect(mockConsole.log).toHaveBeenCalledWith(expected);
expect(mockConsole.log).toHaveBeenCalledWith();
expect(mockConsole.log).toHaveBeenCalledWith(
chalk.bold("To get started:")
);
expect(mockConsole.log).toHaveBeenCalledWith(bold("To get started:"));

expect(mockConsole.log).toHaveBeenCalledWith(
chalk.cyan("Library packages")
);
expect(mockConsole.log).toHaveBeenCalledWith(cyan("Library packages"));

expect(mockConsole.log).toHaveBeenCalledWith(
"- Run commands with Turborepo:"
);

availableScripts.forEach((script) => {
expect(mockConsole.log).toHaveBeenCalledWith(
expect.stringContaining(chalk.cyan(`${packageManager} run ${script}`))
expect.stringContaining(cyan(`${packageManager} run ${script}`))
);
});

Expand Down Expand Up @@ -255,13 +247,13 @@ describe("create-turbo", () => {
expect(mockConsole.error).toHaveBeenCalledTimes(2);
expect(mockConsole.error).toHaveBeenNthCalledWith(
1,
logger.turboRed.bold(">>>"),
chalk.red("Unable to download template from Github")
logger.turboRed(bold(">>>")),
red("Unable to download template from Github")
);
expect(mockConsole.error).toHaveBeenNthCalledWith(
2,
logger.turboRed.bold(">>>"),
chalk.red("Could not connect")
logger.turboRed(bold(">>>")),
red("Could not connect")
);
expect(mockExit.exit).toHaveBeenCalledWith(1);

Expand Down
2 changes: 1 addition & 1 deletion packages/create-turbo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
"lint:prettier": "prettier -c . --cache --ignore-path=../../.prettierignore"
},
"dependencies": {
"chalk": "4.1.2",
"commander": "^11.0.0",
"fs-extra": "^11.1.1",
"inquirer": "^8.0.0",
"picocolors": "1.0.1",
"proxy-agent": "^6.2.2",
"rimraf": "^3.0.2",
"semver": "^7.3.8",
Expand Down
6 changes: 3 additions & 3 deletions packages/create-turbo/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import http from "node:http";
import https from "node:https";
import chalk from "chalk";
import { bold } from "picocolors";
import { Command, Option } from "commander";
import { logger } from "@turbo/utils";
import {
Expand All @@ -27,9 +27,9 @@ const createTurboCli = new Command();

// create
createTurboCli
.name(chalk.bold(logger.turboGradient("create-turbo")))
.name(bold(logger.turboGradient("create-turbo")))
.description("Create a new Turborepo")
.usage(`${chalk.bold("<project-directory>")} [options]`)
.usage(`${bold("<project-directory>")} [options]`)
.hook("preAction", async (_, thisAction) => {
const { telemetry } = await initTelemetry<"create-turbo">({
packageInfo: {
Expand Down
38 changes: 17 additions & 21 deletions packages/create-turbo/src/commands/create/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from "node:path";
import chalk from "chalk";
import { bold, red, cyan, green } from "picocolors";
import type { Project } from "@turbo/workspaces";
import {
getWorkspaceDetails,
Expand Down Expand Up @@ -39,18 +39,18 @@ function handleErrors(
telemetry?.trackCommandStatus({ command: "create", status: "error" });
// handle errors from ../../transforms
if (err instanceof TransformError) {
error(chalk.bold(err.transform), chalk.red(err.message));
error(bold(err.transform), red(err.message));
if (err.fatal) {
process.exit(1);
}
// handle errors from @turbo/workspaces
} else if (err instanceof ConvertError && err.type !== "unknown") {
error(chalk.red(err.message));
error(red(err.message));
process.exit(1);
// handle download errors from @turbo/utils
} else if (err instanceof DownloadError) {
error(chalk.red("Unable to download template from Github"));
error(chalk.red(err.message));
error(red("Unable to download template from Github"));
error(red(err.message));
process.exit(1);
}

Expand Down Expand Up @@ -203,16 +203,14 @@ export async function create(
let lastGroup: string | undefined;
workspacesForDisplay.forEach(({ group, title, description }, idx) => {
if (idx === 0 || group !== lastGroup) {
logger.log(chalk.cyan(group));
logger.log(cyan(group));
}
logger.log(
` - ${chalk.bold(title)}${description ? `: ${description}` : ""}`
);
logger.log(` - ${bold(title)}${description ? `: ${description}` : ""}`);
lastGroup = group;
});
} else {
logger.log(chalk.cyan("apps"));
logger.log(` - ${chalk.bold(projectName)}`);
logger.log(cyan("apps"));
logger.log(` - ${bold(projectName)}`);
}

// run install
Expand Down Expand Up @@ -248,30 +246,28 @@ export async function create(

if (projectDirIsCurrentDir) {
logger.log(
`${chalk.bold(
turboGradient(">>> Success!")
)} Your new Turborepo is ready.`
`${bold(turboGradient(">>> Success!"))} Your new Turborepo is ready.`
);
} else {
logger.log(
`${chalk.bold(
turboGradient(">>> Success!")
)} Created your Turborepo at ${chalk.green(relativeProjectDir)}`
`${bold(turboGradient(">>> Success!"))} Created your Turborepo at ${green(
relativeProjectDir
)}`
);
}

// get the package manager details so we display the right commands to the user in log messages
const packageManagerMeta = getPackageManagerMeta(projectPackageManager);
if (packageManagerMeta && hasPackageJson) {
logger.log();
logger.log(chalk.bold("To get started:"));
logger.log(bold("To get started:"));
if (!projectDirIsCurrentDir) {
logger.log(
`- Change to the directory: ${chalk.cyan(`cd ${relativeProjectDir}`)}`
`- Change to the directory: ${cyan(`cd ${relativeProjectDir}`)}`
);
}
logger.log(
`- Enable Remote Caching (recommended): ${chalk.cyan(
`- Enable Remote Caching (recommended): ${cyan(
`${packageManagerMeta.executable} turbo login`
)}`
);
Expand All @@ -282,7 +278,7 @@ export async function create(
.filter((script) => SCRIPTS_TO_DISPLAY[script])
.forEach((script) => {
logger.log(
` - ${chalk.cyan(`${packageManagerMeta.command} run ${script}`)}: ${
` - ${cyan(`${packageManagerMeta.command} run ${script}`)}: ${
SCRIPTS_TO_DISPLAY[script]
} all apps and packages`
);
Expand Down
6 changes: 2 additions & 4 deletions packages/create-turbo/src/utils/notifyUpdate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import chalk from "chalk";
import { yellow, bold } from "picocolors";
import checkForUpdate from "update-check";
import { logger } from "@turbo/utils";
import cliPkgJson from "../../package.json";
Expand All @@ -10,9 +10,7 @@ export async function notifyUpdate(): Promise<void> {
const res = await update;
if (res?.latest) {
logger.log();
logger.log(
chalk.yellow.bold("A new version of `create-turbo` is available!")
);
logger.log(yellow(bold("A new version of `create-turbo` is available!")));
logger.log();
}
process.exit();
Expand Down
2 changes: 1 addition & 1 deletion packages/devlow-bench/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
},
"dependencies": {
"@datadog/datadog-api-client": "^1.13.0",
"chalk": "2.4.2",
"inquirer": "^9.2.7",
"minimist": "^1.2.8",
"picocolors": "1.0.1",
"pidusage-tree": "^2.0.5",
"playwright-chromium": "^1.39.0",
"split2": "^4.2.0",
Expand Down
28 changes: 17 additions & 11 deletions packages/devlow-bench/src/interfaces/console.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
import { Interface, Scenario, ScenarioVariant } from "../index.js";
import inquirer from "inquirer";
import chalk from "chalk";
import { bgCyan, bold, magenta, red, underline } from "picocolors";
import { formatUnit } from "../units.js";
import { formatVariant } from "../utils.js";

export default function createInterface(): Interface {
const iface: Interface = {
start: async (scenario, props) => {
console.log(
chalk.bold.underline(`Running ${formatVariant(scenario, props)}...`)
bold(underline(`Running ${formatVariant(scenario, props)}...`))
);
},
measurement: async (scenario, props, name, value, unit, relativeTo) => {
console.log(
chalk.bgCyan.bold.magenta(
`${formatVariant(scenario, props)}: ${name} = ${formatUnit(
value,
unit
)}${relativeTo ? ` (from ${relativeTo})` : ""}`
bgCyan(
bold(
magenta(
`${formatVariant(scenario, props)}: ${name} = ${formatUnit(
value,
unit
)}${relativeTo ? ` (from ${relativeTo})` : ""}`
)
)
)
);
},
error: async (scenario, props, error) => {
console.log(
chalk.bold.red(
`${formatVariant(scenario, props)}: ${
(error && (error as any).stack) || error
}`
bold(
red(
`${formatVariant(scenario, props)}: ${
(error && (error as any).stack) || error
}`
)
)
);
},
Expand Down
1 change: 0 additions & 1 deletion packages/devlow-bench/src/interfaces/interactive.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Interface, Scenario, ScenarioVariant } from "../index.js";
import inquirer from "inquirer";
import chalk from "chalk";
import { formatUnit } from "../units.js";
import { formatVariant } from "../utils.js";

Expand Down
1 change: 0 additions & 1 deletion packages/devlow-bench/src/interfaces/json.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Interface, Scenario, ScenarioVariant } from "../index.js";
import inquirer from "inquirer";
import chalk from "chalk";
import { formatUnit } from "../units.js";
import { formatVariant } from "../utils.js";
import { writeFile } from "fs/promises";
Expand Down
1 change: 0 additions & 1 deletion packages/devlow-bench/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
declare module "chalk";
declare module "pidusage-tree";
3 changes: 1 addition & 2 deletions packages/turbo-codemod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
},
"dependencies": {
"axios": "0.27.2",
"chalk": "2.4.2",
"commander": "^9.5.0",
"diff": "^5.1.0",
"find-up": "4.1.0",
Expand All @@ -34,6 +33,7 @@
"json5": "^2.2.3",
"is-git-clean": "^1.1.0",
"ora": "4.1.1",
"picocolors": "1.0.1",
"semver": "^7.3.7",
"update-check": "^1.5.4"
},
Expand All @@ -45,7 +45,6 @@
"@turbo/types": "workspace:*",
"@turbo/utils": "workspace:*",
"@turbo/workspaces": "workspace:*",
"@types/chalk-animation": "^1.6.0",
"@types/diff": "^5.0.2",
"@types/fs-extra": "^9.0.13",
"@types/gradient-string": "^1.1.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/turbo-codemod/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

import chalk from "chalk";
import { red } from "picocolors";
import { logger } from "@turbo/utils";
import { Command } from "commander";
import cliPkg from "../package.json";
Expand Down Expand Up @@ -69,7 +69,7 @@ codemodCli
.then(notifyUpdate)
.catch(async (reason) => {
logger.log();
logger.log(chalk.red("Unexpected error. Please report it as a bug:"));
logger.log(red("Unexpected error. Please report it as a bug:"));
logger.log(reason);

logger.log();
Expand Down
Loading
Loading