Skip to content

Commit 0137d34

Browse files
authored
feat(toolkit-lib): simplify action options (#503)
Simplifies the options for various toolkit-lib actions by standardizing parameter structures and removing unnecessary complexity. --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license.
1 parent 66e0b2d commit 0137d34

File tree

7 files changed

+24
-13
lines changed

7 files changed

+24
-13
lines changed

packages/@aws-cdk-testing/cli-integ/lib/npm.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export async function npmQueryInstalledVersion(packageName: string, dir: string)
2929
cwd: dir,
3030
show: 'error',
3131
captureStderr: false,
32+
outputs: [process.stderr],
3233
});
3334
const report = JSON.parse(reportStr);
3435
return report.dependencies[packageName].version;

packages/@aws-cdk-testing/cli-integ/lib/package-sources/cli-npm-source.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export class RunnerCliNpmSource implements IRunnerSource<ITestCliSource> {
1919
await shell(['node', require.resolve('npm'), 'install', `aws-cdk@${this.range}`], {
2020
cwd: tempDir,
2121
show: 'error',
22+
outputs: [process.stderr],
2223
});
2324
const installedVersion = await npmQueryInstalledVersion('aws-cdk', tempDir);
2425

packages/@aws-cdk-testing/cli-integ/lib/package-sources/library-globalinstall-source.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class RunnerLibraryGlobalInstallSource implements IRunnerSource<ITestLibr
2424
await shell(['node', require.resolve('npm'), 'install', `${this.packageName}@${this.range}`], {
2525
cwd: tempDir,
2626
show: 'error',
27+
outputs: [process.stderr],
2728
});
2829

2930
const symlinkPath = path.join(__dirname, '..', '..', 'node_modules', this.packageName);

packages/@aws-cdk/toolkit-lib/lib/actions/destroy/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import type { StackSelector } from '../../api/cloud-assembly';
33
export interface DestroyOptions {
44
/**
55
* Criteria for selecting stacks to deploy
6+
*
7+
* @default - all stacks
68
*/
7-
readonly stacks: StackSelector;
9+
readonly stacks?: StackSelector;
810

911
/**
10-
* The arn of the IAM role to use
12+
* The arn of the IAM role to use for the stack destroy operation
1113
*/
1214
readonly roleArn?: string;
1315
}

packages/@aws-cdk/toolkit-lib/lib/actions/diff/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,10 @@ export class DiffMethod {
9494
export interface DiffOptions {
9595
/**
9696
* Select the stacks
97+
*
98+
* @default - all stacks
9799
*/
98-
readonly stacks: StackSelector;
100+
readonly stacks?: StackSelector;
99101

100102
/**
101103
* The method to create a stack diff.

packages/@aws-cdk/toolkit-lib/lib/actions/rollback/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import type { StackSelector } from '../../api/cloud-assembly';
33
export interface RollbackOptions {
44
/**
55
* Criteria for selecting stacks to rollback
6+
*
7+
* @default - all stacks
68
*/
7-
readonly stacks: StackSelector;
9+
readonly stacks?: StackSelector;
810

911
/**
1012
* Role to pass to CloudFormation for deployment

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ export class Toolkit extends CloudAssemblySourceBuilder {
212212
/**
213213
* Bootstrap Action
214214
*/
215-
public async bootstrap(environments: BootstrapEnvironments, options: BootstrapOptions): Promise<BootstrapResult> {
215+
public async bootstrap(environments: BootstrapEnvironments, options: BootstrapOptions = {}): Promise<BootstrapResult> {
216216
const startTime = Date.now();
217217
const results: EnvironmentBootstrapResult[] = [];
218218

@@ -323,7 +323,7 @@ export class Toolkit extends CloudAssemblySourceBuilder {
323323
/**
324324
* Diff Action
325325
*/
326-
public async diff(cx: ICloudAssemblySource, options: DiffOptions): Promise<{ [name: string]: TemplateDiff }> {
326+
public async diff(cx: ICloudAssemblySource, options: DiffOptions = {}): Promise<{ [name: string]: TemplateDiff }> {
327327
const ioHelper = asIoHelper(this.ioHost, 'diff');
328328
const selectStacks = options.stacks ?? ALL_STACKS;
329329
const synthSpan = await ioHelper.span(SPAN.SYNTH_ASSEMBLY).begin({ stacks: selectStacks });
@@ -748,7 +748,7 @@ export class Toolkit extends CloudAssemblySourceBuilder {
748748
*
749749
* This function returns immediately, starting a watcher in the background.
750750
*/
751-
public async watch(cx: ICloudAssemblySource, options: WatchOptions): Promise<IWatcher> {
751+
public async watch(cx: ICloudAssemblySource, options: WatchOptions = {}): Promise<IWatcher> {
752752
const ioHelper = asIoHelper(this.ioHost, 'watch');
753753
await using assembly = await assemblyFromSource(ioHelper, cx, false);
754754
const rootDir = options.watchDir ?? process.cwd();
@@ -892,7 +892,7 @@ export class Toolkit extends CloudAssemblySourceBuilder {
892892
*
893893
* Rolls back the selected stacks.
894894
*/
895-
public async rollback(cx: ICloudAssemblySource, options: RollbackOptions): Promise<RollbackResult> {
895+
public async rollback(cx: ICloudAssemblySource, options: RollbackOptions = {}): Promise<RollbackResult> {
896896
const ioHelper = asIoHelper(this.ioHost, 'rollback');
897897
await using assembly = await assemblyFromSource(ioHelper, cx);
898898
return await this._rollback(assembly, 'rollback', options);
@@ -902,9 +902,10 @@ export class Toolkit extends CloudAssemblySourceBuilder {
902902
* Helper to allow rollback being called as part of the deploy or watch action.
903903
*/
904904
private async _rollback(assembly: StackAssembly, action: 'rollback' | 'deploy' | 'watch', options: RollbackOptions): Promise<RollbackResult> {
905+
const selectStacks = options.stacks ?? ALL_STACKS;
905906
const ioHelper = asIoHelper(this.ioHost, action);
906-
const synthSpan = await ioHelper.span(SPAN.SYNTH_ASSEMBLY).begin({ stacks: options.stacks });
907-
const stacks = await assembly.selectStacksV2(options.stacks);
907+
const synthSpan = await ioHelper.span(SPAN.SYNTH_ASSEMBLY).begin({ stacks: selectStacks });
908+
const stacks = await assembly.selectStacksV2(selectStacks);
908909
await this.validateStacksMetadata(stacks, ioHelper);
909910
await synthSpan.end();
910911

@@ -1034,7 +1035,7 @@ export class Toolkit extends CloudAssemblySourceBuilder {
10341035
*
10351036
* Destroys the selected Stacks.
10361037
*/
1037-
public async destroy(cx: ICloudAssemblySource, options: DestroyOptions): Promise<DestroyResult> {
1038+
public async destroy(cx: ICloudAssemblySource, options: DestroyOptions = {}): Promise<DestroyResult> {
10381039
const ioHelper = asIoHelper(this.ioHost, 'destroy');
10391040
await using assembly = await assemblyFromSource(ioHelper, cx);
10401041
return await this._destroy(assembly, 'destroy', options);
@@ -1044,10 +1045,11 @@ export class Toolkit extends CloudAssemblySourceBuilder {
10441045
* Helper to allow destroy being called as part of the deploy action.
10451046
*/
10461047
private async _destroy(assembly: StackAssembly, action: 'deploy' | 'destroy', options: DestroyOptions): Promise<DestroyResult> {
1048+
const selectStacks = options.stacks ?? ALL_STACKS;
10471049
const ioHelper = asIoHelper(this.ioHost, action);
1048-
const synthSpan = await ioHelper.span(SPAN.SYNTH_ASSEMBLY).begin({ stacks: options.stacks });
1050+
const synthSpan = await ioHelper.span(SPAN.SYNTH_ASSEMBLY).begin({ stacks: selectStacks });
10491051
// The stacks will have been ordered for deployment, so reverse them for deletion.
1050-
const stacks = (await assembly.selectStacksV2(options.stacks)).reversed();
1052+
const stacks = (await assembly.selectStacksV2(selectStacks)).reversed();
10511053
await synthSpan.end();
10521054

10531055
const ret: DestroyResult = {

0 commit comments

Comments
 (0)