diff --git a/actions/add.action.ts b/actions/add.action.ts index 4159d73c2..dba13cdbc 100644 --- a/actions/add.action.ts +++ b/actions/add.action.ts @@ -1,4 +1,4 @@ -import * as chalk from 'chalk'; +import { red } from 'ansis'; import { Input } from '../commands'; import { getValueOrDefault } from '../lib/compiler/helpers/get-value-or-default'; import { @@ -40,7 +40,7 @@ export class AddAction extends AbstractAction { await this.addLibrary(collectionName, options, extraFlags); } else { console.error( - chalk.red( + red( MESSAGES.LIBRARY_INSTALLATION_FAILED_BAD_PACKAGE(libraryName), ), ); @@ -109,7 +109,7 @@ export class AddAction extends AbstractAction { installResult = await manager.addProduction([collectionName], tagName); } catch (error) { if (error && error.message) { - console.error(chalk.red(error.message)); + console.error(red(error.message)); } } return installResult; @@ -140,7 +140,7 @@ export class AddAction extends AbstractAction { ); } catch (error) { if (error && error.message) { - console.error(chalk.red(error.message)); + console.error(red(error.message)); return Promise.reject(); } } diff --git a/actions/build.action.ts b/actions/build.action.ts index c21261fc9..136a9b049 100644 --- a/actions/build.action.ts +++ b/actions/build.action.ts @@ -1,4 +1,4 @@ -import * as chalk from 'chalk'; +import { red } from 'ansis'; import { join } from 'path'; import * as ts from 'typescript'; import { Input } from '../commands'; @@ -60,7 +60,7 @@ export class BuildAction extends AbstractAction { if (err instanceof Error) { console.log(`\n${ERROR_PREFIX} ${err.message}\n`); } else { - console.error(`\n${chalk.red(err)}\n`); + console.error(`\n${red(err)}\n`); } process.exit(1); } diff --git a/actions/generate.action.ts b/actions/generate.action.ts index a9eb85d2d..a28753be2 100644 --- a/actions/generate.action.ts +++ b/actions/generate.action.ts @@ -1,4 +1,4 @@ -import * as chalk from 'chalk'; +import { red } from 'ansis'; import * as path from 'path'; import { Input } from '../commands'; import { getValueOrDefault } from '../lib/compiler/helpers/get-value-or-default'; @@ -143,7 +143,7 @@ const generateFiles = async (inputs: Input[]) => { await collection.execute(schematicInput.value as string, schematicOptions); } catch (error) { if (error && error.message) { - console.error(chalk.red(error.message)); + console.error(red(error.message)); } } }; diff --git a/actions/info.action.ts b/actions/info.action.ts index a80c92fa5..0b5ad44eb 100644 --- a/actions/info.action.ts +++ b/actions/info.action.ts @@ -1,4 +1,4 @@ -import * as chalk from 'chalk'; +import { blue, bold, green, red, yellow } from 'ansis'; import { readFileSync } from 'fs'; import { platform, release } from 'os'; import { join } from 'path'; @@ -50,16 +50,16 @@ export class InfoAction extends AbstractAction { } private displayBanner() { - console.info(chalk.red(BANNER)); + console.info(red(BANNER)); } private async displaySystemInformation(): Promise { - console.info(chalk.green('[System Information]')); + console.info(green`[System Information]`); console.info( 'OS Version :', - chalk.blue(osName(platform(), release()), release()), + blue(osName(platform(), release()) + release()), ); - console.info('NodeJS Version :', chalk.blue(process.version)); + console.info('NodeJS Version :', blue(process.version)); await this.displayPackageManagerVersion(); } @@ -68,13 +68,13 @@ export class InfoAction extends AbstractAction { const version: string = await this.manager.version(); console.info( `${this.manager.name} Version :`, - chalk.blue(version), + blue(version), '\n', ); } catch { console.error( `${this.manager.name} Version :`, - chalk.red('Unknown'), + red`Unknown`, '\n', ); } @@ -82,7 +82,7 @@ export class InfoAction extends AbstractAction { async displayNestInformation(): Promise { this.displayCliVersion(); - console.info(chalk.green('[Nest Platform Information]')); + console.info(green`[Nest Platform Information`); await this.displayNestInformationFromPackage(); } @@ -93,16 +93,16 @@ export class InfoAction extends AbstractAction { this.displayNestVersions(dependencies); } catch (err) { console.error( - chalk.red(MESSAGES.NEST_INFORMATION_PACKAGE_MANAGER_FAILED), + red(MESSAGES.NEST_INFORMATION_PACKAGE_MANAGER_FAILED), ); } } displayCliVersion(): void { - console.info(chalk.green('[Nest CLI]')); + console.info(green`[Nest CLI]`); console.info( 'Nest CLI Version :', - chalk.blue( + blue( JSON.parse(readFileSync(join(__dirname, '../package.json')).toString()) .version, ), @@ -125,7 +125,7 @@ export class InfoAction extends AbstractAction { displayNestVersions(dependencies: PackageJsonDependencies) { const nestDependencies = this.buildNestVersionsMessage(dependencies); nestDependencies.forEach((dependency) => - console.info(dependency.name, chalk.blue(dependency.value)), + console.info(dependency.name, blue(dependency.value)), ); this.displayWarningMessage(nestDependencies); @@ -137,13 +137,13 @@ export class InfoAction extends AbstractAction { const majorVersions = Object.keys(warnings); if (majorVersions.length > 0) { console.info('\r'); - console.info(chalk.yellow('[Warnings]')); + console.info(yellow`[Warnings]`); console.info( 'The following packages are not in the same major version', ); console.info('This could lead to runtime errors'); majorVersions.forEach((version) => { - console.info(chalk.bold(`* Under version ${version}`)); + console.info(bold`* Under version ${version}`); warnings[version].forEach(({ packageName, value }) => { console.info(`- ${packageName} ${value}`); }); @@ -152,7 +152,7 @@ export class InfoAction extends AbstractAction { } catch { console.info('\t'); console.error( - chalk.red( + red( MESSAGES.NEST_INFORMATION_PACKAGE_WARNING_FAILED( this.warningMessageDependenciesWhiteList, ), diff --git a/actions/new.action.ts b/actions/new.action.ts index c5a2043c4..a9be127d7 100644 --- a/actions/new.action.ts +++ b/actions/new.action.ts @@ -1,5 +1,5 @@ import { input, select } from '@inquirer/prompts'; -import * as chalk from 'chalk'; +import * as ansis from 'ansis'; import { execSync } from 'child_process'; import * as fs from 'fs'; import { Answers } from 'inquirer'; @@ -151,7 +151,7 @@ const installPackages = async ( let packageManager: AbstractPackageManager; if (dryRunMode) { console.info(); - console.info(chalk.green(MESSAGES.DRY_RUN_MODE)); + console.info(ansis.green(MESSAGES.DRY_RUN_MODE)); console.info(); return; } @@ -160,7 +160,7 @@ const installPackages = async ( await packageManager.install(installDirectory, inputPackageManager); } catch (error) { if (error && error.message) { - console.error(chalk.red(error.message)); + console.error(ansis.red(error.message)); } } }; @@ -176,7 +176,7 @@ const askForPackageManager = async () => { const initializeGitRepository = async (dir: string) => { const runner = new GitRunner(); await runner.run('init', true, join(process.cwd(), dir)).catch(() => { - console.error(chalk.red(MESSAGES.GIT_INITIALIZATION_ERROR)); + console.error(ansis.red(MESSAGES.GIT_INITIALIZATION_ERROR)); }); }; @@ -212,7 +212,7 @@ const printCollective = () => { emptyLine(); emptyLine(); print()( - `${chalk.bold(`${EMOJIS.WINE} Donate:`)} ${chalk.underline( + `${ansis.bold`${EMOJIS.WINE} Donate:`} ${ansis.underline( 'https://opencollective.com/nest', )}`, ); @@ -227,7 +227,7 @@ const print = const leftPaddingLength = Math.floor((terminalCols - strLength) / 2); const leftPadding = ' '.repeat(Math.max(leftPaddingLength, 0)); if (color) { - str = (chalk as any)[color](str); + str = (ansis as any)[color](str); } console.log(leftPadding, str); }; diff --git a/actions/start.action.ts b/actions/start.action.ts index 4e209bcac..4cf9de8b7 100644 --- a/actions/start.action.ts +++ b/actions/start.action.ts @@ -1,4 +1,4 @@ -import * as chalk from 'chalk'; +import { red } from 'ansis'; import { spawn } from 'child_process'; import * as fs from 'fs'; import { join } from 'path'; @@ -107,7 +107,7 @@ export class StartAction extends BuildAction { if (err instanceof Error) { console.log(`\n${ERROR_PREFIX} ${err.message}\n`); } else { - console.error(`\n${chalk.red(err)}\n`); + console.error(`\n${red(err)}\n`); } } } diff --git a/commands/command.loader.ts b/commands/command.loader.ts index ba570a19c..a241c96ad 100644 --- a/commands/command.loader.ts +++ b/commands/command.loader.ts @@ -1,4 +1,4 @@ -import * as chalk from 'chalk'; +import { red } from 'ansis'; import { CommanderStatic } from 'commander'; import { AddAction, @@ -30,11 +30,11 @@ export class CommandLoader { private static handleInvalidCommand(program: CommanderStatic) { program.on('command:*', () => { console.error( - `\n${ERROR_PREFIX} Invalid command: ${chalk.red('%s')}`, + `\n${ERROR_PREFIX} Invalid command: ${red`%s`}`, program.args.join(' '), ); console.log( - `See ${chalk.red('--help')} for a list of available commands.\n`, + `See ${red`--help`} for a list of available commands.\n`, ); process.exit(1); }); diff --git a/commands/generate.command.ts b/commands/generate.command.ts index 41a7437ca..ed697a834 100644 --- a/commands/generate.command.ts +++ b/commands/generate.command.ts @@ -1,4 +1,4 @@ -import * as chalk from 'chalk'; +import { bold, cyan, green } from 'ansis'; import * as Table from 'cli-table3'; import { Command, CommanderStatic } from 'commander'; import { AbstractCollection, CollectionFactory } from '../lib/schematics'; @@ -107,7 +107,7 @@ export class GenerateCommand extends AbstractCommand { const collection = await this.getCollection(); return ( 'Generate a Nest element.\n' + - ` Schematics available on ${chalk.bold(collection)} collection:\n` + + ` Schematics available on ${bold(collection)} collection:\n` + this.buildSchematicsListAsTable(await this.getSchematics(collection)) ); } @@ -129,8 +129,8 @@ export class GenerateCommand extends AbstractCommand { const table: any = new Table(tableConfig); for (const schematic of schematics) { table.push([ - chalk.green(schematic.name), - chalk.cyan(schematic.alias), + green(schematic.name), + cyan(schematic.alias), schematic.description, ]); } diff --git a/lib/compiler/helpers/manual-restart.ts b/lib/compiler/helpers/manual-restart.ts index 398c1284d..cca52b1db 100644 --- a/lib/compiler/helpers/manual-restart.ts +++ b/lib/compiler/helpers/manual-restart.ts @@ -1,4 +1,4 @@ -import * as chalk from 'chalk'; +import { gray } from 'ansis'; export function listenForManualRestart(callback: () => void) { const stdinListener = (data: Buffer) => { @@ -11,5 +11,5 @@ export function listenForManualRestart(callback: () => void) { } export function displayManualRestartTip(): void { - console.log(`To restart at any time, enter ${chalk.gray('rs')}.\n`); + console.log(`To restart at any time, enter ${gray`rs`}.\n`); } diff --git a/lib/compiler/swc/constants.ts b/lib/compiler/swc/constants.ts index 40ca06aac..16653fd68 100644 --- a/lib/compiler/swc/constants.ts +++ b/lib/compiler/swc/constants.ts @@ -1,4 +1,4 @@ -import * as chalk from 'chalk'; +import { bgCyan, bgGreen, bgRed, cyan, green, red } from 'ansis'; export const TSC_NO_ERRORS_MESSAGE = 'Found 0 errors. Watching for file changes.'; @@ -6,19 +6,17 @@ export const TSC_NO_ERRORS_MESSAGE = export const TSC_COMPILATION_STARTED_MESSAGE = 'Starting compilation in watch mode...'; -export const SWC_LOG_PREFIX = chalk.cyan('> ') + chalk.bgCyan.bold(' SWC '); +export const SWC_LOG_PREFIX = cyan('> ') + bgCyan.bold(' SWC '); -export const TSC_LOG_PREFIX = chalk.cyan('> ') + chalk.bgCyan.bold(' TSC '); -export const TSC_LOG_ERROR_PREFIX = chalk.red('> ') + chalk.bgRed.bold(' TSC '); -export const TSC_LOG_SUCCESS_PREFIX = - chalk.green('> ') + chalk.bgGreen.bold(' TSC '); +export const TSC_LOG_PREFIX = cyan('> ') + bgCyan.bold(' TSC '); +export const TSC_LOG_ERROR_PREFIX = red('> ') + bgRed.bold(' TSC '); +export const TSC_LOG_SUCCESS_PREFIX = green('> ') + bgGreen.bold(' TSC '); export const INITIALIZING_TYPE_CHECKER = - chalk.bgCyan.bold(' TSC ') + chalk.cyan(' Initializing type checker...'); + bgCyan.bold(' TSC ') + cyan(' Initializing type checker...'); export const FOUND_NO_ISSUES_METADATA_GENERATION_SKIPPED = - TSC_LOG_SUCCESS_PREFIX + chalk.green(' Found 0 issues.'); + TSC_LOG_SUCCESS_PREFIX + green(' Found 0 issues.'); export const FOUND_NO_ISSUES_GENERATING_METADATA = - TSC_LOG_SUCCESS_PREFIX + - chalk.green(' Found 0 issues. Generating metadata...'); + TSC_LOG_SUCCESS_PREFIX + green(' Found 0 issues. Generating metadata...'); diff --git a/lib/compiler/swc/swc-compiler.ts b/lib/compiler/swc/swc-compiler.ts index de0e6b905..c06a1e7b9 100644 --- a/lib/compiler/swc/swc-compiler.ts +++ b/lib/compiler/swc/swc-compiler.ts @@ -1,4 +1,4 @@ -import * as chalk from 'chalk'; +import { cyan } from 'ansis'; import { fork } from 'child_process'; import * as chokidar from 'chokidar'; import { readFileSync } from 'fs'; @@ -156,7 +156,7 @@ export class SwcCompiler extends BaseCompiler { swcrcFilePath?: string, ) { process.nextTick(() => - console.log(SWC_LOG_PREFIX, chalk.cyan('Running...')), + console.log(SWC_LOG_PREFIX, cyan('Running...')), ); const swcCli = this.loadSwcCliBinary(); diff --git a/lib/compiler/swc/type-checker-host.ts b/lib/compiler/swc/type-checker-host.ts index 69634ab69..0ac3af345 100644 --- a/lib/compiler/swc/type-checker-host.ts +++ b/lib/compiler/swc/type-checker-host.ts @@ -1,4 +1,4 @@ -import * as chalk from 'chalk'; +import { red } from 'ansis'; import * as ora from 'ora'; import * as ts from 'typescript'; import { TsConfigProvider } from '../helpers/tsconfig-provider'; @@ -63,7 +63,7 @@ export class TypeCheckerHost { const reportWatchStatusCallback = (diagnostic: ts.Diagnostic) => { if (diagnostic.messageText !== TSC_NO_ERRORS_MESSAGE) { if ((diagnostic.messageText as string)?.includes('Found')) { - console.log(TSC_LOG_ERROR_PREFIX, chalk.red(diagnostic.messageText)); + console.log(TSC_LOG_ERROR_PREFIX, red(diagnostic.messageText.toString())); } return; } diff --git a/lib/package-managers/abstract.package-manager.ts b/lib/package-managers/abstract.package-manager.ts index d7b051e57..cd9ed6628 100644 --- a/lib/package-managers/abstract.package-manager.ts +++ b/lib/package-managers/abstract.package-manager.ts @@ -1,4 +1,4 @@ -import * as chalk from 'chalk'; +import { bold, gray, red } from 'ansis'; import { readFile } from 'fs'; import * as ora from 'ora'; import { join } from 'path'; @@ -34,17 +34,17 @@ export abstract class AbstractPackageManager { console.info(MESSAGES.PACKAGE_MANAGER_INSTALLATION_SUCCEED(directory)); console.info(MESSAGES.GET_STARTED_INFORMATION); console.info(); - console.info(chalk.gray(MESSAGES.CHANGE_DIR_COMMAND(directory))); - console.info(chalk.gray(MESSAGES.START_COMMAND(packageManager))); + console.info(gray(MESSAGES.CHANGE_DIR_COMMAND(directory))); + console.info(gray(MESSAGES.START_COMMAND(packageManager))); console.info(); } catch { spinner.fail(); const commandArgs = this.cli.install; const commandToRun = this.runner.rawFullCommand(commandArgs); console.error( - chalk.red( + red( MESSAGES.PACKAGE_MANAGER_INSTALLATION_FAILED( - chalk.bold(commandToRun), + bold(commandToRun), ), ), ); diff --git a/lib/runners/abstract.runner.ts b/lib/runners/abstract.runner.ts index cea9e821b..d4c9747f2 100644 --- a/lib/runners/abstract.runner.ts +++ b/lib/runners/abstract.runner.ts @@ -1,4 +1,4 @@ -import * as chalk from 'chalk'; +import { red } from 'ansis'; import { ChildProcess, spawn, SpawnOptions } from 'child_process'; import { MESSAGES } from '../ui'; @@ -35,7 +35,7 @@ export class AbstractRunner { resolve(null); } else { console.error( - chalk.red( + red( MESSAGES.RUNNER_EXECUTION_ERROR(`${this.binary} ${command}`), ), ); diff --git a/lib/runners/runner.factory.ts b/lib/runners/runner.factory.ts index 6b8ce3fa0..9b2045f02 100644 --- a/lib/runners/runner.factory.ts +++ b/lib/runners/runner.factory.ts @@ -1,4 +1,4 @@ -import * as chalk from 'chalk'; +import { yellow } from 'ansis'; import { NpmRunner } from './npm.runner'; import { Runner } from './runner'; import { SchematicRunner } from './schematic.runner'; @@ -21,7 +21,7 @@ export class RunnerFactory { return new PnpmRunner(); default: - console.info(chalk.yellow(`[WARN] Unsupported runner: ${runner}`)); + console.info(yellow`[WARN] Unsupported runner: ${runner}`); } } } diff --git a/lib/ui/messages.ts b/lib/ui/messages.ts index ce35b9a49..c19b2e468 100644 --- a/lib/ui/messages.ts +++ b/lib/ui/messages.ts @@ -1,4 +1,4 @@ -import * as chalk from 'chalk'; +import { green } from 'ansis'; import { EMOJIS } from './emojis'; export const MESSAGES = { @@ -18,7 +18,7 @@ export const MESSAGES = { GIT_INITIALIZATION_ERROR: 'Git repository has not been initialized', PACKAGE_MANAGER_INSTALLATION_SUCCEED: (name: string) => name !== '.' - ? `${EMOJIS.ROCKET} Successfully created project ${chalk.green(name)}` + ? `${EMOJIS.ROCKET} Successfully created project ${green(name)}` : `${EMOJIS.ROCKET} Successfully created a new project`, GET_STARTED_INFORMATION: `${EMOJIS.POINT_RIGHT} Get started with the following commands:`, CHANGE_DIR_COMMAND: (name: string) => `$ cd ${name}`, diff --git a/lib/ui/prefixes.ts b/lib/ui/prefixes.ts index 08157bc88..81cacb4cd 100644 --- a/lib/ui/prefixes.ts +++ b/lib/ui/prefixes.ts @@ -1,8 +1,8 @@ -import * as chalk from 'chalk'; +import { bgRgb } from 'ansis'; -export const ERROR_PREFIX = chalk.bgRgb(210, 0, 75).bold.rgb(0, 0, 0)( +export const ERROR_PREFIX = bgRgb(210, 0, 75).bold.rgb(0, 0, 0)( ' Error ', ); -export const INFO_PREFIX = chalk.bgRgb(60, 190, 100).bold.rgb(0, 0, 0)( +export const INFO_PREFIX = bgRgb(60, 190, 100).bold.rgb(0, 0, 0)( ' Info ', ); diff --git a/package-lock.json b/package-lock.json index f830c62e7..1329dfa60 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,20 +1,20 @@ { "name": "@nestjs/cli", - "version": "10.4.8", + "version": "11.0.0-next.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@nestjs/cli", - "version": "10.4.8", + "version": "11.0.0-next.4", "license": "MIT", "dependencies": { "@angular-devkit/core": "19.0.1", "@angular-devkit/schematics": "19.0.1", "@angular-devkit/schematics-cli": "19.0.1", "@inquirer/prompts": "5.3.8", - "@nestjs/schematics": "^10.0.1", - "chalk": "4.1.2", + "@nestjs/schematics": "next", + "ansis": "3.4.0", "chokidar": "4.0.1", "cli-table3": "0.6.5", "commander": "4.1.1", @@ -59,7 +59,7 @@ "ts-node": "10.9.2" }, "engines": { - "node": ">= 16.14" + "node": ">= 20.11" }, "peerDependencies": { "@swc/cli": "^0.1.62 || ^0.3.0 || ^0.4.0 || ^0.5.0", @@ -4155,6 +4155,15 @@ "node": ">=0.10.0" } }, + "node_modules/ansis": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/ansis/-/ansis-3.4.0.tgz", + "integrity": "sha512-zVESKSQhWaPhGaWiKj1k+UqvpC7vPBBgG3hjQEeIx2YGzylWt8qA3ziAzRuUtm0OnaGsZKjIvfl8D/sJTt/I0w==", + "license": "ISC", + "engines": { + "node": ">=16" + } + }, "node_modules/anymatch": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", @@ -16696,6 +16705,11 @@ "integrity": "sha1-qCJQ3bABXponyoLoLqYDu/pF768=", "dev": true }, + "ansis": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/ansis/-/ansis-3.4.0.tgz", + "integrity": "sha512-zVESKSQhWaPhGaWiKj1k+UqvpC7vPBBgG3hjQEeIx2YGzylWt8qA3ziAzRuUtm0OnaGsZKjIvfl8D/sJTt/I0w==" + }, "anymatch": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", diff --git a/package.json b/package.json index 5efeb7c75..98c805b47 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@angular-devkit/schematics-cli": "19.0.1", "@inquirer/prompts": "5.3.8", "@nestjs/schematics": "next", - "chalk": "4.1.2", + "ansis": "3.4.0", "chokidar": "4.0.1", "cli-table3": "0.6.5", "commander": "4.1.1",