Skip to content

Commit d748fae

Browse files
committed
use new toolkit from old cli
1 parent 1952cfe commit d748fae

File tree

4 files changed

+49
-7
lines changed

4 files changed

+49
-7
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type { AssemblyBuilder } from '../source-builder';
1515
export abstract class CloudAssemblySourceBuilder {
1616
/**
1717
* Helper to provide the CloudAssemblySourceBuilder with required toolkit services
18+
* @internal
1819
* @deprecated this should move to the toolkit really.
1920
*/
2021
protected abstract sourceBuilderServices(): Promise<ToolkitServices>;

packages/@aws-cdk/toolkit-lib/lib/toolkit/toolkit.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class Toolkit extends CloudAssemblySourceBuilder {
9393
/**
9494
* Cache of the internal SDK Provider instance
9595
*/
96-
private _sdkProvider?: SdkProvider;
96+
private sdkProviderCache?: SdkProvider;
9797

9898
public constructor(private readonly props: ToolkitOptions = {}) {
9999
super();
@@ -113,23 +113,25 @@ export class Toolkit extends CloudAssemblySourceBuilder {
113113

114114
/**
115115
* Access to the AWS SDK
116+
* @internal
116117
*/
117-
private async sdkProvider(action: ToolkitAction): Promise<SdkProvider> {
118+
protected async sdkProvider(action: ToolkitAction): Promise<SdkProvider> {
118119
// @todo this needs to be different instance per action
119-
if (!this._sdkProvider) {
120+
if (!this.sdkProviderCache) {
120121
const ioHelper = asIoHelper(this.ioHost, action);
121-
this._sdkProvider = await SdkProvider.withAwsCliCompatibleDefaults({
122+
this.sdkProviderCache = await SdkProvider.withAwsCliCompatibleDefaults({
122123
...this.props.sdkConfig,
123124
ioHelper,
124125
logger: asSdkLogger(ioHelper),
125126
});
126127
}
127128

128-
return this._sdkProvider;
129+
return this.sdkProviderCache;
129130
}
130131

131132
/**
132133
* Helper to provide the CloudAssemblySourceBuilder with required toolkit services
134+
* @internal
133135
*/
134136
protected override async sourceBuilderServices(): Promise<ToolkitServices> {
135137
return {

packages/aws-cdk/lib/cli/cdk-toolkit.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ import * as uuid from 'uuid';
99
import { CliIoHost } from './io-host';
1010
import type { Configuration } from './user-configuration';
1111
import { PROJECT_CONFIG } from './user-configuration';
12+
import type { ToolkitAction } from '../../../@aws-cdk/tmp-toolkit-helpers/src/api';
1213
import { ToolkitError } from '../../../@aws-cdk/tmp-toolkit-helpers/src/api';
1314
import { asIoHelper } from '../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private';
15+
import type { ToolkitOptions } from '../../../@aws-cdk/toolkit-lib/lib/toolkit';
16+
import { Toolkit } from '../../../@aws-cdk/toolkit-lib/lib/toolkit';
1417
import { DEFAULT_TOOLKIT_STACK_NAME } from '../api';
1518
import type { SdkProvider } from '../api/aws-auth';
1619
import type { BootstrapEnvironmentOptions } from '../api/bootstrap';
@@ -139,6 +142,22 @@ export enum AssetBuildTime {
139142
JUST_IN_TIME = 'just-in-time',
140143
}
141144

145+
class InternalToolkit extends Toolkit {
146+
private readonly _sdkProvider: SdkProvider;
147+
public constructor(sdkProvider: SdkProvider, options: ToolkitOptions) {
148+
super(options);
149+
this._sdkProvider = sdkProvider;
150+
}
151+
152+
/**
153+
* Access to the AWS SDK
154+
* @internal
155+
*/
156+
protected override async sdkProvider(_action: ToolkitAction): Promise<SdkProvider> {
157+
return this._sdkProvider;
158+
}
159+
}
160+
142161
/**
143162
* Toolkit logic
144163
*
@@ -148,10 +167,21 @@ export enum AssetBuildTime {
148167
export class CdkToolkit {
149168
private ioHost: CliIoHost;
150169
private toolkitStackName: string;
170+
private toolkit: InternalToolkit;
151171

152172
constructor(private readonly props: CdkToolkitProps) {
153173
this.ioHost = props.ioHost ?? CliIoHost.instance();
154174
this.toolkitStackName = props.toolkitStackName ?? DEFAULT_TOOLKIT_STACK_NAME;
175+
176+
this.toolkit = new InternalToolkit(props.sdkProvider, {
177+
assemblyFailureAt: this.validateMetadataFailAt(),
178+
color: true,
179+
emojis: true,
180+
ioHost: this.ioHost,
181+
sdkConfig: {},
182+
toolkitStackName: this.toolkitStackName,
183+
});
184+
this.toolkit; // aritifical use of this.toolkit to satisfy TS, we want to prepare usage of the new toolkit without using it just yet
155185
}
156186

157187
public async metadata(stackName: string, json: boolean) {
@@ -1250,6 +1280,11 @@ export class CdkToolkit {
12501280
* Validate the stacks for errors and warnings according to the CLI's current settings
12511281
*/
12521282
private async validateStacks(stacks: StackCollection) {
1283+
const failAt = this.validateMetadataFailAt();
1284+
await stacks.validateMetadata(failAt, stackMetadataLogger(this.props.verbose));
1285+
}
1286+
1287+
private validateMetadataFailAt(): 'warn' | 'error' | 'none' {
12531288
let failAt: 'warn' | 'error' | 'none' = 'error';
12541289
if (this.props.ignoreErrors) {
12551290
failAt = 'none';
@@ -1258,7 +1293,7 @@ export class CdkToolkit {
12581293
failAt = 'warn';
12591294
}
12601295

1261-
await stacks.validateMetadata(failAt, stackMetadataLogger(this.props.verbose));
1296+
return failAt;
12621297
}
12631298

12641299
/**

packages/aws-cdk/lib/cxapp/cloud-executable.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,16 @@ export interface CloudExecutableProps {
3636
/**
3737
* Represent the Cloud Executable and the synthesis we can do on it
3838
*/
39-
export class CloudExecutable {
39+
export class CloudExecutable implements ICloudAssemblySource {
4040
private _cloudAssembly?: CloudAssembly;
4141

4242
constructor(private readonly props: CloudExecutableProps) {
4343
}
4444

45+
public async produce(): Promise<cxapi.CloudAssembly> {
46+
return (await this.synthesize(true)).assembly;
47+
}
48+
4549
/**
4650
* Return whether there is an app command from the configuration
4751
*/

0 commit comments

Comments
 (0)