Skip to content

Commit 7693a57

Browse files
committed
use new toolkit from old cli
1 parent 445fd71 commit 7693a57

File tree

5 files changed

+56
-13
lines changed

5 files changed

+56
-13
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
@@ -91,7 +91,7 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab
9191
* The IoHost of this Toolkit
9292
*/
9393
public readonly ioHost: IIoHost;
94-
private _sdkProvider?: SdkProvider;
94+
private sdkProviderCache?: SdkProvider;
9595

9696
public constructor(private readonly props: ToolkitOptions = {}) {
9797
super();
@@ -124,21 +124,23 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab
124124

125125
/**
126126
* Access to the AWS SDK
127+
* @internal
127128
*/
128-
private async sdkProvider(action: ToolkitAction): Promise<SdkProvider> {
129+
protected async sdkProvider(action: ToolkitAction): Promise<SdkProvider> {
129130
// @todo this needs to be different instance per action
130-
if (!this._sdkProvider) {
131-
this._sdkProvider = await SdkProvider.withAwsCliCompatibleDefaults({
131+
if (!this.sdkProviderCache) {
132+
this.sdkProviderCache = await SdkProvider.withAwsCliCompatibleDefaults({
132133
...this.props.sdkConfig,
133134
logger: asSdkLogger(asIoHelper(this.ioHost, action)),
134135
});
135136
}
136137

137-
return this._sdkProvider;
138+
return this.sdkProviderCache;
138139
}
139140

140141
/**
141142
* Helper to provide the CloudAssemblySourceBuilder with required toolkit services
143+
* @internal
142144
*/
143145
protected override async sourceBuilderServices(): Promise<ToolkitServices> {
144146
return {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type * as cxapi from '@aws-cdk/cx-api';
22
import { CloudAssembly } from './cloud-assembly';
33
import { ToolkitError } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api';
44
import { IO, type IoHelper } from '../../../../@aws-cdk/tmp-toolkit-helpers/src/api/io/private';
5+
import type { ICloudAssemblySource } from '../../../../@aws-cdk/toolkit-lib/lib/api/cloud-assembly';
56
import type { Configuration } from '../../cli/user-configuration';
67
import * as contextproviders from '../../context-providers';
78
import type { SdkProvider } from '../aws-auth';
@@ -36,12 +37,16 @@ export interface CloudExecutableProps {
3637
/**
3738
* Represent the Cloud Executable and the synthesis we can do on it
3839
*/
39-
export class CloudExecutable {
40+
export class CloudExecutable implements ICloudAssemblySource {
4041
private _cloudAssembly?: CloudAssembly;
4142

4243
constructor(private readonly props: CloudExecutableProps) {
4344
}
4445

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

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

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ import * as chokidar from 'chokidar';
66
import * as fs from 'fs-extra';
77
import * as promptly from 'promptly';
88
import * as uuid from 'uuid';
9+
import { CliIoHost } from './io-host';
910
import type { Configuration } from './user-configuration';
1011
import { PROJECT_CONFIG } from './user-configuration';
12+
import type { ToolkitAction } from '../../../@aws-cdk/tmp-toolkit-helpers/src/api';
1113
import { ToolkitError } from '../../../@aws-cdk/tmp-toolkit-helpers/src/api';
1214
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';
1317
import { DEFAULT_TOOLKIT_STACK_NAME } from '../api';
1418
import type { SdkProvider } from '../api/aws-auth';
1519
import type { BootstrapEnvironmentOptions } from '../api/bootstrap';
@@ -59,7 +63,6 @@ import {
5963
buildCfnClient,
6064
} from '../commands/migrate';
6165
import { result as logResult, debug, error, highlight, info, success, warning } from '../logging';
62-
import { CliIoHost } from './io-host';
6366
import { partition, validateSnsTopicArn, formatErrorMessage, deserializeStructure, obscureTemplate, serializeStructure, formatTime } from '../util';
6467

6568
// Must use a require() otherwise esbuild complains about calling a namespace
@@ -145,6 +148,22 @@ export enum AssetBuildTime {
145148
JUST_IN_TIME = 'just-in-time',
146149
}
147150

151+
class InternalToolkit extends Toolkit {
152+
private readonly _sdkProvider: SdkProvider;
153+
public constructor(sdkProvider: SdkProvider, options: ToolkitOptions) {
154+
super(options);
155+
this._sdkProvider = sdkProvider;
156+
}
157+
158+
/**
159+
* Access to the AWS SDK
160+
* @internal
161+
*/
162+
protected override async sdkProvider(_action: ToolkitAction): Promise<SdkProvider> {
163+
return this._sdkProvider;
164+
}
165+
}
166+
148167
/**
149168
* Toolkit logic
150169
*
@@ -154,10 +173,21 @@ export enum AssetBuildTime {
154173
export class CdkToolkit {
155174
private ioHost: CliIoHost;
156175
private toolkitStackName: string;
176+
private toolkit: InternalToolkit;
157177

158178
constructor(private readonly props: CdkToolkitProps) {
159179
this.ioHost = props.ioHost ?? CliIoHost.instance();
160180
this.toolkitStackName = props.toolkitStackName ?? DEFAULT_TOOLKIT_STACK_NAME;
181+
182+
this.toolkit = new InternalToolkit(props.sdkProvider, {
183+
assemblyFailureAt: this.validateMetadataFailAt(),
184+
color: true,
185+
emojis: true,
186+
ioHost: this.ioHost,
187+
sdkConfig: {},
188+
toolkitStackName: this.toolkitStackName,
189+
});
190+
this.toolkit; // aritifical use of this.toolkit to satisfy TS, we want to prepare usage of the new toolkit without using it just yet
161191
}
162192

163193
public async metadata(stackName: string, json: boolean) {
@@ -1251,6 +1281,11 @@ export class CdkToolkit {
12511281
* Validate the stacks for errors and warnings according to the CLI's current settings
12521282
*/
12531283
private async validateStacks(stacks: StackCollection) {
1284+
const failAt = this.validateMetadataFailAt();
1285+
await stacks.validateMetadata(failAt, stackMetadataLogger(this.props.verbose));
1286+
}
1287+
1288+
private validateMetadataFailAt(): 'warn' | 'error' | 'none' {
12541289
let failAt: 'warn' | 'error' | 'none' = 'error';
12551290
if (this.props.ignoreErrors) {
12561291
failAt = 'none';
@@ -1259,7 +1294,7 @@ export class CdkToolkit {
12591294
failAt = 'warn';
12601295
}
12611296

1262-
await stacks.validateMetadata(failAt, stackMetadataLogger(this.props.verbose));
1297+
return failAt;
12631298
}
12641299

12651300
/**

packages/aws-cdk/lib/legacy-exports-source.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ export * from './legacy-logging-source';
88
export { deepClone, flatten, ifDefined, isArray, isEmpty, numberFromBool, partition, padLeft as leftPad, contentHash, deepMerge, lowerCaseFirstCharacter } from './util';
99
export { deployStack } from './api/deployments/deploy-stack';
1010
export { cli, exec } from './cli/cli';
11-
export { SdkProvider } from './api/aws-auth';
11+
export { SdkProvider } from './api/aws-auth/sdk-provider';
12+
export { setSdkTracing as enableTracing } from './api/aws-auth/tracing';
13+
export { CredentialPlugins } from './api/aws-auth/credential-plugins';
14+
export { cached } from './api/aws-auth/cached';
15+
export { AwsCliCompatible } from './api/aws-auth/awscli-compatible';
1216
export { PluginHost } from './api/plugin';
1317
export { Command, Configuration, PROJECT_CONTEXT } from './cli/user-configuration';
1418
export { Settings } from './api/settings';
@@ -17,13 +21,9 @@ export { CloudExecutable } from './api/cxapp/cloud-executable';
1721
export { execProgram } from './api/cxapp/exec';
1822
export { RequireApproval } from './commands/diff';
1923
export { formatAsBanner } from './cli/util/console-formatters';
20-
export { setSdkTracing as enableTracing } from './api/aws-auth/tracing';
2124
export { aliases, command, describe } from './commands/docs';
2225
export { Deployments } from './api/deployments';
2326
export { cliRootDir as rootDir } from './cli/root-dir';
2427
export { latestVersionIfHigher, versionNumber } from './cli/version';
2528
export { availableInitTemplates } from './commands/init';
26-
export { cached } from './api/aws-auth/cached';
2729
export { CfnEvaluationException } from './api/cloudformation/evaluate-cloudformation-template';
28-
export { CredentialPlugins } from './api/aws-auth/credential-plugins';
29-
export { AwsCliCompatible } from './api/aws-auth/awscli-compatible';

0 commit comments

Comments
 (0)