diff --git a/packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/private/context-aware-source.ts b/packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/private/context-aware-source.ts index ac7f98caf..4ad2a2169 100644 --- a/packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/private/context-aware-source.ts +++ b/packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/private/context-aware-source.ts @@ -2,7 +2,7 @@ import type { MissingContext } from '@aws-cdk/cloud-assembly-schema'; import type * as cxapi from '@aws-cdk/cx-api'; import type { ToolkitServices } from '../../../toolkit/private'; import { type Context, contextproviders, PROJECT_CONTEXT } from '../../aws-cdk'; -import { CODES } from '../../io/private'; +import { IO } from '../../io/private'; import type { ActionAwareIoHost } from '../../shared-private'; import { ToolkitError } from '../../shared-public'; import type { ICloudAssemblySource } from '../types'; @@ -77,14 +77,14 @@ export class ContextAwareCloudAssembly implements ICloudAssemblySource { let tryLookup = true; if (previouslyMissingKeys && equalSets(missingKeysSet, previouslyMissingKeys)) { - await this.ioHost.notify(CODES.CDK_ASSEMBLY_I0240.msg('Not making progress trying to resolve environmental context. Giving up.', { missingKeys })); + await this.ioHost.notify(IO.CDK_ASSEMBLY_I0240.msg('Not making progress trying to resolve environmental context. Giving up.', { missingKeys })); tryLookup = false; } previouslyMissingKeys = missingKeysSet; if (tryLookup) { - await this.ioHost.notify(CODES.CDK_ASSEMBLY_I0241.msg('Some context information is missing. Fetching...', { missingKeys })); + await this.ioHost.notify(IO.CDK_ASSEMBLY_I0241.msg('Some context information is missing. Fetching...', { missingKeys })); await contextproviders.provideContextValues( assembly.manifest.missing, this.context, @@ -92,7 +92,7 @@ export class ContextAwareCloudAssembly implements ICloudAssemblySource { ); // Cache the new context to disk - await this.ioHost.notify(CODES.CDK_ASSEMBLY_I0042.msg(`Writing updated context to ${this.contextFile}...`, { + await this.ioHost.notify(IO.CDK_ASSEMBLY_I0042.msg(`Writing updated context to ${this.contextFile}...`, { contextFile: this.contextFile, context: this.context.all, })); diff --git a/packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/private/prepare-source.ts b/packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/private/prepare-source.ts index 3c6f3cb0b..7a08b953b 100644 --- a/packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/private/prepare-source.ts +++ b/packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/private/prepare-source.ts @@ -8,7 +8,7 @@ import { lte } from 'semver'; import { prepareDefaultEnvironment as oldPrepare, prepareContext, spaceAvailableForContext, Settings, loadTree, some, versionNumber } from '../../../api/aws-cdk'; import { splitBySize } from '../../../private/util'; import type { ToolkitServices } from '../../../toolkit/private'; -import { CODES } from '../../io/private'; +import { IO } from '../../io/private'; import type { ActionAwareIoHost } from '../../shared-private'; import { ToolkitError } from '../../shared-public'; import type { AppSynthOptions, LoadAssemblyOptions } from '../source-builder'; @@ -38,7 +38,7 @@ export function determineOutputDirectory(outdir?: string) { * @param context The context key/value bash. */ export async function prepareDefaultEnvironment(services: ToolkitServices, props: { outdir?: string } = {}): Promise { - const logFn = (msg: string, ...args: any) => services.ioHost.notify(CODES.CDK_ASSEMBLY_I0010.msg(format(msg, ...args))); + const logFn = (msg: string, ...args: any) => services.ioHost.notify(IO.CDK_ASSEMBLY_I0010.msg(format(msg, ...args))); const env = await oldPrepare(services.sdkProvider, logFn); if (props.outdir) { @@ -142,7 +142,7 @@ export async function checkContextOverflowSupport(assembly: cxapi.CloudAssembly, // We're dealing with an old version of the framework here. It is unaware of the temporary // file, which means that it will ignore the context overflow. if (frameworkDoesNotSupportContextOverflow) { - await ioHost.notify(CODES.CDK_ASSEMBLY_W0010.msg('Part of the context could not be sent to the application. Please update the AWS CDK library to the latest version.')); + await ioHost.notify(IO.CDK_ASSEMBLY_W0010.msg('Part of the context could not be sent to the application. Please update the AWS CDK library to the latest version.')); } } @@ -164,7 +164,7 @@ export async function assemblyFromDirectory(assemblyDir: string, ioHost: ActionA // this means the CLI version is too old. // we instruct the user to upgrade. const message = 'This AWS CDK Toolkit is not compatible with the AWS CDK library used by your application. Please upgrade to the latest version.'; - await ioHost.notify(CODES.CDK_ASSEMBLY_E1111.msg(message, { error: err })); + await ioHost.notify(IO.CDK_ASSEMBLY_E1111.msg(message, { error: err })); throw new ToolkitError(`${message}\n(${err.message}`); } throw err; diff --git a/packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/private/source-builder.ts b/packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/private/source-builder.ts index 970c823b2..cd38fba1b 100644 --- a/packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/private/source-builder.ts +++ b/packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/private/source-builder.ts @@ -8,7 +8,7 @@ import { assemblyFromDirectory, changeDir, determineOutputDirectory, guessExecut import type { ToolkitServices } from '../../../toolkit/private'; import type { ILock } from '../../aws-cdk'; import { Context, RWLock, Settings } from '../../aws-cdk'; -import { CODES } from '../../io/private'; +import { IO } from '../../io/private'; import { ToolkitError, AssemblyError } from '../../shared-public'; import type { AssemblyBuilder } from '../source-builder'; @@ -89,7 +89,7 @@ export abstract class CloudAssemblySourceBuilder { { produce: async () => { // @todo build - await services.ioHost.notify(CODES.CDK_ASSEMBLY_I0150.msg('--app points to a cloud assembly, so we bypass synth')); + await services.ioHost.notify(IO.CDK_ASSEMBLY_I0150.msg('--app points to a cloud assembly, so we bypass synth')); return assemblyFromDirectory(directory, services.ioHost, props.loadAssemblyOptions); }, }, @@ -139,10 +139,10 @@ export abstract class CloudAssemblySourceBuilder { eventPublisher: async (type, line) => { switch (type) { case 'data_stdout': - await services.ioHost.notify(CODES.CDK_ASSEMBLY_I1001.msg(line)); + await services.ioHost.notify(IO.CDK_ASSEMBLY_I1001.msg(line)); break; case 'data_stderr': - await services.ioHost.notify(CODES.CDK_ASSEMBLY_E1002.msg(line)); + await services.ioHost.notify(IO.CDK_ASSEMBLY_E1002.msg(line)); break; } }, diff --git a/packages/@aws-cdk/toolkit-lib/lib/api/io/private/index.ts b/packages/@aws-cdk/toolkit-lib/lib/api/io/private/index.ts index 3338ca1e6..6093bf42b 100644 --- a/packages/@aws-cdk/toolkit-lib/lib/api/io/private/index.ts +++ b/packages/@aws-cdk/toolkit-lib/lib/api/io/private/index.ts @@ -1,4 +1,4 @@ -export * from './codes'; +export * from './messages'; export * from './io-host-wrappers'; export * from './level-priority'; export * from './timer'; diff --git a/packages/@aws-cdk/toolkit-lib/lib/api/io/private/codes.ts b/packages/@aws-cdk/toolkit-lib/lib/api/io/private/messages.ts similarity index 99% rename from packages/@aws-cdk/toolkit-lib/lib/api/io/private/codes.ts rename to packages/@aws-cdk/toolkit-lib/lib/api/io/private/messages.ts index 57f515625..a455e9188 100644 --- a/packages/@aws-cdk/toolkit-lib/lib/api/io/private/codes.ts +++ b/packages/@aws-cdk/toolkit-lib/lib/api/io/private/messages.ts @@ -17,7 +17,7 @@ import * as make from '../../shared-private'; * - X000-X009 are reserved for timings * - X900-X999 are reserved for results */ -export const CODES = { +export const IO = { // Defaults DEFAULT_TOOLKIT_INFO: make.info({ code: 'CDK_TOOLKIT_I0000', diff --git a/packages/@aws-cdk/toolkit-lib/lib/api/io/private/sdk-logger.ts b/packages/@aws-cdk/toolkit-lib/lib/api/io/private/sdk-logger.ts index f444598c5..2f9152237 100644 --- a/packages/@aws-cdk/toolkit-lib/lib/api/io/private/sdk-logger.ts +++ b/packages/@aws-cdk/toolkit-lib/lib/api/io/private/sdk-logger.ts @@ -1,7 +1,7 @@ import { inspect } from 'util'; import type { Logger } from '@smithy/types'; -import { CODES } from './codes'; +import { IO } from './messages'; import { replacerBufferWithInfo } from '../../../private/util'; import type { ActionAwareIoHost } from '../../shared-private'; @@ -63,14 +63,14 @@ export function asSdkLogger(ioHost: ActionAwareIoHost): Logger { * ``` */ public info(...content: any[]) { - void ioHost.notify(CODES.CDK_SDK_I0100.msg(`[sdk info] ${formatSdkLoggerContent(content)}`, { + void ioHost.notify(IO.CDK_SDK_I0100.msg(`[sdk info] ${formatSdkLoggerContent(content)}`, { sdkLevel: 'info', content, })); } public warn(...content: any[]) { - void ioHost.notify(CODES.CDK_SDK_I0100.msg(`[sdk warn] ${formatSdkLoggerContent(content)}`, { + void ioHost.notify(IO.CDK_SDK_I0100.msg(`[sdk warn] ${formatSdkLoggerContent(content)}`, { sdkLevel: 'warn', content, })); @@ -98,7 +98,7 @@ export function asSdkLogger(ioHost: ActionAwareIoHost): Logger { * ``` */ public error(...content: any[]) { - void ioHost.notify(CODES.CDK_SDK_I0100.msg(`[sdk error] ${formatSdkLoggerContent(content)}`, { + void ioHost.notify(IO.CDK_SDK_I0100.msg(`[sdk error] ${formatSdkLoggerContent(content)}`, { sdkLevel: 'error', content, })); diff --git a/packages/@aws-cdk/toolkit-lib/lib/api/io/private/timer.ts b/packages/@aws-cdk/toolkit-lib/lib/api/io/private/timer.ts index d083df1c4..00556c596 100644 --- a/packages/@aws-cdk/toolkit-lib/lib/api/io/private/timer.ts +++ b/packages/@aws-cdk/toolkit-lib/lib/api/io/private/timer.ts @@ -1,5 +1,5 @@ import { format } from 'util'; -import { CODES } from './codes'; +import { IO } from './messages'; import { formatTime } from '../../../private/util'; import type { ActionAwareIoHost } from '../../shared-private'; @@ -52,10 +52,10 @@ function timerMessage(type: 'synth' | 'deploy' | 'rollback'| 'destroy' | 'bootst const payload = { duration: duration.asMs }; switch (type) { - case 'synth': return CODES.CDK_TOOLKIT_I1000.msg(format(message, 'Synthesis'), payload); - case 'deploy': return CODES.CDK_TOOLKIT_I5000.msg(format(message, 'Deployment'), payload); - case 'rollback': return CODES.CDK_TOOLKIT_I6000.msg(format(message, 'Rollback'), payload); - case 'destroy': return CODES.CDK_TOOLKIT_I7000.msg(format(message, 'Destroy'), payload); - case 'bootstrap': return CODES.CDK_TOOLKIT_I9000.msg(format(message, 'Bootstrap'), payload); + case 'synth': return IO.CDK_TOOLKIT_I1000.msg(format(message, 'Synthesis'), payload); + case 'deploy': return IO.CDK_TOOLKIT_I5000.msg(format(message, 'Deployment'), payload); + case 'rollback': return IO.CDK_TOOLKIT_I6000.msg(format(message, 'Rollback'), payload); + case 'destroy': return IO.CDK_TOOLKIT_I7000.msg(format(message, 'Destroy'), payload); + case 'bootstrap': return IO.CDK_TOOLKIT_I9000.msg(format(message, 'Bootstrap'), payload); } } diff --git a/packages/@aws-cdk/toolkit-lib/lib/toolkit/toolkit.ts b/packages/@aws-cdk/toolkit-lib/lib/toolkit/toolkit.ts index b2514d98b..b0738145f 100644 --- a/packages/@aws-cdk/toolkit-lib/lib/toolkit/toolkit.ts +++ b/packages/@aws-cdk/toolkit-lib/lib/toolkit/toolkit.ts @@ -25,7 +25,7 @@ import { StackSelectionStrategy } from '../api/cloud-assembly'; import type { StackAssembly } from '../api/cloud-assembly/private'; import { ALL_STACKS, CloudAssemblySourceBuilder, IdentityCloudAssemblySource } from '../api/cloud-assembly/private'; import type { IIoHost, IoMessageLevel } from '../api/io'; -import { Timer, CODES, asSdkLogger, withoutColor, withoutEmojis, withTrimmedWhitespace } from '../api/io/private'; +import { Timer, IO, asSdkLogger, withoutColor, withoutEmojis, withTrimmedWhitespace } from '../api/io/private'; import type { ActionAwareIoHost } from '../api/shared-private'; import { withAction } from '../api/shared-private'; import type { ToolkitAction } from '../api/shared-public'; @@ -161,7 +161,7 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab // eslint-disable-next-line @cdklabs/promiseall-no-unbounded-parallelism await Promise.all(bootstrapEnvironments.map((environment: cxapi.Environment, currentIdx) => limit(async () => { - await ioHost.notify(CODES.CDK_TOOLKIT_I9100.msg(`${chalk.bold(environment.name)}: bootstrapping...`, { + await ioHost.notify(IO.CDK_TOOLKIT_I9100.msg(`${chalk.bold(environment.name)}: bootstrapping...`, { total: bootstrapEnvironments.length, current: currentIdx+1, environment, @@ -184,10 +184,10 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab ? ` ✅ ${environment.name} (no changes)` : ` ✅ ${environment.name}`; - await ioHost.notify(CODES.CDK_TOOLKIT_I9900.msg(chalk.green('\n' + message), { environment })); + await ioHost.notify(IO.CDK_TOOLKIT_I9900.msg(chalk.green('\n' + message), { environment })); await bootstrapTimer.endAs(ioHost, 'bootstrap'); } catch (e: any) { - await ioHost.notify(CODES.CDK_TOOLKIT_E9900.msg(`\n ❌ ${chalk.bold(environment.name)} failed: ${formatErrorMessage(e)}`, { error: e })); + await ioHost.notify(IO.CDK_TOOLKIT_E9900.msg(`\n ❌ ${chalk.bold(environment.name)} failed: ${formatErrorMessage(e)}`, { error: e })); throw e; } }))); @@ -217,7 +217,7 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab const firstStack = stacks.firstStack!; const template = firstStack.template; const obscuredTemplate = obscureTemplate(template); - await ioHost.notify(CODES.CDK_TOOLKIT_I1901.msg(message, { + await ioHost.notify(IO.CDK_TOOLKIT_I1901.msg(message, { ...assemblyData, stack: { stackName: firstStack.stackName, @@ -229,8 +229,8 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab })); } else { // not outputting template to stdout, let's explain things to the user a little bit... - await ioHost.notify(CODES.CDK_TOOLKIT_I1902.msg(chalk.green(message), assemblyData)); - await ioHost.notify(CODES.DEFAULT_TOOLKIT_INFO.msg(`Supply a stack id (${stacks.stackArtifacts.map((s) => chalk.green(s.hierarchicalId)).join(', ')}) to display its template.`)); + await ioHost.notify(IO.CDK_TOOLKIT_I1902.msg(chalk.green(message), assemblyData)); + await ioHost.notify(IO.DEFAULT_TOOLKIT_INFO.msg(`Supply a stack id (${stacks.stackArtifacts.map((s) => chalk.green(s.hierarchicalId)).join(', ')}) to display its template.`)); } return new IdentityCloudAssemblySource(assembly.assembly); @@ -251,7 +251,7 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab const stacks = stackCollection.withDependencies(); const message = stacks.map(s => s.id).join('\n'); - await ioHost.notify(CODES.CDK_TOOLKIT_I2901.msg(message, { stacks })); + await ioHost.notify(IO.CDK_TOOLKIT_I2901.msg(message, { stacks })); return stacks; } @@ -276,7 +276,7 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab const synthDuration = await synthTimer.endAs(ioHost, 'synth'); if (stackCollection.stackCount === 0) { - await ioHost.notify(CODES.CDK_TOOLKIT_E5001.msg('This app contains no stacks')); + await ioHost.notify(IO.CDK_TOOLKIT_E5001.msg('This app contains no stacks')); return; } @@ -289,7 +289,7 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab const hotswapMode = options.hotswap ?? HotswapMode.FULL_DEPLOYMENT; if (hotswapMode !== HotswapMode.FULL_DEPLOYMENT) { - await ioHost.notify(CODES.CDK_TOOLKIT_W5400.msg([ + await ioHost.notify(IO.CDK_TOOLKIT_W5400.msg([ '⚠️ The --hotswap and --hotswap-fallback flags deliberately introduce CloudFormation drift to speed up deployments', '⚠️ They should only be used for development - never use them for your production Stacks!', ].join('\n'))); @@ -323,7 +323,7 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab const deployStack = async (stackNode: StackNode) => { const stack = stackNode.stack; if (stackCollection.stackCount !== 1) { - await ioHost.notify(CODES.DEFAULT_TOOLKIT_INFO.msg(chalk.bold(stack.displayName))); + await ioHost.notify(IO.DEFAULT_TOOLKIT_INFO.msg(chalk.bold(stack.displayName))); } if (!stack.environment) { @@ -337,11 +337,11 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab // stack is empty and doesn't exist => do nothing const stackExists = await deployments.stackExists({ stack }); if (!stackExists) { - return ioHost.notify(CODES.CDK_TOOLKIT_W5021.msg(`${chalk.bold(stack.displayName)}: stack has no resources, skipping deployment.`)); + return ioHost.notify(IO.CDK_TOOLKIT_W5021.msg(`${chalk.bold(stack.displayName)}: stack has no resources, skipping deployment.`)); } // stack is empty, but exists => delete - await ioHost.notify(CODES.CDK_TOOLKIT_W5022.msg(`${chalk.bold(stack.displayName)}: stack has no resources, deleting existing stack.`)); + await ioHost.notify(IO.CDK_TOOLKIT_W5022.msg(`${chalk.bold(stack.displayName)}: stack has no resources, deleting existing stack.`)); await this._destroy(assembly, 'deploy', { stacks: { patterns: [stack.hierarchicalId], strategy: StackSelectionStrategy.PATTERN_MUST_MATCH_SINGLE }, roleArn: options.roleArn, @@ -355,7 +355,7 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab const permissionChangeType = determinePermissionType(currentTemplate, stack); const deployMotivation = '"--require-approval" is enabled and stack includes security-sensitive updates.'; const deployQuestion = `${deployMotivation}\nDo you wish to deploy these changes`; - const deployConfirmed = await ioHost.requestResponse(CODES.CDK_TOOLKIT_I5060.req(deployQuestion, { + const deployConfirmed = await ioHost.requestResponse(IO.CDK_TOOLKIT_I5060.req(deployQuestion, { motivation: deployMotivation, concurrency, permissionChangeType: permissionChangeType, @@ -380,7 +380,7 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab } const stackIndex = stacks.indexOf(stack) + 1; - await ioHost.notify(CODES.CDK_TOOLKIT_I5100.msg(`${chalk.bold(stack.displayName)}: deploying... [${stackIndex}/${stackCollection.stackCount}]`, { + await ioHost.notify(IO.CDK_TOOLKIT_I5100.msg(`${chalk.bold(stack.displayName)}: deploying... [${stackIndex}/${stackCollection.stackCount}]`, { total: stackCollection.stackCount, current: stackIndex, stack, @@ -434,9 +434,9 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab const question = `${motivation}. Perform a regular deployment`; if (options.force) { - await ioHost.notify(CODES.DEFAULT_TOOLKIT_WARN.msg(`${motivation}. Rolling back first (--force).`)); + await ioHost.notify(IO.DEFAULT_TOOLKIT_WARN.msg(`${motivation}. Rolling back first (--force).`)); } else { - const confirmed = await ioHost.requestResponse(CODES.CDK_TOOLKIT_I5050.req(question, { + const confirmed = await ioHost.requestResponse(IO.CDK_TOOLKIT_I5050.req(question, { motivation, concurrency, })); @@ -462,9 +462,9 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab // @todo no force here if (options.force) { - await ioHost.notify(CODES.DEFAULT_TOOLKIT_WARN.msg(`${motivation}. Proceeding with regular deployment (--force).`)); + await ioHost.notify(IO.DEFAULT_TOOLKIT_WARN.msg(`${motivation}. Proceeding with regular deployment (--force).`)); } else { - const confirmed = await ioHost.requestResponse(CODES.CDK_TOOLKIT_I5050.req(question, { + const confirmed = await ioHost.requestResponse(IO.CDK_TOOLKIT_I5050.req(question, { motivation, concurrency, })); @@ -487,7 +487,7 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab ? ` ✅ ${stack.displayName} (no changes)` : ` ✅ ${stack.displayName}`; - await ioHost.notify(CODES.CDK_TOOLKIT_I5900.msg(chalk.green('\n' + message), deployResult)); + await ioHost.notify(IO.CDK_TOOLKIT_I5900.msg(chalk.green('\n' + message), deployResult)); deployDuration = await deployTimer.endAs(ioHost, 'deploy'); if (Object.keys(deployResult.outputs).length > 0) { @@ -498,9 +498,9 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab const value = deployResult.outputs[name]; buffer.push(`${chalk.cyan(stack.id)}.${chalk.cyan(name)} = ${chalk.underline(chalk.cyan(value))}`); } - await ioHost.notify(CODES.CDK_TOOLKIT_I5901.msg(buffer.join('\n'))); + await ioHost.notify(IO.CDK_TOOLKIT_I5901.msg(buffer.join('\n'))); } - await ioHost.notify(CODES.CDK_TOOLKIT_I5901.msg(`Stack ARN:\n${deployResult.stackArn}`)); + await ioHost.notify(IO.CDK_TOOLKIT_I5901.msg(`Stack ARN:\n${deployResult.stackArn}`)); } catch (e: any) { // It has to be exactly this string because an integration test tests for // "bold(stackname) failed: ResourceNotReady: " @@ -517,7 +517,7 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab foundLogGroupsResult.sdk, foundLogGroupsResult.logGroupNames, ); - await ioHost.notify(CODES.CDK_TOOLKIT_I5031.msg(`The following log groups are added: ${foundLogGroupsResult.logGroupNames}`)); + await ioHost.notify(IO.CDK_TOOLKIT_I5031.msg(`The following log groups are added: ${foundLogGroupsResult.logGroupNames}`)); } // If an outputs file has been specified, create the file path and write stack outputs to it once. @@ -532,7 +532,7 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab } } const duration = synthDuration.asMs + (deployDuration?.asMs ?? 0); - await ioHost.notify(CODES.CDK_TOOLKIT_I5001.msg(`\n✨ Total time: ${formatTime(duration)}s\n`, { duration })); + await ioHost.notify(IO.CDK_TOOLKIT_I5001.msg(`\n✨ Total time: ${formatTime(duration)}s\n`, { duration })); }; const assetBuildTime = options.assetBuildTime ?? AssetBuildTime.ALL_BEFORE_DEPLOY; @@ -604,7 +604,7 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab }).concat(`${outdir}/**`, '**/.*', '**/.*/**', '**/node_modules/**'); // Print some debug information on computed settings - await ioHost.notify(CODES.CDK_TOOLKIT_I5310.msg([ + await ioHost.notify(IO.CDK_TOOLKIT_I5310.msg([ `root directory used for 'watch' is: ${rootDir}`, `'include' patterns for 'watch': ${JSON.stringify(watchIncludes)}`, `'exclude' patterns for 'watch': ${JSON.stringify(watchExcludes)}`, @@ -641,7 +641,7 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab // TypeScript doesn't realize latch can change between 'awaits', // and thinks the above 'while' condition is always 'false' without the cast latch = 'deploying'; - await ioHost.notify(CODES.CDK_TOOLKIT_I5315.msg("Detected file changes during deployment. Invoking 'cdk deploy' again")); + await ioHost.notify(IO.CDK_TOOLKIT_I5315.msg("Detected file changes during deployment. Invoking 'cdk deploy' again")); await this.invokeDeployFromWatch(assembly, options, cloudWatchLogMonitor); } latch = 'open'; @@ -655,8 +655,8 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab }) .on('ready', async () => { latch = 'open'; - await ioHost.notify(CODES.DEFAULT_TOOLKIT_DEBUG.msg("'watch' received the 'ready' event. From now on, all file changes will trigger a deployment")); - await ioHost.notify(CODES.CDK_TOOLKIT_I5314.msg("Triggering initial 'cdk deploy'")); + await ioHost.notify(IO.DEFAULT_TOOLKIT_DEBUG.msg("'watch' received the 'ready' event. From now on, all file changes will trigger a deployment")); + await ioHost.notify(IO.CDK_TOOLKIT_I5314.msg("Triggering initial 'cdk deploy'")); await deployAndWatch(); }) .on('all', async (event: 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir', filePath: string) => { @@ -665,14 +665,14 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab path: filePath, }; if (latch === 'pre-ready') { - await ioHost.notify(CODES.CDK_TOOLKIT_I5311.msg(`'watch' is observing ${event === 'addDir' ? 'directory' : 'the file'} '${filePath}' for changes`, watchEvent)); + await ioHost.notify(IO.CDK_TOOLKIT_I5311.msg(`'watch' is observing ${event === 'addDir' ? 'directory' : 'the file'} '${filePath}' for changes`, watchEvent)); } else if (latch === 'open') { - await ioHost.notify(CODES.CDK_TOOLKIT_I5312.msg(`Detected change to '${filePath}' (type: ${event}). Triggering 'cdk deploy'`, watchEvent)); + await ioHost.notify(IO.CDK_TOOLKIT_I5312.msg(`Detected change to '${filePath}' (type: ${event}). Triggering 'cdk deploy'`, watchEvent)); await deployAndWatch(); } else { // this means latch is either 'deploying' or 'queued' latch = 'queued'; - await ioHost.notify(CODES.CDK_TOOLKIT_I5313.msg( + await ioHost.notify(IO.CDK_TOOLKIT_I5313.msg( `Detected change to '${filePath}' (type: ${event}) while 'cdk deploy' is still running. Will queue for another deployment after this one finishes'`, watchEvent, )); @@ -701,14 +701,14 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab await synthTimer.endAs(ioHost, 'synth'); if (stacks.stackCount === 0) { - await ioHost.notify(CODES.CDK_TOOLKIT_E6001.msg('No stacks selected')); + await ioHost.notify(IO.CDK_TOOLKIT_E6001.msg('No stacks selected')); return; } let anyRollbackable = false; for (const [index, stack] of stacks.stackArtifacts.entries()) { - await ioHost.notify(CODES.CDK_TOOLKIT_I6100.msg(`Rolling back ${chalk.bold(stack.displayName)}`, { + await ioHost.notify(IO.CDK_TOOLKIT_I6100.msg(`Rolling back ${chalk.bold(stack.displayName)}`, { total: stacks.stackCount, current: index + 1, stack, @@ -729,7 +729,7 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab } await rollbackTimer.endAs(ioHost, 'rollback'); } catch (e: any) { - await ioHost.notify(CODES.CDK_TOOLKIT_E6900.msg(`\n ❌ ${chalk.bold(stack.displayName)} failed: ${formatErrorMessage(e)}`, { error: e })); + await ioHost.notify(IO.CDK_TOOLKIT_E6900.msg(`\n ❌ ${chalk.bold(stack.displayName)} failed: ${formatErrorMessage(e)}`, { error: e })); throw new ToolkitError('Rollback failed (use --force to orphan failing resources)'); } } @@ -760,15 +760,15 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab const motivation = 'Destroying stacks is an irreversible action'; const question = `Are you sure you want to delete: ${chalk.red(stacks.hierarchicalIds.join(', '))}`; - const confirmed = await ioHost.requestResponse(CODES.CDK_TOOLKIT_I7010.req(question, { motivation })); + const confirmed = await ioHost.requestResponse(IO.CDK_TOOLKIT_I7010.req(question, { motivation })); if (!confirmed) { - return ioHost.notify(CODES.CDK_TOOLKIT_E7010.msg('Aborted by user')); + return ioHost.notify(IO.CDK_TOOLKIT_E7010.msg('Aborted by user')); } const destroyTimer = Timer.start(); try { for (const [index, stack] of stacks.stackArtifacts.entries()) { - await ioHost.notify(CODES.CDK_TOOLKIT_I7100.msg(chalk.green(`${chalk.blue(stack.displayName)}: destroying... [${index + 1}/${stacks.stackCount}]`), { + await ioHost.notify(IO.CDK_TOOLKIT_I7100.msg(chalk.green(`${chalk.blue(stack.displayName)}: destroying... [${index + 1}/${stacks.stackCount}]`), { total: stacks.stackCount, current: index + 1, stack, @@ -780,9 +780,9 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab deployName: stack.stackName, roleArn: options.roleArn, }); - await ioHost.notify(CODES.CDK_TOOLKIT_I7900.msg(chalk.green(`\n ✅ ${chalk.blue(stack.displayName)}: ${action}ed`), stack)); + await ioHost.notify(IO.CDK_TOOLKIT_I7900.msg(chalk.green(`\n ✅ ${chalk.blue(stack.displayName)}: ${action}ed`), stack)); } catch (e: any) { - await ioHost.notify(CODES.CDK_TOOLKIT_E7900.msg(`\n ❌ ${chalk.blue(stack.displayName)}: ${action} failed ${e}`, { error: e })); + await ioHost.notify(IO.CDK_TOOLKIT_E7900.msg(`\n ❌ ${chalk.blue(stack.displayName)}: ${action} failed ${e}`, { error: e })); throw e; } } @@ -797,9 +797,9 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab private async validateStacksMetadata(stacks: StackCollection, ioHost: ActionAwareIoHost) { const builder = (level: IoMessageLevel) => { switch (level) { - case 'error': return CODES.CDK_ASSEMBLY_E9999; - case 'warn': return CODES.CDK_ASSEMBLY_W9999; - default: return CODES.CDK_ASSEMBLY_I9999; + case 'error': return IO.CDK_ASSEMBLY_E9999; + case 'warn': return IO.CDK_ASSEMBLY_W9999; + default: return IO.CDK_ASSEMBLY_I9999; } }; await stacks.validateMetadata( diff --git a/packages/@aws-cdk/toolkit-lib/scripts/gen-code-registry.ts b/packages/@aws-cdk/toolkit-lib/scripts/gen-code-registry.ts index 3460355b9..d41d0ebfb 100644 --- a/packages/@aws-cdk/toolkit-lib/scripts/gen-code-registry.ts +++ b/packages/@aws-cdk/toolkit-lib/scripts/gen-code-registry.ts @@ -1,5 +1,5 @@ import * as fs from 'fs'; -import { CODES } from '../lib/api/io/private/codes'; +import { IO } from '../lib/api/io/private/messages'; function codesToMarkdownTable(codes: Record