Skip to content

Commit a6d4516

Browse files
authored
chore(toolkit-lib): rename CODES to IO (#206)
I don't want to type `CODES` all the time and the new name is more inline with the new purpose of a message builder registry anyway. --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
1 parent 8c5ec76 commit a6d4516

File tree

9 files changed

+68
-68
lines changed

9 files changed

+68
-68
lines changed

packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/private/context-aware-source.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { MissingContext } from '@aws-cdk/cloud-assembly-schema';
22
import type * as cxapi from '@aws-cdk/cx-api';
33
import type { ToolkitServices } from '../../../toolkit/private';
44
import { type Context, contextproviders, PROJECT_CONTEXT } from '../../aws-cdk';
5-
import { CODES } from '../../io/private';
5+
import { IO } from '../../io/private';
66
import type { ActionAwareIoHost } from '../../shared-private';
77
import { ToolkitError } from '../../shared-public';
88
import type { ICloudAssemblySource } from '../types';
@@ -77,22 +77,22 @@ export class ContextAwareCloudAssembly implements ICloudAssemblySource {
7777

7878
let tryLookup = true;
7979
if (previouslyMissingKeys && equalSets(missingKeysSet, previouslyMissingKeys)) {
80-
await this.ioHost.notify(CODES.CDK_ASSEMBLY_I0240.msg('Not making progress trying to resolve environmental context. Giving up.', { missingKeys }));
80+
await this.ioHost.notify(IO.CDK_ASSEMBLY_I0240.msg('Not making progress trying to resolve environmental context. Giving up.', { missingKeys }));
8181
tryLookup = false;
8282
}
8383

8484
previouslyMissingKeys = missingKeysSet;
8585

8686
if (tryLookup) {
87-
await this.ioHost.notify(CODES.CDK_ASSEMBLY_I0241.msg('Some context information is missing. Fetching...', { missingKeys }));
87+
await this.ioHost.notify(IO.CDK_ASSEMBLY_I0241.msg('Some context information is missing. Fetching...', { missingKeys }));
8888
await contextproviders.provideContextValues(
8989
assembly.manifest.missing,
9090
this.context,
9191
this.props.services.sdkProvider,
9292
);
9393

9494
// Cache the new context to disk
95-
await this.ioHost.notify(CODES.CDK_ASSEMBLY_I0042.msg(`Writing updated context to ${this.contextFile}...`, {
95+
await this.ioHost.notify(IO.CDK_ASSEMBLY_I0042.msg(`Writing updated context to ${this.contextFile}...`, {
9696
contextFile: this.contextFile,
9797
context: this.context.all,
9898
}));

packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/private/prepare-source.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { lte } from 'semver';
88
import { prepareDefaultEnvironment as oldPrepare, prepareContext, spaceAvailableForContext, Settings, loadTree, some, versionNumber } from '../../../api/aws-cdk';
99
import { splitBySize } from '../../../private/util';
1010
import type { ToolkitServices } from '../../../toolkit/private';
11-
import { CODES } from '../../io/private';
11+
import { IO } from '../../io/private';
1212
import type { ActionAwareIoHost } from '../../shared-private';
1313
import { ToolkitError } from '../../shared-public';
1414
import type { AppSynthOptions, LoadAssemblyOptions } from '../source-builder';
@@ -38,7 +38,7 @@ export function determineOutputDirectory(outdir?: string) {
3838
* @param context The context key/value bash.
3939
*/
4040
export async function prepareDefaultEnvironment(services: ToolkitServices, props: { outdir?: string } = {}): Promise<Env> {
41-
const logFn = (msg: string, ...args: any) => services.ioHost.notify(CODES.CDK_ASSEMBLY_I0010.msg(format(msg, ...args)));
41+
const logFn = (msg: string, ...args: any) => services.ioHost.notify(IO.CDK_ASSEMBLY_I0010.msg(format(msg, ...args)));
4242
const env = await oldPrepare(services.sdkProvider, logFn);
4343

4444
if (props.outdir) {
@@ -142,7 +142,7 @@ export async function checkContextOverflowSupport(assembly: cxapi.CloudAssembly,
142142
// We're dealing with an old version of the framework here. It is unaware of the temporary
143143
// file, which means that it will ignore the context overflow.
144144
if (frameworkDoesNotSupportContextOverflow) {
145-
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.'));
145+
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.'));
146146
}
147147
}
148148

@@ -164,7 +164,7 @@ export async function assemblyFromDirectory(assemblyDir: string, ioHost: ActionA
164164
// this means the CLI version is too old.
165165
// we instruct the user to upgrade.
166166
const message = 'This AWS CDK Toolkit is not compatible with the AWS CDK library used by your application. Please upgrade to the latest version.';
167-
await ioHost.notify(CODES.CDK_ASSEMBLY_E1111.msg(message, { error: err }));
167+
await ioHost.notify(IO.CDK_ASSEMBLY_E1111.msg(message, { error: err }));
168168
throw new ToolkitError(`${message}\n(${err.message}`);
169169
}
170170
throw err;

packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/private/source-builder.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { assemblyFromDirectory, changeDir, determineOutputDirectory, guessExecut
88
import type { ToolkitServices } from '../../../toolkit/private';
99
import type { ILock } from '../../aws-cdk';
1010
import { Context, RWLock, Settings } from '../../aws-cdk';
11-
import { CODES } from '../../io/private';
11+
import { IO } from '../../io/private';
1212
import { ToolkitError, AssemblyError } from '../../shared-public';
1313
import type { AssemblyBuilder } from '../source-builder';
1414

@@ -89,7 +89,7 @@ export abstract class CloudAssemblySourceBuilder {
8989
{
9090
produce: async () => {
9191
// @todo build
92-
await services.ioHost.notify(CODES.CDK_ASSEMBLY_I0150.msg('--app points to a cloud assembly, so we bypass synth'));
92+
await services.ioHost.notify(IO.CDK_ASSEMBLY_I0150.msg('--app points to a cloud assembly, so we bypass synth'));
9393
return assemblyFromDirectory(directory, services.ioHost, props.loadAssemblyOptions);
9494
},
9595
},
@@ -139,10 +139,10 @@ export abstract class CloudAssemblySourceBuilder {
139139
eventPublisher: async (type, line) => {
140140
switch (type) {
141141
case 'data_stdout':
142-
await services.ioHost.notify(CODES.CDK_ASSEMBLY_I1001.msg(line));
142+
await services.ioHost.notify(IO.CDK_ASSEMBLY_I1001.msg(line));
143143
break;
144144
case 'data_stderr':
145-
await services.ioHost.notify(CODES.CDK_ASSEMBLY_E1002.msg(line));
145+
await services.ioHost.notify(IO.CDK_ASSEMBLY_E1002.msg(line));
146146
break;
147147
}
148148
},

packages/@aws-cdk/toolkit-lib/lib/api/io/private/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export * from './codes';
1+
export * from './messages';
22
export * from './io-host-wrappers';
33
export * from './level-priority';
44
export * from './timer';

packages/@aws-cdk/toolkit-lib/lib/api/io/private/codes.ts renamed to packages/@aws-cdk/toolkit-lib/lib/api/io/private/messages.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import * as make from '../../shared-private';
1717
* - X000-X009 are reserved for timings
1818
* - X900-X999 are reserved for results
1919
*/
20-
export const CODES = {
20+
export const IO = {
2121
// Defaults
2222
DEFAULT_TOOLKIT_INFO: make.info({
2323
code: 'CDK_TOOLKIT_I0000',

packages/@aws-cdk/toolkit-lib/lib/api/io/private/sdk-logger.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
import { inspect } from 'util';
33
import type { Logger } from '@smithy/types';
4-
import { CODES } from './codes';
4+
import { IO } from './messages';
55
import { replacerBufferWithInfo } from '../../../private/util';
66
import type { ActionAwareIoHost } from '../../shared-private';
77

@@ -63,14 +63,14 @@ export function asSdkLogger(ioHost: ActionAwareIoHost): Logger {
6363
* ```
6464
*/
6565
public info(...content: any[]) {
66-
void ioHost.notify(CODES.CDK_SDK_I0100.msg(`[sdk info] ${formatSdkLoggerContent(content)}`, {
66+
void ioHost.notify(IO.CDK_SDK_I0100.msg(`[sdk info] ${formatSdkLoggerContent(content)}`, {
6767
sdkLevel: 'info',
6868
content,
6969
}));
7070
}
7171

7272
public warn(...content: any[]) {
73-
void ioHost.notify(CODES.CDK_SDK_I0100.msg(`[sdk warn] ${formatSdkLoggerContent(content)}`, {
73+
void ioHost.notify(IO.CDK_SDK_I0100.msg(`[sdk warn] ${formatSdkLoggerContent(content)}`, {
7474
sdkLevel: 'warn',
7575
content,
7676
}));
@@ -98,7 +98,7 @@ export function asSdkLogger(ioHost: ActionAwareIoHost): Logger {
9898
* ```
9999
*/
100100
public error(...content: any[]) {
101-
void ioHost.notify(CODES.CDK_SDK_I0100.msg(`[sdk error] ${formatSdkLoggerContent(content)}`, {
101+
void ioHost.notify(IO.CDK_SDK_I0100.msg(`[sdk error] ${formatSdkLoggerContent(content)}`, {
102102
sdkLevel: 'error',
103103
content,
104104
}));

packages/@aws-cdk/toolkit-lib/lib/api/io/private/timer.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { format } from 'util';
2-
import { CODES } from './codes';
2+
import { IO } from './messages';
33
import { formatTime } from '../../../private/util';
44
import type { ActionAwareIoHost } from '../../shared-private';
55

@@ -52,10 +52,10 @@ function timerMessage(type: 'synth' | 'deploy' | 'rollback'| 'destroy' | 'bootst
5252
const payload = { duration: duration.asMs };
5353

5454
switch (type) {
55-
case 'synth': return CODES.CDK_TOOLKIT_I1000.msg(format(message, 'Synthesis'), payload);
56-
case 'deploy': return CODES.CDK_TOOLKIT_I5000.msg(format(message, 'Deployment'), payload);
57-
case 'rollback': return CODES.CDK_TOOLKIT_I6000.msg(format(message, 'Rollback'), payload);
58-
case 'destroy': return CODES.CDK_TOOLKIT_I7000.msg(format(message, 'Destroy'), payload);
59-
case 'bootstrap': return CODES.CDK_TOOLKIT_I9000.msg(format(message, 'Bootstrap'), payload);
55+
case 'synth': return IO.CDK_TOOLKIT_I1000.msg(format(message, 'Synthesis'), payload);
56+
case 'deploy': return IO.CDK_TOOLKIT_I5000.msg(format(message, 'Deployment'), payload);
57+
case 'rollback': return IO.CDK_TOOLKIT_I6000.msg(format(message, 'Rollback'), payload);
58+
case 'destroy': return IO.CDK_TOOLKIT_I7000.msg(format(message, 'Destroy'), payload);
59+
case 'bootstrap': return IO.CDK_TOOLKIT_I9000.msg(format(message, 'Bootstrap'), payload);
6060
}
6161
}

0 commit comments

Comments
 (0)