From 610e1123466b353967d8691c18773e45c4c41607 Mon Sep 17 00:00:00 2001 From: Ian Clanton-Thuon Date: Tue, 20 Feb 2024 16:44:37 -0400 Subject: [PATCH] Replace colors with Colorize. --- apps/api-documenter/package.json | 6 +- apps/api-documenter/src/cli/BaseAction.ts | 4 +- .../src/documenters/OfficeYamlDocumenter.ts | 4 +- .../src/markdown/CustomMarkdownEmitter.ts | 7 +- apps/api-documenter/src/start.ts | 6 +- apps/api-extractor/package.json | 10 +- apps/api-extractor/src/api/CompilerState.ts | 4 +- .../src/cli/ApiExtractorCommandLine.ts | 4 +- apps/api-extractor/src/cli/InitAction.ts | 6 +- apps/api-extractor/src/cli/RunAction.ts | 8 +- .../src/collector/MessageRouter.ts | 8 +- apps/api-extractor/src/start.ts | 8 +- apps/lockfile-explorer/package.json | 6 +- apps/lockfile-explorer/src/start.ts | 13 +- apps/rush/package.json | 5 +- apps/rush/src/RushCommandSelector.ts | 4 +- apps/rush/src/start.ts | 9 +- apps/trace-import/package.json | 6 +- .../src/TraceImportCommandLineParser.ts | 4 +- apps/trace-import/src/start.ts | 6 +- apps/trace-import/src/traceImport.ts | 9 +- .../api-extractor-scenarios.api.json | 4 +- .../api-extractor-scenarios.api.md | 4 +- .../etc/importEquals/rollup.d.ts | 4 +- .../api-extractor-scenarios/package.json | 4 +- .../src/importEquals/index.ts | 6 +- .../dist/api-extractor-test-04-beta.d.ts | 2 + .../dist/api-extractor-test-04-public.d.ts | 2 + .../workspace/common/pnpm-lock.yaml | 120 +++++++++--------- .../api-documenter/main_2024-02-20-20-42.json | 11 ++ .../api-extractor/main_2024-02-20-20-42.json | 11 ++ .../rush/main_2024-02-20-20-42.json | 11 ++ .../main_2024-02-20-20-42.json | 11 ++ .../main_2024-02-20-20-42.json | 11 ++ .../terminal/main_2024-02-20-20-42.json | 11 ++ .../trace-import/main_2024-02-20-20-42.json | 11 ++ .../main_2024-02-20-20-42.json | 11 ++ common/config/rush/pnpm-lock.yaml | 42 +++--- common/reviews/api/terminal.api.md | 2 + libraries/rush-lib/package.json | 1 - .../src/api/CustomTipsConfiguration.ts | 8 +- .../api/test/CustomTipsConfiguration.test.ts | 6 - .../src/cli/CommandLineMigrationAdvisor.ts | 7 +- .../rush-lib/src/cli/RushCommandLineParser.ts | 5 +- .../rush-lib/src/cli/RushStartupBanner.ts | 10 +- .../rush-lib/src/cli/RushXCommandLine.ts | 23 ++-- .../src/cli/actions/BaseInstallAction.ts | 14 +- .../src/cli/actions/BaseRushAction.ts | 4 +- .../rush-lib/src/cli/actions/ChangeAction.ts | 5 +- .../rush-lib/src/cli/actions/CheckAction.ts | 5 +- .../rush-lib/src/cli/actions/InitAction.ts | 12 +- .../cli/actions/InitAutoinstallerAction.ts | 5 +- .../src/cli/actions/InitDeployAction.ts | 9 +- .../rush-lib/src/cli/actions/PublishAction.ts | 4 +- .../rush-lib/src/cli/actions/PurgeAction.ts | 5 +- .../rush-lib/src/cli/actions/ScanAction.ts | 14 +- .../cli/scriptActions/GlobalScriptAction.ts | 5 +- .../cli/scriptActions/PhasedScriptAction.ts | 11 +- .../src/cli/test/CommandLineHelp.test.ts | 11 -- .../src/cli/test/RushXCommandLine.test.ts | 11 -- .../RushXCommandLine.test.ts.snap | 6 +- libraries/rush-lib/src/logic/Autoinstaller.ts | 21 ++- .../rush-lib/src/logic/EventHooksManager.ts | 8 +- libraries/rush-lib/src/logic/Git.ts | 8 +- .../rush-lib/src/logic/InteractiveUpgrader.ts | 4 +- .../rush-lib/src/logic/NodeJsCompatibility.ts | 12 +- .../rush-lib/src/logic/PackageJsonUpdater.ts | 37 +++--- libraries/rush-lib/src/logic/PurgeManager.ts | 6 +- libraries/rush-lib/src/logic/SetupChecks.ts | 11 +- libraries/rush-lib/src/logic/UnlinkManager.ts | 4 +- .../src/logic/base/BaseInstallManager.ts | 36 +++--- .../src/logic/base/BaseLinkManager.ts | 6 +- .../src/logic/base/BaseShrinkwrapFile.ts | 4 +- .../logic/installManager/InstallHelpers.ts | 6 +- .../installManager/RushInstallManager.ts | 27 ++-- .../installManager/WorkspaceInstallManager.ts | 20 +-- .../rush-lib/src/logic/npm/NpmLinkManager.ts | 4 +- .../logic/operations/ConsoleTimelinePlugin.ts | 36 +++--- .../operations/OperationExecutionManager.ts | 29 +++-- .../OperationResultSummarizerPlugin.ts | 23 ++-- .../test/OperationExecutionManager.test.ts | 24 ++-- .../OperationExecutionManager.test.ts.snap | 2 +- .../src/logic/pnpm/PnpmLinkManager.ts | 8 +- .../src/logic/pnpm/PnpmShrinkwrapFile.ts | 15 ++- .../src/logic/policy/GitEmailPolicy.ts | 20 +-- .../rush-lib/src/logic/setup/KeyboardLoop.ts | 6 +- .../rush-lib/src/logic/setup/TerminalInput.ts | 16 +-- .../versionMismatch/VersionMismatchFinder.ts | 9 +- .../src/utilities/InteractiveUpgradeUI.ts | 32 ++--- .../src/utilities/prompts/SearchListPrompt.ts | 14 +- .../terminal/src/ConsoleTerminalProvider.ts | 4 +- .../terminal/src/test/AnsiEscape.test.ts | 3 +- .../src/test/RemoveColorsTextRewriter.test.ts | 23 +--- .../src/test/TextRewriterTransform.test.ts | 6 +- libraries/ts-command-line/package.json | 2 +- .../src/providers/CommandLineParser.ts | 6 +- .../src/test/CommandLineParameter.test.ts | 9 +- .../src/test/CommandLineRemainder.test.ts | 6 +- .../src/test/ScopedCommandLineAction.test.ts | 6 +- 99 files changed, 581 insertions(+), 528 deletions(-) create mode 100644 common/changes/@microsoft/api-documenter/main_2024-02-20-20-42.json create mode 100644 common/changes/@microsoft/api-extractor/main_2024-02-20-20-42.json create mode 100644 common/changes/@microsoft/rush/main_2024-02-20-20-42.json create mode 100644 common/changes/@rushstack/lockfile-explorer/main_2024-02-20-20-42.json create mode 100644 common/changes/@rushstack/node-core-library/main_2024-02-20-20-42.json create mode 100644 common/changes/@rushstack/terminal/main_2024-02-20-20-42.json create mode 100644 common/changes/@rushstack/trace-import/main_2024-02-20-20-42.json create mode 100644 common/changes/@rushstack/ts-command-line/main_2024-02-20-20-42.json diff --git a/apps/api-documenter/package.json b/apps/api-documenter/package.json index 2ba67bb8dca..fad8e5c508b 100644 --- a/apps/api-documenter/package.json +++ b/apps/api-documenter/package.json @@ -23,15 +23,15 @@ "@microsoft/api-extractor-model": "workspace:*", "@microsoft/tsdoc": "0.14.2", "@rushstack/node-core-library": "workspace:*", + "@rushstack/terminal": "workspace:*", "@rushstack/ts-command-line": "workspace:*", - "colors": "~1.2.1", "js-yaml": "~3.13.1", "resolve": "~1.22.1" }, "devDependencies": { "@rushstack/heft": "workspace:*", - "local-node-rig": "workspace:*", "@types/js-yaml": "3.12.1", - "@types/resolve": "1.20.2" + "@types/resolve": "1.20.2", + "local-node-rig": "workspace:*" } } diff --git a/apps/api-documenter/src/cli/BaseAction.ts b/apps/api-documenter/src/cli/BaseAction.ts index 01925f43a9e..73d73cdbe37 100644 --- a/apps/api-documenter/src/cli/BaseAction.ts +++ b/apps/api-documenter/src/cli/BaseAction.ts @@ -3,7 +3,6 @@ import * as path from 'path'; import type * as tsdoc from '@microsoft/tsdoc'; -import colors from 'colors/safe'; import { CommandLineAction, @@ -18,6 +17,7 @@ import { ApiDocumentedItem, type IResolveDeclarationReferenceResult } from '@microsoft/api-extractor-model'; +import { Colorize } from '@rushstack/terminal'; export interface IBuildApiModelResult { apiModel: ApiModel; @@ -94,7 +94,7 @@ export abstract class BaseAction extends CommandLineAction { if (result.errorMessage) { console.log( - colors.yellow( + Colorize.yellow( `Warning: Unresolved @inheritDoc tag for ${apiItem.displayName}: ` + result.errorMessage ) ); diff --git a/apps/api-documenter/src/documenters/OfficeYamlDocumenter.ts b/apps/api-documenter/src/documenters/OfficeYamlDocumenter.ts index 929ebb629b3..968ed0d6ba9 100644 --- a/apps/api-documenter/src/documenters/OfficeYamlDocumenter.ts +++ b/apps/api-documenter/src/documenters/OfficeYamlDocumenter.ts @@ -1,12 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors'; import * as path from 'path'; import yaml = require('js-yaml'); import type { ApiModel } from '@microsoft/api-extractor-model'; import { FileSystem } from '@rushstack/node-core-library'; +import { Colorize } from '@rushstack/terminal'; import type { IYamlTocItem } from '../yaml/IYamlTocFile'; import type { IYamlItem } from '../yaml/IYamlApiFile'; @@ -59,7 +59,7 @@ export class OfficeYamlDocumenter extends YamlDocumenter { // After we generate everything, check for any unused snippets console.log(); for (const apiName of Object.keys(this._snippets)) { - console.error(colors.yellow('Warning: Unused snippet ' + apiName)); + console.error(Colorize.yellow('Warning: Unused snippet ' + apiName)); } } diff --git a/apps/api-documenter/src/markdown/CustomMarkdownEmitter.ts b/apps/api-documenter/src/markdown/CustomMarkdownEmitter.ts index aeb76a538fa..b54cb55fd81 100644 --- a/apps/api-documenter/src/markdown/CustomMarkdownEmitter.ts +++ b/apps/api-documenter/src/markdown/CustomMarkdownEmitter.ts @@ -1,10 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors'; - import type { DocNode, DocLinkTag, StringBuilder } from '@microsoft/tsdoc'; import type { ApiModel, IResolveDeclarationReferenceResult, ApiItem } from '@microsoft/api-extractor-model'; +import { Colorize } from '@rushstack/terminal'; import { CustomDocNodeKind } from '../nodes/CustomDocNodeKind'; import type { DocHeading } from '../nodes/DocHeading'; @@ -183,12 +182,12 @@ export class CustomMarkdownEmitter extends MarkdownEmitter { context.writer.write(encodedLinkText); context.writer.write(`](${filename!})`); } else { - console.log(colors.yellow('WARNING: Unable to determine link text')); + console.log(Colorize.yellow('WARNING: Unable to determine link text')); } } } else if (result.errorMessage) { console.log( - colors.yellow( + Colorize.yellow( `WARNING: Unable to resolve reference "${docLinkTag.codeDestination!.emitAsTsdoc()}": ` + result.errorMessage ) diff --git a/apps/api-documenter/src/start.ts b/apps/api-documenter/src/start.ts index 592e84d2ed6..2b40065aefe 100644 --- a/apps/api-documenter/src/start.ts +++ b/apps/api-documenter/src/start.ts @@ -2,9 +2,9 @@ // See LICENSE in the project root for license information. import * as os from 'os'; -import colors from 'colors'; import { PackageJsonLookup } from '@rushstack/node-core-library'; +import { Colorize } from '@rushstack/terminal'; import { ApiDocumenterCommandLine } from './cli/ApiDocumenterCommandLine'; @@ -12,7 +12,9 @@ const myPackageVersion: string = PackageJsonLookup.loadOwnPackageJson(__dirname) console.log( os.EOL + - colors.bold(`api-documenter ${myPackageVersion} ` + colors.cyan(' - https://api-extractor.com/') + os.EOL) + Colorize.bold( + `api-documenter ${myPackageVersion} ` + Colorize.cyan(' - https://api-extractor.com/') + os.EOL + ) ); const parser: ApiDocumenterCommandLine = new ApiDocumenterCommandLine(); diff --git a/apps/api-extractor/package.json b/apps/api-extractor/package.json index f4704775d50..5dab8c308ea 100644 --- a/apps/api-extractor/package.json +++ b/apps/api-extractor/package.json @@ -38,12 +38,12 @@ }, "dependencies": { "@microsoft/api-extractor-model": "workspace:*", - "@microsoft/tsdoc": "0.14.2", "@microsoft/tsdoc-config": "~0.16.1", + "@microsoft/tsdoc": "0.14.2", "@rushstack/node-core-library": "workspace:*", "@rushstack/rig-package": "workspace:*", + "@rushstack/terminal": "workspace:*", "@rushstack/ts-command-line": "workspace:*", - "colors": "~1.2.1", "lodash": "~4.17.15", "resolve": "~1.22.1", "semver": "~7.5.4", @@ -51,13 +51,13 @@ "typescript": "5.3.3" }, "devDependencies": { - "local-eslint-config": "workspace:*", - "@rushstack/heft": "0.64.0", "@rushstack/heft-node-rig": "2.4.0", + "@rushstack/heft": "0.64.0", "@types/heft-jest": "1.0.1", "@types/lodash": "4.14.116", "@types/node": "18.17.15", "@types/resolve": "1.20.2", - "@types/semver": "7.5.0" + "@types/semver": "7.5.0", + "local-eslint-config": "workspace:*" } } diff --git a/apps/api-extractor/src/api/CompilerState.ts b/apps/api-extractor/src/api/CompilerState.ts index 6b6896d7bff..7c9513884c9 100644 --- a/apps/api-extractor/src/api/CompilerState.ts +++ b/apps/api-extractor/src/api/CompilerState.ts @@ -3,12 +3,12 @@ import * as path from 'path'; import * as ts from 'typescript'; -import colors = require('colors'); import { JsonFile } from '@rushstack/node-core-library'; import { ExtractorConfig } from './ExtractorConfig'; import type { IExtractorInvokeOptions } from './Extractor'; +import { Colorize } from '@rushstack/terminal'; /** * Options for {@link CompilerState.create} @@ -60,7 +60,7 @@ export class CompilerState { if (!commandLine.options.skipLibCheck && extractorConfig.skipLibCheck) { commandLine.options.skipLibCheck = true; console.log( - colors.cyan( + Colorize.cyan( 'API Extractor was invoked with skipLibCheck. This is not recommended and may cause ' + 'incorrect type analysis.' ) diff --git a/apps/api-extractor/src/cli/ApiExtractorCommandLine.ts b/apps/api-extractor/src/cli/ApiExtractorCommandLine.ts index 1e814444df9..b1651e06e14 100644 --- a/apps/api-extractor/src/cli/ApiExtractorCommandLine.ts +++ b/apps/api-extractor/src/cli/ApiExtractorCommandLine.ts @@ -1,11 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors'; import * as os from 'os'; import { CommandLineParser, type CommandLineFlagParameter } from '@rushstack/ts-command-line'; import { InternalError } from '@rushstack/node-core-library'; +import { Colorize } from '@rushstack/terminal'; import { RunAction } from './RunAction'; import { InitAction } from './InitAction'; @@ -42,7 +42,7 @@ export class ApiExtractorCommandLine extends CommandLineParser { if (this._debugParameter.value) { console.error(os.EOL + error.stack); } else { - console.error(os.EOL + colors.red('ERROR: ' + error.message.trim())); + console.error(os.EOL + Colorize.red('ERROR: ' + error.message.trim())); } process.exitCode = 1; diff --git a/apps/api-extractor/src/cli/InitAction.ts b/apps/api-extractor/src/cli/InitAction.ts index 28ecdaf182b..22b1fea690a 100644 --- a/apps/api-extractor/src/cli/InitAction.ts +++ b/apps/api-extractor/src/cli/InitAction.ts @@ -1,10 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors'; import * as path from 'path'; import { FileSystem } from '@rushstack/node-core-library'; import { CommandLineAction } from '@rushstack/ts-command-line'; +import { Colorize } from '@rushstack/terminal'; import type { ApiExtractorCommandLine } from './ApiExtractorCommandLine'; import { ExtractorConfig } from '../api/ExtractorConfig'; @@ -27,12 +27,12 @@ export class InitAction extends CommandLineAction { const outputFilePath: string = path.resolve(ExtractorConfig.FILENAME); if (FileSystem.exists(outputFilePath)) { - console.log(colors.red('The output file already exists:')); + console.log(Colorize.red('The output file already exists:')); console.log('\n ' + outputFilePath + '\n'); throw new Error('Unable to write output file'); } - console.log(colors.green('Writing file: ') + outputFilePath); + console.log(Colorize.green('Writing file: ') + outputFilePath); FileSystem.copyFile({ sourcePath: inputFilePath, destinationPath: outputFilePath diff --git a/apps/api-extractor/src/cli/RunAction.ts b/apps/api-extractor/src/cli/RunAction.ts index 9d69438f359..243290d232c 100644 --- a/apps/api-extractor/src/cli/RunAction.ts +++ b/apps/api-extractor/src/cli/RunAction.ts @@ -1,11 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors'; import * as os from 'os'; import * as path from 'path'; import { PackageJsonLookup, FileSystem, type IPackageJson, Path } from '@rushstack/node-core-library'; - +import { Colorize } from '@rushstack/terminal'; import { CommandLineAction, type CommandLineStringParameter, @@ -13,7 +12,6 @@ import { } from '@rushstack/ts-command-line'; import { Extractor, type ExtractorResult } from '../api/Extractor'; - import type { ApiExtractorCommandLine } from './ApiExtractorCommandLine'; import { ExtractorConfig, type IExtractorConfigPrepareOptions } from '../api/ExtractorConfig'; @@ -144,9 +142,9 @@ export class RunAction extends CommandLineAction { process.exitCode = 1; if (extractorResult.errorCount > 0) { - console.log(os.EOL + colors.red('API Extractor completed with errors')); + console.log(os.EOL + Colorize.red('API Extractor completed with errors')); } else { - console.log(os.EOL + colors.yellow('API Extractor completed with warnings')); + console.log(os.EOL + Colorize.yellow('API Extractor completed with warnings')); } } } diff --git a/apps/api-extractor/src/collector/MessageRouter.ts b/apps/api-extractor/src/collector/MessageRouter.ts index a4bd7463973..4ea05d81442 100644 --- a/apps/api-extractor/src/collector/MessageRouter.ts +++ b/apps/api-extractor/src/collector/MessageRouter.ts @@ -1,10 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors'; import * as ts from 'typescript'; import type * as tsdoc from '@microsoft/tsdoc'; import { Sort, InternalError } from '@rushstack/node-core-library'; +import { Colorize } from '@rushstack/terminal'; import { AstDeclaration } from '../analyzer/AstDeclaration'; import type { AstSymbol } from '../analyzer/AstSymbol'; @@ -597,17 +597,17 @@ export class MessageRouter { switch (message.logLevel) { case ExtractorLogLevel.Error: - console.error(colors.red('Error: ' + messageText)); + console.error(Colorize.red('Error: ' + messageText)); break; case ExtractorLogLevel.Warning: - console.warn(colors.yellow('Warning: ' + messageText)); + console.warn(Colorize.yellow('Warning: ' + messageText)); break; case ExtractorLogLevel.Info: console.log(messageText); break; case ExtractorLogLevel.Verbose: if (this.showVerboseMessages) { - console.log(colors.cyan(messageText)); + console.log(Colorize.cyan(messageText)); } break; default: diff --git a/apps/api-extractor/src/start.ts b/apps/api-extractor/src/start.ts index f2ae9e9c45e..bd59b62ad17 100644 --- a/apps/api-extractor/src/start.ts +++ b/apps/api-extractor/src/start.ts @@ -2,19 +2,21 @@ // See LICENSE in the project root for license information. import * as os from 'os'; -import colors from 'colors'; +import { Colorize } from '@rushstack/terminal'; import { ApiExtractorCommandLine } from './cli/ApiExtractorCommandLine'; import { Extractor } from './api/Extractor'; console.log( os.EOL + - colors.bold(`api-extractor ${Extractor.version} ` + colors.cyan(' - https://api-extractor.com/') + os.EOL) + Colorize.bold( + `api-extractor ${Extractor.version} ` + Colorize.cyan(' - https://api-extractor.com/') + os.EOL + ) ); const parser: ApiExtractorCommandLine = new ApiExtractorCommandLine(); parser.execute().catch((error) => { - console.error(colors.red(`An unexpected error occurred: ${error}`)); + console.error(Colorize.red(`An unexpected error occurred: ${error}`)); process.exit(1); }); diff --git a/apps/lockfile-explorer/package.json b/apps/lockfile-explorer/package.json index f3f5c562091..2eda39fa32c 100644 --- a/apps/lockfile-explorer/package.json +++ b/apps/lockfile-explorer/package.json @@ -38,18 +38,18 @@ }, "devDependencies": { "@microsoft/rush-lib": "workspace:*", - "local-node-rig": "workspace:*", "@rushstack/heft": "workspace:*", "@rushstack/lockfile-explorer-web": "workspace:*", "@types/cors": "~2.8.12", "@types/express": "4.17.13", "@types/js-yaml": "3.12.1", - "@types/update-notifier": "~6.0.1" + "@types/update-notifier": "~6.0.1", + "local-node-rig": "workspace:*" }, "dependencies": { "@rushstack/node-core-library": "workspace:*", + "@rushstack/terminal": "workspace:*", "@types/express": "4.17.13", - "colors": "~1.2.1", "cors": "~2.8.5", "express": "4.18.1", "js-yaml": "~3.13.1", diff --git a/apps/lockfile-explorer/src/start.ts b/apps/lockfile-explorer/src/start.ts index d3025af9cfa..2b38a8ea94c 100644 --- a/apps/lockfile-explorer/src/start.ts +++ b/apps/lockfile-explorer/src/start.ts @@ -5,14 +5,15 @@ import express from 'express'; import yaml from 'js-yaml'; import cors from 'cors'; import process from 'process'; -import colors from 'colors/safe'; import open from 'open'; import updateNotifier from 'update-notifier'; +import { AlreadyReportedError } from '@rushstack/node-core-library'; import { FileSystem, type IPackageJson, JsonFile, PackageJsonLookup } from '@rushstack/node-core-library'; import type { IAppContext } from '@rushstack/lockfile-explorer-web/lib/AppContext'; +import { Colorize } from '@rushstack/terminal'; + import { init } from './init'; import type { IAppState } from './state'; -import { AlreadyReportedError } from '@rushstack/node-core-library'; function startApp(debugMode: boolean): void { const lockfileExplorerProjectRoot: string = PackageJsonLookup.instance.tryGetPackageFolderFor(__dirname)!; @@ -22,7 +23,7 @@ function startApp(debugMode: boolean): void { const appVersion: string = lockfileExplorerPackageJson.version; console.log( - colors.bold(`\nRush Lockfile Explorer ${appVersion}`) + colors.cyan(' - https://lfx.rushstack.io/\n') + Colorize.bold(`\nRush Lockfile Explorer ${appVersion}`) + Colorize.cyan(' - https://lfx.rushstack.io/\n') ); updateNotifier({ @@ -66,7 +67,7 @@ function startApp(debugMode: boolean): void { let disconnected: boolean = false; setInterval(() => { if (!isClientConnected && !awaitingFirstConnect && !disconnected) { - console.log(colors.red('The client has disconnected!')); + console.log(Colorize.red('The client has disconnected!')); console.log(`Please open a browser window at http://localhost:${PORT}/app`); disconnected = true; } else if (!awaitingFirstConnect) { @@ -104,7 +105,7 @@ function startApp(debugMode: boolean): void { isClientConnected = true; if (disconnected) { disconnected = false; - console.log(colors.green('The client has reconnected!')); + console.log(Colorize.green('The client has reconnected!')); } res.status(200).send(); }); @@ -201,7 +202,7 @@ if (debugMode) { } catch (error) { if (!(error instanceof AlreadyReportedError)) { console.error(); - console.error(colors.red('ERROR: ' + error.message)); + console.error(Colorize.red('ERROR: ' + error.message)); } } } diff --git a/apps/rush/package.json b/apps/rush/package.json index 5ff2b2f15f3..91cc952fe1a 100644 --- a/apps/rush/package.json +++ b/apps/rush/package.json @@ -38,9 +38,8 @@ "dependencies": { "@microsoft/rush-lib": "workspace:*", "@rushstack/node-core-library": "workspace:*", - "colors": "~1.2.1", - "semver": "~7.5.4", - "@rushstack/terminal": "workspace:*" + "@rushstack/terminal": "workspace:*", + "semver": "~7.5.4" }, "devDependencies": { "@rushstack/heft": "workspace:*", diff --git a/apps/rush/src/RushCommandSelector.ts b/apps/rush/src/RushCommandSelector.ts index 08eb1a435bb..3fe04ce8cd5 100644 --- a/apps/rush/src/RushCommandSelector.ts +++ b/apps/rush/src/RushCommandSelector.ts @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; import * as path from 'path'; import type * as rushLib from '@microsoft/rush-lib'; +import { Colorize } from '@rushstack/terminal'; type CommandName = 'rush' | 'rush-pnpm' | 'rushx' | undefined; @@ -64,7 +64,7 @@ export class RushCommandSelector { } private static _failWithError(message: string): never { - console.log(colors.red(message)); + console.log(Colorize.red(message)); return process.exit(1); } diff --git a/apps/rush/src/start.ts b/apps/rush/src/start.ts index fb56a08d9af..90f79a835d1 100644 --- a/apps/rush/src/start.ts +++ b/apps/rush/src/start.ts @@ -18,12 +18,11 @@ const alreadyReportedNodeTooNewError: boolean = NodeJsCompatibility.warnAboutVer alreadyReportedNodeTooNewError: false }); -import colors from 'colors/safe'; import * as os from 'os'; import * as semver from 'semver'; import { Text, PackageJsonLookup } from '@rushstack/node-core-library'; -import { ConsoleTerminalProvider, type ITerminalProvider } from '@rushstack/terminal'; +import { Colorize, ConsoleTerminalProvider, type ITerminalProvider } from '@rushstack/terminal'; import { EnvironmentVariableNames } from '@microsoft/rush-lib'; import * as rushLib from '@microsoft/rush-lib'; @@ -44,7 +43,7 @@ const previewVersion: string | undefined = process.env[EnvironmentVariableNames. if (previewVersion) { if (!semver.valid(previewVersion, false)) { console.error( - colors.red(`Invalid value for RUSH_PREVIEW_VERSION environment variable: "${previewVersion}"`) + Colorize.red(`Invalid value for RUSH_PREVIEW_VERSION environment variable: "${previewVersion}"`) ); process.exit(1); } @@ -70,7 +69,7 @@ if (previewVersion) { `*********************************************************************` ); - console.error(lines.map((line) => colors.black(colors.bgYellow(line))).join(os.EOL)); + console.error(lines.map((line) => Colorize.black(Colorize.yellowBackground(line))).join(os.EOL)); } else if (configuration) { rushVersionToLoad = configuration.rushVersion; } @@ -95,7 +94,7 @@ if (rushVersionToLoad && rushVersionToLoad !== currentPackageVersion) { versionSelector .ensureRushVersionInstalledAsync(rushVersionToLoad, configuration, launchOptions) .catch((error: Error) => { - console.log(colors.red('Error: ' + error.message)); + console.log(Colorize.red('Error: ' + error.message)); }); } else { // Otherwise invoke the rush-lib that came with this rush package diff --git a/apps/trace-import/package.json b/apps/trace-import/package.json index f66d8643827..8636e77a32f 100644 --- a/apps/trace-import/package.json +++ b/apps/trace-import/package.json @@ -19,16 +19,16 @@ }, "dependencies": { "@rushstack/node-core-library": "workspace:*", + "@rushstack/terminal": "workspace:*", "@rushstack/ts-command-line": "workspace:*", - "colors": "~1.2.1", "resolve": "~1.22.1", "semver": "~7.5.4", "typescript": "~5.3.3" }, "devDependencies": { "@rushstack/heft": "workspace:*", - "local-node-rig": "workspace:*", "@types/resolve": "1.20.2", - "@types/semver": "7.5.0" + "@types/semver": "7.5.0", + "local-node-rig": "workspace:*" } } diff --git a/apps/trace-import/src/TraceImportCommandLineParser.ts b/apps/trace-import/src/TraceImportCommandLineParser.ts index cc28e08165e..91ff9aba0f9 100644 --- a/apps/trace-import/src/TraceImportCommandLineParser.ts +++ b/apps/trace-import/src/TraceImportCommandLineParser.ts @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; import { CommandLineParser, type CommandLineFlagParameter, @@ -9,6 +8,7 @@ import { type CommandLineChoiceParameter } from '@rushstack/ts-command-line'; import { InternalError } from '@rushstack/node-core-library'; +import { Colorize } from '@rushstack/terminal'; import { type ResolutionType, traceImport } from './traceImport'; @@ -80,7 +80,7 @@ export class TraceImportCommandLineParser extends CommandLineParser { if (this._debugParameter.value) { console.error('\n' + error.stack); } else { - console.error('\n' + colors.red('ERROR: ' + error.message.trim())); + console.error('\n' + Colorize.red('ERROR: ' + error.message.trim())); } } } diff --git a/apps/trace-import/src/start.ts b/apps/trace-import/src/start.ts index 13364229d1a..978828cf388 100644 --- a/apps/trace-import/src/start.ts +++ b/apps/trace-import/src/start.ts @@ -1,15 +1,15 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; - import { PackageJsonLookup } from '@rushstack/node-core-library'; +import { Colorize } from '@rushstack/terminal'; + import { TraceImportCommandLineParser } from './TraceImportCommandLineParser'; const toolVersion: string = PackageJsonLookup.loadOwnPackageJson(__dirname).version; console.log(); -console.log(colors.bold(`trace-import ${toolVersion}`) + ' - ' + colors.cyan('https://rushstack.io')); +console.log(Colorize.bold(`trace-import ${toolVersion}`) + ' - ' + Colorize.cyan('https://rushstack.io')); console.log(); const commandLine: TraceImportCommandLineParser = new TraceImportCommandLineParser(); diff --git a/apps/trace-import/src/traceImport.ts b/apps/trace-import/src/traceImport.ts index 37e79f744e8..26e8b4c4e36 100644 --- a/apps/trace-import/src/traceImport.ts +++ b/apps/trace-import/src/traceImport.ts @@ -8,7 +8,8 @@ import { JsonFile, PackageName } from '@rushstack/node-core-library'; -import colors from 'colors/safe'; +import { Colorize } from '@rushstack/terminal'; + import * as path from 'path'; import * as process from 'process'; import * as Resolve from 'resolve'; @@ -36,11 +37,11 @@ interface IExecuteOptions { const packageImportPathRegExp: RegExp = /^((?:@[a-z0-9_][a-z0-9\-_\.]*\/)?[a-z0-9_][a-z0-9\-_\.]*)(\/.*)?$/i; function logInputField(title: string, value: string): void { - console.log(colors.cyan(title.padEnd(25)) + value); + console.log(Colorize.cyan(title.padEnd(25)) + value); } function logOutputField(title: string, value: string): void { - console.log(colors.green(title.padEnd(25)) + value); + console.log(Colorize.green(title.padEnd(25)) + value); } function traceTypeScriptPackage(options: { @@ -323,7 +324,7 @@ export function traceImport(options: IExecuteOptions): void { if (warnings.length) { console.log(); for (const warning of warnings) { - console.log(colors.yellow('Warning: ' + warning)); + console.log(Colorize.yellow('Warning: ' + warning)); } } } diff --git a/build-tests/api-extractor-scenarios/etc/importEquals/api-extractor-scenarios.api.json b/build-tests/api-extractor-scenarios/etc/importEquals/api-extractor-scenarios.api.json index 99e2120fe4f..1e8595978bb 100644 --- a/build-tests/api-extractor-scenarios/etc/importEquals/api-extractor-scenarios.api.json +++ b/build-tests/api-extractor-scenarios/etc/importEquals/api-extractor-scenarios.api.json @@ -187,8 +187,8 @@ }, { "kind": "Reference", - "text": "colors.zebra", - "canonicalReference": "colors!zebra:var" + "text": "Colorize.red", + "canonicalReference": "@rushstack/terminal!Colorize.red:member" }, { "kind": "Content", diff --git a/build-tests/api-extractor-scenarios/etc/importEquals/api-extractor-scenarios.api.md b/build-tests/api-extractor-scenarios/etc/importEquals/api-extractor-scenarios.api.md index c12c59a717e..d6c801106bd 100644 --- a/build-tests/api-extractor-scenarios/etc/importEquals/api-extractor-scenarios.api.md +++ b/build-tests/api-extractor-scenarios/etc/importEquals/api-extractor-scenarios.api.md @@ -4,10 +4,10 @@ ```ts -import colors = require('colors'); +import { Colorize } from '@rushstack/terminal'; // @public (undocumented) -export function useColors(): typeof colors.zebra; +export function useColors(): typeof Colorize.red; // (No @packageDocumentation comment for this package) diff --git a/build-tests/api-extractor-scenarios/etc/importEquals/rollup.d.ts b/build-tests/api-extractor-scenarios/etc/importEquals/rollup.d.ts index 144348ae07f..49db8d3d46d 100644 --- a/build-tests/api-extractor-scenarios/etc/importEquals/rollup.d.ts +++ b/build-tests/api-extractor-scenarios/etc/importEquals/rollup.d.ts @@ -1,6 +1,6 @@ -import colors = require('colors'); +import { Colorize } from '@rushstack/terminal'; /** @public */ -export declare function useColors(): typeof colors.zebra; +export declare function useColors(): typeof Colorize.red; export { } diff --git a/build-tests/api-extractor-scenarios/package.json b/build-tests/api-extractor-scenarios/package.json index fe2238f9aeb..99636945410 100644 --- a/build-tests/api-extractor-scenarios/package.json +++ b/build-tests/api-extractor-scenarios/package.json @@ -12,12 +12,12 @@ "devDependencies": { "@microsoft/api-extractor": "workspace:*", "@microsoft/teams-js": "1.3.0-beta.4", + "@rushstack/heft": "workspace:*", "@rushstack/node-core-library": "workspace:*", + "@rushstack/terminal": "workspace:*", "api-extractor-lib1-test": "workspace:*", "api-extractor-lib2-test": "workspace:*", "api-extractor-lib3-test": "workspace:*", - "colors": "~1.2.1", - "@rushstack/heft": "workspace:*", "local-node-rig": "workspace:*" } } diff --git a/build-tests/api-extractor-scenarios/src/importEquals/index.ts b/build-tests/api-extractor-scenarios/src/importEquals/index.ts index d57b9076617..6af3a22b33f 100644 --- a/build-tests/api-extractor-scenarios/src/importEquals/index.ts +++ b/build-tests/api-extractor-scenarios/src/importEquals/index.ts @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors = require('colors'); +import { Colorize } from '@rushstack/terminal'; /** @public */ -export function useColors(): typeof colors.zebra { - return colors.zebra; +export function useColors(): typeof Colorize.red { + return Colorize.red; } diff --git a/build-tests/api-extractor-test-04/dist/api-extractor-test-04-beta.d.ts b/build-tests/api-extractor-test-04/dist/api-extractor-test-04-beta.d.ts index 9b9be28f436..449c8aedea6 100644 --- a/build-tests/api-extractor-test-04/dist/api-extractor-test-04-beta.d.ts +++ b/build-tests/api-extractor-test-04/dist/api-extractor-test-04-beta.d.ts @@ -6,6 +6,8 @@ * @packageDocumentation */ +import { Lib1Interface } from 'api-extractor-lib1-test'; + /* Excluded from this release type: AlphaClass */ /** diff --git a/build-tests/api-extractor-test-04/dist/api-extractor-test-04-public.d.ts b/build-tests/api-extractor-test-04/dist/api-extractor-test-04-public.d.ts index d146365e6bd..3f31586f792 100644 --- a/build-tests/api-extractor-test-04/dist/api-extractor-test-04-public.d.ts +++ b/build-tests/api-extractor-test-04/dist/api-extractor-test-04-public.d.ts @@ -6,6 +6,8 @@ * @packageDocumentation */ +import { Lib1Interface } from 'api-extractor-lib1-test'; + /* Excluded from this release type: AlphaClass */ /* Excluded from this release type: BetaClass */ diff --git a/build-tests/install-test-workspace/workspace/common/pnpm-lock.yaml b/build-tests/install-test-workspace/workspace/common/pnpm-lock.yaml index 32d2400acb1..7edf4f64f85 100644 --- a/build-tests/install-test-workspace/workspace/common/pnpm-lock.yaml +++ b/build-tests/install-test-workspace/workspace/common/pnpm-lock.yaml @@ -11,8 +11,8 @@ importers: rush-lib-test: dependencies: '@microsoft/rush-lib': - specifier: file:microsoft-rush-lib-5.114.0.tgz - version: file:../temp/tarballs/microsoft-rush-lib-5.114.0.tgz(@types/node@18.17.15) + specifier: file:microsoft-rush-lib-5.114.1.tgz + version: file:../temp/tarballs/microsoft-rush-lib-5.114.1.tgz(@types/node@18.17.15) '@rushstack/terminal': specifier: file:rushstack-terminal-0.8.1.tgz version: file:../temp/tarballs/rushstack-terminal-0.8.1.tgz(@types/node@18.17.15) @@ -30,12 +30,12 @@ importers: rush-sdk-test: dependencies: '@rushstack/rush-sdk': - specifier: file:rushstack-rush-sdk-5.114.0.tgz - version: file:../temp/tarballs/rushstack-rush-sdk-5.114.0.tgz(@types/node@18.17.15) + specifier: file:rushstack-rush-sdk-5.114.1.tgz + version: file:../temp/tarballs/rushstack-rush-sdk-5.114.1.tgz(@types/node@18.17.15) devDependencies: '@microsoft/rush-lib': - specifier: file:microsoft-rush-lib-5.114.0.tgz - version: file:../temp/tarballs/microsoft-rush-lib-5.114.0.tgz(@types/node@18.17.15) + specifier: file:microsoft-rush-lib-5.114.1.tgz + version: file:../temp/tarballs/microsoft-rush-lib-5.114.1.tgz(@types/node@18.17.15) '@types/node': specifier: 18.17.15 version: 18.17.15 @@ -52,14 +52,14 @@ importers: specifier: file:rushstack-eslint-config-3.6.4.tgz version: file:../temp/tarballs/rushstack-eslint-config-3.6.4.tgz(eslint@8.7.0)(typescript@5.3.3) '@rushstack/heft': - specifier: file:rushstack-heft-0.65.1.tgz - version: file:../temp/tarballs/rushstack-heft-0.65.1.tgz + specifier: file:rushstack-heft-0.65.2.tgz + version: file:../temp/tarballs/rushstack-heft-0.65.2.tgz '@rushstack/heft-lint-plugin': - specifier: file:rushstack-heft-lint-plugin-0.3.10.tgz - version: file:../temp/tarballs/rushstack-heft-lint-plugin-0.3.10.tgz(@rushstack/heft@0.65.1) + specifier: file:rushstack-heft-lint-plugin-0.3.11.tgz + version: file:../temp/tarballs/rushstack-heft-lint-plugin-0.3.11.tgz(@rushstack/heft@0.65.2) '@rushstack/heft-typescript-plugin': - specifier: file:rushstack-heft-typescript-plugin-0.3.10.tgz - version: file:../temp/tarballs/rushstack-heft-typescript-plugin-0.3.10.tgz(@rushstack/heft@0.65.1) + specifier: file:rushstack-heft-typescript-plugin-0.3.11.tgz + version: file:../temp/tarballs/rushstack-heft-typescript-plugin-0.3.11.tgz(@rushstack/heft@0.65.2) eslint: specifier: ~8.7.0 version: 8.7.0 @@ -76,14 +76,14 @@ importers: specifier: file:rushstack-eslint-config-3.6.4.tgz version: file:../temp/tarballs/rushstack-eslint-config-3.6.4.tgz(eslint@8.7.0)(typescript@4.7.4) '@rushstack/heft': - specifier: file:rushstack-heft-0.65.1.tgz - version: file:../temp/tarballs/rushstack-heft-0.65.1.tgz + specifier: file:rushstack-heft-0.65.2.tgz + version: file:../temp/tarballs/rushstack-heft-0.65.2.tgz '@rushstack/heft-lint-plugin': - specifier: file:rushstack-heft-lint-plugin-0.3.10.tgz - version: file:../temp/tarballs/rushstack-heft-lint-plugin-0.3.10.tgz(@rushstack/heft@0.65.1) + specifier: file:rushstack-heft-lint-plugin-0.3.11.tgz + version: file:../temp/tarballs/rushstack-heft-lint-plugin-0.3.11.tgz(@rushstack/heft@0.65.2) '@rushstack/heft-typescript-plugin': - specifier: file:rushstack-heft-typescript-plugin-0.3.10.tgz - version: file:../temp/tarballs/rushstack-heft-typescript-plugin-0.3.10.tgz(@rushstack/heft@0.65.1) + specifier: file:rushstack-heft-typescript-plugin-0.3.11.tgz + version: file:../temp/tarballs/rushstack-heft-typescript-plugin-0.3.11.tgz(@rushstack/heft@0.65.2) eslint: specifier: ~8.7.0 version: 8.7.0 @@ -4233,28 +4233,27 @@ packages: optionalDependencies: commander: 2.20.3 - file:../temp/tarballs/microsoft-rush-lib-5.114.0.tgz(@types/node@18.17.15): - resolution: {tarball: file:../temp/tarballs/microsoft-rush-lib-5.114.0.tgz} - id: file:../temp/tarballs/microsoft-rush-lib-5.114.0.tgz + file:../temp/tarballs/microsoft-rush-lib-5.114.1.tgz(@types/node@18.17.15): + resolution: {tarball: file:../temp/tarballs/microsoft-rush-lib-5.114.1.tgz} + id: file:../temp/tarballs/microsoft-rush-lib-5.114.1.tgz name: '@microsoft/rush-lib' - version: 5.114.0 + version: 5.114.1 engines: {node: '>=5.6.0'} dependencies: '@pnpm/dependency-path': 2.1.2 '@pnpm/link-bins': 5.3.25 '@rushstack/heft-config-file': file:../temp/tarballs/rushstack-heft-config-file-0.14.12.tgz(@types/node@18.17.15) '@rushstack/node-core-library': file:../temp/tarballs/rushstack-node-core-library-4.0.1.tgz(@types/node@18.17.15) - '@rushstack/package-deps-hash': file:../temp/tarballs/rushstack-package-deps-hash-4.1.28.tgz(@types/node@18.17.15) - '@rushstack/package-extractor': file:../temp/tarballs/rushstack-package-extractor-0.6.30.tgz(@types/node@18.17.15) + '@rushstack/package-deps-hash': file:../temp/tarballs/rushstack-package-deps-hash-4.1.29.tgz(@types/node@18.17.15) + '@rushstack/package-extractor': file:../temp/tarballs/rushstack-package-extractor-0.6.31.tgz(@types/node@18.17.15) '@rushstack/rig-package': file:../temp/tarballs/rushstack-rig-package-0.5.2.tgz - '@rushstack/stream-collator': file:../temp/tarballs/rushstack-stream-collator-4.1.28.tgz(@types/node@18.17.15) + '@rushstack/stream-collator': file:../temp/tarballs/rushstack-stream-collator-4.1.29.tgz(@types/node@18.17.15) '@rushstack/terminal': file:../temp/tarballs/rushstack-terminal-0.8.1.tgz(@types/node@18.17.15) - '@rushstack/ts-command-line': file:../temp/tarballs/rushstack-ts-command-line-4.17.2.tgz + '@rushstack/ts-command-line': file:../temp/tarballs/rushstack-ts-command-line-4.17.2.tgz(@types/node@18.17.15) '@types/node-fetch': 2.6.2 '@yarnpkg/lockfile': 1.0.2 builtin-modules: 3.1.0 cli-table: 0.3.11 - colors: 1.2.5 dependency-path: 9.2.8 fast-glob: 3.3.1 figures: 3.0.0 @@ -4436,10 +4435,10 @@ packages: - typescript dev: true - file:../temp/tarballs/rushstack-heft-0.65.1.tgz: - resolution: {tarball: file:../temp/tarballs/rushstack-heft-0.65.1.tgz} + file:../temp/tarballs/rushstack-heft-0.65.2.tgz: + resolution: {tarball: file:../temp/tarballs/rushstack-heft-0.65.2.tgz} name: '@rushstack/heft' - version: 0.65.1 + version: 0.65.2 engines: {node: '>=10.13.0'} hasBin: true dependencies: @@ -4448,7 +4447,7 @@ packages: '@rushstack/operation-graph': file:../temp/tarballs/rushstack-operation-graph-0.2.11.tgz '@rushstack/rig-package': file:../temp/tarballs/rushstack-rig-package-0.5.2.tgz '@rushstack/terminal': file:../temp/tarballs/rushstack-terminal-0.8.1.tgz(@types/node@18.17.15) - '@rushstack/ts-command-line': file:../temp/tarballs/rushstack-ts-command-line-4.17.2.tgz + '@rushstack/ts-command-line': file:../temp/tarballs/rushstack-ts-command-line-4.17.2.tgz(@types/node@18.17.15) '@types/tapable': 1.0.6 fast-glob: 3.3.1 git-repo-info: 2.1.1 @@ -4474,30 +4473,30 @@ packages: transitivePeerDependencies: - '@types/node' - file:../temp/tarballs/rushstack-heft-lint-plugin-0.3.10.tgz(@rushstack/heft@0.65.1): - resolution: {tarball: file:../temp/tarballs/rushstack-heft-lint-plugin-0.3.10.tgz} - id: file:../temp/tarballs/rushstack-heft-lint-plugin-0.3.10.tgz + file:../temp/tarballs/rushstack-heft-lint-plugin-0.3.11.tgz(@rushstack/heft@0.65.2): + resolution: {tarball: file:../temp/tarballs/rushstack-heft-lint-plugin-0.3.11.tgz} + id: file:../temp/tarballs/rushstack-heft-lint-plugin-0.3.11.tgz name: '@rushstack/heft-lint-plugin' - version: 0.3.10 + version: 0.3.11 peerDependencies: '@rushstack/heft': '*' dependencies: - '@rushstack/heft': file:../temp/tarballs/rushstack-heft-0.65.1.tgz + '@rushstack/heft': file:../temp/tarballs/rushstack-heft-0.65.2.tgz '@rushstack/node-core-library': file:../temp/tarballs/rushstack-node-core-library-4.0.1.tgz(@types/node@18.17.15) semver: 7.5.4 transitivePeerDependencies: - '@types/node' dev: true - file:../temp/tarballs/rushstack-heft-typescript-plugin-0.3.10.tgz(@rushstack/heft@0.65.1): - resolution: {tarball: file:../temp/tarballs/rushstack-heft-typescript-plugin-0.3.10.tgz} - id: file:../temp/tarballs/rushstack-heft-typescript-plugin-0.3.10.tgz + file:../temp/tarballs/rushstack-heft-typescript-plugin-0.3.11.tgz(@rushstack/heft@0.65.2): + resolution: {tarball: file:../temp/tarballs/rushstack-heft-typescript-plugin-0.3.11.tgz} + id: file:../temp/tarballs/rushstack-heft-typescript-plugin-0.3.11.tgz name: '@rushstack/heft-typescript-plugin' - version: 0.3.10 + version: 0.3.11 peerDependencies: '@rushstack/heft': '*' dependencies: - '@rushstack/heft': file:../temp/tarballs/rushstack-heft-0.65.1.tgz + '@rushstack/heft': file:../temp/tarballs/rushstack-heft-0.65.2.tgz '@rushstack/heft-config-file': file:../temp/tarballs/rushstack-heft-config-file-0.14.12.tgz(@types/node@18.17.15) '@rushstack/node-core-library': file:../temp/tarballs/rushstack-node-core-library-4.0.1.tgz(@types/node@18.17.15) '@types/tapable': 1.0.6 @@ -4540,21 +4539,21 @@ packages: '@rushstack/terminal': file:../temp/tarballs/rushstack-terminal-0.8.1.tgz(@types/node@18.17.15) dev: true - file:../temp/tarballs/rushstack-package-deps-hash-4.1.28.tgz(@types/node@18.17.15): - resolution: {tarball: file:../temp/tarballs/rushstack-package-deps-hash-4.1.28.tgz} - id: file:../temp/tarballs/rushstack-package-deps-hash-4.1.28.tgz + file:../temp/tarballs/rushstack-package-deps-hash-4.1.29.tgz(@types/node@18.17.15): + resolution: {tarball: file:../temp/tarballs/rushstack-package-deps-hash-4.1.29.tgz} + id: file:../temp/tarballs/rushstack-package-deps-hash-4.1.29.tgz name: '@rushstack/package-deps-hash' - version: 4.1.28 + version: 4.1.29 dependencies: '@rushstack/node-core-library': file:../temp/tarballs/rushstack-node-core-library-4.0.1.tgz(@types/node@18.17.15) transitivePeerDependencies: - '@types/node' - file:../temp/tarballs/rushstack-package-extractor-0.6.30.tgz(@types/node@18.17.15): - resolution: {tarball: file:../temp/tarballs/rushstack-package-extractor-0.6.30.tgz} - id: file:../temp/tarballs/rushstack-package-extractor-0.6.30.tgz + file:../temp/tarballs/rushstack-package-extractor-0.6.31.tgz(@types/node@18.17.15): + resolution: {tarball: file:../temp/tarballs/rushstack-package-extractor-0.6.31.tgz} + id: file:../temp/tarballs/rushstack-package-extractor-0.6.31.tgz name: '@rushstack/package-extractor' - version: 0.6.30 + version: 0.6.31 dependencies: '@pnpm/link-bins': 5.3.25 '@rushstack/node-core-library': file:../temp/tarballs/rushstack-node-core-library-4.0.1.tgz(@types/node@18.17.15) @@ -4575,11 +4574,11 @@ packages: resolve: 1.22.1 strip-json-comments: 3.1.1 - file:../temp/tarballs/rushstack-rush-sdk-5.114.0.tgz(@types/node@18.17.15): - resolution: {tarball: file:../temp/tarballs/rushstack-rush-sdk-5.114.0.tgz} - id: file:../temp/tarballs/rushstack-rush-sdk-5.114.0.tgz + file:../temp/tarballs/rushstack-rush-sdk-5.114.1.tgz(@types/node@18.17.15): + resolution: {tarball: file:../temp/tarballs/rushstack-rush-sdk-5.114.1.tgz} + id: file:../temp/tarballs/rushstack-rush-sdk-5.114.1.tgz name: '@rushstack/rush-sdk' - version: 5.114.0 + version: 5.114.1 dependencies: '@rushstack/node-core-library': file:../temp/tarballs/rushstack-node-core-library-4.0.1.tgz(@types/node@18.17.15) '@rushstack/terminal': file:../temp/tarballs/rushstack-terminal-0.8.1.tgz(@types/node@18.17.15) @@ -4589,11 +4588,11 @@ packages: - '@types/node' dev: false - file:../temp/tarballs/rushstack-stream-collator-4.1.28.tgz(@types/node@18.17.15): - resolution: {tarball: file:../temp/tarballs/rushstack-stream-collator-4.1.28.tgz} - id: file:../temp/tarballs/rushstack-stream-collator-4.1.28.tgz + file:../temp/tarballs/rushstack-stream-collator-4.1.29.tgz(@types/node@18.17.15): + resolution: {tarball: file:../temp/tarballs/rushstack-stream-collator-4.1.29.tgz} + id: file:../temp/tarballs/rushstack-stream-collator-4.1.29.tgz name: '@rushstack/stream-collator' - version: 4.1.28 + version: 4.1.29 dependencies: '@rushstack/node-core-library': file:../temp/tarballs/rushstack-node-core-library-4.0.1.tgz(@types/node@18.17.15) '@rushstack/terminal': file:../temp/tarballs/rushstack-terminal-0.8.1.tgz(@types/node@18.17.15) @@ -4621,12 +4620,15 @@ packages: version: 0.3.3 dev: true - file:../temp/tarballs/rushstack-ts-command-line-4.17.2.tgz: + file:../temp/tarballs/rushstack-ts-command-line-4.17.2.tgz(@types/node@18.17.15): resolution: {tarball: file:../temp/tarballs/rushstack-ts-command-line-4.17.2.tgz} + id: file:../temp/tarballs/rushstack-ts-command-line-4.17.2.tgz name: '@rushstack/ts-command-line' version: 4.17.2 dependencies: + '@rushstack/terminal': file:../temp/tarballs/rushstack-terminal-0.8.1.tgz(@types/node@18.17.15) '@types/argparse': 1.0.38 argparse: 1.0.10 - colors: 1.2.5 string-argv: 0.3.1 + transitivePeerDependencies: + - '@types/node' diff --git a/common/changes/@microsoft/api-documenter/main_2024-02-20-20-42.json b/common/changes/@microsoft/api-documenter/main_2024-02-20-20-42.json new file mode 100644 index 00000000000..8bf6356e11a --- /dev/null +++ b/common/changes/@microsoft/api-documenter/main_2024-02-20-20-42.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "Replace the dependency on the `colors` package with `Colorize` from `@rushstack/terminal`.", + "type": "patch", + "packageName": "@microsoft/api-documenter" + } + ], + "packageName": "@microsoft/api-documenter", + "email": "iclanton@users.noreply.github.com" +} \ No newline at end of file diff --git a/common/changes/@microsoft/api-extractor/main_2024-02-20-20-42.json b/common/changes/@microsoft/api-extractor/main_2024-02-20-20-42.json new file mode 100644 index 00000000000..8f1ab0299fc --- /dev/null +++ b/common/changes/@microsoft/api-extractor/main_2024-02-20-20-42.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "Replace the dependency on the `colors` package with `Colorize` from `@rushstack/terminal`.", + "type": "patch", + "packageName": "@microsoft/api-extractor" + } + ], + "packageName": "@microsoft/api-extractor", + "email": "iclanton@users.noreply.github.com" +} \ No newline at end of file diff --git a/common/changes/@microsoft/rush/main_2024-02-20-20-42.json b/common/changes/@microsoft/rush/main_2024-02-20-20-42.json new file mode 100644 index 00000000000..7e379a52fb6 --- /dev/null +++ b/common/changes/@microsoft/rush/main_2024-02-20-20-42.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "Replace the dependency on the `colors` package with `Colorize` from `@rushstack/terminal`.", + "type": "none", + "packageName": "@microsoft/rush" + } + ], + "packageName": "@microsoft/rush", + "email": "iclanton@users.noreply.github.com" +} \ No newline at end of file diff --git a/common/changes/@rushstack/lockfile-explorer/main_2024-02-20-20-42.json b/common/changes/@rushstack/lockfile-explorer/main_2024-02-20-20-42.json new file mode 100644 index 00000000000..455d50ed6f5 --- /dev/null +++ b/common/changes/@rushstack/lockfile-explorer/main_2024-02-20-20-42.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "Replace the dependency on the `colors` package with `Colorize` from `@rushstack/terminal`.", + "type": "patch", + "packageName": "@rushstack/lockfile-explorer" + } + ], + "packageName": "@rushstack/lockfile-explorer", + "email": "iclanton@users.noreply.github.com" +} \ No newline at end of file diff --git a/common/changes/@rushstack/node-core-library/main_2024-02-20-20-42.json b/common/changes/@rushstack/node-core-library/main_2024-02-20-20-42.json new file mode 100644 index 00000000000..bef47b3cef0 --- /dev/null +++ b/common/changes/@rushstack/node-core-library/main_2024-02-20-20-42.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "Replace the dependency on the `colors` package with `Colorize` from `@rushstack/terminal`.", + "type": "patch", + "packageName": "@rushstack/node-core-library" + } + ], + "packageName": "@rushstack/node-core-library", + "email": "iclanton@users.noreply.github.com" +} \ No newline at end of file diff --git a/common/changes/@rushstack/terminal/main_2024-02-20-20-42.json b/common/changes/@rushstack/terminal/main_2024-02-20-20-42.json new file mode 100644 index 00000000000..2f7a39dc88b --- /dev/null +++ b/common/changes/@rushstack/terminal/main_2024-02-20-20-42.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "Expose a `supportsColor` property on `ConsoleTerminalProvider`.", + "type": "minor", + "packageName": "@rushstack/terminal" + } + ], + "packageName": "@rushstack/terminal", + "email": "iclanton@users.noreply.github.com" +} \ No newline at end of file diff --git a/common/changes/@rushstack/trace-import/main_2024-02-20-20-42.json b/common/changes/@rushstack/trace-import/main_2024-02-20-20-42.json new file mode 100644 index 00000000000..89619e0ab59 --- /dev/null +++ b/common/changes/@rushstack/trace-import/main_2024-02-20-20-42.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "Replace the dependency on the `colors` package with `Colorize` from `@rushstack/terminal`.", + "type": "patch", + "packageName": "@rushstack/trace-import" + } + ], + "packageName": "@rushstack/trace-import", + "email": "iclanton@users.noreply.github.com" +} \ No newline at end of file diff --git a/common/changes/@rushstack/ts-command-line/main_2024-02-20-20-42.json b/common/changes/@rushstack/ts-command-line/main_2024-02-20-20-42.json new file mode 100644 index 00000000000..893dd087803 --- /dev/null +++ b/common/changes/@rushstack/ts-command-line/main_2024-02-20-20-42.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "Replace the dependency on the `colors` package with `Colorize` from `@rushstack/terminal`.", + "type": "patch", + "packageName": "@rushstack/ts-command-line" + } + ], + "packageName": "@rushstack/ts-command-line", + "email": "iclanton@users.noreply.github.com" +} \ No newline at end of file diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 5621e165ffa..ac96eb1d49f 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -24,12 +24,12 @@ importers: '@rushstack/node-core-library': specifier: workspace:* version: link:../../libraries/node-core-library + '@rushstack/terminal': + specifier: workspace:* + version: link:../../libraries/terminal '@rushstack/ts-command-line': specifier: workspace:* version: link:../../libraries/ts-command-line - colors: - specifier: ~1.2.1 - version: 1.2.5 js-yaml: specifier: ~3.13.1 version: 3.13.1 @@ -67,12 +67,12 @@ importers: '@rushstack/rig-package': specifier: workspace:* version: link:../../libraries/rig-package + '@rushstack/terminal': + specifier: workspace:* + version: link:../../libraries/terminal '@rushstack/ts-command-line': specifier: workspace:* version: link:../../libraries/ts-command-line - colors: - specifier: ~1.2.1 - version: 1.2.5 lodash: specifier: ~4.17.15 version: 4.17.21 @@ -186,12 +186,12 @@ importers: '@rushstack/node-core-library': specifier: workspace:* version: link:../../libraries/node-core-library + '@rushstack/terminal': + specifier: workspace:* + version: link:../../libraries/terminal '@types/express': specifier: 4.17.13 version: 4.17.13 - colors: - specifier: ~1.2.1 - version: 1.2.5 cors: specifier: ~2.8.5 version: 2.8.5 @@ -297,9 +297,6 @@ importers: '@rushstack/terminal': specifier: workspace:* version: link:../../libraries/terminal - colors: - specifier: ~1.2.1 - version: 1.2.5 semver: specifier: ~7.5.4 version: 7.5.4 @@ -331,12 +328,12 @@ importers: '@rushstack/node-core-library': specifier: workspace:* version: link:../../libraries/node-core-library + '@rushstack/terminal': + specifier: workspace:* + version: link:../../libraries/terminal '@rushstack/ts-command-line': specifier: workspace:* version: link:../../libraries/ts-command-line - colors: - specifier: ~1.2.1 - version: 1.2.5 resolve: specifier: ~1.22.1 version: 1.22.4 @@ -968,6 +965,9 @@ importers: '@rushstack/node-core-library': specifier: workspace:* version: link:../../libraries/node-core-library + '@rushstack/terminal': + specifier: workspace:* + version: link:../../libraries/terminal api-extractor-lib1-test: specifier: workspace:* version: link:../api-extractor-lib1-test @@ -977,9 +977,6 @@ importers: api-extractor-lib3-test: specifier: workspace:* version: link:../api-extractor-lib3-test - colors: - specifier: ~1.2.1 - version: 1.2.5 local-node-rig: specifier: workspace:* version: link:../../rigs/local-node-rig @@ -3205,9 +3202,6 @@ importers: cli-table: specifier: ~0.3.1 version: 0.3.11 - colors: - specifier: ~1.2.1 - version: 1.2.5 dependency-path: specifier: ~9.2.8 version: 9.2.8 @@ -3484,15 +3478,15 @@ importers: ../../libraries/ts-command-line: dependencies: + '@rushstack/terminal': + specifier: workspace:* + version: link:../terminal '@types/argparse': specifier: 1.0.38 version: 1.0.38 argparse: specifier: ~1.0.9 version: 1.0.10 - colors: - specifier: ~1.2.1 - version: 1.2.5 string-argv: specifier: ~0.3.1 version: 0.3.2 diff --git a/common/reviews/api/terminal.api.md b/common/reviews/api/terminal.api.md index 6827400e8fe..e84e590dad3 100644 --- a/common/reviews/api/terminal.api.md +++ b/common/reviews/api/terminal.api.md @@ -83,6 +83,8 @@ export class ConsoleTerminalProvider implements ITerminalProvider { constructor(options?: Partial); debugEnabled: boolean; get eolCharacter(): string; + // (undocumented) + static readonly supportsColor: boolean; get supportsColor(): boolean; verboseEnabled: boolean; write(data: string, severity: TerminalProviderSeverity): void; diff --git a/libraries/rush-lib/package.json b/libraries/rush-lib/package.json index 65f4be23899..d6db72c8d7f 100644 --- a/libraries/rush-lib/package.json +++ b/libraries/rush-lib/package.json @@ -36,7 +36,6 @@ "@yarnpkg/lockfile": "~1.0.2", "builtin-modules": "~3.1.0", "cli-table": "~0.3.1", - "colors": "~1.2.1", "dependency-path": "~9.2.8", "fast-glob": "~3.3.1", "figures": "3.0.0", diff --git a/libraries/rush-lib/src/api/CustomTipsConfiguration.ts b/libraries/rush-lib/src/api/CustomTipsConfiguration.ts index baf2c793712..421e8275129 100644 --- a/libraries/rush-lib/src/api/CustomTipsConfiguration.ts +++ b/libraries/rush-lib/src/api/CustomTipsConfiguration.ts @@ -3,8 +3,8 @@ import * as path from 'path'; import { FileSystem, JsonFile, JsonSchema } from '@rushstack/node-core-library'; -import { type ITerminal, PrintUtilities } from '@rushstack/terminal'; -import colors from 'colors/safe'; +import { type ITerminal, PrintUtilities, Colorize } from '@rushstack/terminal'; + import schemaJson from '../schemas/custom-tips.schema.json'; /** @@ -336,11 +336,11 @@ export class CustomTipsConfiguration { switch (severity) { case CustomTipSeverity.Error: writeFunction = terminal.writeErrorLine.bind(terminal); - prefix = colors.red('| '); + prefix = Colorize.red('| '); break; case CustomTipSeverity.Warning: writeFunction = terminal.writeWarningLine.bind(terminal); - prefix = colors.yellow('| '); + prefix = Colorize.yellow('| '); break; default: writeFunction = terminal.writeLine.bind(terminal); diff --git a/libraries/rush-lib/src/api/test/CustomTipsConfiguration.test.ts b/libraries/rush-lib/src/api/test/CustomTipsConfiguration.test.ts index e638637f1a5..59150474534 100644 --- a/libraries/rush-lib/src/api/test/CustomTipsConfiguration.test.ts +++ b/libraries/rush-lib/src/api/test/CustomTipsConfiguration.test.ts @@ -1,12 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -jest.mock('colors/safe', () => { - const colors = jest.requireActual('colors/safe'); - colors.enabled = true; - return colors; -}); - import { JsonFile } from '@rushstack/node-core-library'; import { PrintUtilities, StringBufferTerminalProvider, Terminal } from '@rushstack/terminal'; diff --git a/libraries/rush-lib/src/cli/CommandLineMigrationAdvisor.ts b/libraries/rush-lib/src/cli/CommandLineMigrationAdvisor.ts index 9b731eb546c..dd96e13cf6a 100644 --- a/libraries/rush-lib/src/cli/CommandLineMigrationAdvisor.ts +++ b/libraries/rush-lib/src/cli/CommandLineMigrationAdvisor.ts @@ -1,8 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; -import { PrintUtilities } from '@rushstack/terminal'; +import { Colorize, PrintUtilities } from '@rushstack/terminal'; import { RushConstants } from '../logic/RushConstants'; @@ -56,14 +55,14 @@ export class CommandLineMigrationAdvisor { private static _reportDeprecated(message: string): void { // eslint-disable-next-line no-console console.error( - colors.red( + Colorize.red( PrintUtilities.wrapWords( 'ERROR: You specified an outdated command-line that is no longer supported by this version of Rush:' ) ) ); // eslint-disable-next-line no-console - console.error(colors.yellow(PrintUtilities.wrapWords(message))); + console.error(Colorize.yellow(PrintUtilities.wrapWords(message))); // eslint-disable-next-line no-console console.error(); // eslint-disable-next-line no-console diff --git a/libraries/rush-lib/src/cli/RushCommandLineParser.ts b/libraries/rush-lib/src/cli/RushCommandLineParser.ts index 93f5b78f7e4..57c776a37b1 100644 --- a/libraries/rush-lib/src/cli/RushCommandLineParser.ts +++ b/libraries/rush-lib/src/cli/RushCommandLineParser.ts @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; import * as path from 'path'; import { @@ -10,7 +9,7 @@ import { CommandLineHelper } from '@rushstack/ts-command-line'; import { InternalError, AlreadyReportedError } from '@rushstack/node-core-library'; -import { ConsoleTerminalProvider, Terminal, PrintUtilities } from '@rushstack/terminal'; +import { ConsoleTerminalProvider, Terminal, PrintUtilities, Colorize } from '@rushstack/terminal'; import { RushConfiguration } from '../api/RushConfiguration'; import { RushConstants } from '../logic/RushConstants'; @@ -416,7 +415,7 @@ export class RushCommandLineParser extends CommandLineParser { // line individually. const message: string = PrintUtilities.wrapWords(prefix + error.message) .split(/\r?\n/) - .map((line) => colors.red(line)) + .map((line) => Colorize.red(line)) .join('\n'); // eslint-disable-next-line no-console console.error(`\n${message}`); diff --git a/libraries/rush-lib/src/cli/RushStartupBanner.ts b/libraries/rush-lib/src/cli/RushStartupBanner.ts index 6c2167b4288..b9002310642 100644 --- a/libraries/rush-lib/src/cli/RushStartupBanner.ts +++ b/libraries/rush-lib/src/cli/RushStartupBanner.ts @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; +import { Colorize } from '@rushstack/terminal'; import { RushConstants } from '../logic/RushConstants'; import { NodeJsCompatibility } from '../logic/NodeJsCompatibility'; @@ -14,8 +14,8 @@ export class RushStartupBanner { // eslint-disable-next-line no-console console.log( '\n' + - colors.bold(`Rush Multi-Project Build Tool${versionSuffix}`) + - colors.cyan(` - ${RushConstants.rushWebSiteUrl}`) + + Colorize.bold(`Rush Multi-Project Build Tool${versionSuffix}`) + + Colorize.cyan(` - ${RushConstants.rushWebSiteUrl}`) + `\nNode.js version is ${nodeVersion}\n` ); } @@ -25,7 +25,7 @@ export class RushStartupBanner { const versionSuffix: string = rushVersion ? ' ' + this._formatRushVersion(rushVersion, isManaged) : ''; // eslint-disable-next-line no-console - console.log(colors.bold(`Rush Multi-Project Build Tool${versionSuffix}`) + ` - Node.js ${nodeVersion}`); + console.log(Colorize.bold(`Rush Multi-Project Build Tool${versionSuffix}`) + ` - Node.js ${nodeVersion}`); } private static _formatNodeVersion(): string { @@ -39,6 +39,6 @@ export class RushStartupBanner { } private static _formatRushVersion(rushVersion: string, isManaged: boolean): string { - return rushVersion + colors.yellow(isManaged ? '' : ' (unmanaged)'); + return rushVersion + Colorize.yellow(isManaged ? '' : ' (unmanaged)'); } } diff --git a/libraries/rush-lib/src/cli/RushXCommandLine.ts b/libraries/rush-lib/src/cli/RushXCommandLine.ts index aaa032d6ef6..673f9aa47ba 100644 --- a/libraries/rush-lib/src/cli/RushXCommandLine.ts +++ b/libraries/rush-lib/src/cli/RushXCommandLine.ts @@ -1,10 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; import * as path from 'path'; import { PackageJsonLookup, type IPackageJson, Text, FileSystem, Async } from '@rushstack/node-core-library'; -import { DEFAULT_CONSOLE_WIDTH, PrintUtilities } from '@rushstack/terminal'; +import { Colorize, DEFAULT_CONSOLE_WIDTH, PrintUtilities } from '@rushstack/terminal'; +import { pnpmSyncCopyAsync } from 'pnpm-sync-lib'; import { Utilities } from '../utilities/Utilities'; import { ProjectCommandSet } from '../logic/ProjectCommandSet'; @@ -15,7 +15,6 @@ import { RushStartupBanner } from './RushStartupBanner'; import { EventHooksManager } from '../logic/EventHooksManager'; import { Event } from '../api/EventHooks'; import { EnvironmentVariableNames } from '../api/EnvironmentConfiguration'; -import { pnpmSyncCopyAsync } from 'pnpm-sync-lib'; interface IRushXCommandLineArguments { /** @@ -82,7 +81,7 @@ export class RushXCommandLine { eventHooksManager?.handle(Event.preRushx, rushxArguments.isDebug, rushxArguments.ignoreHooks); } catch (error) { // eslint-disable-next-line no-console - console.error(colors.red('PreRushx hook error: ' + (error as Error).message)); + console.error(Colorize.red('PreRushx hook error: ' + (error as Error).message)); } } // Node.js can sometimes accidentally terminate with a zero exit code (e.g. for an uncaught @@ -95,7 +94,7 @@ export class RushXCommandLine { eventHooksManager?.handle(Event.postRushx, rushxArguments.isDebug, rushxArguments.ignoreHooks); } catch (error) { // eslint-disable-next-line no-console - console.error(colors.red('PostRushx hook error: ' + (error as Error).message)); + console.error(Colorize.red('PostRushx hook error: ' + (error as Error).message)); } } @@ -108,7 +107,7 @@ export class RushXCommandLine { process.exitCode = 1; } // eslint-disable-next-line no-console - console.error(colors.red('Error: ' + (error as Error).message)); + console.error(Colorize.red('Error: ' + (error as Error).message)); } } @@ -145,7 +144,7 @@ export class RushXCommandLine { // did not install the project's dependencies, because the project was not registered. // eslint-disable-next-line no-console console.log( - colors.yellow( + Colorize.yellow( 'Warning: You are invoking "rushx" inside a Rush repository, but this project is not registered in rush.json.' ) ); @@ -279,7 +278,7 @@ export class RushXCommandLine { // Future TODO: Instead of just displaying usage info, we could display a // specific error about the unknown flag the user tried to pass to rushx. // eslint-disable-next-line no-console - console.log(colors.red(`Unknown arguments: ${unknownArgs.map((x) => JSON.stringify(x)).join(', ')}`)); + console.log(Colorize.red(`Unknown arguments: ${unknownArgs.map((x) => JSON.stringify(x)).join(', ')}`)); help = true; } @@ -310,7 +309,7 @@ export class RushXCommandLine { if (projectCommandSet.commandNames.length > 0) { // eslint-disable-next-line no-console - console.log(`Project commands for ${colors.cyan(packageJson.name)}:`); + console.log(`Project commands for ${Colorize.cyan(packageJson.name)}:`); // Calculate the length of the longest script name, for formatting let maxLength: number = 0; @@ -332,7 +331,7 @@ export class RushXCommandLine { console.log( // Example: " command: " ' ' + - colors.cyan(Text.padEnd(commandName + ':', maxLength + 2)) + + Colorize.cyan(Text.padEnd(commandName + ':', maxLength + 2)) + // Example: "do some thin..." Text.truncateWithEllipsis(escapedScriptBody, truncateLength) ); @@ -342,7 +341,7 @@ export class RushXCommandLine { // eslint-disable-next-line no-console console.log( '\n' + - colors.yellow( + Colorize.yellow( 'Warning: Some "scripts" entries in the package.json file' + ' have malformed names: ' + projectCommandSet.malformedScriptNames.map((x) => `"${x}"`).join(', ') @@ -351,7 +350,7 @@ export class RushXCommandLine { } } else { // eslint-disable-next-line no-console - console.log(colors.yellow('Warning: No commands are defined yet for this project.')); + console.log(Colorize.yellow('Warning: No commands are defined yet for this project.')); // eslint-disable-next-line no-console console.log( 'You can define a command by adding a "scripts" table to the project\'s package.json file.' diff --git a/libraries/rush-lib/src/cli/actions/BaseInstallAction.ts b/libraries/rush-lib/src/cli/actions/BaseInstallAction.ts index 2207bd768f0..a8b988ced91 100644 --- a/libraries/rush-lib/src/cli/actions/BaseInstallAction.ts +++ b/libraries/rush-lib/src/cli/actions/BaseInstallAction.ts @@ -1,15 +1,13 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; - import type { CommandLineFlagParameter, CommandLineIntegerParameter, CommandLineStringParameter } from '@rushstack/ts-command-line'; import { AlreadyReportedError } from '@rushstack/node-core-library'; -import { ConsoleTerminalProvider, type ITerminal, Terminal } from '@rushstack/terminal'; +import { ConsoleTerminalProvider, type ITerminal, Terminal, Colorize } from '@rushstack/terminal'; import { BaseRushAction, type IBaseRushActionOptions } from './BaseRushAction'; import { Event } from '../../api/EventHooks'; @@ -118,7 +116,7 @@ export abstract class BaseInstallAction extends BaseRushAction { console.log(); // eslint-disable-next-line no-console console.log( - colors.red( + Colorize.red( `The "--subspace" parameter can only be passed if "subspacesEnabled" is set to true in subspaces.json.` ) ); @@ -160,7 +158,7 @@ export abstract class BaseInstallAction extends BaseRushAction { console.log(); // eslint-disable-next-line no-console console.log( - colors.red( + Colorize.red( `The subspaces preventSelectingAllSubspaces configuration is enabled, which enforces installation for a specified set of subspace,` + ` passed by the "--subspace" parameter or selected from targeted projects using any project selector.` ) @@ -237,7 +235,7 @@ export abstract class BaseInstallAction extends BaseRushAction { for (const selectedSubspace of selectedSubspaces) { installManagerOptions.subspace = selectedSubspace; // eslint-disable-next-line no-console - console.log(colors.green(`Installing for subspace: ${selectedSubspace.subspaceName}`)); + console.log(Colorize.green(`Installing for subspace: ${selectedSubspace.subspaceName}`)); await this._doInstall(installManagerFactoryModule, purgeManager, installManagerOptions); } } else { @@ -263,7 +261,7 @@ export abstract class BaseInstallAction extends BaseRushAction { // eslint-disable-next-line no-console console.log( '\n' + - colors.yellow( + Colorize.yellow( 'Rush refreshed some files in the "common/scripts" folder.' + ' Please commit this change to Git.' ) @@ -272,7 +270,7 @@ export abstract class BaseInstallAction extends BaseRushAction { // eslint-disable-next-line no-console console.log( - '\n' + colors.green(`Rush ${this.actionName} finished successfully. (${stopwatch.toString()})`) + '\n' + Colorize.green(`Rush ${this.actionName} finished successfully. (${stopwatch.toString()})`) ); } diff --git a/libraries/rush-lib/src/cli/actions/BaseRushAction.ts b/libraries/rush-lib/src/cli/actions/BaseRushAction.ts index cde875dc321..c6301dfd95f 100644 --- a/libraries/rush-lib/src/cli/actions/BaseRushAction.ts +++ b/libraries/rush-lib/src/cli/actions/BaseRushAction.ts @@ -1,11 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; import * as path from 'path'; import { CommandLineAction, type ICommandLineActionOptions } from '@rushstack/ts-command-line'; import { LockFile } from '@rushstack/node-core-library'; +import { Colorize } from '@rushstack/terminal'; import type { RushConfiguration } from '../../api/RushConfiguration'; import { EventHooksManager } from '../../logic/EventHooksManager'; @@ -66,7 +66,7 @@ export abstract class BaseConfiglessRushAction extends CommandLineAction impleme if (!this._safeForSimultaneousRushProcesses) { if (!LockFile.tryAcquire(this.rushConfiguration.commonTempFolder, 'rush')) { // eslint-disable-next-line no-console - console.log(colors.red(`Another Rush command is already running in this repository.`)); + console.log(Colorize.red(`Another Rush command is already running in this repository.`)); process.exit(1); } } diff --git a/libraries/rush-lib/src/cli/actions/ChangeAction.ts b/libraries/rush-lib/src/cli/actions/ChangeAction.ts index 3617557fefb..962c11e3b55 100644 --- a/libraries/rush-lib/src/cli/actions/ChangeAction.ts +++ b/libraries/rush-lib/src/cli/actions/ChangeAction.ts @@ -3,7 +3,6 @@ import * as path from 'path'; import * as child_process from 'child_process'; -import colors from 'colors/safe'; import type { CommandLineFlagParameter, @@ -11,7 +10,7 @@ import type { CommandLineChoiceParameter } from '@rushstack/ts-command-line'; import { FileSystem, AlreadyReportedError } from '@rushstack/node-core-library'; -import { Terminal, type ITerminal, ConsoleTerminalProvider } from '@rushstack/terminal'; +import { Terminal, type ITerminal, ConsoleTerminalProvider, Colorize } from '@rushstack/terminal'; import { getRepoRoot } from '@rushstack/package-deps-hash'; import type { RushConfigurationProject } from '../../api/RushConfigurationProject'; @@ -632,7 +631,7 @@ export class ChangeAction extends BaseRushAction { // eslint-disable-next-line no-console console.log( '\n' + - colors.yellow( + Colorize.yellow( 'Warning: You have unstaged changes, which do not trigger prompting for change ' + 'descriptions.' ) diff --git a/libraries/rush-lib/src/cli/actions/CheckAction.ts b/libraries/rush-lib/src/cli/actions/CheckAction.ts index db1b3ceaf50..761aa775f83 100644 --- a/libraries/rush-lib/src/cli/actions/CheckAction.ts +++ b/libraries/rush-lib/src/cli/actions/CheckAction.ts @@ -1,9 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; import type { CommandLineStringParameter, CommandLineFlagParameter } from '@rushstack/ts-command-line'; -import { ConsoleTerminalProvider, type ITerminal, Terminal } from '@rushstack/terminal'; +import { ConsoleTerminalProvider, type ITerminal, Terminal, Colorize } from '@rushstack/terminal'; import type { RushCommandLineParser } from '../RushCommandLineParser'; import { BaseRushAction } from './BaseRushAction'; @@ -49,7 +48,7 @@ export class CheckAction extends BaseRushAction { if (!this._variant.value && variant) { // eslint-disable-next-line no-console console.log( - colors.yellow( + Colorize.yellow( `Variant '${variant}' has been installed, but 'rush check' is currently checking the default variant. ` + `Use 'rush check --variant '${variant}' to check the current installation.` ) diff --git a/libraries/rush-lib/src/cli/actions/InitAction.ts b/libraries/rush-lib/src/cli/actions/InitAction.ts index 557a6e60ee1..832a5a89136 100644 --- a/libraries/rush-lib/src/cli/actions/InitAction.ts +++ b/libraries/rush-lib/src/cli/actions/InitAction.ts @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; import * as path from 'path'; import { FileSystem, @@ -11,6 +10,7 @@ import { type FileSystemStats } from '@rushstack/node-core-library'; import type { CommandLineFlagParameter } from '@rushstack/ts-command-line'; +import { Colorize } from '@rushstack/terminal'; import type { RushCommandLineParser } from '../RushCommandLineParser'; import { BaseConfiglessRushAction } from './BaseRushAction'; @@ -120,7 +120,7 @@ export class InitAction extends BaseConfiglessRushAction { if (this.rushConfiguration !== undefined) { // eslint-disable-next-line no-console console.error( - colors.red('ERROR: Found an existing configuration in: ' + this.rushConfiguration.rushJsonFile) + Colorize.red('ERROR: Found an existing configuration in: ' + this.rushConfiguration.rushJsonFile) ); // eslint-disable-next-line no-console console.log( @@ -142,14 +142,14 @@ export class InitAction extends BaseConfiglessRushAction { // or "CONTRIBUTING.md" if (stats.isDirectory()) { // eslint-disable-next-line no-console - console.error(colors.red(`ERROR: Found a subdirectory: "${itemName}"`)); + console.error(Colorize.red(`ERROR: Found a subdirectory: "${itemName}"`)); // eslint-disable-next-line no-console console.log('\nThe "rush init" command must be run in a new folder with no projects added yet.'); return false; } else { if (itemName.toLowerCase() === 'package.json') { // eslint-disable-next-line no-console - console.error(colors.red(`ERROR: Found a package.json file in this folder`)); + console.error(Colorize.red(`ERROR: Found a package.json file in this folder`)); // eslint-disable-next-line no-console console.log('\nThe "rush init" command must be run in a new folder with no projects added yet.'); return false; @@ -250,14 +250,14 @@ export class InitAction extends BaseConfiglessRushAction { if (!this._overwriteParameter.value) { if (destinationFileExists) { // eslint-disable-next-line no-console - console.log(colors.yellow('Not overwriting already existing file: ') + destinationPath); + console.log(Colorize.yellow('Not overwriting already existing file: ') + destinationPath); return; } } if (destinationFileExists) { // eslint-disable-next-line no-console - console.log(colors.yellow(`Overwriting: ${destinationPath}`)); + console.log(Colorize.yellow(`Overwriting: ${destinationPath}`)); } else { // eslint-disable-next-line no-console console.log(`Generating: ${destinationPath}`); diff --git a/libraries/rush-lib/src/cli/actions/InitAutoinstallerAction.ts b/libraries/rush-lib/src/cli/actions/InitAutoinstallerAction.ts index 1e7f0b01d82..1b854308e60 100644 --- a/libraries/rush-lib/src/cli/actions/InitAutoinstallerAction.ts +++ b/libraries/rush-lib/src/cli/actions/InitAutoinstallerAction.ts @@ -1,10 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; - import type { CommandLineStringParameter } from '@rushstack/ts-command-line'; import { FileSystem, NewlineKind, type IPackageJson, JsonFile } from '@rushstack/node-core-library'; +import { Colorize } from '@rushstack/terminal'; import { BaseRushAction } from './BaseRushAction'; import type { RushCommandLineParser } from '../RushCommandLineParser'; @@ -57,7 +56,7 @@ export class InitAutoinstallerAction extends BaseRushAction { }; // eslint-disable-next-line no-console - console.log(colors.green('Creating package: ') + autoinstaller.packageJsonPath); + console.log(Colorize.green('Creating package: ') + autoinstaller.packageJsonPath); JsonFile.save(packageJson, autoinstaller.packageJsonPath, { ensureFolderExists: true, diff --git a/libraries/rush-lib/src/cli/actions/InitDeployAction.ts b/libraries/rush-lib/src/cli/actions/InitDeployAction.ts index 4f364fe43dc..eefb7a33447 100644 --- a/libraries/rush-lib/src/cli/actions/InitDeployAction.ts +++ b/libraries/rush-lib/src/cli/actions/InitDeployAction.ts @@ -1,11 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; +import { FileSystem, NewlineKind } from '@rushstack/node-core-library'; +import type { CommandLineStringParameter } from '@rushstack/ts-command-line'; +import { Colorize } from '@rushstack/terminal'; + import { BaseRushAction } from './BaseRushAction'; import type { RushCommandLineParser } from '../RushCommandLineParser'; -import type { CommandLineStringParameter } from '@rushstack/ts-command-line'; -import { FileSystem, NewlineKind } from '@rushstack/node-core-library'; import type { RushConfigurationProject } from '../../api/RushConfigurationProject'; import { DeployScenarioConfiguration } from '../../logic/deploy/DeployScenarioConfiguration'; import { assetsFolderPath } from '../../utilities/PathConstants'; @@ -63,7 +64,7 @@ export class InitDeployAction extends BaseRushAction { } // eslint-disable-next-line no-console - console.log(colors.green('Creating scenario file: ') + scenarioFilePath); + console.log(Colorize.green('Creating scenario file: ') + scenarioFilePath); const shortProjectName: string = this._project.value!; const rushProject: RushConfigurationProject | undefined = diff --git a/libraries/rush-lib/src/cli/actions/PublishAction.ts b/libraries/rush-lib/src/cli/actions/PublishAction.ts index 53a3fd51359..173b01dcf64 100644 --- a/libraries/rush-lib/src/cli/actions/PublishAction.ts +++ b/libraries/rush-lib/src/cli/actions/PublishAction.ts @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; import * as path from 'path'; import * as semver from 'semver'; import type { @@ -10,6 +9,7 @@ import type { CommandLineChoiceParameter } from '@rushstack/ts-command-line'; import { FileSystem } from '@rushstack/node-core-library'; +import { Colorize } from '@rushstack/terminal'; import { type IChangeInfo, ChangeType } from '../../api/ChangeManagement'; import type { RushConfigurationProject } from '../../api/RushConfigurationProject'; @@ -251,7 +251,7 @@ export class PublishAction extends BaseRushAction { } // eslint-disable-next-line no-console - console.log('\n' + colors.green('Rush publish finished successfully.')); + console.log('\n' + Colorize.green('Rush publish finished successfully.')); } /** diff --git a/libraries/rush-lib/src/cli/actions/PurgeAction.ts b/libraries/rush-lib/src/cli/actions/PurgeAction.ts index a74fef203da..efc4a03152f 100644 --- a/libraries/rush-lib/src/cli/actions/PurgeAction.ts +++ b/libraries/rush-lib/src/cli/actions/PurgeAction.ts @@ -1,9 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; - import type { CommandLineFlagParameter } from '@rushstack/ts-command-line'; +import { Colorize } from '@rushstack/terminal'; import { BaseRushAction } from './BaseRushAction'; import type { RushCommandLineParser } from '../RushCommandLineParser'; @@ -53,7 +52,7 @@ export class PurgeAction extends BaseRushAction { // eslint-disable-next-line no-console console.log( '\n' + - colors.green( + Colorize.green( `Rush purge started successfully and will complete asynchronously. (${stopwatch.toString()})` ) ); diff --git a/libraries/rush-lib/src/cli/actions/ScanAction.ts b/libraries/rush-lib/src/cli/actions/ScanAction.ts index a5e05c943e9..b99e7da7f63 100644 --- a/libraries/rush-lib/src/cli/actions/ScanAction.ts +++ b/libraries/rush-lib/src/cli/actions/ScanAction.ts @@ -1,13 +1,13 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; import * as path from 'path'; import builtinPackageNames from 'builtin-modules'; - +import { Colorize } from '@rushstack/terminal'; +import type { CommandLineFlagParameter } from '@rushstack/ts-command-line'; import { FileSystem } from '@rushstack/node-core-library'; + import type { RushCommandLineParser } from '../RushCommandLineParser'; -import type { CommandLineFlagParameter } from '@rushstack/ts-command-line'; import { BaseConfiglessRushAction } from './BaseRushAction'; export interface IJsonOutput { @@ -131,7 +131,7 @@ export class ScanAction extends BaseConfiglessRushAction { } } catch (error) { // eslint-disable-next-line no-console - console.log(colors.bold('Skipping file due to error: ' + filename)); + console.log(Colorize.bold('Skipping file due to error: ' + filename)); } } @@ -227,7 +227,7 @@ export class ScanAction extends BaseConfiglessRushAction { if (missingDependencies.length > 0) { // eslint-disable-next-line no-console console.log( - colors.yellow('Possible phantom dependencies') + + Colorize.yellow('Possible phantom dependencies') + " - these seem to be imported but aren't listed in package.json:" ); for (const packageName of missingDependencies) { @@ -244,7 +244,7 @@ export class ScanAction extends BaseConfiglessRushAction { } // eslint-disable-next-line no-console console.log( - colors.yellow('Possible unused dependencies') + + Colorize.yellow('Possible unused dependencies') + " - these are listed in package.json but don't seem to be imported:" ); for (const packageName of unusedDependencies) { @@ -257,7 +257,7 @@ export class ScanAction extends BaseConfiglessRushAction { if (!wroteAnything) { // eslint-disable-next-line no-console console.log( - colors.green('Everything looks good.') + ' No missing or unused dependencies were found.' + Colorize.green('Everything looks good.') + ' No missing or unused dependencies were found.' ); } } diff --git a/libraries/rush-lib/src/cli/scriptActions/GlobalScriptAction.ts b/libraries/rush-lib/src/cli/scriptActions/GlobalScriptAction.ts index 60de3deabf3..a87e8fe03fe 100644 --- a/libraries/rush-lib/src/cli/scriptActions/GlobalScriptAction.ts +++ b/libraries/rush-lib/src/cli/scriptActions/GlobalScriptAction.ts @@ -2,7 +2,7 @@ // See LICENSE in the project root for license information. import * as path from 'path'; -import colors from 'colors/safe'; + import type { AsyncSeriesHook } from 'tapable'; import { @@ -12,6 +12,7 @@ import { AlreadyReportedError, Text } from '@rushstack/node-core-library'; +import { Colorize } from '@rushstack/terminal'; import type { IGlobalCommand } from '../../pluginFramework/RushLifeCycle'; import { BaseScriptAction, type IBaseScriptActionOptions } from './BaseScriptAction'; @@ -186,7 +187,7 @@ export class GlobalScriptAction extends BaseScriptAction { if (exitCode > 0) { // eslint-disable-next-line no-console - console.log('\n' + colors.red(`The script failed with exit code ${exitCode}`)); + console.log('\n' + Colorize.red(`The script failed with exit code ${exitCode}`)); throw new AlreadyReportedError(); } } diff --git a/libraries/rush-lib/src/cli/scriptActions/PhasedScriptAction.ts b/libraries/rush-lib/src/cli/scriptActions/PhasedScriptAction.ts index 72f14bacac4..2f14abfa447 100644 --- a/libraries/rush-lib/src/cli/scriptActions/PhasedScriptAction.ts +++ b/libraries/rush-lib/src/cli/scriptActions/PhasedScriptAction.ts @@ -1,11 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; import type { AsyncSeriesHook } from 'tapable'; import { AlreadyReportedError, InternalError } from '@rushstack/node-core-library'; -import { type ITerminal, Terminal } from '@rushstack/terminal'; +import { type ITerminal, Terminal, Colorize } from '@rushstack/terminal'; import type { CommandLineFlagParameter, CommandLineParameter, @@ -343,7 +342,7 @@ export class PhasedScriptAction extends BaseScriptAction { if (!projectSelection.size) { terminal.writeLine( - colors.yellow(`The command line selection parameters did not match any projects.`) + Colorize.yellow(`The command line selection parameters did not match any projects.`) ); return; } @@ -580,7 +579,7 @@ export class PhasedScriptAction extends BaseScriptAction { ); const names: string[] = [...changedProjects].map((x) => x.packageName).sort(); for (const name of names) { - terminal.writeLine(` ${colors.cyan(name)}`); + terminal.writeLine(` ${Colorize.cyan(name)}`); } // Account for consumer relationships @@ -651,7 +650,7 @@ export class PhasedScriptAction extends BaseScriptAction { const message: string = `rush ${this.actionName} (${stopwatch.toString()})`; if (result.status === OperationStatus.Success) { - terminal.writeLine(colors.green(message)); + terminal.writeLine(Colorize.green(message)); } else { terminal.writeLine(message); } @@ -670,7 +669,7 @@ export class PhasedScriptAction extends BaseScriptAction { } } - terminal.writeErrorLine(colors.red(`rush ${this.actionName} - Errors! (${stopwatch.toString()})`)); + terminal.writeErrorLine(Colorize.red(`rush ${this.actionName} - Errors! (${stopwatch.toString()})`)); } } diff --git a/libraries/rush-lib/src/cli/test/CommandLineHelp.test.ts b/libraries/rush-lib/src/cli/test/CommandLineHelp.test.ts index e8d12da6902..ed1226af566 100644 --- a/libraries/rush-lib/src/cli/test/CommandLineHelp.test.ts +++ b/libraries/rush-lib/src/cli/test/CommandLineHelp.test.ts @@ -2,13 +2,11 @@ // See LICENSE in the project root for license information. import { AnsiEscape } from '@rushstack/terminal'; -import * as colorsPackage from 'colors'; import { RushCommandLineParser } from '../RushCommandLineParser'; describe('CommandLineHelp', () => { let oldCwd: string | undefined; - let colorsEnabled: boolean; let parser: RushCommandLineParser; @@ -23,11 +21,6 @@ describe('CommandLineHelp', () => { process.chdir(localCwd); - colorsEnabled = colorsPackage.enabled; - if (!colorsEnabled) { - colorsPackage.enable(); - } - // This call may terminate the entire test run because it invokes process.exit() // if it encounters errors. // TODO Remove the calls to process.exit() or override them for testing. @@ -40,10 +33,6 @@ describe('CommandLineHelp', () => { if (oldCwd) { process.chdir(oldCwd); } - - if (!colorsEnabled) { - colorsPackage.disable(); - } }); it('prints the global help', () => { diff --git a/libraries/rush-lib/src/cli/test/RushXCommandLine.test.ts b/libraries/rush-lib/src/cli/test/RushXCommandLine.test.ts index b06f0bdfd7d..35e2c2b5c1e 100644 --- a/libraries/rush-lib/src/cli/test/RushXCommandLine.test.ts +++ b/libraries/rush-lib/src/cli/test/RushXCommandLine.test.ts @@ -2,7 +2,6 @@ // See LICENSE in the project root for license information. import { PackageJsonLookup } from '@rushstack/node-core-library'; -import * as colorsPackage from 'colors'; import { Utilities } from '../../utilities/Utilities'; import { Rush, type ILaunchOptions } from '../../api/Rush'; @@ -18,14 +17,8 @@ describe(RushXCommandLine.name, () => { let executeLifecycleCommandMock: jest.SpyInstance | undefined; let logMock: jest.SpyInstance | undefined; let rushConfiguration: RushConfiguration | undefined; - let colorsEnabled: boolean; beforeEach(() => { - colorsEnabled = colorsPackage.enabled; - if (!colorsEnabled) { - colorsPackage.enable(); - } - // Mock process $argv = process.argv; process.argv = [...process.argv]; @@ -80,10 +73,6 @@ describe(RushXCommandLine.name, () => { }); afterEach(() => { - if (!colorsEnabled) { - colorsPackage.disable(); - } - process.argv = $argv; Object.defineProperty(process, 'versions', { value: $versions diff --git a/libraries/rush-lib/src/cli/test/__snapshots__/RushXCommandLine.test.ts.snap b/libraries/rush-lib/src/cli/test/__snapshots__/RushXCommandLine.test.ts.snap index e171ae4d905..c821490c0d9 100644 --- a/libraries/rush-lib/src/cli/test/__snapshots__/RushXCommandLine.test.ts.snap +++ b/libraries/rush-lib/src/cli/test/__snapshots__/RushXCommandLine.test.ts.snap @@ -3,7 +3,7 @@ exports[`RushXCommandLine launchRushXAsync executes a valid package script 1`] = ` Array [ Array [ - "Rush Multi-Project Build Tool 40.40.40 - Node.js 12.12.12 (LTS)", + "Rush Multi-Project Build Tool 40.40.40 - Node.js 12.12.12 (LTS)", ], Array [ "> \\"an acme project build command\\" @@ -17,7 +17,7 @@ exports[`RushXCommandLine launchRushXAsync executes a valid package script with exports[`RushXCommandLine launchRushXAsync fails if the package does not contain a matching script 1`] = ` Array [ Array [ - "Rush Multi-Project Build Tool 40.40.40 - Node.js 12.12.12 (LTS)", + "Rush Multi-Project Build Tool 40.40.40 - Node.js 12.12.12 (LTS)", ], ] `; @@ -25,7 +25,7 @@ Array [ exports[`RushXCommandLine launchRushXAsync prints usage info 1`] = ` Array [ Array [ - "Rush Multi-Project Build Tool 40.40.40 - Node.js 12.12.12 (LTS)", + "Rush Multi-Project Build Tool 40.40.40 - Node.js 12.12.12 (LTS)", ], Array [ "usage: rushx [-h]", diff --git a/libraries/rush-lib/src/logic/Autoinstaller.ts b/libraries/rush-lib/src/logic/Autoinstaller.ts index 9108c25e4f8..237262894a2 100644 --- a/libraries/rush-lib/src/logic/Autoinstaller.ts +++ b/libraries/rush-lib/src/logic/Autoinstaller.ts @@ -1,13 +1,20 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; import * as path from 'path'; -import { FileSystem, type IPackageJson, JsonFile, LockFile, NewlineKind } from '@rushstack/node-core-library'; -import { Utilities } from '../utilities/Utilities'; +import { + FileSystem, + type IPackageJson, + JsonFile, + LockFile, + NewlineKind, + PackageName, + type IParsedPackageNameOrError +} from '@rushstack/node-core-library'; +import { Colorize } from '@rushstack/terminal'; -import { PackageName, type IParsedPackageNameOrError } from '@rushstack/node-core-library'; +import { Utilities } from '../utilities/Utilities'; import type { RushConfiguration } from '../api/RushConfiguration'; import { PackageJsonEditor } from '../api/PackageJsonEditor'; import { InstallHelpers } from './installManager/InstallHelpers'; @@ -221,7 +228,7 @@ export class Autoinstaller { this._logIfConsoleOutputIsNotRestricted(); if (this._rushConfiguration.packageManager === 'npm') { - this._logIfConsoleOutputIsNotRestricted(colors.bold('Running "npm shrinkwrap"...')); + this._logIfConsoleOutputIsNotRestricted(Colorize.bold('Running "npm shrinkwrap"...')); Utilities.executeCommand({ command: this._rushConfiguration.packageManagerToolFilename, args: ['shrinkwrap'], @@ -243,11 +250,11 @@ export class Autoinstaller { }); if (oldFileContents !== newFileContents) { this._logIfConsoleOutputIsNotRestricted( - colors.green('The shrinkwrap file has been updated.') + ' Please commit the updated file:' + Colorize.green('The shrinkwrap file has been updated.') + ' Please commit the updated file:' ); this._logIfConsoleOutputIsNotRestricted(`\n ${this.shrinkwrapFilePath}`); } else { - this._logIfConsoleOutputIsNotRestricted(colors.green('Already up to date.')); + this._logIfConsoleOutputIsNotRestricted(Colorize.green('Already up to date.')); } } diff --git a/libraries/rush-lib/src/logic/EventHooksManager.ts b/libraries/rush-lib/src/logic/EventHooksManager.ts index 9adca3f769a..a7324a8f119 100644 --- a/libraries/rush-lib/src/logic/EventHooksManager.ts +++ b/libraries/rush-lib/src/logic/EventHooksManager.ts @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; +import { Colorize } from '@rushstack/terminal'; import type { EventHooks } from '../api/EventHooks'; import { type IEnvironment, Utilities } from '../utilities/Utilities'; @@ -36,7 +36,7 @@ export class EventHooksManager { const stopwatch: Stopwatch = Stopwatch.start(); // eslint-disable-next-line no-console - console.log('\n' + colors.green(`Executing event hooks for ${Event[event]}`)); + console.log('\n' + Colorize.green(`Executing event hooks for ${Event[event]}`)); const printEventHooksOutputToConsole: boolean | undefined = isDebug || @@ -64,7 +64,7 @@ export class EventHooksManager { // eslint-disable-next-line no-console console.error( '\n' + - colors.yellow( + Colorize.yellow( `Event hook "${script}" failed: ${error}\nRun "rush" with --debug` + ` to see detailed error information.` ) @@ -77,7 +77,7 @@ export class EventHooksManager { }); stopwatch.stop(); // eslint-disable-next-line no-console - console.log('\n' + colors.green(`Event hooks finished. (${stopwatch.toString()})`)); + console.log('\n' + Colorize.green(`Event hooks finished. (${stopwatch.toString()})`)); } } } diff --git a/libraries/rush-lib/src/logic/Git.ts b/libraries/rush-lib/src/logic/Git.ts index b20daac6623..16d78598990 100644 --- a/libraries/rush-lib/src/logic/Git.ts +++ b/libraries/rush-lib/src/logic/Git.ts @@ -5,10 +5,10 @@ import type child_process from 'child_process'; import gitInfo from 'git-repo-info'; import * as path from 'path'; import * as url from 'url'; -import colors from 'colors/safe'; + import { trueCasePathSync } from 'true-case-path'; import { Executable, AlreadyReportedError, Path } from '@rushstack/node-core-library'; -import type { ITerminal } from '@rushstack/terminal'; +import { Colorize, type ITerminal } from '@rushstack/terminal'; import { ensureGitMinimumVersion } from '@rushstack/package-deps-hash'; import { Utilities } from '../utilities/Utilities'; @@ -369,14 +369,14 @@ export class Git { )}). ` : `Unable to find a git remote matching the repository URL (${repositoryUrls[0]}). `; // eslint-disable-next-line no-console - console.log(colors.yellow(errorMessage + 'Detected changes are likely to be incorrect.')); + console.log(Colorize.yellow(errorMessage + 'Detected changes are likely to be incorrect.')); return this._rushConfiguration.repositoryDefaultFullyQualifiedRemoteBranch; } } else { // eslint-disable-next-line no-console console.log( - colors.yellow( + Colorize.yellow( 'A git remote URL has not been specified in rush.json. Setting the baseline remote URL is recommended.' ) ); diff --git a/libraries/rush-lib/src/logic/InteractiveUpgrader.ts b/libraries/rush-lib/src/logic/InteractiveUpgrader.ts index 27cd0105af2..32af47612dc 100644 --- a/libraries/rush-lib/src/logic/InteractiveUpgrader.ts +++ b/libraries/rush-lib/src/logic/InteractiveUpgrader.ts @@ -3,7 +3,7 @@ import npmCheck from 'npm-check'; import type * as NpmCheck from 'npm-check'; -import colors from 'colors/safe'; +import { Colorize } from '@rushstack/terminal'; import type { RushConfiguration } from '../api/RushConfiguration'; import { upgradeInteractive, type IDepsToUpgradeAnswers } from '../utilities/InteractiveUpgradeUI'; @@ -56,7 +56,7 @@ export class InteractiveUpgrader { type: 'list', choices: projects.map((project) => { return { - name: colors.green(project.packageName), + name: Colorize.green(project.packageName), value: project }; }), diff --git a/libraries/rush-lib/src/logic/NodeJsCompatibility.ts b/libraries/rush-lib/src/logic/NodeJsCompatibility.ts index f33c0d43bae..40dda35eac5 100644 --- a/libraries/rush-lib/src/logic/NodeJsCompatibility.ts +++ b/libraries/rush-lib/src/logic/NodeJsCompatibility.ts @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; import * as semver from 'semver'; +import { Colorize } from '@rushstack/terminal'; // Minimize dependencies to avoid compatibility errors that might be encountered before // NodeJsCompatibility.terminateIfVersionIsTooOld() gets to run. @@ -52,7 +52,7 @@ export class NodeJsCompatibility { if (semver.satisfies(nodeVersion, '<14.18.0')) { // eslint-disable-next-line no-console console.error( - colors.red( + Colorize.red( `Your version of Node.js (${nodeVersion}) is very old and incompatible with Rush. ` + `Please upgrade to the latest Long-Term Support (LTS) version.\n` ) @@ -89,7 +89,7 @@ export class NodeJsCompatibility { if (options.isRushLib) { // eslint-disable-next-line no-console console.warn( - colors.yellow( + Colorize.yellow( `Your version of Node.js (${nodeVersion}) has not been tested with this release ` + `of the Rush engine. Please consider upgrading the "rushVersion" setting in rush.json, ` + `or downgrading Node.js.\n` @@ -98,7 +98,7 @@ export class NodeJsCompatibility { } else { // eslint-disable-next-line no-console console.warn( - colors.yellow( + Colorize.yellow( `Your version of Node.js (${nodeVersion}) has not been tested with this release ` + `of Rush. Please consider installing a newer version of the "@microsoft/rush" ` + `package, or downgrading Node.js.\n` @@ -117,7 +117,7 @@ export class NodeJsCompatibility { if (rushConfiguration && !rushConfiguration.suppressNodeLtsWarning && !NodeJsCompatibility.isLtsVersion) { // eslint-disable-next-line no-console console.warn( - colors.yellow( + Colorize.yellow( `Your version of Node.js (${nodeVersion}) is not a Long-Term Support (LTS) release. ` + 'These versions frequently have bugs. Please consider installing a stable release.\n' ) @@ -133,7 +133,7 @@ export class NodeJsCompatibility { if (NodeJsCompatibility.isOddNumberedVersion) { // eslint-disable-next-line no-console console.warn( - colors.yellow( + Colorize.yellow( `Your version of Node.js (${nodeVersion}) is an odd-numbered release. ` + `These releases frequently have bugs. Please consider installing a Long Term Support (LTS) ` + `version instead.\n` diff --git a/libraries/rush-lib/src/logic/PackageJsonUpdater.ts b/libraries/rush-lib/src/logic/PackageJsonUpdater.ts index 8599b5d9b7e..d504df73718 100644 --- a/libraries/rush-lib/src/logic/PackageJsonUpdater.ts +++ b/libraries/rush-lib/src/logic/PackageJsonUpdater.ts @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; import * as semver from 'semver'; import type * as NpmCheck from 'npm-check'; import { ConsoleTerminalProvider, Terminal, type ITerminalProvider, Colorize } from '@rushstack/terminal'; @@ -167,7 +166,7 @@ export class PackageJsonUpdater { } this._terminal.writeLine( - colors.green(`Updating projects to use `) + moduleName + '@' + colors.cyan(version) + Colorize.green(`Updating projects to use `) + moduleName + '@' + Colorize.cyan(version) ); this._terminal.writeLine(); @@ -233,7 +232,7 @@ export class PackageJsonUpdater { for (const [filePath, project] of allPackageUpdates) { if (project.saveIfModified()) { - this._terminal.writeLine(colors.green('Wrote ') + filePath); + this._terminal.writeLine(Colorize.green('Wrote ') + filePath); } } @@ -545,9 +544,9 @@ export class PackageJsonUpdater { explicitlyPreferredVersion: string | undefined, rangeStyle: SemVerStyle ): Promise { - this._terminal.writeLine(colors.gray(`Determining new version for dependency: ${packageName}`)); + this._terminal.writeLine(Colorize.gray(`Determining new version for dependency: ${packageName}`)); if (initialSpec) { - this._terminal.writeLine(`Specified version selector: ${colors.cyan(initialSpec)}`); + this._terminal.writeLine(`Specified version selector: ${Colorize.cyan(initialSpec)}`); } else { this._terminal.writeLine( `No version selector was specified, so the version will be determined automatically.` @@ -560,9 +559,9 @@ export class PackageJsonUpdater { if (initialSpec) { if (initialSpec === implicitlyPreferredVersion) { this._terminal.writeLine( - colors.green('Assigning "') + - colors.cyan(initialSpec) + - colors.green( + Colorize.green('Assigning "') + + Colorize.cyan(initialSpec) + + Colorize.green( `" for "${packageName}" because it matches what other projects are using in this repo.` ) ); @@ -571,9 +570,9 @@ export class PackageJsonUpdater { if (initialSpec === explicitlyPreferredVersion) { this._terminal.writeLine( - colors.green('Assigning "') + - colors.cyan(initialSpec) + - colors.green( + Colorize.green('Assigning "') + + Colorize.cyan(initialSpec) + + Colorize.green( `" for "${packageName}" because it is the preferred version listed in ${RushConstants.commonVersionsFilename}.` ) ); @@ -584,7 +583,7 @@ export class PackageJsonUpdater { if (this._rushConfiguration.ensureConsistentVersions && !initialSpec) { if (implicitlyPreferredVersion) { this._terminal.writeLine( - `Assigning the version "${colors.cyan(implicitlyPreferredVersion)}" for "${packageName}" ` + + `Assigning the version "${Colorize.cyan(implicitlyPreferredVersion)}" for "${packageName}" ` + 'because it is already used by other projects in this repo.' ); return implicitlyPreferredVersion; @@ -592,7 +591,7 @@ export class PackageJsonUpdater { if (explicitlyPreferredVersion) { this._terminal.writeLine( - `Assigning the version "${colors.cyan(explicitlyPreferredVersion)}" for "${packageName}" ` + + `Assigning the version "${Colorize.cyan(explicitlyPreferredVersion)}" for "${packageName}" ` + `because it is the preferred version listed in ${RushConstants.commonVersionsFilename}.` ); return explicitlyPreferredVersion; @@ -625,7 +624,7 @@ export class PackageJsonUpdater { let selectedVersionPrefix: string = ''; if (initialSpec && initialSpec !== 'latest') { - this._terminal.writeLine(colors.gray('Finding versions that satisfy the selector: ') + initialSpec); + this._terminal.writeLine(Colorize.gray('Finding versions that satisfy the selector: ') + initialSpec); this._terminal.writeLine(); if (localProject !== undefined) { @@ -671,13 +670,13 @@ export class PackageJsonUpdater { versionList = JSON.parse(allVersions); } - this._terminal.writeLine(colors.gray(`Found ${versionList.length} available versions.`)); + this._terminal.writeLine(Colorize.gray(`Found ${versionList.length} available versions.`)); for (const version of versionList) { if (semver.satisfies(version, initialSpec)) { selectedVersion = initialSpec; this._terminal.writeLine( - `Found a version that satisfies ${initialSpec}: ${colors.cyan(version)}` + `Found a version that satisfies ${initialSpec}: ${Colorize.cyan(version)}` ); break; } @@ -703,7 +702,7 @@ export class PackageJsonUpdater { } else { if (!this._rushConfiguration.ensureConsistentVersions) { this._terminal.writeLine( - colors.gray( + Colorize.gray( `The "ensureConsistentVersions" policy is NOT active, so we will assign the latest version.` ) ); @@ -728,7 +727,7 @@ export class PackageJsonUpdater { this._terminal.writeLine(); - this._terminal.writeLine(`Found latest version: ${colors.cyan(selectedVersion)}`); + this._terminal.writeLine(`Found latest version: ${Colorize.cyan(selectedVersion)}`); } this._terminal.writeLine(); @@ -764,7 +763,7 @@ export class PackageJsonUpdater { const normalizedVersion: string = selectedVersionPrefix + selectedVersion; this._terminal.writeLine( - colors.gray(`Assigning version "${normalizedVersion}" for "${packageName}"${reasonForModification}.`) + Colorize.gray(`Assigning version "${normalizedVersion}" for "${packageName}"${reasonForModification}.`) ); return normalizedVersion; } diff --git a/libraries/rush-lib/src/logic/PurgeManager.ts b/libraries/rush-lib/src/logic/PurgeManager.ts index 6c2c15e9e01..b99773ebe6a 100644 --- a/libraries/rush-lib/src/logic/PurgeManager.ts +++ b/libraries/rush-lib/src/logic/PurgeManager.ts @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; import * as path from 'path'; +import { Colorize } from '@rushstack/terminal'; import { AsyncRecycler } from '../utilities/AsyncRecycler'; import type { RushConfiguration } from '../api/RushConfiguration'; @@ -93,7 +93,7 @@ export class PurgeManager { this._rushConfiguration.pnpmOptions.pnpmStorePath ) { // eslint-disable-next-line no-console - console.warn(colors.yellow(`Purging the global pnpm-store`)); + console.warn(Colorize.yellow(`Purging the global pnpm-store`)); this._rushUserFolderRecycler.moveAllItemsInFolder(this._rushConfiguration.pnpmOptions.pnpmStorePath); } } @@ -122,7 +122,7 @@ export class PurgeManager { // Warn that we won't dispose this folder // eslint-disable-next-line no-console console.log( - colors.yellow( + Colorize.yellow( "The active process's folder will not be deleted: " + path.join(folderToRecycle, firstPart) ) ); diff --git a/libraries/rush-lib/src/logic/SetupChecks.ts b/libraries/rush-lib/src/logic/SetupChecks.ts index 487dd553209..72a0c037d3a 100644 --- a/libraries/rush-lib/src/logic/SetupChecks.ts +++ b/libraries/rush-lib/src/logic/SetupChecks.ts @@ -1,11 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; import * as path from 'path'; import * as semver from 'semver'; import { FileSystem, AlreadyReportedError } from '@rushstack/node-core-library'; -import { PrintUtilities } from '@rushstack/terminal'; +import { Colorize, PrintUtilities } from '@rushstack/terminal'; import type { RushConfiguration } from '../api/RushConfiguration'; import { RushConstants } from '../logic/RushConstants'; @@ -34,7 +33,7 @@ export class SetupChecks { if (errorMessage) { // eslint-disable-next-line no-console - console.error(colors.red(PrintUtilities.wrapWords(errorMessage))); + console.error(Colorize.red(PrintUtilities.wrapWords(errorMessage))); throw new AlreadyReportedError(); } } @@ -78,7 +77,7 @@ export class SetupChecks { if (phantomFolders.length === 1) { // eslint-disable-next-line no-console console.log( - colors.yellow( + Colorize.yellow( PrintUtilities.wrapWords( 'Warning: A phantom "node_modules" folder was found. This defeats Rush\'s protection against' + ' NPM phantom dependencies and may cause confusing build errors. It is recommended to' + @@ -89,7 +88,7 @@ export class SetupChecks { } else { // eslint-disable-next-line no-console console.log( - colors.yellow( + Colorize.yellow( PrintUtilities.wrapWords( 'Warning: Phantom "node_modules" folders were found. This defeats Rush\'s protection against' + ' NPM phantom dependencies and may cause confusing build errors. It is recommended to' + @@ -100,7 +99,7 @@ export class SetupChecks { } for (const folder of phantomFolders) { // eslint-disable-next-line no-console - console.log(colors.yellow(`"${folder}"`)); + console.log(Colorize.yellow(`"${folder}"`)); } // eslint-disable-next-line no-console console.log(); // add a newline diff --git a/libraries/rush-lib/src/logic/UnlinkManager.ts b/libraries/rush-lib/src/logic/UnlinkManager.ts index fa0c269baff..736ed7fa0b1 100644 --- a/libraries/rush-lib/src/logic/UnlinkManager.ts +++ b/libraries/rush-lib/src/logic/UnlinkManager.ts @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; import * as path from 'path'; import { FileSystem, AlreadyReportedError } from '@rushstack/node-core-library'; +import { Colorize } from '@rushstack/terminal'; import type { RushConfiguration } from '../api/RushConfiguration'; import { Utilities } from '../utilities/Utilities'; @@ -32,7 +32,7 @@ export class UnlinkManager { if (!force && useWorkspaces) { // eslint-disable-next-line no-console console.log( - colors.red( + Colorize.red( 'Unlinking is not supported when using workspaces. Run "rush purge" to remove ' + 'project node_modules folders.' ) diff --git a/libraries/rush-lib/src/logic/base/BaseInstallManager.ts b/libraries/rush-lib/src/logic/base/BaseInstallManager.ts index b0bbcfb9220..1d25de40309 100644 --- a/libraries/rush-lib/src/logic/base/BaseInstallManager.ts +++ b/libraries/rush-lib/src/logic/base/BaseInstallManager.ts @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; import type * as fetch from 'node-fetch'; import * as os from 'os'; import * as path from 'path'; @@ -20,7 +19,8 @@ import { PrintUtilities, ConsoleTerminalProvider, Terminal, - type ITerminalProvider + type ITerminalProvider, + Colorize } from '@rushstack/terminal'; import { ApprovedPackagesChecker } from '../ApprovedPackagesChecker'; @@ -116,7 +116,7 @@ export abstract class BaseInstallManager { console.log(); // eslint-disable-next-line no-console console.log( - colors.red( + Colorize.red( 'Project filtering arguments can only be used when running in a workspace environment. Run the ' + 'command again without specifying these arguments.' ) @@ -132,7 +132,7 @@ export abstract class BaseInstallManager { console.log(); // eslint-disable-next-line no-console console.log( - colors.red( + Colorize.red( 'Project filtering arguments cannot be used when running "rush update". Run the command again ' + 'without specifying these arguments.' ) @@ -155,7 +155,7 @@ export abstract class BaseInstallManager { } // eslint-disable-next-line no-console - console.log('\n' + colors.bold(`Checking installation in "${subspace.getSubspaceTempFolder()}"`)); + console.log('\n' + Colorize.bold(`Checking installation in "${subspace.getSubspaceTempFolder()}"`)); // This marker file indicates that the last "rush install" completed successfully. // Always perform a clean install if filter flags were provided. Additionally, if @@ -206,7 +206,7 @@ export abstract class BaseInstallManager { if (publishedRelease === false) { // eslint-disable-next-line no-console console.log( - colors.yellow('Warning: This release of the Rush tool was unpublished; it may be unstable.') + Colorize.yellow('Warning: This release of the Rush tool was unpublished; it may be unstable.') ); } @@ -241,7 +241,7 @@ export abstract class BaseInstallManager { if (subspace.getRepoState().refreshState(this.rushConfiguration, subspace)) { // eslint-disable-next-line no-console console.log( - colors.yellow( + Colorize.yellow( `${RushConstants.repoStateFilename} has been modified and must be committed to source control.` ) ); @@ -326,7 +326,7 @@ export abstract class BaseInstallManager { if (allowShrinkwrapUpdates) { // eslint-disable-next-line no-console console.log( - colors.yellow( + Colorize.yellow( 'Approved package files have been updated. These updates should be committed to source control' ) ); @@ -365,7 +365,7 @@ export abstract class BaseInstallManager { // eslint-disable-next-line no-console console.log(); // eslint-disable-next-line no-console - console.log(colors.red('You need to run "rush update" to fix this problem')); + console.log(Colorize.red('You need to run "rush update" to fix this problem')); throw new AlreadyReportedError(); } @@ -390,12 +390,12 @@ export abstract class BaseInstallManager { // eslint-disable-next-line no-console console.log(); // eslint-disable-next-line no-console - console.log(colors.bold(`Using variant '${this.options.variant}' for installation.`)); + console.log(Colorize.bold(`Using variant '${this.options.variant}' for installation.`)); } else if (!variantIsUpToDate && !this.options.variant) { // eslint-disable-next-line no-console console.log(); // eslint-disable-next-line no-console - console.log(colors.bold('Using the default variant for installation.')); + console.log(Colorize.bold('Using the default variant for installation.')); } const extraNpmrcLines: string[] = []; @@ -484,7 +484,7 @@ export abstract class BaseInstallManager { console.log(); // eslint-disable-next-line no-console console.log( - colors.yellow( + Colorize.yellow( PrintUtilities.wrapWords( `The ${this.rushConfiguration.shrinkwrapFilePhrase} contains the following issues:` ) @@ -493,7 +493,7 @@ export abstract class BaseInstallManager { for (const shrinkwrapWarning of shrinkwrapWarnings) { // eslint-disable-next-line no-console - console.log(colors.yellow(' ' + shrinkwrapWarning)); + console.log(Colorize.yellow(' ' + shrinkwrapWarning)); } // eslint-disable-next-line no-console console.log(); @@ -513,7 +513,7 @@ export abstract class BaseInstallManager { hasErrors = true; this._terminal.writeErrorLine(); this._terminal.writeErrorLine( - colors.red( + Colorize.red( `The ${RushConstants.projectImpactGraphFilename} file is missing or out of date. You need to run "rush update".` ) ); @@ -540,10 +540,10 @@ export abstract class BaseInstallManager { const hookFilenames: string[] = allHookFilenames.filter((x) => !/\.sample$/.test(x)); if (hookFilenames.length > 0) { // eslint-disable-next-line no-console - console.log('\n' + colors.bold('Found files in the "common/git-hooks" folder.')); + console.log('\n' + Colorize.bold('Found files in the "common/git-hooks" folder.')); if (!git.isHooksPathDefault()) { - const color: (str: string) => string = this.options.bypassPolicy ? colors.yellow : colors.red; + const color: (str: string) => string = this.options.bypassPolicy ? Colorize.yellow : Colorize.red; // eslint-disable-next-line no-console console.error( color( @@ -977,12 +977,12 @@ ${gitLfsHookHandling} // eslint-disable-next-line no-console console.error(); // eslint-disable-next-line no-console - console.error(colors.red('ERROR: NPM credentials are missing or expired')); + console.error(Colorize.red('ERROR: NPM credentials are missing or expired')); // eslint-disable-next-line no-console console.error(); // eslint-disable-next-line no-console console.error( - colors.bold( + Colorize.bold( '==> Please run "rush setup" to update your NPM token. ' + `(Or append "${RushConstants.bypassPolicyFlagLongName}" to proceed anyway.)` ) diff --git a/libraries/rush-lib/src/logic/base/BaseLinkManager.ts b/libraries/rush-lib/src/logic/base/BaseLinkManager.ts index 12ec22b8fae..96198d6aa30 100644 --- a/libraries/rush-lib/src/logic/base/BaseLinkManager.ts +++ b/libraries/rush-lib/src/logic/base/BaseLinkManager.ts @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; import * as path from 'path'; import { @@ -10,6 +9,7 @@ import { type IFileSystemCreateLinkOptions, InternalError } from '@rushstack/node-core-library'; +import { Colorize } from '@rushstack/terminal'; import type { RushConfiguration } from '../../api/RushConfiguration'; import { Utilities } from '../../utilities/Utilities'; @@ -191,7 +191,7 @@ export abstract class BaseLinkManager { */ public async createSymlinksForProjects(force: boolean): Promise { // eslint-disable-next-line no-console - console.log('\n' + colors.bold('Linking local projects')); + console.log('\n' + Colorize.bold('Linking local projects')); const stopwatch: Stopwatch = Stopwatch.start(); await this._linkProjects(); @@ -201,7 +201,7 @@ export abstract class BaseLinkManager { stopwatch.stop(); // eslint-disable-next-line no-console - console.log('\n' + colors.green(`Linking finished successfully. (${stopwatch.toString()})`)); + console.log('\n' + Colorize.green(`Linking finished successfully. (${stopwatch.toString()})`)); // eslint-disable-next-line no-console console.log('\nNext you should probably run "rush build" or "rush rebuild"'); } diff --git a/libraries/rush-lib/src/logic/base/BaseShrinkwrapFile.ts b/libraries/rush-lib/src/logic/base/BaseShrinkwrapFile.ts index 353529a8288..ae1574233b5 100644 --- a/libraries/rush-lib/src/logic/base/BaseShrinkwrapFile.ts +++ b/libraries/rush-lib/src/logic/base/BaseShrinkwrapFile.ts @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; import * as semver from 'semver'; +import { Colorize } from '@rushstack/terminal'; import { RushConstants } from '../../logic/RushConstants'; import { type DependencySpecifier, DependencySpecifierType } from '../DependencySpecifier'; @@ -218,7 +218,7 @@ export abstract class BaseShrinkwrapFile { this._alreadyWarnedSpecs.add(projectDependency.versionSpecifier); // eslint-disable-next-line no-console console.log( - colors.yellow( + Colorize.yellow( `WARNING: Not validating ${projectDependency.specifierType}-based` + ` specifier: "${projectDependency.versionSpecifier}"` ) diff --git a/libraries/rush-lib/src/logic/installManager/InstallHelpers.ts b/libraries/rush-lib/src/logic/installManager/InstallHelpers.ts index f8dade3d5ed..671b529e46c 100644 --- a/libraries/rush-lib/src/logic/installManager/InstallHelpers.ts +++ b/libraries/rush-lib/src/logic/installManager/InstallHelpers.ts @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; import * as path from 'path'; import { FileConstants, @@ -10,6 +9,7 @@ import { JsonFile, LockFile } from '@rushstack/node-core-library'; +import { Colorize } from '@rushstack/terminal'; import { LastInstallFlag } from '../../api/LastInstallFlag'; import type { PackageManagerName } from '../../api/packageManager/PackageManager'; @@ -171,7 +171,7 @@ export class InstallHelpers { if (!packageManagerMarker.isValid() || lock.dirtyWhenAcquired) { logIfConsoleOutputIsNotRestricted( - colors.bold(`Installing ${packageManager} version ${packageManagerVersion}\n`) + Colorize.bold(`Installing ${packageManager} version ${packageManagerVersion}\n`) ); // note that this will remove the last-install flag from the directory @@ -265,7 +265,7 @@ export class InstallHelpers { console.log(`Overriding the environment variable with the value set in rush.json.`); } else { // eslint-disable-next-line no-console - console.log(colors.yellow(`WARNING: Not overriding the value of the environment variable.`)); + console.log(Colorize.yellow(`WARNING: Not overriding the value of the environment variable.`)); } } diff --git a/libraries/rush-lib/src/logic/installManager/RushInstallManager.ts b/libraries/rush-lib/src/logic/installManager/RushInstallManager.ts index e6eb78769ce..57f3cdf5ec3 100644 --- a/libraries/rush-lib/src/logic/installManager/RushInstallManager.ts +++ b/libraries/rush-lib/src/logic/installManager/RushInstallManager.ts @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; import * as fs from 'fs'; import * as path from 'path'; import * as semver from 'semver'; @@ -15,7 +14,7 @@ import { InternalError, AlreadyReportedError } from '@rushstack/node-core-library'; -import { PrintUtilities } from '@rushstack/terminal'; +import { Colorize, PrintUtilities } from '@rushstack/terminal'; import { BaseInstallManager } from '../base/BaseInstallManager'; import type { IInstallManagerOptions } from '../base/BaseInstallManagerTypes'; @@ -98,7 +97,7 @@ export class RushInstallManager extends BaseInstallManager { ); // eslint-disable-next-line no-console - console.log('\n' + colors.bold('Updating temp projects in ' + tempProjectsFolder)); + console.log('\n' + Colorize.bold('Updating temp projects in ' + tempProjectsFolder)); Utilities.createFolderWithRetry(tempProjectsFolder); @@ -115,7 +114,7 @@ export class RushInstallManager extends BaseInstallManager { console.log(); // eslint-disable-next-line no-console console.log( - colors.red( + Colorize.red( 'The shrinkwrap file had previously been updated to support workspaces. Run "rush update --full" ' + 'to update the shrinkwrap file.' ) @@ -320,7 +319,7 @@ export class RushInstallManager extends BaseInstallManager { console.log(`Updating ${tarballFile}`); } catch (error) { // eslint-disable-next-line no-console - console.log(colors.yellow(error as string)); + console.log(Colorize.yellow(error as string)); // delete everything in case of any error FileSystem.deleteFile(tarballFile); FileSystem.deleteFile(tempPackageJsonFilename); @@ -351,7 +350,7 @@ export class RushInstallManager extends BaseInstallManager { if (packageJson.saveIfModified()) { // eslint-disable-next-line no-console console.log( - colors.yellow( + Colorize.yellow( `"${rushProject.packageName}" depends on one or more local packages which used "workspace:" ` + 'notation. The package.json has been modified and must be committed to source control.' ) @@ -586,7 +585,7 @@ export class RushInstallManager extends BaseInstallManager { // eslint-disable-next-line no-console console.log( '\n' + - colors.bold( + Colorize.bold( `Running "${this.rushConfiguration.packageManager} install" in` + ` ${this.rushConfiguration.commonTempFolder}` ) + @@ -598,7 +597,7 @@ export class RushInstallManager extends BaseInstallManager { // eslint-disable-next-line no-console console.log( '\n' + - colors.green('Invoking package manager: ') + + Colorize.green('Invoking package manager: ') + FileSystem.getRealPath(packageManagerFilename) + ' ' + installArgs.join(' ') + @@ -618,7 +617,7 @@ export class RushInstallManager extends BaseInstallManager { () => { if (this.rushConfiguration.packageManager === 'pnpm') { // eslint-disable-next-line no-console - console.log(colors.yellow(`Deleting the "node_modules" folder`)); + console.log(Colorize.yellow(`Deleting the "node_modules" folder`)); this.installRecycler.moveFolder(commonNodeModulesFolder); // Leave the pnpm-store as is for the retry. This ensures that packages that have already @@ -632,7 +631,7 @@ export class RushInstallManager extends BaseInstallManager { if (this.rushConfiguration.packageManager === 'npm') { // eslint-disable-next-line no-console - console.log('\n' + colors.bold('Running "npm shrinkwrap"...')); + console.log('\n' + Colorize.bold('Running "npm shrinkwrap"...')); const npmArgs: string[] = ['shrinkwrap']; this.pushConfigurationArgs(npmArgs, this.options, subspace); Utilities.executeCommand({ @@ -654,7 +653,7 @@ export class RushInstallManager extends BaseInstallManager { } else { // eslint-disable-next-line no-console console.log( - '\n' + colors.yellow('Since "--no-link" was specified, you will need to run "rush link" manually.') + '\n' + Colorize.yellow('Since "--no-link" was specified, you will need to run "rush link" manually.') ); } } @@ -703,7 +702,9 @@ export class RushInstallManager extends BaseInstallManager { if (anyChanges) { // eslint-disable-next-line no-console - console.log('\n' + colors.yellow(PrintUtilities.wrapWords(`Applied workaround for NPM 5 bug`)) + '\n'); + console.log( + '\n' + Colorize.yellow(PrintUtilities.wrapWords(`Applied workaround for NPM 5 bug`)) + '\n' + ); } } @@ -721,7 +722,7 @@ export class RushInstallManager extends BaseInstallManager { // eslint-disable-next-line no-console console.log( '\n' + - colors.yellow( + Colorize.yellow( PrintUtilities.wrapWords( `Your ${this.rushConfiguration.shrinkwrapFilePhrase} is missing the project "${rushProject.packageName}".` ) diff --git a/libraries/rush-lib/src/logic/installManager/WorkspaceInstallManager.ts b/libraries/rush-lib/src/logic/installManager/WorkspaceInstallManager.ts index c3e092eb394..5ec937003d8 100644 --- a/libraries/rush-lib/src/logic/installManager/WorkspaceInstallManager.ts +++ b/libraries/rush-lib/src/logic/installManager/WorkspaceInstallManager.ts @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; import * as path from 'path'; import * as semver from 'semver'; import { @@ -37,6 +36,7 @@ import { PnpmShrinkwrapFile } from '../pnpm/PnpmShrinkwrapFile'; import { objectsAreDeepEqual } from '../../utilities/objectUtilities'; import { type ILockfile, pnpmSyncPrepareAsync } from 'pnpm-sync-lib'; import type { Subspace } from '../../api/Subspace'; +import { Colorize, ConsoleTerminalProvider } from '@rushstack/terminal'; /** * This class implements common logic between "rush install" and "rush update". @@ -50,7 +50,7 @@ export class WorkspaceInstallManager extends BaseInstallManager { if (this.options.noLink) { // eslint-disable-next-line no-console console.log( - colors.red( + Colorize.red( 'The "--no-link" option was provided but is not supported when using workspaces. Run the command again ' + 'without specifying this argument.' ) @@ -82,7 +82,7 @@ export class WorkspaceInstallManager extends BaseInstallManager { } // eslint-disable-next-line no-console - console.log('\n' + colors.bold('Updating workspace files in ' + subspace.getSubspaceTempFolder())); + console.log('\n' + Colorize.bold('Updating workspace files in ' + subspace.getSubspaceTempFolder())); const shrinkwrapWarnings: string[] = []; @@ -98,7 +98,7 @@ export class WorkspaceInstallManager extends BaseInstallManager { console.log(); // eslint-disable-next-line no-console console.log( - colors.red( + Colorize.red( 'The shrinkwrap file has not been updated to support workspaces. Run "rush update --full" to update ' + 'the shrinkwrap file.' ) @@ -204,7 +204,7 @@ export class WorkspaceInstallManager extends BaseInstallManager { console.log(); // eslint-disable-next-line no-console console.log( - colors.red( + Colorize.red( `"${rushProject.packageName}" depends on package "${name}" (${version}) which exists ` + 'within the workspace but cannot be fulfilled with the specified version range. Either ' + 'specify a valid version range, or add the package as a cyclic dependency.' @@ -218,7 +218,7 @@ export class WorkspaceInstallManager extends BaseInstallManager { console.log(); // eslint-disable-next-line no-console console.log( - colors.red( + Colorize.red( `"${rushProject.packageName}" depends on package "${name}" (${version}) which exists within ` + 'the workspace. Run "rush update" to update workspace references for this package.' ) @@ -248,7 +248,7 @@ export class WorkspaceInstallManager extends BaseInstallManager { if (packageJson.saveIfModified()) { // eslint-disable-next-line no-console console.log( - colors.yellow( + Colorize.yellow( `"${rushProject.packageName}" depends on one or more workspace packages which did not use "workspace:" ` + 'notation. The package.json has been modified and must be committed to source control.' ) @@ -361,7 +361,7 @@ export class WorkspaceInstallManager extends BaseInstallManager { this.rushConfiguration, this.options ); - if (colors.enabled) { + if (ConsoleTerminalProvider.supportsColor) { packageManagerEnv.FORCE_COLOR = '1'; } @@ -396,7 +396,7 @@ export class WorkspaceInstallManager extends BaseInstallManager { // eslint-disable-next-line no-console console.log( '\n' + - colors.bold( + Colorize.bold( `Running "${this.rushConfiguration.packageManager} install" in` + ` ${subspace.getSubspaceTempFolder()}` ) + @@ -413,7 +413,7 @@ export class WorkspaceInstallManager extends BaseInstallManager { // eslint-disable-next-line no-console console.log( '\n' + - colors.green('Invoking package manager: ') + + Colorize.green('Invoking package manager: ') + FileSystem.getRealPath(packageManagerFilename) + ' ' + installArgs.join(' ') + diff --git a/libraries/rush-lib/src/logic/npm/NpmLinkManager.ts b/libraries/rush-lib/src/logic/npm/NpmLinkManager.ts index 243b6865cec..0149ad2eed4 100644 --- a/libraries/rush-lib/src/logic/npm/NpmLinkManager.ts +++ b/libraries/rush-lib/src/logic/npm/NpmLinkManager.ts @@ -1,12 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; import * as path from 'path'; import * as semver from 'semver'; import * as tar from 'tar'; import readPackageTree from 'read-package-tree'; import { FileSystem, FileConstants, LegacyAdapters } from '@rushstack/node-core-library'; +import { Colorize } from '@rushstack/terminal'; import { RushConstants } from '../../logic/RushConstants'; import type { RushConfigurationProject } from '../../api/RushConfigurationProject'; @@ -180,7 +180,7 @@ export class NpmLinkManager extends BaseLinkManager { // eslint-disable-next-line no-console console.log( - colors.yellow( + Colorize.yellow( `Rush will not locally link ${dependency.name} for ${localPackage.name}` + ` because the requested version "${dependency.versionRange}" is incompatible` + ` with the local version ${matchedVersion}` diff --git a/libraries/rush-lib/src/logic/operations/ConsoleTimelinePlugin.ts b/libraries/rush-lib/src/logic/operations/ConsoleTimelinePlugin.ts index 94d71c43b99..beae3f7162d 100644 --- a/libraries/rush-lib/src/logic/operations/ConsoleTimelinePlugin.ts +++ b/libraries/rush-lib/src/logic/operations/ConsoleTimelinePlugin.ts @@ -2,8 +2,8 @@ // See LICENSE in the project root for license information. import type { ITerminal } from '@rushstack/terminal'; -import { PrintUtilities } from '@rushstack/terminal'; -import colors from 'colors/safe'; +import { Colorize, PrintUtilities } from '@rushstack/terminal'; + import type { IPhase } from '../../api/CommandLineConfiguration'; import type { ICreateOperationsContext, @@ -93,18 +93,18 @@ const TIMELINE_CHART_SYMBOLS: Record = { * Timeline - colorizer for each operation status */ const TIMELINE_CHART_COLORIZER: Record string> = { - [OperationStatus.Waiting]: colors.yellow, - [OperationStatus.Ready]: colors.yellow, - [OperationStatus.Queued]: colors.yellow, - [OperationStatus.Executing]: colors.yellow, - [OperationStatus.RemoteExecuting]: colors.yellow, - [OperationStatus.Success]: colors.green, - [OperationStatus.SuccessWithWarning]: colors.yellow, - [OperationStatus.Failure]: colors.red, - [OperationStatus.Blocked]: colors.red, - [OperationStatus.Skipped]: colors.green, - [OperationStatus.FromCache]: colors.green, - [OperationStatus.NoOp]: colors.gray + [OperationStatus.Waiting]: Colorize.yellow, + [OperationStatus.Ready]: Colorize.yellow, + [OperationStatus.Queued]: Colorize.yellow, + [OperationStatus.Executing]: Colorize.yellow, + [OperationStatus.RemoteExecuting]: Colorize.yellow, + [OperationStatus.Success]: Colorize.green, + [OperationStatus.SuccessWithWarning]: Colorize.yellow, + [OperationStatus.Failure]: Colorize.red, + [OperationStatus.Blocked]: Colorize.red, + [OperationStatus.Skipped]: Colorize.green, + [OperationStatus.FromCache]: Colorize.green, + [OperationStatus.NoOp]: Colorize.gray }; interface ITimelineRecord { @@ -251,11 +251,11 @@ export function _printTimeline({ terminal, result, cobuildConfiguration }: IPrin const length: number = endIdx - startIdx + 1; const chart: string = - colors.gray('-'.repeat(startIdx)) + + Colorize.gray('-'.repeat(startIdx)) + TIMELINE_CHART_COLORIZER[status](getChartSymbol(record).repeat(length)) + - colors.gray('-'.repeat(chartWidth - endIdx)); + Colorize.gray('-'.repeat(chartWidth - endIdx)); terminal.writeLine( - `${colors.cyan(name.padStart(longestNameLength))} ${chart} ${colors.white( + `${Colorize.cyan(name.padStart(longestNameLength))} ${chart} ${Colorize.white( durationString.padStart(longestDurationLength) + 's' )}` ); @@ -307,7 +307,7 @@ export function _printTimeline({ terminal, result, cobuildConfiguration }: IPrin } for (const [phase, duration] of durationByPhase.entries()) { - terminal.writeLine(` ${colors.cyan(phase.name.padStart(maxPhaseName))} ${duration.toFixed(1)}s`); + terminal.writeLine(` ${Colorize.cyan(phase.name.padStart(maxPhaseName))} ${duration.toFixed(1)}s`); } } diff --git a/libraries/rush-lib/src/logic/operations/OperationExecutionManager.ts b/libraries/rush-lib/src/logic/operations/OperationExecutionManager.ts index 5c7d34a9098..60afa48538a 100644 --- a/libraries/rush-lib/src/logic/operations/OperationExecutionManager.ts +++ b/libraries/rush-lib/src/logic/operations/OperationExecutionManager.ts @@ -1,8 +1,13 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; -import { type TerminalWritable, StdioWritable, TextRewriterTransform } from '@rushstack/terminal'; +import { + type TerminalWritable, + StdioWritable, + TextRewriterTransform, + Colorize, + ConsoleTerminalProvider +} from '@rushstack/terminal'; import { StreamCollator, type CollatedTerminal, type CollatedWriter } from '@rushstack/stream-collator'; import { NewlineKind, Async, InternalError } from '@rushstack/node-core-library'; @@ -107,7 +112,7 @@ export class OperationExecutionManager { this._colorsNewlinesTransform = new TextRewriterTransform({ destination: this._outputWritable, normalizeNewlines: NewlineKind.OsDefault, - removeColors: !colors.enabled + removeColors: !ConsoleTerminalProvider.supportsColor }); this._streamCollator = new StreamCollator({ destination: this._colorsNewlinesTransform, @@ -169,12 +174,12 @@ export class OperationExecutionManager { // ==[ @rushstack/the-long-thing ]=================[ 1 of 1000 ]== // leftPart: "==[ @rushstack/the-long-thing " - const leftPart: string = colors.gray('==[') + ' ' + colors.cyan(writer.taskName) + ' '; + const leftPart: string = Colorize.gray('==[') + ' ' + Colorize.cyan(writer.taskName) + ' '; const leftPartLength: number = 4 + writer.taskName.length + 1; // rightPart: " 1 of 1000 ]==" const completedOfTotal: string = `${this._completedOperations} of ${this._totalOperations}`; - const rightPart: string = ' ' + colors.white(completedOfTotal) + ' ' + colors.gray(']=='); + const rightPart: string = ' ' + Colorize.white(completedOfTotal) + ' ' + Colorize.gray(']=='); const rightPartLength: number = 1 + completedOfTotal.length + 4; // middlePart: "]=================[" @@ -184,7 +189,7 @@ export class OperationExecutionManager { 0 ); - const middlePart: string = colors.gray(']' + '='.repeat(middlePartLengthMinusTwoBrackets) + '['); + const middlePart: string = Colorize.gray(']' + '='.repeat(middlePartLengthMinusTwoBrackets) + '['); this._terminal.writeStdoutLine('\n' + leftPart + middlePart + rightPart); @@ -314,7 +319,7 @@ export class OperationExecutionManager { if (message) { terminal.writeStderrLine(message); } - terminal.writeStderrLine(colors.red(`"${name}" failed to build.`)); + terminal.writeStderrLine(Colorize.red(`"${name}" failed to build.`)); const blockedQueue: Set = new Set(record.consumers); for (const blockedRecord of blockedQueue) { @@ -350,7 +355,7 @@ export class OperationExecutionManager { case OperationStatus.FromCache: { if (!silent) { record.collatedWriter.terminal.writeStdoutLine( - colors.green(`"${name}" was restored from the build cache.`) + Colorize.green(`"${name}" was restored from the build cache.`) ); } break; @@ -361,7 +366,7 @@ export class OperationExecutionManager { */ case OperationStatus.Skipped: { if (!silent) { - record.collatedWriter.terminal.writeStdoutLine(colors.green(`"${name}" was skipped.`)); + record.collatedWriter.terminal.writeStdoutLine(Colorize.green(`"${name}" was skipped.`)); } break; } @@ -371,7 +376,7 @@ export class OperationExecutionManager { */ case OperationStatus.NoOp: { if (!silent) { - record.collatedWriter.terminal.writeStdoutLine(colors.gray(`"${name}" did not define any work.`)); + record.collatedWriter.terminal.writeStdoutLine(Colorize.gray(`"${name}" did not define any work.`)); } break; } @@ -379,7 +384,7 @@ export class OperationExecutionManager { case OperationStatus.Success: { if (!silent) { record.collatedWriter.terminal.writeStdoutLine( - colors.green(`"${name}" completed successfully in ${record.stopwatch.toString()}.`) + Colorize.green(`"${name}" completed successfully in ${record.stopwatch.toString()}.`) ); } break; @@ -388,7 +393,7 @@ export class OperationExecutionManager { case OperationStatus.SuccessWithWarning: { if (!silent) { record.collatedWriter.terminal.writeStderrLine( - colors.yellow(`"${name}" completed with warnings in ${record.stopwatch.toString()}.`) + Colorize.yellow(`"${name}" completed with warnings in ${record.stopwatch.toString()}.`) ); } this._hasAnyNonAllowedWarnings = this._hasAnyNonAllowedWarnings || !runner.warningsAreAllowed; diff --git a/libraries/rush-lib/src/logic/operations/OperationResultSummarizerPlugin.ts b/libraries/rush-lib/src/logic/operations/OperationResultSummarizerPlugin.ts index df9d93369a4..a0bd482bf19 100644 --- a/libraries/rush-lib/src/logic/operations/OperationResultSummarizerPlugin.ts +++ b/libraries/rush-lib/src/logic/operations/OperationResultSummarizerPlugin.ts @@ -1,9 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; import { InternalError } from '@rushstack/node-core-library'; -import type { ITerminal } from '@rushstack/terminal'; +import { Colorize, type ITerminal } from '@rushstack/terminal'; import type { ICreateOperationsContext, @@ -90,7 +89,7 @@ export function _printOperationStatus(terminal: ITerminal, result: IExecutionRes terminal, OperationStatus.Skipped, operationsByStatus, - colors.green, + Colorize.green, 'These operations were already up to date:' ); @@ -98,7 +97,7 @@ export function _printOperationStatus(terminal: ITerminal, result: IExecutionRes terminal, OperationStatus.NoOp, operationsByStatus, - colors.gray, + Colorize.gray, 'These operations did not define any work:' ); @@ -106,7 +105,7 @@ export function _printOperationStatus(terminal: ITerminal, result: IExecutionRes terminal, OperationStatus.FromCache, operationsByStatus, - colors.green, + Colorize.green, 'These operations were restored from the build cache:' ); @@ -114,7 +113,7 @@ export function _printOperationStatus(terminal: ITerminal, result: IExecutionRes terminal, OperationStatus.Success, operationsByStatus, - colors.green, + Colorize.green, 'These operations completed successfully:' ); @@ -122,7 +121,7 @@ export function _printOperationStatus(terminal: ITerminal, result: IExecutionRes terminal, OperationStatus.SuccessWithWarning, operationsByStatus, - colors.yellow, + Colorize.yellow, 'WARNING' ); @@ -130,11 +129,11 @@ export function _printOperationStatus(terminal: ITerminal, result: IExecutionRes terminal, OperationStatus.Blocked, operationsByStatus, - colors.white, + Colorize.white, 'These operations were blocked by dependencies that failed:' ); - writeDetailedSummary(terminal, OperationStatus.Failure, operationsByStatus, colors.red); + writeDetailedSummary(terminal, OperationStatus.Failure, operationsByStatus, Colorize.red); terminal.writeLine(''); @@ -243,9 +242,9 @@ function writeDetailedSummary( ); terminal.writeLine( - `${colors.gray('--[')} ${headingColor(subheadingText)} ${colors.gray( + `${Colorize.gray('--[')} ${headingColor(subheadingText)} ${Colorize.gray( `]${'-'.repeat(middlePartLengthMinusTwoBrackets)}[` - )} ${colors.white(time)} ${colors.gray(']--')}\n` + )} ${Colorize.white(time)} ${Colorize.gray(']--')}\n` ); const details: string = operationResult.stdioSummarizer.getReport(); @@ -282,7 +281,7 @@ function writeSummaryHeader( // rightPart: "]======================" terminal.writeLine( - `${colors.gray('==[')} ${headingColor(headingText)} ${colors.gray( + `${Colorize.gray('==[')} ${headingColor(headingText)} ${Colorize.gray( `]${'='.repeat(rightPartLengthMinusBracket)}` )}\n` ); diff --git a/libraries/rush-lib/src/logic/operations/test/OperationExecutionManager.test.ts b/libraries/rush-lib/src/logic/operations/test/OperationExecutionManager.test.ts index 281703c752a..2eefd22dd5a 100644 --- a/libraries/rush-lib/src/logic/operations/test/OperationExecutionManager.test.ts +++ b/libraries/rush-lib/src/logic/operations/test/OperationExecutionManager.test.ts @@ -4,7 +4,16 @@ // The TaskExecutionManager prints "x.xx seconds" in TestRunner.test.ts.snap; ensure that the Stopwatch timing is deterministic jest.mock('../../../utilities/Utilities'); -import colors from 'colors/safe'; +jest.mock('@rushstack/terminal', () => { + const originalModule = jest.requireActual('@rushstack/terminal'); + return { + ...originalModule, + ConsoleTerminalProvider: { + ...originalModule.ConsoleTerminalProvider, + supportsColor: true + } + }; +}); import { Terminal } from '@rushstack/terminal'; import { CollatedTerminal } from '@rushstack/stream-collator'; @@ -51,19 +60,6 @@ describe(OperationExecutionManager.name, () => { let executionManager: OperationExecutionManager; let executionManagerOptions: IOperationExecutionManagerOptions; - let initialColorsEnabled: boolean; - - beforeAll(() => { - initialColorsEnabled = colors.enabled; - colors.enable(); - }); - - afterAll(() => { - if (!initialColorsEnabled) { - colors.disable(); - } - }); - beforeEach(() => { jest.spyOn(PrintUtilities, 'getConsoleWidth').mockReturnValue(90); mockWritable.reset(); diff --git a/libraries/rush-lib/src/logic/operations/test/__snapshots__/OperationExecutionManager.test.ts.snap b/libraries/rush-lib/src/logic/operations/test/__snapshots__/OperationExecutionManager.test.ts.snap index 72414d79905..ffc0bf86867 100644 --- a/libraries/rush-lib/src/logic/operations/test/__snapshots__/OperationExecutionManager.test.ts.snap +++ b/libraries/rush-lib/src/logic/operations/test/__snapshots__/OperationExecutionManager.test.ts.snap @@ -408,7 +408,7 @@ Array [ }, Object { "kind": "O", - "text": "[cyan]success with warnings (success)[default] [yellow]!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!![default] [white]0.2s[default] + "text": "[cyan]success with warnings (success)[default] [gray][default][yellow]!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!![default][gray][default] [white]0.2s[default] ", }, Object { diff --git a/libraries/rush-lib/src/logic/pnpm/PnpmLinkManager.ts b/libraries/rush-lib/src/logic/pnpm/PnpmLinkManager.ts index b8a80a967df..eae9a15e5e7 100644 --- a/libraries/rush-lib/src/logic/pnpm/PnpmLinkManager.ts +++ b/libraries/rush-lib/src/logic/pnpm/PnpmLinkManager.ts @@ -6,7 +6,6 @@ import * as crypto from 'crypto'; import uriEncode from 'strict-uri-encode'; import pnpmLinkBins from '@pnpm/link-bins'; import * as semver from 'semver'; -import colors from 'colors/safe'; import { AlreadyReportedError, @@ -15,6 +14,7 @@ import { InternalError, Path } from '@rushstack/node-core-library'; +import { Colorize } from '@rushstack/terminal'; import { BaseLinkManager } from '../base/BaseLinkManager'; import { BasePackage } from '../base/BasePackage'; @@ -45,7 +45,7 @@ export class PnpmLinkManager extends BaseLinkManager { if (useWorkspaces) { // eslint-disable-next-line no-console console.log( - colors.red( + Colorize.red( 'Linking is not supported when using workspaces. Run "rush install" or "rush update" ' + 'to restore project node_modules folders.' ) @@ -76,7 +76,7 @@ export class PnpmLinkManager extends BaseLinkManager { } else { // eslint-disable-next-line no-console console.log( - colors.yellow( + Colorize.yellow( '\nWarning: Nothing to do. Please edit rush.json and add at least one project' + ' to the "projects" section.\n' ) @@ -281,7 +281,7 @@ export class PnpmLinkManager extends BaseLinkManager { await pnpmLinkBins(projectFolder, projectBinFolder, { warn: (msg: string) => { // eslint-disable-next-line no-console - console.warn(colors.yellow(msg)); + console.warn(Colorize.yellow(msg)); } }); } diff --git a/libraries/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts b/libraries/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts index 52bc7f492d0..ba94c34c0b2 100644 --- a/libraries/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts +++ b/libraries/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts @@ -4,7 +4,7 @@ import * as path from 'path'; import * as semver from 'semver'; import crypto from 'crypto'; -import colors from 'colors/safe'; + import { FileSystem, AlreadyReportedError, @@ -13,6 +13,7 @@ import { type IPackageJson, InternalError } from '@rushstack/node-core-library'; +import { Colorize } from '@rushstack/terminal'; import { BaseShrinkwrapFile } from '../base/BaseShrinkwrapFile'; import { DependencySpecifier } from '../DependencySpecifier'; @@ -350,7 +351,7 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile { if (!policyOptions.repoState.isValid) { // eslint-disable-next-line no-console console.log( - colors.red( + Colorize.red( `The ${RushConstants.repoStateFilename} file is invalid. There may be a merge conflict marker ` + 'in the file. You may need to run "rush update" to refresh its contents.' ) + '\n' @@ -364,7 +365,7 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile { if (!policyOptions.repoState.pnpmShrinkwrapHash) { // eslint-disable-next-line no-console console.log( - colors.red( + Colorize.red( 'The existing shrinkwrap file hash could not be found. You may need to run "rush update" to ' + 'populate the hash. See the "preventManualShrinkwrapChanges" setting documentation for details.' ) + '\n' @@ -375,7 +376,7 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile { if (this.getShrinkwrapHash(experimentsConfig) !== policyOptions.repoState.pnpmShrinkwrapHash) { // eslint-disable-next-line no-console console.log( - colors.red( + Colorize.red( 'The shrinkwrap file hash does not match the expected hash. Please run "rush update" to ensure the ' + 'shrinkwrap file is up to date. See the "preventManualShrinkwrapChanges" setting documentation for ' + 'details.' @@ -743,14 +744,14 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile { if (err instanceof SyntaxError) { // eslint-disable-next-line no-console console.error( - colors.red( + Colorize.red( `A syntax error in the ${RushConstants.pnpmfileV6Filename} at ${subspacePnpmfilePath}\n` ) ); } else { // eslint-disable-next-line no-console console.error( - colors.red( + Colorize.red( `Error during pnpmfile execution. pnpmfile: "${subspacePnpmfilePath}". Error: "${err.message}".` + '\n' ) @@ -773,7 +774,7 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile { } catch (err) { // eslint-disable-next-line no-console console.error( - colors.red( + Colorize.red( `Error during readPackage hook execution. pnpmfile: "${subspacePnpmfilePath}". Error: "${err.message}".` + '\n' ) diff --git a/libraries/rush-lib/src/logic/policy/GitEmailPolicy.ts b/libraries/rush-lib/src/logic/policy/GitEmailPolicy.ts index 863062eec3f..5a995b3ce03 100644 --- a/libraries/rush-lib/src/logic/policy/GitEmailPolicy.ts +++ b/libraries/rush-lib/src/logic/policy/GitEmailPolicy.ts @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; import { AlreadyReportedError } from '@rushstack/node-core-library'; +import { Colorize } from '@rushstack/terminal'; import type { RushConfiguration } from '../../api/RushConfiguration'; import { Utilities } from '../../utilities/Utilities'; @@ -18,7 +18,7 @@ export function validate(rushConfiguration: RushConfiguration, options: IPolicyV // then we don't care about the Git email // eslint-disable-next-line no-console console.log( - colors.cyan('Ignoring Git validation because the Git binary was not found in the shell path.') + '\n' + Colorize.cyan('Ignoring Git validation because the Git binary was not found in the shell path.') + '\n' ); return; } @@ -27,7 +27,7 @@ export function validate(rushConfiguration: RushConfiguration, options: IPolicyV // If Git isn't installed, or this Rush project is not under a Git working folder, // then we don't care about the Git email // eslint-disable-next-line no-console - console.log(colors.cyan('Ignoring Git validation because this is not a Git working folder.') + '\n'); + console.log(Colorize.cyan('Ignoring Git validation because this is not a Git working folder.') + '\n'); return; } @@ -52,7 +52,7 @@ export function validate(rushConfiguration: RushConfiguration, options: IPolicyV // eslint-disable-next-line no-console console.log( [ - colors.red('Your Git email address is invalid: ' + JSON.stringify(userEmail)), + Colorize.red('Your Git email address is invalid: ' + JSON.stringify(userEmail)), '', `To configure your Git email address, try something like this:`, '', @@ -70,7 +70,7 @@ export function validate(rushConfiguration: RushConfiguration, options: IPolicyV } // eslint-disable-next-line no-console - console.log(colors.red(errorMessage)); + console.log(Colorize.red(errorMessage)); throw e; } else { throw e; @@ -95,7 +95,7 @@ export function validate(rushConfiguration: RushConfiguration, options: IPolicyV // Show the user's name as well. // Ex. "Example Name " - let fancyEmail: string = colors.cyan(userEmail); + let fancyEmail: string = Colorize.cyan(userEmail); try { const userName: string = Utilities.executeCommandAndCaptureOutput( git.gitPath!, @@ -115,7 +115,7 @@ export function validate(rushConfiguration: RushConfiguration, options: IPolicyV 'Hey there! To keep things tidy, this repo asks you to submit your Git commits using an email like ' + (rushConfiguration.gitAllowedEmailRegExps.length > 1 ? 'one of these patterns:' : 'this pattern:'), '', - ...rushConfiguration.gitAllowedEmailRegExps.map((pattern) => ' ' + colors.cyan(pattern)), + ...rushConfiguration.gitAllowedEmailRegExps.map((pattern) => ' ' + Colorize.cyan(pattern)), '', '...but yours is configured like this:', '', @@ -134,14 +134,14 @@ export function validate(rushConfiguration: RushConfiguration, options: IPolicyV } // eslint-disable-next-line no-console - console.log(colors.red(errorMessage)); + console.log(Colorize.red(errorMessage)); throw new AlreadyReportedError(); } export function getEmailExampleLines(rushConfiguration: RushConfiguration): string[] { return [ - colors.cyan(' git config --local user.name "Example Name"'), - colors.cyan( + Colorize.cyan(' git config --local user.name "Example Name"'), + Colorize.cyan( ` git config --local user.email "${rushConfiguration.gitSampleEmail || 'name@example.com'}"` ) ]; diff --git a/libraries/rush-lib/src/logic/setup/KeyboardLoop.ts b/libraries/rush-lib/src/logic/setup/KeyboardLoop.ts index b5dfd578442..403ba12ebb3 100644 --- a/libraries/rush-lib/src/logic/setup/KeyboardLoop.ts +++ b/libraries/rush-lib/src/logic/setup/KeyboardLoop.ts @@ -1,10 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; import * as readline from 'readline'; import * as process from 'process'; import { AlreadyReportedError, InternalError } from '@rushstack/node-core-library'; +import { Colorize } from '@rushstack/terminal'; // TODO: Integrate these into the AnsiEscape API in @rushstack/terminal // As part of that work we should generalize the "Colorize" API to support more general @@ -55,7 +55,7 @@ export class KeyboardLoop { // Git Bash has a known problem where the Node.js TTY is lost when invoked via an NPM binary script. // eslint-disable-next-line no-console console.error( - colors.red( + Colorize.red( 'ERROR: It appears that Rush was invoked from Git Bash shell, which does not support the\n' + 'TTY mode for interactive input that is required by this feature.' ) + @@ -72,7 +72,7 @@ export class KeyboardLoop { // eslint-disable-next-line no-console console.error( - colors.red( + Colorize.red( 'ERROR: Rush was invoked by a command whose STDIN does not support the TTY mode for\n' + 'interactive input that is required by this feature.' ) + '\n\nTry invoking "rush" directly from your shell.' diff --git a/libraries/rush-lib/src/logic/setup/TerminalInput.ts b/libraries/rush-lib/src/logic/setup/TerminalInput.ts index 47bf4f144ae..9c838414411 100644 --- a/libraries/rush-lib/src/logic/setup/TerminalInput.ts +++ b/libraries/rush-lib/src/logic/setup/TerminalInput.ts @@ -3,8 +3,8 @@ import * as readline from 'readline'; import * as process from 'process'; -import colors from 'colors/safe'; -import { AnsiEscape } from '@rushstack/terminal'; + +import { AnsiEscape, Colorize } from '@rushstack/terminal'; import { KeyboardLoop } from './KeyboardLoop'; @@ -36,8 +36,8 @@ class YesNoKeyboardLoop extends KeyboardLoop { } protected onStart(): void { - this.stderr.write(colors.green('==>') + ' '); - this.stderr.write(colors.bold(this.options.message)); + this.stderr.write(Colorize.green('==>') + ' '); + this.stderr.write(Colorize.bold(this.options.message)); let optionSuffix: string = ''; switch (this.options.defaultValue) { case true: @@ -50,7 +50,7 @@ class YesNoKeyboardLoop extends KeyboardLoop { optionSuffix = '(y/n)'; break; } - this.stderr.write(' ' + colors.bold(optionSuffix) + ' '); + this.stderr.write(' ' + Colorize.bold(optionSuffix) + ' '); } protected onKeypress(character: string, key: readline.Key): void { @@ -107,7 +107,7 @@ class PasswordKeyboardLoop extends KeyboardLoop { readline.cursorTo(this.stderr, 0); readline.clearLine(this.stderr, 1); - const prefix: string = colors.green('==>') + ' ' + colors.bold(this._options.message) + ' '; + const prefix: string = Colorize.green('==>') + ' ' + Colorize.bold(this._options.message) + ' '; this.stderr.write(prefix); let lineStartIndex: number = prefix.lastIndexOf('\n'); @@ -225,8 +225,8 @@ export class TerminalInput { public static async promptLine(options: IPromptLineOptions): Promise { const stderr: NodeJS.WriteStream = process.stderr; - stderr.write(colors.green('==>') + ' '); - stderr.write(colors.bold(options.message)); + stderr.write(Colorize.green('==>') + ' '); + stderr.write(Colorize.bold(options.message)); stderr.write(' '); return await TerminalInput._readLine(); } diff --git a/libraries/rush-lib/src/logic/versionMismatch/VersionMismatchFinder.ts b/libraries/rush-lib/src/logic/versionMismatch/VersionMismatchFinder.ts index cebeff4b29c..532e76637ab 100644 --- a/libraries/rush-lib/src/logic/versionMismatch/VersionMismatchFinder.ts +++ b/libraries/rush-lib/src/logic/versionMismatch/VersionMismatchFinder.ts @@ -1,9 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors/safe'; import { AlreadyReportedError } from '@rushstack/node-core-library'; -import type { ITerminal } from '@rushstack/terminal'; +import { Colorize, type ITerminal } from '@rushstack/terminal'; import type { RushConfiguration } from '../../api/RushConfiguration'; import { type PackageJsonDependency, DependencyType } from '../../api/PackageJsonEditor'; @@ -150,7 +149,7 @@ export class VersionMismatchFinder { if (mismatchFinder.numberOfMismatches > 0) { // eslint-disable-next-line no-console console.log( - colors.red( + Colorize.red( `Found ${mismatchFinder.numberOfMismatches} mis-matching dependencies ${ options.subspaceName ? `in subspace: ${options.subspaceName}` : '' }` @@ -172,7 +171,7 @@ export class VersionMismatchFinder { } else { if (options.isRushCheckCommand) { // eslint-disable-next-line no-console - console.log(colors.green(`Found no mis-matching dependencies!`)); + console.log(Colorize.green(`Found no mis-matching dependencies!`)); } } } @@ -244,7 +243,7 @@ export class VersionMismatchFinder { // Iterate over the list. For any dependency with mismatching versions, print the projects this.getMismatches().forEach((dependency: string) => { // eslint-disable-next-line no-console - console.log(colors.yellow(dependency)); + console.log(Colorize.yellow(dependency)); this.getVersionsOfMismatch(dependency)!.forEach((version: string) => { // eslint-disable-next-line no-console console.log(` ${version}`); diff --git a/libraries/rush-lib/src/utilities/InteractiveUpgradeUI.ts b/libraries/rush-lib/src/utilities/InteractiveUpgradeUI.ts index af697bfdf1c..eb9562f9f31 100644 --- a/libraries/rush-lib/src/utilities/InteractiveUpgradeUI.ts +++ b/libraries/rush-lib/src/utilities/InteractiveUpgradeUI.ts @@ -6,10 +6,10 @@ // Extended to use one type of text table import inquirer from 'inquirer'; -import colors from 'colors/safe'; import CliTable from 'cli-table'; import type Separator from 'inquirer/lib/objects/separator'; import type * as NpmCheck from 'npm-check'; +import { AnsiEscape, Colorize } from '@rushstack/terminal'; export interface IUIGroup { title: string; @@ -34,19 +34,19 @@ export interface IUpgradeInteractiveDepChoice { type ChoiceTable = (Separator | IUpgradeInteractiveDepChoice | boolean | undefined)[] | undefined; function greenUnderlineBold(text: string): string { - return colors.underline(colors.bold(colors.green(text))); + return Colorize.underline(Colorize.bold(Colorize.green(text))); } function yellowUnderlineBold(text: string): string { - return colors.underline(colors.bold(colors.yellow(text))); + return Colorize.underline(Colorize.bold(Colorize.yellow(text))); } function redUnderlineBold(text: string): string { - return colors.underline(colors.bold(colors.red(text))); + return Colorize.underline(Colorize.bold(Colorize.red(text))); } function magentaUnderlineBold(text: string): string { - return colors.underline(colors.bold(colors.magenta(text))); + return Colorize.underline(Colorize.bold(Colorize.magenta(text))); } export const UI_GROUPS: IUIGroup[] = [ @@ -55,26 +55,26 @@ export const UI_GROUPS: IUIGroup[] = [ filter: { mismatch: true, bump: undefined } }, { - title: `${greenUnderlineBold('Missing.')} ${colors.green('You probably want these.')}`, + title: `${greenUnderlineBold('Missing.')} ${Colorize.green('You probably want these.')}`, filter: { notInstalled: true, bump: undefined } }, { - title: `${greenUnderlineBold('Patch Update')} ${colors.green('Backwards-compatible bug fixes.')}`, + title: `${greenUnderlineBold('Patch Update')} ${Colorize.green('Backwards-compatible bug fixes.')}`, filter: { bump: 'patch' } }, { - title: `${yellowUnderlineBold('Minor Update')} ${colors.yellow('New backwards-compatible features.')}`, + title: `${yellowUnderlineBold('Minor Update')} ${Colorize.yellow('New backwards-compatible features.')}`, bgColor: 'yellow', filter: { bump: 'minor' } }, { - title: `${redUnderlineBold('Major Update')} ${colors.red( + title: `${redUnderlineBold('Major Update')} ${Colorize.red( 'Potentially breaking API changes. Use caution.' )}`, filter: { bump: 'major' } }, { - title: `${magentaUnderlineBold('Non-Semver')} ${colors.magenta('Versions less than 1.0.0, caution.')}`, + title: `${magentaUnderlineBold('Non-Semver')} ${Colorize.magenta('Versions less than 1.0.0, caution.')}`, filter: { bump: 'nonSemver' } } ]; @@ -82,16 +82,16 @@ export const UI_GROUPS: IUIGroup[] = [ function label(dep: NpmCheck.INpmCheckPackage): string[] { const bumpInstalled: string = dep.bump ? dep.installed : ''; const installed: string = dep.mismatch ? dep.packageJson : bumpInstalled; - const name: string = colors.yellow(dep.moduleName); - const type: string = dep.devDependency ? colors.green(' devDep') : ''; - const missing: string = dep.notInstalled ? colors.red(' missing') : ''; - const homepage: string = dep.homepage ? colors.blue(colors.underline(dep.homepage)) : ''; + const name: string = Colorize.yellow(dep.moduleName); + const type: string = dep.devDependency ? Colorize.green(' devDep') : ''; + const missing: string = dep.notInstalled ? Colorize.red(' missing') : ''; + const homepage: string = dep.homepage ? Colorize.blue(Colorize.underline(dep.homepage)) : ''; return [ name + type + missing, installed, installed && '>', - colors.bold(dep.latest || ''), + Colorize.bold(dep.latest || ''), dep.latest ? homepage : dep.regError || dep.pkgError ]; } @@ -113,7 +113,7 @@ function getChoice(dep: NpmCheck.INpmCheckPackage): IUpgradeInteractiveDepChoice } function unselectable(options?: { title: string }): Separator { - return new inquirer.Separator(colors.reset(options ? options.title : '')); + return new inquirer.Separator(AnsiEscape.removeCodes(options ? options.title : '')); } function createChoices(packages: NpmCheck.INpmCheckPackage[], options: IUIGroup): ChoiceTable { diff --git a/libraries/rush-lib/src/utilities/prompts/SearchListPrompt.ts b/libraries/rush-lib/src/utilities/prompts/SearchListPrompt.ts index b7b0165a104..7065ef21a13 100644 --- a/libraries/rush-lib/src/utilities/prompts/SearchListPrompt.ts +++ b/libraries/rush-lib/src/utilities/prompts/SearchListPrompt.ts @@ -2,7 +2,7 @@ // See LICENSE in the project root for license information. import type { Interface } from 'readline'; -import colors from 'colors/safe'; +import { Colorize } from '@rushstack/terminal'; // Modified from the choice list prompt in inquirer: // https://github.com/SBoudrias/Inquirer.js/blob/inquirer%407.3.3/packages/inquirer/lib/prompts/list.js @@ -214,12 +214,12 @@ export class SearchListPrompt extends BasePrompt { let bottomContent: string = ''; if (this._firstRender) { - message += colors.dim(' (Use arrow keys)'); + message += Colorize.dim(' (Use arrow keys)'); } // Render choices or answer depending on the state if (this.status === 'answered') { - message += colors.cyan(this.opt.choices.getChoice(this._selected).short!); + message += Colorize.cyan(this.opt.choices.getChoice(this._selected).short!); } else { const choicesStr: string = listRender(this.opt.choices, this._selected); const indexPosition: number = this.opt.choices.indexOf( @@ -254,13 +254,15 @@ export class SearchListPrompt extends BasePrompt { // eslint-disable-next-line no-bitwise realIndexPosition += ((line.length / process.stdout.columns!) | 0) + 1; } - message += `\n${colors.white(colors.bold('Start typing to filter:'))} ${colors.cyan(this._query)}`; + message += `\n${Colorize.white(Colorize.bold('Start typing to filter:'))} ${Colorize.cyan( + this._query + )}`; // @ts-expect-error Types are wrong message += '\n' + this._paginator.paginate(choicesStr, realIndexPosition, this.opt.pageSize!); } if (error) { - bottomContent = colors.red('>> ') + error; + bottomContent = Colorize.red('>> ') + error; } this.screen.render(message, bottomContent); @@ -279,7 +281,7 @@ function listRender(choices: Choices, pointer: number): string { if (!choice.disabled) { const line: string = choice.name; if (i === pointer) { - output += colors.cyan(figures.pointer + line); + output += Colorize.cyan(figures.pointer + line); } else { output += ' ' + line; } diff --git a/libraries/terminal/src/ConsoleTerminalProvider.ts b/libraries/terminal/src/ConsoleTerminalProvider.ts index 0d362396a46..e4aaba7a6d3 100644 --- a/libraries/terminal/src/ConsoleTerminalProvider.ts +++ b/libraries/terminal/src/ConsoleTerminalProvider.ts @@ -27,11 +27,13 @@ export interface IConsoleTerminalProviderOptions { /** * Terminal provider that prints to STDOUT (for log- and verbose-level messages) and - * STDERR (for warning- and error-level messsages). + * STDERR (for warning- and error-level messages). * * @beta */ export class ConsoleTerminalProvider implements ITerminalProvider { + public static readonly supportsColor: boolean = supportsColor; + /** * If true, verbose-level messages should be written to the console. */ diff --git a/libraries/terminal/src/test/AnsiEscape.test.ts b/libraries/terminal/src/test/AnsiEscape.test.ts index 8747d13d5bf..644f8eb09dd 100644 --- a/libraries/terminal/src/test/AnsiEscape.test.ts +++ b/libraries/terminal/src/test/AnsiEscape.test.ts @@ -1,7 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import * as colors from 'colors'; +// Explicitly use the colors package here instead of Colorize +import colors from 'colors/safe'; import { AnsiEscape } from '../AnsiEscape'; describe(AnsiEscape.name, () => { diff --git a/libraries/terminal/src/test/RemoveColorsTextRewriter.test.ts b/libraries/terminal/src/test/RemoveColorsTextRewriter.test.ts index ffffcb976c0..ba3a789f17b 100644 --- a/libraries/terminal/src/test/RemoveColorsTextRewriter.test.ts +++ b/libraries/terminal/src/test/RemoveColorsTextRewriter.test.ts @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors'; import { AnsiEscape } from '../AnsiEscape'; +import { Colorize } from '../Colorize'; import { RemoveColorsTextRewriter } from '../RemoveColorsTextRewriter'; import type { TextRewriterState } from '../TextRewriter'; @@ -24,19 +24,6 @@ function testCase(inputs: string[]): void { } describe(RemoveColorsTextRewriter.name, () => { - let initialColorsEnabled: boolean; - - beforeAll(() => { - initialColorsEnabled = colors.enabled; - colors.enable(); - }); - - afterAll(() => { - if (!initialColorsEnabled) { - colors.disable(); - } - }); - it('01 should process empty inputs', () => { testCase([]); testCase(['']); @@ -44,13 +31,13 @@ describe(RemoveColorsTextRewriter.name, () => { }); it('02 should remove colors from complete chunks', () => { - testCase([colors.red('1')]); - testCase([colors.red('1') + colors.green('2')]); - testCase([colors.red('1') + '2' + colors.green('3')]); + testCase([Colorize.red('1')]); + testCase([Colorize.red('1') + Colorize.green('2')]); + testCase([Colorize.red('1') + '2' + Colorize.green('3')]); }); it('03 should remove colors from 1-character chunks', () => { - const source: string = '1' + colors.red('2'); + const source: string = '1' + Colorize.red('2'); const inputs: string[] = []; for (let i: number = 0; i < source.length; ++i) { inputs.push(source.substr(i, 1)); diff --git a/libraries/terminal/src/test/TextRewriterTransform.test.ts b/libraries/terminal/src/test/TextRewriterTransform.test.ts index 74c1a5ba6a4..583cf70316d 100644 --- a/libraries/terminal/src/test/TextRewriterTransform.test.ts +++ b/libraries/terminal/src/test/TextRewriterTransform.test.ts @@ -1,12 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import colors from 'colors'; +import { NewlineKind, Text } from '@rushstack/node-core-library'; +import { Colorize } from '../Colorize'; import { TerminalChunkKind } from '../ITerminalChunk'; import { MockWritable } from '../MockWritable'; import { TextRewriterTransform } from '../TextRewriterTransform'; -import { NewlineKind, Text } from '@rushstack/node-core-library'; describe(TextRewriterTransform.name, () => { it('should apply standard rewriters', () => { @@ -19,7 +19,7 @@ describe(TextRewriterTransform.name, () => { }); // This color code will be removed - transform.writeChunk({ text: colors.red('RED'), kind: TerminalChunkKind.Stderr }); + transform.writeChunk({ text: Colorize.red('RED'), kind: TerminalChunkKind.Stderr }); // These newlines will be converted to \n transform.writeChunk({ text: 'stderr 1\r\nstderr 2\r\n', kind: TerminalChunkKind.Stderr }); diff --git a/libraries/ts-command-line/package.json b/libraries/ts-command-line/package.json index 2d543f92948..0f207a3be1f 100644 --- a/libraries/ts-command-line/package.json +++ b/libraries/ts-command-line/package.json @@ -16,9 +16,9 @@ }, "license": "MIT", "dependencies": { + "@rushstack/terminal": "workspace:*", "@types/argparse": "1.0.38", "argparse": "~1.0.9", - "colors": "~1.2.1", "string-argv": "~0.3.1" }, "devDependencies": { diff --git a/libraries/ts-command-line/src/providers/CommandLineParser.ts b/libraries/ts-command-line/src/providers/CommandLineParser.ts index bfae5a4b7da..bb0d4dd4a98 100644 --- a/libraries/ts-command-line/src/providers/CommandLineParser.ts +++ b/libraries/ts-command-line/src/providers/CommandLineParser.ts @@ -2,7 +2,7 @@ // See LICENSE in the project root for license information. import type * as argparse from 'argparse'; -import colors from 'colors'; +import { Colorize } from '@rushstack/terminal'; import type { CommandLineAction } from './CommandLineAction'; import type { AliasCommandLineAction } from './AliasCommandLineAction'; @@ -78,7 +78,7 @@ export abstract class CommandLineParser extends CommandLineParameterProvider { addHelp: true, prog: this._options.toolFilename, description: this._options.toolDescription, - epilog: colors.bold( + epilog: Colorize.bold( this._options.toolEpilog ?? `For detailed help about a specific command, use: ${this._options.toolFilename} -h` ) @@ -178,7 +178,7 @@ export abstract class CommandLineParser extends CommandLineParameterProvider { // eslint-disable-next-line no-console console.error(); // eslint-disable-next-line no-console - console.error(colors.red(message)); + console.error(Colorize.red(message)); if (!process.exitCode) { process.exitCode = 1; diff --git a/libraries/ts-command-line/src/test/CommandLineParameter.test.ts b/libraries/ts-command-line/src/test/CommandLineParameter.test.ts index 795b0f6e015..6c802279934 100644 --- a/libraries/ts-command-line/src/test/CommandLineParameter.test.ts +++ b/libraries/ts-command-line/src/test/CommandLineParameter.test.ts @@ -1,13 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import * as colors from 'colors'; - import { DynamicCommandLineParser } from '../providers/DynamicCommandLineParser'; import { DynamicCommandLineAction } from '../providers/DynamicCommandLineAction'; import { CommandLineParameter } from '../parameters/BaseClasses'; import type { CommandLineParser } from '../providers/CommandLineParser'; import type { CommandLineAction } from '../providers/CommandLineAction'; +import { AnsiEscape } from '@rushstack/terminal'; function createParser(): DynamicCommandLineParser { const commandLineParser: DynamicCommandLineParser = new DynamicCommandLineParser({ @@ -154,13 +153,15 @@ const snapshotPropertyNames: string[] = [ describe(CommandLineParameter.name, () => { it('prints the global help', () => { const commandLineParser: CommandLineParser = createParser(); - const helpText: string = colors.stripColors(commandLineParser.renderHelpText()); + const helpText: string = AnsiEscape.removeCodes(commandLineParser.renderHelpText()); expect(helpText).toMatchSnapshot(); }); it('prints the action help', () => { const commandLineParser: CommandLineParser = createParser(); - const helpText: string = colors.stripColors(commandLineParser.getAction('do:the-job').renderHelpText()); + const helpText: string = AnsiEscape.removeCodes( + commandLineParser.getAction('do:the-job').renderHelpText() + ); expect(helpText).toMatchSnapshot(); }); diff --git a/libraries/ts-command-line/src/test/CommandLineRemainder.test.ts b/libraries/ts-command-line/src/test/CommandLineRemainder.test.ts index e0cc2d2a6f4..e0a1f32463e 100644 --- a/libraries/ts-command-line/src/test/CommandLineRemainder.test.ts +++ b/libraries/ts-command-line/src/test/CommandLineRemainder.test.ts @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import * as colors from 'colors'; +import { AnsiEscape } from '@rushstack/terminal'; import type { CommandLineAction } from '../providers/CommandLineAction'; import type { CommandLineParser } from '../providers/CommandLineParser'; @@ -45,13 +45,13 @@ function createParser(): DynamicCommandLineParser { describe(CommandLineRemainder.name, () => { it('prints the global help', () => { const commandLineParser: CommandLineParser = createParser(); - const helpText: string = colors.stripColors(commandLineParser.renderHelpText()); + const helpText: string = AnsiEscape.removeCodes(commandLineParser.renderHelpText()); expect(helpText).toMatchSnapshot(); }); it('prints the action help', () => { const commandLineParser: CommandLineParser = createParser(); - const helpText: string = colors.stripColors(commandLineParser.getAction('run').renderHelpText()); + const helpText: string = AnsiEscape.removeCodes(commandLineParser.getAction('run').renderHelpText()); expect(helpText).toMatchSnapshot(); }); diff --git a/libraries/ts-command-line/src/test/ScopedCommandLineAction.test.ts b/libraries/ts-command-line/src/test/ScopedCommandLineAction.test.ts index 30c4999667b..be20da6abb8 100644 --- a/libraries/ts-command-line/src/test/ScopedCommandLineAction.test.ts +++ b/libraries/ts-command-line/src/test/ScopedCommandLineAction.test.ts @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import * as colors from 'colors'; +import { AnsiEscape } from '@rushstack/terminal'; import { ScopedCommandLineAction } from '../providers/ScopedCommandLineAction'; import type { CommandLineStringParameter } from '../parameters/CommandLineStringParameter'; @@ -98,7 +98,7 @@ describe(CommandLineParser.name, () => { it('prints the action help', () => { const commandLineParser: TestCommandLine = new TestCommandLine(); - const helpText: string = colors.stripColors( + const helpText: string = AnsiEscape.removeCodes( commandLineParser.getAction('scoped-action').renderHelpText() ); expect(helpText).toMatchSnapshot(); @@ -113,7 +113,7 @@ describe(CommandLineParser.name, () => { _getScopedCommandLineParser(): CommandLineParser; }; const scopedCommandLineParser: CommandLineParser = scopedAction._getScopedCommandLineParser(); - const helpText: string = colors.stripColors(scopedCommandLineParser.renderHelpText()); + const helpText: string = AnsiEscape.removeCodes(scopedCommandLineParser.renderHelpText()); expect(helpText).toMatchSnapshot(); });