diff --git a/packages/aws-cdk/lib/api/cxapp/cloud-assembly.ts b/packages/aws-cdk/lib/api/cxapp/cloud-assembly.ts index d02e9b12d5008..421efe55327e0 100644 --- a/packages/aws-cdk/lib/api/cxapp/cloud-assembly.ts +++ b/packages/aws-cdk/lib/api/cxapp/cloud-assembly.ts @@ -1,10 +1,10 @@ import * as cxapi from '@aws-cdk/cx-api'; -import * as chalk from 'chalk'; import { minimatch } from 'minimatch'; import * as semver from 'semver'; import { error, print, warning } from '../../logging'; import { ToolkitError } from '../../toolkit/error'; import { flatten } from '../../util'; +import * as chalk from '../../util/cdk-chalk'; export enum DefaultSelection { /** diff --git a/packages/aws-cdk/lib/api/deploy-stack.ts b/packages/aws-cdk/lib/api/deploy-stack.ts index 8ec387466a14e..fa093a5c8928e 100644 --- a/packages/aws-cdk/lib/api/deploy-stack.ts +++ b/packages/aws-cdk/lib/api/deploy-stack.ts @@ -7,7 +7,6 @@ import type { UpdateStackCommandInput, Tag, } from '@aws-sdk/client-cloudformation'; -import * as chalk from 'chalk'; import * as uuid from 'uuid'; import type { SDK, SdkProvider, ICloudFormationClient } from './aws-auth'; import type { EnvironmentResources } from './environment-resources'; @@ -32,6 +31,7 @@ import { type TemplateBodyParameter, makeBodyParameter } from './util/template-b import { AssetManifestBuilder } from '../util/asset-manifest-builder'; import { determineAllowCrossAccountAssetPublishing } from './util/checks'; import { publishAssets } from '../util/asset-publishing'; +import * as chalk from '../util/cdk-chalk'; import { StringWithoutPlaceholders } from './util/placeholders'; export type DeployStackResult = diff --git a/packages/aws-cdk/lib/api/deployments.ts b/packages/aws-cdk/lib/api/deployments.ts index 030a68b90b689..d495220e71ebc 100644 --- a/packages/aws-cdk/lib/api/deployments.ts +++ b/packages/aws-cdk/lib/api/deployments.ts @@ -2,7 +2,7 @@ import { randomUUID } from 'crypto'; import * as cxapi from '@aws-cdk/cx-api'; import * as cdk_assets from 'cdk-assets'; import { AssetManifest, IManifestEntry } from 'cdk-assets'; -import * as chalk from 'chalk'; +import * as chalk from '../util/cdk-chalk'; import type { SdkProvider } from './aws-auth/sdk-provider'; import { type DeploymentMethod, deployStack, DeployStackResult, destroyStack } from './deploy-stack'; import { type EnvironmentResources } from './environment-resources'; diff --git a/packages/aws-cdk/lib/api/garbage-collection/garbage-collector.ts b/packages/aws-cdk/lib/api/garbage-collection/garbage-collector.ts index 2d7123a6e0266..d87a3180a13b5 100644 --- a/packages/aws-cdk/lib/api/garbage-collection/garbage-collector.ts +++ b/packages/aws-cdk/lib/api/garbage-collection/garbage-collector.ts @@ -1,9 +1,9 @@ import * as cxapi from '@aws-cdk/cx-api'; import { ImageIdentifier } from '@aws-sdk/client-ecr'; import { Tag } from '@aws-sdk/client-s3'; -import * as chalk from 'chalk'; import * as promptly from 'promptly'; import { debug, print } from '../../logging'; +import * as chalk from '../../util/cdk-chalk'; import { IECRClient, IS3Client, SDK, SdkProvider } from '../aws-auth'; import { DEFAULT_TOOLKIT_STACK_NAME, ToolkitInfo } from '../toolkit-info'; import { ProgressPrinter } from './progress-printer'; diff --git a/packages/aws-cdk/lib/api/garbage-collection/progress-printer.ts b/packages/aws-cdk/lib/api/garbage-collection/progress-printer.ts index 37c75d622c966..4c2778c55174d 100644 --- a/packages/aws-cdk/lib/api/garbage-collection/progress-printer.ts +++ b/packages/aws-cdk/lib/api/garbage-collection/progress-printer.ts @@ -1,6 +1,6 @@ -import * as chalk from 'chalk'; import { GcAsset as GCAsset } from './garbage-collector'; import { print } from '../../logging'; +import * as chalk from '../../util/cdk-chalk'; export class ProgressPrinter { private totalAssets: number; diff --git a/packages/aws-cdk/lib/api/hotswap-deployments.ts b/packages/aws-cdk/lib/api/hotswap-deployments.ts index 8ff3103df3fb9..a1f0d3ba2cd8c 100644 --- a/packages/aws-cdk/lib/api/hotswap-deployments.ts +++ b/packages/aws-cdk/lib/api/hotswap-deployments.ts @@ -1,11 +1,11 @@ import * as cfn_diff from '@aws-cdk/cloudformation-diff'; import * as cxapi from '@aws-cdk/cx-api'; import { WaiterResult } from '@smithy/util-waiter'; -import * as chalk from 'chalk'; import type { SDK, SdkProvider } from './aws-auth'; import type { SuccessfulDeployStackResult } from './deploy-stack'; import { EvaluateCloudFormationTemplate } from './evaluate-cloudformation-template'; import { print } from '../logging'; +import * as chalk from '../util/cdk-chalk'; import { isHotswappableAppSyncChange } from './hotswap/appsync-mapping-templates'; import { isHotswappableCodeBuildProjectChange } from './hotswap/code-build-projects'; import { diff --git a/packages/aws-cdk/lib/api/logs/logs-monitor.ts b/packages/aws-cdk/lib/api/logs/logs-monitor.ts index 5594d3f4cb8ff..8336e4b89e163 100644 --- a/packages/aws-cdk/lib/api/logs/logs-monitor.ts +++ b/packages/aws-cdk/lib/api/logs/logs-monitor.ts @@ -1,8 +1,8 @@ import * as util from 'util'; import * as cxapi from '@aws-cdk/cx-api'; -import * as chalk from 'chalk'; import { print, error } from '../../logging'; import { flatten } from '../../util/arrays'; +import * as chalk from '../../util/cdk-chalk'; import type { SDK } from '../aws-auth'; /** diff --git a/packages/aws-cdk/lib/api/plugin/plugin.ts b/packages/aws-cdk/lib/api/plugin/plugin.ts index 484dd9fa2ec8c..67410354fef89 100644 --- a/packages/aws-cdk/lib/api/plugin/plugin.ts +++ b/packages/aws-cdk/lib/api/plugin/plugin.ts @@ -1,10 +1,10 @@ import { inspect } from 'util'; import type { CredentialProviderSource, IPluginHost, Plugin } from '@aws-cdk/cli-plugin-contract'; -import * as chalk from 'chalk'; import { type ContextProviderPlugin, isContextProviderPlugin } from './context-provider-plugin'; import { error } from '../../logging'; import { ToolkitError } from '../../toolkit/error'; +import * as chalk from '../../util/cdk-chalk'; export let TESTING = false; diff --git a/packages/aws-cdk/lib/api/toolkit-info.ts b/packages/aws-cdk/lib/api/toolkit-info.ts index cd8a7420b6dd6..a06fcc943afed 100644 --- a/packages/aws-cdk/lib/api/toolkit-info.ts +++ b/packages/aws-cdk/lib/api/toolkit-info.ts @@ -1,7 +1,7 @@ import * as cxapi from '@aws-cdk/cx-api'; -import * as chalk from 'chalk'; import type { SDK } from './aws-auth'; import { debug } from '../logging'; +import * as chalk from '../util/cdk-chalk'; import { BOOTSTRAP_VARIANT_PARAMETER, BOOTSTRAP_VERSION_OUTPUT, diff --git a/packages/aws-cdk/lib/api/util/cloudformation/stack-activity-monitor.ts b/packages/aws-cdk/lib/api/util/cloudformation/stack-activity-monitor.ts index 9f1812b217af2..5f02e2314d540 100644 --- a/packages/aws-cdk/lib/api/util/cloudformation/stack-activity-monitor.ts +++ b/packages/aws-cdk/lib/api/util/cloudformation/stack-activity-monitor.ts @@ -1,10 +1,10 @@ import * as util from 'util'; import { ArtifactMetadataEntryType, type MetadataEntry } from '@aws-cdk/cloud-assembly-schema'; import type { CloudFormationStackArtifact } from '@aws-cdk/cx-api'; -import * as chalk from 'chalk'; import { ResourceEvent, StackEventPoller } from './stack-event-poller'; import { error, setIoMessageThreshold, info } from '../../../logging'; import { IoMessageLevel } from '../../../toolkit/cli-io-host'; +import * as chalk from '../../../util/cdk-chalk'; import type { ICloudFormationClient } from '../../aws-auth'; import { RewritableBlock } from '../display'; diff --git a/packages/aws-cdk/lib/api/util/template-body-parameter.ts b/packages/aws-cdk/lib/api/util/template-body-parameter.ts index 67d645127437d..8c1ee26f2e783 100644 --- a/packages/aws-cdk/lib/api/util/template-body-parameter.ts +++ b/packages/aws-cdk/lib/api/util/template-body-parameter.ts @@ -2,11 +2,11 @@ import * as path from 'path'; import { type CloudFormationStackArtifact, type Environment, EnvironmentPlaceholders } from '@aws-cdk/cx-api'; import { HeadObjectCommand, S3Client } from '@aws-sdk/client-s3'; import { getEndpointFromInstructions } from '@smithy/middleware-endpoint'; -import * as chalk from 'chalk'; import * as fs from 'fs-extra'; import { debug, error } from '../../logging'; import { toYAML } from '../../serialize'; import { AssetManifestBuilder } from '../../util/asset-manifest-builder'; +import * as chalk from '../../util/cdk-chalk'; import { contentHash } from '../../util/content-hash'; import { EnvironmentResources } from '../environment-resources'; diff --git a/packages/aws-cdk/lib/assets.ts b/packages/aws-cdk/lib/assets.ts index e1bdd5ce4fb3c..26c3be147d5ef 100644 --- a/packages/aws-cdk/lib/assets.ts +++ b/packages/aws-cdk/lib/assets.ts @@ -2,12 +2,12 @@ import * as path from 'path'; import * as cxschema from '@aws-cdk/cloud-assembly-schema'; import * as cxapi from '@aws-cdk/cx-api'; -import * as chalk from 'chalk'; import { EnvironmentResources } from './api/environment-resources'; import { ToolkitInfo } from './api/toolkit-info'; import { debug } from './logging'; import { ToolkitError } from './toolkit/error'; import { AssetManifestBuilder } from './util/asset-manifest-builder'; +import * as chalk from './util/cdk-chalk'; /** * Take the metadata assets from the given stack and add them to the given asset manifest diff --git a/packages/aws-cdk/lib/cdk-toolkit.ts b/packages/aws-cdk/lib/cdk-toolkit.ts index 0b29ef54607ea..01750f2b08c0d 100644 --- a/packages/aws-cdk/lib/cdk-toolkit.ts +++ b/packages/aws-cdk/lib/cdk-toolkit.ts @@ -1,7 +1,6 @@ import * as path from 'path'; import { format } from 'util'; import * as cxapi from '@aws-cdk/cx-api'; -import * as chalk from 'chalk'; import * as chokidar from 'chokidar'; import * as fs from 'fs-extra'; import * as promptly from 'promptly'; @@ -50,6 +49,7 @@ import { deserializeStructure, serializeStructure } from './serialize'; import { Configuration, PROJECT_CONFIG } from './settings'; import { ToolkitError } from './toolkit/error'; import { numberFromBool, partition } from './util'; +import * as chalk from './util/cdk-chalk'; import { validateSnsTopicArn } from './util/validate-notification-arn'; import { Concurrency, WorkGraph } from './util/work-graph'; import { WorkGraphBuilder } from './util/work-graph-builder'; @@ -601,9 +601,9 @@ export class CdkToolkit { anyRollbackable = true; } const elapsedRollbackTime = new Date().getTime() - startRollbackTime; - print('\n✨ Rollback time: %ss\n', formatTime(elapsedRollbackTime).toString()); + print(`\n✨ Rollback time: ${formatTime(elapsedRollbackTime).toString()}s\n`); } catch (e: any) { - error('\n ❌ %s failed: %s', chalk.bold(stack.displayName), e.message); + error(`\n ❌ ${chalk.bold(stack.displayName)} failed: ${e.message}`); throw new ToolkitError('Rollback failed (use --force to orphan failing resources)'); } } diff --git a/packages/aws-cdk/lib/cli.ts b/packages/aws-cdk/lib/cli.ts index b69b20f730a75..5af56a168a6f5 100644 --- a/packages/aws-cdk/lib/cli.ts +++ b/packages/aws-cdk/lib/cli.ts @@ -1,13 +1,13 @@ import * as cxapi from '@aws-cdk/cx-api'; import '@jsii/check-node/run'; -import * as chalk from 'chalk'; - import { DeploymentMethod } from './api'; import { HotswapMode } from './api/hotswap/common'; import { ILock } from './api/util/rwlock'; import { parseCommandLineArguments } from './parse-command-line-arguments'; import { checkForPlatformWarnings } from './platform-warnings'; import { IoMessageLevel, CliIoHost } from './toolkit/cli-io-host'; +import * as chalk from './util/cdk-chalk'; + import { enableTracing } from './util/tracing'; import { SdkProvider } from '../lib/api/aws-auth'; import { BootstrapSource, Bootstrapper } from '../lib/api/bootstrap'; diff --git a/packages/aws-cdk/lib/commands/context.ts b/packages/aws-cdk/lib/commands/context.ts index 8568efb9e1c4b..4437a2e4f603d 100644 --- a/packages/aws-cdk/lib/commands/context.ts +++ b/packages/aws-cdk/lib/commands/context.ts @@ -1,9 +1,9 @@ -import * as chalk from 'chalk'; import { minimatch } from 'minimatch'; import * as version from '../../lib/version'; import { print, error, warning, info } from '../logging'; import { Context, PROJECT_CONFIG, PROJECT_CONTEXT, USER_DEFAULTS } from '../settings'; import { renderTable } from '../util'; +import * as chalk from '../util/cdk-chalk'; /** * Options for the context command diff --git a/packages/aws-cdk/lib/commands/docs.ts b/packages/aws-cdk/lib/commands/docs.ts index 7baa89e639b6d..04ee7273c09d9 100644 --- a/packages/aws-cdk/lib/commands/docs.ts +++ b/packages/aws-cdk/lib/commands/docs.ts @@ -1,6 +1,6 @@ import * as childProcess from 'child_process'; -import * as chalk from 'chalk'; import { debug, print, warning } from '../../lib/logging'; +import * as chalk from '../util/cdk-chalk'; export const command = 'docs'; export const describe = 'Opens the reference documentation in a browser'; diff --git a/packages/aws-cdk/lib/commands/doctor.ts b/packages/aws-cdk/lib/commands/doctor.ts index 724a6cec23577..01ee18b6020b2 100644 --- a/packages/aws-cdk/lib/commands/doctor.ts +++ b/packages/aws-cdk/lib/commands/doctor.ts @@ -1,8 +1,8 @@ import * as process from 'process'; import * as cxapi from '@aws-cdk/cx-api'; -import * as chalk from 'chalk'; import { print } from '../../lib/logging'; import * as version from '../../lib/version'; +import * as chalk from '../util/cdk-chalk'; export async function doctor(): Promise { let exitStatus: number = 0; diff --git a/packages/aws-cdk/lib/commands/migrate.ts b/packages/aws-cdk/lib/commands/migrate.ts index a6da22715ddc5..a7ff30911b221 100644 --- a/packages/aws-cdk/lib/commands/migrate.ts +++ b/packages/aws-cdk/lib/commands/migrate.ts @@ -17,12 +17,12 @@ import type { ScannedResourceIdentifier, } from '@aws-sdk/client-cloudformation'; import * as cdk_from_cfn from 'cdk-from-cfn'; -import * as chalk from 'chalk'; import { cliInit } from '../../lib/init'; import { print } from '../../lib/logging'; import type { ICloudFormationClient, SdkProvider } from '../api/aws-auth'; import { CloudFormationStack } from '../api/util/cloudformation'; import { zipDirectory } from '../util/archive'; +import * as chalk from '../util/cdk-chalk'; const camelCase = require('camelcase'); const decamelize = require('decamelize'); /** The list of languages supported by the built-in noctilucent binary. */ diff --git a/packages/aws-cdk/lib/diff.ts b/packages/aws-cdk/lib/diff.ts index 77270c05bc048..1513ccab023fe 100644 --- a/packages/aws-cdk/lib/diff.ts +++ b/packages/aws-cdk/lib/diff.ts @@ -10,10 +10,10 @@ import { mangleLikeCloudFormation, } from '@aws-cdk/cloudformation-diff'; import * as cxapi from '@aws-cdk/cx-api'; -import * as chalk from 'chalk'; import { NestedStackTemplates } from './api/nested-stack-helpers'; import { print, warning } from './logging'; import { ToolkitError } from './toolkit/error'; +import * as chalk from './util/cdk-chalk'; /** * Pretty-prints the differences between two template states to the console. diff --git a/packages/aws-cdk/lib/import.ts b/packages/aws-cdk/lib/import.ts index 3d34fee6985ff..6c889b8d4e294 100644 --- a/packages/aws-cdk/lib/import.ts +++ b/packages/aws-cdk/lib/import.ts @@ -2,7 +2,6 @@ import { DeployOptions } from '@aws-cdk/cloud-assembly-schema'; import * as cfnDiff from '@aws-cdk/cloudformation-diff'; import { ResourceDifference } from '@aws-cdk/cloudformation-diff'; import * as cxapi from '@aws-cdk/cx-api'; -import * as chalk from 'chalk'; import * as fs from 'fs-extra'; import * as promptly from 'promptly'; import { DeploymentMethod } from './api'; @@ -13,6 +12,7 @@ import { StackActivityProgress } from './api/util/cloudformation/stack-activity- import { Tag } from './cdk-toolkit'; import { error, print, success, warning } from './logging'; import { ToolkitError } from './toolkit/error'; +import * as chalk from './util/cdk-chalk'; export interface ImportDeploymentOptions extends DeployOptions { deploymentMethod?: DeploymentMethod; diff --git a/packages/aws-cdk/lib/init.ts b/packages/aws-cdk/lib/init.ts index 8c87c2db08781..46f1b17f8d509 100644 --- a/packages/aws-cdk/lib/init.ts +++ b/packages/aws-cdk/lib/init.ts @@ -1,10 +1,10 @@ import * as childProcess from 'child_process'; import * as path from 'path'; -import * as chalk from 'chalk'; import * as fs from 'fs-extra'; import { invokeBuiltinHooks } from './init-hooks'; import { error, print, warning } from './logging'; import { ToolkitError } from './toolkit/error'; +import * as chalk from './util/cdk-chalk'; import { cdkHomeDir, rootDir } from './util/directories'; import { rangeFromSemver } from './util/version-range'; diff --git a/packages/aws-cdk/lib/logging.ts b/packages/aws-cdk/lib/logging.ts index bf2ca762f18e2..fcb0a15ceb0e1 100644 --- a/packages/aws-cdk/lib/logging.ts +++ b/packages/aws-cdk/lib/logging.ts @@ -1,6 +1,6 @@ import * as util from 'util'; -import * as chalk from 'chalk'; import { IoMessageLevel, IoMessage, CliIoHost, validateMessageCode } from './toolkit/cli-io-host'; +import * as chalk from './util/cdk-chalk'; // Corking mechanism let CORK_COUNTER = 0; @@ -70,10 +70,10 @@ interface LogOptions { */ forceStdout?: boolean; /** - * Message code of the format [CATEGORY]_[NUMBER_CODE] - * @pattern [A-Z]+_[0-2][0-9]{3} - * @default TOOLKIT_[0/1/2]000 - */ + * Message code of the format [CATEGORY]_[NUMBER_CODE] + * @pattern [A-Z]+_[0-2][0-9]{3} + * @default TOOLKIT_[0/1/2]000 + */ code?: string; } diff --git a/packages/aws-cdk/lib/os.ts b/packages/aws-cdk/lib/os.ts index c6d0da3f11607..ef2d00c5fafa7 100644 --- a/packages/aws-cdk/lib/os.ts +++ b/packages/aws-cdk/lib/os.ts @@ -1,7 +1,7 @@ import * as child_process from 'child_process'; -import * as chalk from 'chalk'; import { debug, data } from './logging'; import { ToolkitError } from './toolkit/error'; +import * as chalk from './util/cdk-chalk'; /** * OS helpers diff --git a/packages/aws-cdk/lib/toolkit/cli-io-host.ts b/packages/aws-cdk/lib/toolkit/cli-io-host.ts index c9d07533b1bcf..16572bfa11dad 100644 --- a/packages/aws-cdk/lib/toolkit/cli-io-host.ts +++ b/packages/aws-cdk/lib/toolkit/cli-io-host.ts @@ -1,4 +1,4 @@ -import * as chalk from 'chalk'; +import * as chalk from '../util/cdk-chalk'; /** * Basic message structure for toolkit notifications. @@ -97,13 +97,17 @@ export class CliIoHost { /** * Whether the host should apply chalk styles to messages. Defaults to false if the host is not running in a TTY. + * + * @default false */ private isTTY: boolean; /** * Whether the CliIoHost is running in CI mode. In CI mode, all non-error output goes to stdout instead of stderr. + * + * @default false */ - private ci: boolean = false; + private ci: boolean; /** * the current {@link IoAction} set by the CLI. @@ -112,6 +116,7 @@ export class CliIoHost { private constructor() { this.isTTY = process.stdout.isTTY ?? false; + this.ci = false; } public static get currentAction(): IoAction | undefined { diff --git a/packages/aws-cdk/lib/util/cdk-chalk.ts b/packages/aws-cdk/lib/util/cdk-chalk.ts new file mode 100644 index 0000000000000..2d9c736d2d637 --- /dev/null +++ b/packages/aws-cdk/lib/util/cdk-chalk.ts @@ -0,0 +1,55 @@ +import * as chalk from 'chalk'; + +// Create a new chalk instance with color support disabled if we're not in a TTY +const wrapper = new chalk.Instance({ + level: process.stdout.isTTY ? 2 : 0, +}); + +export default wrapper; + +// Export individual methods +export const { + black, + red, + green, + yellow, + blue, + magenta, + cyan, + white, + gray, + grey, + blackBright, + redBright, + greenBright, + yellowBright, + blueBright, + magentaBright, + cyanBright, + whiteBright, + bgBlack, + bgRed, + bgGreen, + bgYellow, + bgBlue, + bgMagenta, + bgCyan, + bgWhite, + bgBlackBright, + bgRedBright, + bgGreenBright, + bgYellowBright, + bgBlueBright, + bgMagentaBright, + bgCyanBright, + bgWhiteBright, + bold, + dim, + italic, + underline, + inverse, + hidden, + strikethrough, + visible, + reset, +} = wrapper; diff --git a/packages/aws-cdk/lib/version.ts b/packages/aws-cdk/lib/version.ts index a3b7f8383a28b..3f540d88c0738 100644 --- a/packages/aws-cdk/lib/version.ts +++ b/packages/aws-cdk/lib/version.ts @@ -1,7 +1,7 @@ import * as path from 'path'; -import * as chalk from 'chalk'; import * as fs from 'fs-extra'; import * as semver from 'semver'; +import * as chalk from './util/cdk-chalk'; import { cdkCacheDir, rootDir } from './util/directories'; import { getLatestVersionFromNpm } from './util/npm'; import { debug, print } from '../lib/logging'; diff --git a/packages/aws-cdk/test/api/stack-activity-monitor.test.ts b/packages/aws-cdk/test/api/stack-activity-monitor.test.ts index a5cf50df7ec25..ad34373862678 100644 --- a/packages/aws-cdk/test/api/stack-activity-monitor.test.ts +++ b/packages/aws-cdk/test/api/stack-activity-monitor.test.ts @@ -1,5 +1,5 @@ /* eslint-disable import/order */ -import { bold, reset, green, yellow, red } from 'chalk'; +import * as chalk from '../../lib/util/cdk-chalk'; import { stderr } from './console-listener'; import { HistoryActivityPrinter } from '../../lib/api/util/cloudformation/stack-activity-monitor'; import { ResourceStatus } from '@aws-sdk/client-cloudformation'; @@ -35,7 +35,7 @@ test('prints 0/4 progress report, when addActivity is called with an "IN_PROGRES }); expect(output[0].trim()).toStrictEqual( - `stack-name | 0/4 | ${HUMAN_TIME} | ${reset('CREATE_IN_PROGRESS ')} | AWS::CloudFormation::Stack | ${reset(bold('stack1'))}`, + `stack-name | 0/4 | ${HUMAN_TIME} | ${chalk.reset('CREATE_IN_PROGRESS ')} | AWS::CloudFormation::Stack | ${chalk.reset(chalk.bold('stack1'))}`, ); }); @@ -62,7 +62,7 @@ test('prints 1/4 progress report, when addActivity is called with an "UPDATE_COM }); expect(output[0].trim()).toStrictEqual( - `stack-name | 1/4 | ${HUMAN_TIME} | ${green('UPDATE_COMPLETE ')} | AWS::CloudFormation::Stack | ${green(bold('stack1'))}`, + `stack-name | 1/4 | ${HUMAN_TIME} | ${chalk.green('UPDATE_COMPLETE ')} | AWS::CloudFormation::Stack | ${chalk.green(chalk.bold('stack1'))}`, ); }); @@ -89,7 +89,7 @@ test('prints 1/4 progress report, when addActivity is called with an "UPDATE_COM }); expect(output[0].trim()).toStrictEqual( - `stack-name | 1/4 | ${HUMAN_TIME} | ${green('UPDATE_COMPLETE ')} | AWS::CloudFormation::Stack | ${green(bold('stack1'))}`, + `stack-name | 1/4 | ${HUMAN_TIME} | ${chalk.green('UPDATE_COMPLETE ')} | AWS::CloudFormation::Stack | ${chalk.green(chalk.bold('stack1'))}`, ); }); @@ -116,7 +116,7 @@ test('prints 1/4 progress report, when addActivity is called with an "ROLLBACK_C }); expect(output[0].trim()).toStrictEqual( - `stack-name | 1/4 | ${HUMAN_TIME} | ${yellow('ROLLBACK_COMPLETE ')} | AWS::CloudFormation::Stack | ${yellow(bold('stack1'))}`, + `stack-name | 1/4 | ${HUMAN_TIME} | ${chalk.yellow('ROLLBACK_COMPLETE ')} | AWS::CloudFormation::Stack | ${chalk.yellow(chalk.bold('stack1'))}`, ); }); @@ -143,7 +143,7 @@ test('prints 0/4 progress report, when addActivity is called with an "UPDATE_FAI }); expect(output[0].trim()).toStrictEqual( - `stack-name | 0/4 | ${HUMAN_TIME} | ${red('UPDATE_FAILED ')} | AWS::CloudFormation::Stack | ${red(bold('stack1'))}`, + `stack-name | 0/4 | ${HUMAN_TIME} | ${chalk.red('UPDATE_FAILED ')} | AWS::CloudFormation::Stack | ${chalk.red(chalk.bold('stack1'))}`, ); }); @@ -196,13 +196,13 @@ test('does not print "Failed Resources:" list, when all deployments are successf expect(output.length).toStrictEqual(3); expect(output[0].trim()).toStrictEqual( - `stack-name | 0/2 | ${HUMAN_TIME} | ${reset('UPDATE_IN_PROGRESS ')} | AWS::CloudFormation::Stack | ${reset(bold('stack1'))}`, + `stack-name | 0/2 | ${HUMAN_TIME} | ${chalk.reset('UPDATE_IN_PROGRESS ')} | AWS::CloudFormation::Stack | ${chalk.reset(chalk.bold('stack1'))}`, ); expect(output[1].trim()).toStrictEqual( - `stack-name | 1/2 | ${HUMAN_TIME} | ${green('UPDATE_COMPLETE ')} | AWS::CloudFormation::Stack | ${green(bold('stack1'))}`, + `stack-name | 1/2 | ${HUMAN_TIME} | ${chalk.green('UPDATE_COMPLETE ')} | AWS::CloudFormation::Stack | ${chalk.green(chalk.bold('stack1'))}`, ); expect(output[2].trim()).toStrictEqual( - `stack-name | 2/2 | ${HUMAN_TIME} | ${green('UPDATE_COMPLETE ')} | AWS::CloudFormation::Stack | ${green(bold('stack2'))}`, + `stack-name | 2/2 | ${HUMAN_TIME} | ${chalk.green('UPDATE_COMPLETE ')} | AWS::CloudFormation::Stack | ${chalk.green(chalk.bold('stack2'))}`, ); }); @@ -243,14 +243,14 @@ test('prints "Failed Resources:" list, when at least one deployment fails', () = expect(output.length).toStrictEqual(4); expect(output[0].trim()).toStrictEqual( - `stack-name | 0/2 | ${HUMAN_TIME} | ${reset('UPDATE_IN_PROGRESS ')} | AWS::CloudFormation::Stack | ${reset(bold('stack1'))}`, + `stack-name | 0/2 | ${HUMAN_TIME} | ${chalk.reset('UPDATE_IN_PROGRESS ')} | AWS::CloudFormation::Stack | ${chalk.reset(chalk.bold('stack1'))}`, ); expect(output[1].trim()).toStrictEqual( - `stack-name | 0/2 | ${HUMAN_TIME} | ${red('UPDATE_FAILED ')} | AWS::CloudFormation::Stack | ${red(bold('stack1'))}`, + `stack-name | 0/2 | ${HUMAN_TIME} | ${chalk.red('UPDATE_FAILED ')} | AWS::CloudFormation::Stack | ${chalk.red(chalk.bold('stack1'))}`, ); expect(output[2].trim()).toStrictEqual('Failed resources:'); expect(output[3].trim()).toStrictEqual( - `stack-name | ${HUMAN_TIME} | ${red('UPDATE_FAILED ')} | AWS::CloudFormation::Stack | ${red(bold('stack1'))}`, + `stack-name | ${HUMAN_TIME} | ${chalk.red('UPDATE_FAILED ')} | AWS::CloudFormation::Stack | ${chalk.red(chalk.bold('stack1'))}`, ); }); @@ -295,13 +295,13 @@ test('print failed resources because of hook failures', () => { expect(output.length).toStrictEqual(4); expect(output[0].trim()).toStrictEqual( - `stack-name | 0/2 | ${HUMAN_TIME} | ${reset('UPDATE_IN_PROGRESS ')} | AWS::CloudFormation::Stack | ${reset(bold('stack1'))}`, + `stack-name | 0/2 | ${HUMAN_TIME} | ${chalk.reset('UPDATE_IN_PROGRESS ')} | AWS::CloudFormation::Stack | ${chalk.reset(chalk.bold('stack1'))}`, ); expect(output[1].trim()).toStrictEqual( - `stack-name | 0/2 | ${HUMAN_TIME} | ${red('UPDATE_FAILED ')} | AWS::CloudFormation::Stack | ${red(bold('stack1'))} ${red(bold('The following hook(s) failed: hook1 : stack1 must obey certain rules'))}`, + `stack-name | 0/2 | ${HUMAN_TIME} | ${chalk.red('UPDATE_FAILED ')} | AWS::CloudFormation::Stack | ${chalk.red(chalk.bold('stack1'))} ${chalk.red(chalk.bold('The following hook(s) failed: hook1 : stack1 must obey certain rules'))}`, ); expect(output[2].trim()).toStrictEqual('Failed resources:'); expect(output[3].trim()).toStrictEqual( - `stack-name | ${HUMAN_TIME} | ${red('UPDATE_FAILED ')} | AWS::CloudFormation::Stack | ${red(bold('stack1'))} ${red(bold('The following hook(s) failed: hook1 : stack1 must obey certain rules'))}`, + `stack-name | ${HUMAN_TIME} | ${chalk.red('UPDATE_FAILED ')} | AWS::CloudFormation::Stack | ${chalk.red(chalk.bold('stack1'))} ${chalk.red(chalk.bold('The following hook(s) failed: hook1 : stack1 must obey certain rules'))}`, ); }); diff --git a/packages/aws-cdk/test/toolkit/cli-io-host.test.ts b/packages/aws-cdk/test/toolkit/cli-io-host.test.ts index 4e5ec49ff664d..100d619d2dbb1 100644 --- a/packages/aws-cdk/test/toolkit/cli-io-host.test.ts +++ b/packages/aws-cdk/test/toolkit/cli-io-host.test.ts @@ -1,5 +1,5 @@ -import * as chalk from 'chalk'; import { CliIoHost, IoMessage, validateMessageCode } from '../../lib/toolkit/cli-io-host'; +import * as chalk from '../../lib/util/cdk-chalk'; describe('CliIoHost', () => { let mockStdout: jest.Mock;