Skip to content

Commit db6aa96

Browse files
authored
refactor(cli): make the cli use more shared code (#207)
Removes duplicated interfaces. I know this is messy. Please bear with me 🙈 --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
1 parent 2dca898 commit db6aa96

File tree

24 files changed

+101
-190
lines changed

24 files changed

+101
-190
lines changed

.projenrc.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,8 @@ tmpToolkitHelpers.eslint?.addRules({
733733
'@typescript-eslint/consistent-type-imports': 'error',
734734
});
735735

736+
tmpToolkitHelpers.gitignore.addPatterns('test/**/*.map');
737+
736738
//////////////////////////////////////////////////////////////////////
737739

738740
let CLI_SDK_VERSION: '2' | '3' = ('3' as any);

packages/@aws-cdk/tmp-toolkit-helpers/.gitignore

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
export * from './action-aware';
1+
export * from './io-helper';
2+
export * from './level-priority';
23
export * from './message-maker';
34
export * from './types';

packages/@aws-cdk/tmp-toolkit-helpers/src/api/io/private/action-aware.ts renamed to packages/@aws-cdk/tmp-toolkit-helpers/src/api/io/private/io-helper.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,22 @@ export type ActionLessMessage<T> = Omit<IoMessage<T>, 'action'>;
88
export type ActionLessRequest<T, U> = Omit<IoRequest<T, U>, 'action'>;
99

1010
/**
11-
* Helper type for IoHosts that are action aware
11+
* Helper for IO messaging.
12+
*
13+
* Wraps a client provided IoHost and provides additional features & services to toolkit internal classes.
1214
*/
13-
export interface ActionAwareIoHost extends IIoHost {
15+
export interface IoHelper extends IIoHost {
16+
action: ToolkitAction;
1417
notify<T>(msg: ActionLessMessage<T>): Promise<void>;
1518
requestResponse<T, U>(msg: ActionLessRequest<T, U>): Promise<U>;
1619
}
1720

1821
/**
19-
* An IoHost wrapper that adds the given action to an actionless message before
20-
* sending the message to the given IoHost
22+
* Wraps an IoHost and creates an IoHelper from it
2123
*/
22-
export function withAction(ioHost: IIoHost, action: ToolkitAction): ActionAwareIoHost {
24+
export function asIoHelper(ioHost: IIoHost, action: ToolkitAction): IoHelper {
2325
return {
26+
action,
2427
notify: async <T>(msg: Omit<IoMessage<T>, 'action'>) => {
2528
await ioHost.notify({
2629
...msg,

packages/@aws-cdk/toolkit-lib/lib/api/io/private/level-priority.ts renamed to packages/@aws-cdk/tmp-toolkit-helpers/src/api/io/private/level-priority.ts

File renamed without changes.

packages/@aws-cdk/tmp-toolkit-helpers/src/api/io/private/message-maker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { IoMessageCode, IoMessageLevel } from '../io-message';
2-
import type { ActionLessMessage, ActionLessRequest } from './action-aware';
2+
import type { ActionLessMessage, ActionLessRequest } from './io-helper';
33

44
/**
55
* Information for each IO Message Code.

packages/@aws-cdk/toolkit-lib/test/api/io/io-message.test.ts renamed to packages/@aws-cdk/tmp-toolkit-helpers/test/api/io/io-message.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isMessageRelevantForLevel } from '../../../lib/api/io/private/level-priority';
1+
import { isMessageRelevantForLevel } from '../../../src/api/io/private/level-priority';
22

33
describe('IoMessageLevel', () => {
44
test.each`

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ 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';
55
import { IO } from '../../io/private';
6-
import type { ActionAwareIoHost } from '../../shared-private';
6+
import type { IoHelper } from '../../shared-private';
77
import { ToolkitError } from '../../shared-public';
88
import type { ICloudAssemblySource } from '../types';
99

@@ -43,7 +43,7 @@ export class ContextAwareCloudAssembly implements ICloudAssemblySource {
4343
private canLookup: boolean;
4444
private context: Context;
4545
private contextFile: string;
46-
private ioHost: ActionAwareIoHost;
46+
private ioHost: IoHelper;
4747

4848
constructor(private readonly source: ICloudAssemblySource, private readonly props: ContextAwareCloudAssemblyProps) {
4949
this.canLookup = props.lookups ?? true;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { prepareDefaultEnvironment as oldPrepare, prepareContext, spaceAvailable
99
import { splitBySize } from '../../../private/util';
1010
import type { ToolkitServices } from '../../../toolkit/private';
1111
import { IO } from '../../io/private';
12-
import type { ActionAwareIoHost } from '../../shared-private';
12+
import type { IoHelper } from '../../shared-private';
1313
import { ToolkitError } from '../../shared-public';
1414
import type { AppSynthOptions, LoadAssemblyOptions } from '../source-builder';
1515

@@ -130,7 +130,7 @@ export async function withContext<T>(
130130
*
131131
* @param assembly the assembly to check
132132
*/
133-
export async function checkContextOverflowSupport(assembly: cxapi.CloudAssembly, ioHost: ActionAwareIoHost): Promise<void> {
133+
export async function checkContextOverflowSupport(assembly: cxapi.CloudAssembly, ioHost: IoHelper): Promise<void> {
134134
const tree = loadTree(assembly);
135135
const frameworkDoesNotSupportContextOverflow = some(tree, node => {
136136
const fqn = node.constructInfo?.fqn;
@@ -149,7 +149,7 @@ export async function checkContextOverflowSupport(assembly: cxapi.CloudAssembly,
149149
/**
150150
* Safely create an assembly from a cloud assembly directory
151151
*/
152-
export async function assemblyFromDirectory(assemblyDir: string, ioHost: ActionAwareIoHost, loadOptions: LoadAssemblyOptions = {}) {
152+
export async function assemblyFromDirectory(assemblyDir: string, ioHost: IoHelper, loadOptions: LoadAssemblyOptions = {}) {
153153
try {
154154
const assembly = new cxapi.CloudAssembly(assemblyDir, {
155155
skipVersionCheck: !(loadOptions.checkVersion ?? true),
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export * from './messages';
22
export * from './io-host-wrappers';
3-
export * from './level-priority';
43
export * from './timer';
54
export * from './sdk-logger';

0 commit comments

Comments
 (0)