From 2e6f65fc8251e3da80bd78bd7bee1a37c25efc47 Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Fri, 21 Aug 2020 13:08:36 +0200 Subject: [PATCH 01/11] feat(cli): skip bundling for operations where stack is not needed --- packages/@aws-cdk/core/lib/asset-staging.ts | 14 +++++++--- packages/@aws-cdk/cx-api/lib/app.ts | 5 ++++ packages/aws-cdk/bin/cdk.ts | 29 ++++++++++++++++----- packages/aws-cdk/lib/api/cxapp/exec.ts | 3 +++ packages/aws-cdk/lib/settings.ts | 1 + 5 files changed, 43 insertions(+), 9 deletions(-) diff --git a/packages/@aws-cdk/core/lib/asset-staging.ts b/packages/@aws-cdk/core/lib/asset-staging.ts index 4c16b960bbb12..3eed778f1ad78 100644 --- a/packages/@aws-cdk/core/lib/asset-staging.ts +++ b/packages/@aws-cdk/core/lib/asset-staging.ts @@ -7,6 +7,7 @@ import { AssetHashType, AssetOptions } from './assets'; import { BundlingOptions } from './bundling'; import { Construct } from './construct-compat'; import { FileSystem, FingerprintOptions } from './fs'; +import { Stack } from './stack'; import { Stage } from './stage'; const STAGING_TMP = '.cdk.staging'; @@ -89,14 +90,21 @@ export class AssetStaging extends Construct { this.sourcePath = props.sourcePath; this.fingerprintOptions = props; - if (props.bundling) { + const bundlingStacks: string[] = this.node.tryGetContext(cxapi.BUNDLING_STACKS) ?? []; + const runBundling = bundlingStacks.includes(Stack.of(this).stackName) || bundlingStacks.includes('*'); + if (props.bundling && runBundling) { this.bundleDir = this.bundle(props.bundling); } - this.assetHash = this.calculateHash(props); + this.assetHash = this.calculateHash({ + ...props, + ...!runBundling + ? { assetHashType: AssetHashType.CUSTOM, assetHash: this.node.path } + : {}, + }); const stagingDisabled = this.node.tryGetContext(cxapi.DISABLE_ASSET_STAGING_CONTEXT); - if (stagingDisabled) { + if (stagingDisabled || !runBundling) { this.stagedPath = this.bundleDir ?? this.sourcePath; } else { this.relativePath = `asset.${this.assetHash}${path.extname(this.bundleDir ?? this.sourcePath)}`; diff --git a/packages/@aws-cdk/cx-api/lib/app.ts b/packages/@aws-cdk/cx-api/lib/app.ts index d135e9cf40f07..41283679f0db2 100644 --- a/packages/@aws-cdk/cx-api/lib/app.ts +++ b/packages/@aws-cdk/cx-api/lib/app.ts @@ -27,3 +27,8 @@ export const DISABLE_ASSET_STAGING_CONTEXT = 'aws:cdk:disable-asset-staging'; * Omits stack traces from construct metadata entries. */ export const DISABLE_METADATA_STACK_TRACE = 'aws:cdk:disable-stack-trace'; + +/** + * Run bundling for stacks specified in this context key + */ +export const BUNDLING_STACKS = 'aws:cdk:bundling-stacks'; diff --git a/packages/aws-cdk/bin/cdk.ts b/packages/aws-cdk/bin/cdk.ts index 016a0855494be..6cfea1019df31 100644 --- a/packages/aws-cdk/bin/cdk.ts +++ b/packages/aws-cdk/bin/cdk.ts @@ -62,10 +62,13 @@ async function parseCommandLineArguments() { .option('output', { type: 'string', alias: 'o', desc: 'Emits the synthesized cloud assembly into a directory (default: cdk.out)', requiresArg: true }) .option('no-color', { type: 'boolean', desc: 'Removes colors and other style from console output', default: false }) .command(['list [STACKS..]', 'ls [STACKS..]'], 'Lists all stacks in the app', yargs => yargs - .option('long', { type: 'boolean', default: false, alias: 'l', desc: 'Display environment information for each stack' }), + .option('long', { type: 'boolean', default: false, alias: 'l', desc: 'Display environment information for each stack' }) + .option('bundling', { type: 'array', default: [], alias: 'b', desc: 'Run bundling only for given stacks (defaults to no stacks)' }), ) .command(['synthesize [STACKS..]', 'synth [STACKS..]'], 'Synthesizes and prints the CloudFormation template for this stack', yargs => yargs - .option('exclusively', { type: 'boolean', alias: 'e', desc: 'Only synthesize requested stacks, don\'t include dependencies' })) + .option('exclusively', { type: 'boolean', alias: 'e', desc: 'Only synthesize requested stacks, don\'t include dependencies' }) + .option('bundling', { type: 'array', default: ['*'], alias: 'b', desc: 'Run bundling only for given stacks (defaults to STACKS if `exclusively` is used, all stacks otherwise)' }), + ) .command('bootstrap [ENVIRONMENTS..]', 'Deploys the CDK toolkit stack into an AWS environment', yargs => yargs .option('bootstrap-bucket-name', { type: 'string', alias: ['b', 'toolkit-bucket-name'], desc: 'The name of the CDK toolkit bucket; bucket will be created and must not exist', default: undefined }) .option('bootstrap-kms-key-id', { type: 'string', desc: 'AWS KMS master key ID used for the SSE-KMS encryption', default: undefined }) @@ -89,16 +92,21 @@ async function parseCommandLineArguments() { .option('force', { alias: 'f', type: 'boolean', desc: 'Always deploy stack even if templates are identical', default: false }) .option('parameters', { type: 'array', desc: 'Additional parameters passed to CloudFormation at deploy time (STACK:KEY=VALUE)', nargs: 1, requiresArg: true, default: {} }) .option('outputs-file', { type: 'string', alias: 'O', desc: 'Path to file where stack outputs will be written as JSON', requiresArg: true }) - .option('previous-parameters', { type: 'boolean', default: true, desc: 'Use previous values for existing parameters (you must specify all parameters on every deployment if this is disabled)' }), + .option('previous-parameters', { type: 'boolean', default: true, desc: 'Use previous values for existing parameters (you must specify all parameters on every deployment if this is disabled)' }) + .option('bundling', { type: 'array', default: ['*'], alias: 'b', desc: 'Run bundling only for given stacks (defaults to STACKS if `exclusively` is used, all stacks otherwise)' }), ) .command('destroy [STACKS..]', 'Destroy the stack(s) named STACKS', yargs => yargs .option('exclusively', { type: 'boolean', alias: 'e', desc: 'Only destroy requested stacks, don\'t include dependees' }) - .option('force', { type: 'boolean', alias: 'f', desc: 'Do not ask for confirmation before destroying the stacks' })) + .option('force', { type: 'boolean', alias: 'f', desc: 'Do not ask for confirmation before destroying the stacks' }) + .option('bundling', { type: 'array', default: [], alias: 'b', desc: 'Run bundling only for given stacks (defaults to no stacks)' }), + ) .command('diff [STACKS..]', 'Compares the specified stack with the deployed stack or a local template file, and returns with status 1 if any difference is found', yargs => yargs .option('exclusively', { type: 'boolean', alias: 'e', desc: 'Only diff requested stacks, don\'t include dependencies' }) .option('context-lines', { type: 'number', desc: 'Number of context lines to include in arbitrary JSON diff rendering', default: 3, requiresArg: true }) .option('template', { type: 'string', desc: 'The path to the CloudFormation template to compare with', requiresArg: true }) - .option('strict', { type: 'boolean', desc: 'Do not filter out AWS::CDK::Metadata resources', default: false })) + .option('strict', { type: 'boolean', desc: 'Do not filter out AWS::CDK::Metadata resources', default: false }) + .option('bundling', { type: 'array', default: ['*'], alias: 'b', desc: 'Run bundling only for given stacks (defaults to STACKS if `exclusively` is used, all stacks otherwise)' }), + ) .option('fail', { type: 'boolean', desc: 'Fail with exit code 1 in case of diff', default: false }) .command('metadata [STACK]', 'Returns all metadata associated with this stack') .command('init [TEMPLATE]', 'Create a new, empty CDK project from a template. Invoked without TEMPLATE, the app template will be used.', yargs => yargs @@ -123,6 +131,8 @@ if (!process.stdout.isTTY) { colors.disable(); } +const CUSTOM_BUNDLING_DEFAULT_COMMANDS = ['deploy', 'diff', 'synth', 'synthesize']; + async function initCommandLine() { const argv = await parseCommandLineArguments(); if (argv.verbose) { @@ -131,7 +141,14 @@ async function initCommandLine() { debug('CDK toolkit version:', version.DISPLAY_VERSION); debug('Command line arguments:', argv); - const configuration = new Configuration(argv); + // Custom `bundling` default. If we deploy or diff a list of stacks + // exclusively we skip bundling for all other stacks. + let bundling = argv.bundling; + if (CUSTOM_BUNDLING_DEFAULT_COMMANDS.includes(argv._[0]) && argv.exclusively) { + bundling = argv.STACKS as string[]; + } + + const configuration = new Configuration({ ...argv, bundling }); await configuration.load(); const sdkProvider = await SdkProvider.withAwsCliCompatibleDefaults({ diff --git a/packages/aws-cdk/lib/api/cxapp/exec.ts b/packages/aws-cdk/lib/api/cxapp/exec.ts index 597a236ec1b3c..6646ded093c02 100644 --- a/packages/aws-cdk/lib/api/cxapp/exec.ts +++ b/packages/aws-cdk/lib/api/cxapp/exec.ts @@ -39,6 +39,9 @@ export async function execProgram(aws: SdkProvider, config: Configuration): Prom context[cxapi.DISABLE_ASSET_STAGING_CONTEXT] = true; } + const bundlingStacks = config.settings.get(['bundling']) ?? []; + context[cxapi.BUNDLING_STACKS] = bundlingStacks; + debug('context:', context); env[cxapi.CONTEXT_ENV] = JSON.stringify(context); diff --git a/packages/aws-cdk/lib/settings.ts b/packages/aws-cdk/lib/settings.ts index 79e7cee92fe2a..7d78fdae2c7ed 100644 --- a/packages/aws-cdk/lib/settings.ts +++ b/packages/aws-cdk/lib/settings.ts @@ -204,6 +204,7 @@ export class Settings { versionReporting: argv.versionReporting, staging: argv.staging, output: argv.output, + bundling: argv.bundling, }); } From 6140dab5330d4d352c6260d6dd9eefe44a089527 Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Fri, 21 Aug 2020 13:23:42 +0200 Subject: [PATCH 02/11] move custom default and test it --- packages/@aws-cdk/core/lib/asset-staging.ts | 2 +- packages/@aws-cdk/core/lib/tag-aspect.ts | 2 +- packages/aws-cdk/bin/cdk.ts | 11 +---------- packages/aws-cdk/lib/settings.ts | 13 +++++++++++-- packages/aws-cdk/test/context.test.ts | 2 +- packages/aws-cdk/test/settings.test.ts | 20 ++++++++++++++++---- 6 files changed, 31 insertions(+), 19 deletions(-) diff --git a/packages/@aws-cdk/core/lib/asset-staging.ts b/packages/@aws-cdk/core/lib/asset-staging.ts index 3eed778f1ad78..a1f9cc8301c09 100644 --- a/packages/@aws-cdk/core/lib/asset-staging.ts +++ b/packages/@aws-cdk/core/lib/asset-staging.ts @@ -90,7 +90,7 @@ export class AssetStaging extends Construct { this.sourcePath = props.sourcePath; this.fingerprintOptions = props; - const bundlingStacks: string[] = this.node.tryGetContext(cxapi.BUNDLING_STACKS) ?? []; + const bundlingStacks: string[] = this.node.tryGetContext(cxapi.BUNDLING_STACKS) ?? ['*']; const runBundling = bundlingStacks.includes(Stack.of(this).stackName) || bundlingStacks.includes('*'); if (props.bundling && runBundling) { this.bundleDir = this.bundle(props.bundling); diff --git a/packages/@aws-cdk/core/lib/tag-aspect.ts b/packages/@aws-cdk/core/lib/tag-aspect.ts index 34d9a6dfd4e40..d56c28b551d87 100644 --- a/packages/@aws-cdk/core/lib/tag-aspect.ts +++ b/packages/@aws-cdk/core/lib/tag-aspect.ts @@ -1,8 +1,8 @@ // import * as cxapi from '@aws-cdk/cx-api'; +import { Annotations } from './annotations'; import { IAspect, Aspects } from './aspect'; import { Construct, IConstruct } from './construct-compat'; import { ITaggable, TagManager } from './tag-manager'; -import { Annotations } from './annotations'; /** * Properties for a tag diff --git a/packages/aws-cdk/bin/cdk.ts b/packages/aws-cdk/bin/cdk.ts index 6cfea1019df31..1b970b72d3687 100644 --- a/packages/aws-cdk/bin/cdk.ts +++ b/packages/aws-cdk/bin/cdk.ts @@ -131,8 +131,6 @@ if (!process.stdout.isTTY) { colors.disable(); } -const CUSTOM_BUNDLING_DEFAULT_COMMANDS = ['deploy', 'diff', 'synth', 'synthesize']; - async function initCommandLine() { const argv = await parseCommandLineArguments(); if (argv.verbose) { @@ -141,14 +139,7 @@ async function initCommandLine() { debug('CDK toolkit version:', version.DISPLAY_VERSION); debug('Command line arguments:', argv); - // Custom `bundling` default. If we deploy or diff a list of stacks - // exclusively we skip bundling for all other stacks. - let bundling = argv.bundling; - if (CUSTOM_BUNDLING_DEFAULT_COMMANDS.includes(argv._[0]) && argv.exclusively) { - bundling = argv.STACKS as string[]; - } - - const configuration = new Configuration({ ...argv, bundling }); + const configuration = new Configuration(argv); await configuration.load(); const sdkProvider = await SdkProvider.withAwsCliCompatibleDefaults({ diff --git a/packages/aws-cdk/lib/settings.ts b/packages/aws-cdk/lib/settings.ts index 7d78fdae2c7ed..4150d64333b06 100644 --- a/packages/aws-cdk/lib/settings.ts +++ b/packages/aws-cdk/lib/settings.ts @@ -18,7 +18,9 @@ export const TRANSIENT_CONTEXT_KEY = '$dontSaveContext'; const CONTEXT_KEY = 'context'; -export type Arguments = { readonly [name: string]: unknown }; +const CUSTOM_BUNDLING_DEFAULT_COMMANDS = ['deploy', 'diff', 'synth', 'synthesize']; + +export type Arguments = { readonly [name: string]: unknown, readonly _: string[] }; /** * All sources of settings combined @@ -185,6 +187,13 @@ export class Settings { const context = this.parseStringContextListToObject(argv); const tags = this.parseStringTagsListToObject(argv); + // Custom `bundling` default. If we deploy, diff or synth a list of stacks + // exclusively we skip bundling for all other stacks. + let bundling = argv.bundling ?? ['*']; + if (CUSTOM_BUNDLING_DEFAULT_COMMANDS.includes(argv._[0]) && argv.exclusively) { + bundling = argv.STACKS ?? []; + } + return new Settings({ app: argv.app, browser: argv.browser, @@ -204,7 +213,7 @@ export class Settings { versionReporting: argv.versionReporting, staging: argv.staging, output: argv.output, - bundling: argv.bundling, + bundling, }); } diff --git a/packages/aws-cdk/test/context.test.ts b/packages/aws-cdk/test/context.test.ts index 373c42090daec..04a5626c2d4b7 100644 --- a/packages/aws-cdk/test/context.test.ts +++ b/packages/aws-cdk/test/context.test.ts @@ -100,7 +100,7 @@ test('surive no context in old file', async () => { test('command line context is merged with stored context', async () => { // GIVEN await fs.writeJSON('cdk.context.json', { boo: 'far' }); - const config = await new Configuration({ context: ['foo=bar'] } as any).load(); + const config = await new Configuration({ context: ['foo=bar'], _: ['command'] } as any).load(); // WHEN expect(config.context.all).toEqual({ foo: 'bar', boo: 'far' }); diff --git a/packages/aws-cdk/test/settings.test.ts b/packages/aws-cdk/test/settings.test.ts index 28d07d686dcc8..3c0a31a0aa824 100644 --- a/packages/aws-cdk/test/settings.test.ts +++ b/packages/aws-cdk/test/settings.test.ts @@ -62,8 +62,8 @@ test('can clear all values in all objects', () => { test('can parse string context from command line arguments', () => { // GIVEN - const settings1 = Settings.fromCommandLineArguments({ context: ['foo=bar'] }); - const settings2 = Settings.fromCommandLineArguments({ context: ['foo='] }); + const settings1 = Settings.fromCommandLineArguments({ context: ['foo=bar'], _: ['command'] }); + const settings2 = Settings.fromCommandLineArguments({ context: ['foo='], _: ['command'] }); // THEN expect(settings1.get(['context']).foo).toEqual( 'bar'); @@ -72,10 +72,22 @@ test('can parse string context from command line arguments', () => { test('can parse string context from command line arguments with equals sign in value', () => { // GIVEN - const settings1 = Settings.fromCommandLineArguments({ context: ['foo==bar='] }); - const settings2 = Settings.fromCommandLineArguments({ context: ['foo=bar='] }); + const settings1 = Settings.fromCommandLineArguments({ context: ['foo==bar='], _: ['command'] }); + const settings2 = Settings.fromCommandLineArguments({ context: ['foo=bar='], _: ['command'] }); // THEN expect(settings1.get(['context']).foo).toEqual( '=bar='); expect(settings2.get(['context']).foo).toEqual( 'bar='); }); + +test('custom default for bundling', () => { + // GIVEN + const settings = Settings.fromCommandLineArguments({ + _: ['deploy'], + exclusively: true, + STACKS: ['cool-stack'], + }); + + // THEN + expect(settings.get(['bundling'])).toEqual(['cool-stack']); +}); From cb40202964aaa941b5a2a720cbab84539f5b69b9 Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Fri, 21 Aug 2020 13:51:51 +0200 Subject: [PATCH 03/11] add tests in core --- packages/@aws-cdk/core/test/test.staging.ts | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/@aws-cdk/core/test/test.staging.ts b/packages/@aws-cdk/core/test/test.staging.ts index c2d050ba85e43..67a91f6e6e488 100644 --- a/packages/@aws-cdk/core/test/test.staging.ts +++ b/packages/@aws-cdk/core/test/test.staging.ts @@ -352,6 +352,30 @@ export = { test.done(); }, + + 'bundling looks at bundling stacks in context'(test: Test) { + // GIVEN + const app = new App(); + const stack = new Stack(app, 'MyStack'); + stack.node.setContext(cxapi.BUNDLING_STACKS, ['OtherStack']); + const directory = path.join(__dirname, 'fs', 'fixtures', 'test1'); + + // WHEN + const asset = new AssetStaging(stack, 'Asset', { + sourcePath: directory, + bundling: { + image: BundlingDockerImage.fromRegistry('alpine'), + command: [DockerStubCommand.SUCCESS], + }, + }); + + test.throws(() => readDockerStubInput()); + test.equal(asset.assetHash, '3d96e735e26b857743a7c44523c9160c285c2d3ccf273d80fa38a1e674c32cb3'); // hash of MyStack/Asset + test.deepEqual(asset.sourcePath, directory); + test.deepEqual(stack.resolve(asset.stagedPath), directory); + + test.done(); + }, }; function readDockerStubInput() { From f51f73ad6daa85753f03f7b8a4aefb210284f58a Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Fri, 21 Aug 2020 13:58:31 +0200 Subject: [PATCH 04/11] README --- packages/aws-cdk/README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/aws-cdk/README.md b/packages/aws-cdk/README.md index 7a4695cf8280c..c8887d6a97a65 100644 --- a/packages/aws-cdk/README.md +++ b/packages/aws-cdk/README.md @@ -266,6 +266,11 @@ $ cdk doctor - AWS_SDK_LOAD_CONFIG = 1 ``` +#### Bundling +By default asset bundling is skipped for `cdk list` and `cdk destroy`. For `cdk deploy`, `cdk diff` +and `cdk synthesize` the default is to bundle assets for all stacks unless `exclusively` is specified. +In this case, only the listed stacks will have their assets bundled. + ### MFA support If `mfa_serial` is found in the active profile of the shared ini file AWS CDK From 86c35c4cb9dae6d77b4d252dfe84ea8e6d470022 Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Sun, 23 Aug 2020 10:25:21 +0200 Subject: [PATCH 05/11] tests --- packages/@aws-cdk/core/test/test.staging.ts | 4 ++-- packages/aws-cdk/lib/api/cxapp/exec.ts | 2 +- packages/aws-cdk/test/settings.test.ts | 13 ++++++++++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/@aws-cdk/core/test/test.staging.ts b/packages/@aws-cdk/core/test/test.staging.ts index 67a91f6e6e488..8ab88e8065c4e 100644 --- a/packages/@aws-cdk/core/test/test.staging.ts +++ b/packages/@aws-cdk/core/test/test.staging.ts @@ -371,8 +371,8 @@ export = { test.throws(() => readDockerStubInput()); test.equal(asset.assetHash, '3d96e735e26b857743a7c44523c9160c285c2d3ccf273d80fa38a1e674c32cb3'); // hash of MyStack/Asset - test.deepEqual(asset.sourcePath, directory); - test.deepEqual(stack.resolve(asset.stagedPath), directory); + test.equal(asset.sourcePath, directory); + test.equal(stack.resolve(asset.stagedPath), directory); test.done(); }, diff --git a/packages/aws-cdk/lib/api/cxapp/exec.ts b/packages/aws-cdk/lib/api/cxapp/exec.ts index 6646ded093c02..6e5c2cbad9d0f 100644 --- a/packages/aws-cdk/lib/api/cxapp/exec.ts +++ b/packages/aws-cdk/lib/api/cxapp/exec.ts @@ -39,7 +39,7 @@ export async function execProgram(aws: SdkProvider, config: Configuration): Prom context[cxapi.DISABLE_ASSET_STAGING_CONTEXT] = true; } - const bundlingStacks = config.settings.get(['bundling']) ?? []; + const bundlingStacks = config.settings.get(['bundling']) ?? ['*']; context[cxapi.BUNDLING_STACKS] = bundlingStacks; debug('context:', context); diff --git a/packages/aws-cdk/test/settings.test.ts b/packages/aws-cdk/test/settings.test.ts index 3c0a31a0aa824..7aa3c05400c87 100644 --- a/packages/aws-cdk/test/settings.test.ts +++ b/packages/aws-cdk/test/settings.test.ts @@ -80,7 +80,7 @@ test('can parse string context from command line arguments with equals sign in v expect(settings2.get(['context']).foo).toEqual( 'bar='); }); -test('custom default for bundling', () => { +test('custom default for bundling in case of deploy', () => { // GIVEN const settings = Settings.fromCommandLineArguments({ _: ['deploy'], @@ -91,3 +91,14 @@ test('custom default for bundling', () => { // THEN expect(settings.get(['bundling'])).toEqual(['cool-stack']); }); + +test('bundling defaults to *', () => { + // GIVEN + // GIVEN + const settings = Settings.fromCommandLineArguments({ + _: ['command'], + }); + + // THEN + expect(settings.get(['bundling'])).toEqual(['*']); +}); From cebbdb11d6fa6ba812aeb49fe17594826aefd003 Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Wed, 26 Aug 2020 11:02:31 +0200 Subject: [PATCH 06/11] revert change in tag-aspect --- packages/@aws-cdk/core/lib/tag-aspect.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/core/lib/tag-aspect.ts b/packages/@aws-cdk/core/lib/tag-aspect.ts index d56c28b551d87..34d9a6dfd4e40 100644 --- a/packages/@aws-cdk/core/lib/tag-aspect.ts +++ b/packages/@aws-cdk/core/lib/tag-aspect.ts @@ -1,8 +1,8 @@ // import * as cxapi from '@aws-cdk/cx-api'; -import { Annotations } from './annotations'; import { IAspect, Aspects } from './aspect'; import { Construct, IConstruct } from './construct-compat'; import { ITaggable, TagManager } from './tag-manager'; +import { Annotations } from './annotations'; /** * Properties for a tag From cf2f0e76e40cb440006174304ba0a503a22af3fe Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Wed, 26 Aug 2020 11:14:44 +0200 Subject: [PATCH 07/11] correct default --- packages/aws-cdk/bin/cdk.ts | 6 +++--- packages/aws-cdk/lib/settings.ts | 10 +++++++--- packages/aws-cdk/test/settings.test.ts | 14 +++++++++++++- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/packages/aws-cdk/bin/cdk.ts b/packages/aws-cdk/bin/cdk.ts index 1b970b72d3687..31ca0d04da9c7 100644 --- a/packages/aws-cdk/bin/cdk.ts +++ b/packages/aws-cdk/bin/cdk.ts @@ -67,7 +67,7 @@ async function parseCommandLineArguments() { ) .command(['synthesize [STACKS..]', 'synth [STACKS..]'], 'Synthesizes and prints the CloudFormation template for this stack', yargs => yargs .option('exclusively', { type: 'boolean', alias: 'e', desc: 'Only synthesize requested stacks, don\'t include dependencies' }) - .option('bundling', { type: 'array', default: ['*'], alias: 'b', desc: 'Run bundling only for given stacks (defaults to STACKS if `exclusively` is used, all stacks otherwise)' }), + .option('bundling', { type: 'array', alias: 'b', desc: 'Run bundling only for given stacks (defaults to STACKS if `exclusively` is used, all stacks otherwise)' }), ) .command('bootstrap [ENVIRONMENTS..]', 'Deploys the CDK toolkit stack into an AWS environment', yargs => yargs .option('bootstrap-bucket-name', { type: 'string', alias: ['b', 'toolkit-bucket-name'], desc: 'The name of the CDK toolkit bucket; bucket will be created and must not exist', default: undefined }) @@ -93,7 +93,7 @@ async function parseCommandLineArguments() { .option('parameters', { type: 'array', desc: 'Additional parameters passed to CloudFormation at deploy time (STACK:KEY=VALUE)', nargs: 1, requiresArg: true, default: {} }) .option('outputs-file', { type: 'string', alias: 'O', desc: 'Path to file where stack outputs will be written as JSON', requiresArg: true }) .option('previous-parameters', { type: 'boolean', default: true, desc: 'Use previous values for existing parameters (you must specify all parameters on every deployment if this is disabled)' }) - .option('bundling', { type: 'array', default: ['*'], alias: 'b', desc: 'Run bundling only for given stacks (defaults to STACKS if `exclusively` is used, all stacks otherwise)' }), + .option('bundling', { type: 'array', alias: 'b', desc: 'Run bundling only for given stacks (defaults to STACKS if `exclusively` is used, all stacks otherwise)' }), ) .command('destroy [STACKS..]', 'Destroy the stack(s) named STACKS', yargs => yargs .option('exclusively', { type: 'boolean', alias: 'e', desc: 'Only destroy requested stacks, don\'t include dependees' }) @@ -105,7 +105,7 @@ async function parseCommandLineArguments() { .option('context-lines', { type: 'number', desc: 'Number of context lines to include in arbitrary JSON diff rendering', default: 3, requiresArg: true }) .option('template', { type: 'string', desc: 'The path to the CloudFormation template to compare with', requiresArg: true }) .option('strict', { type: 'boolean', desc: 'Do not filter out AWS::CDK::Metadata resources', default: false }) - .option('bundling', { type: 'array', default: ['*'], alias: 'b', desc: 'Run bundling only for given stacks (defaults to STACKS if `exclusively` is used, all stacks otherwise)' }), + .option('bundling', { type: 'array', alias: 'b', desc: 'Run bundling only for given stacks (defaults to STACKS if `exclusively` is used, all stacks otherwise)' }), ) .option('fail', { type: 'boolean', desc: 'Fail with exit code 1 in case of diff', default: false }) .command('metadata [STACK]', 'Returns all metadata associated with this stack') diff --git a/packages/aws-cdk/lib/settings.ts b/packages/aws-cdk/lib/settings.ts index 4150d64333b06..9903560b9e87d 100644 --- a/packages/aws-cdk/lib/settings.ts +++ b/packages/aws-cdk/lib/settings.ts @@ -189,9 +189,13 @@ export class Settings { // Custom `bundling` default. If we deploy, diff or synth a list of stacks // exclusively we skip bundling for all other stacks. - let bundling = argv.bundling ?? ['*']; - if (CUSTOM_BUNDLING_DEFAULT_COMMANDS.includes(argv._[0]) && argv.exclusively) { - bundling = argv.STACKS ?? []; + let bundling = argv.bundling; + if (!bundling) { + if (CUSTOM_BUNDLING_DEFAULT_COMMANDS.includes(argv._[0]) && argv.exclusively) { + bundling = argv.STACKS ?? []; + } else { + bundling = ['*']; + } } return new Settings({ diff --git a/packages/aws-cdk/test/settings.test.ts b/packages/aws-cdk/test/settings.test.ts index 7aa3c05400c87..4cc5b62dd64b9 100644 --- a/packages/aws-cdk/test/settings.test.ts +++ b/packages/aws-cdk/test/settings.test.ts @@ -93,7 +93,6 @@ test('custom default for bundling in case of deploy', () => { }); test('bundling defaults to *', () => { - // GIVEN // GIVEN const settings = Settings.fromCommandLineArguments({ _: ['command'], @@ -102,3 +101,16 @@ test('bundling defaults to *', () => { // THEN expect(settings.get(['bundling'])).toEqual(['*']); }); + +test('deploy with bundling specified', () => { + // GIVEN + const settings = Settings.fromCommandLineArguments({ + _: ['deploy'], + exclusively: true, + STACKS: ['cool-stack'], + bundling: ['other-stack', 'cool-stack'], + }); + + // THEN + expect(settings.get(['bundling'])).toEqual(['other-stack', 'cool-stack']); +}); From 5e44f797421e89e684582fee0c6f4309705fa981 Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Wed, 2 Sep 2020 11:44:15 +0200 Subject: [PATCH 08/11] remove CLI option --- packages/aws-cdk/bin/cdk.ts | 15 +++++---------- packages/aws-cdk/lib/api/cxapp/exec.ts | 2 +- packages/aws-cdk/lib/settings.ts | 23 ++++++++++++----------- packages/aws-cdk/test/settings.test.ts | 19 ++++++++----------- 4 files changed, 26 insertions(+), 33 deletions(-) diff --git a/packages/aws-cdk/bin/cdk.ts b/packages/aws-cdk/bin/cdk.ts index 25c18bea23dfb..b401977085593 100644 --- a/packages/aws-cdk/bin/cdk.ts +++ b/packages/aws-cdk/bin/cdk.ts @@ -63,12 +63,10 @@ async function parseCommandLineArguments() { .option('output', { type: 'string', alias: 'o', desc: 'Emits the synthesized cloud assembly into a directory (default: cdk.out)', requiresArg: true }) .option('no-color', { type: 'boolean', desc: 'Removes colors and other style from console output', default: false }) .command(['list [STACKS..]', 'ls [STACKS..]'], 'Lists all stacks in the app', yargs => yargs - .option('long', { type: 'boolean', default: false, alias: 'l', desc: 'Display environment information for each stack' }) - .option('bundling', { type: 'array', default: [], alias: 'b', desc: 'Run bundling only for given stacks (defaults to no stacks)' }), + .option('long', { type: 'boolean', default: false, alias: 'l', desc: 'Display environment information for each stack' }), ) .command(['synthesize [STACKS..]', 'synth [STACKS..]'], 'Synthesizes and prints the CloudFormation template for this stack', yargs => yargs - .option('exclusively', { type: 'boolean', alias: 'e', desc: 'Only synthesize requested stacks, don\'t include dependencies' }) - .option('bundling', { type: 'array', alias: 'b', desc: 'Run bundling only for given stacks (defaults to STACKS if `exclusively` is used, all stacks otherwise)' }), + .option('exclusively', { type: 'boolean', alias: 'e', desc: 'Only synthesize requested stacks, don\'t include dependencies' }), ) .command('bootstrap [ENVIRONMENTS..]', 'Deploys the CDK toolkit stack into an AWS environment', yargs => yargs .option('bootstrap-bucket-name', { type: 'string', alias: ['b', 'toolkit-bucket-name'], desc: 'The name of the CDK toolkit bucket; bucket will be created and must not exist', default: undefined }) @@ -96,20 +94,17 @@ async function parseCommandLineArguments() { .option('parameters', { type: 'array', desc: 'Additional parameters passed to CloudFormation at deploy time (STACK:KEY=VALUE)', nargs: 1, requiresArg: true, default: {} }) .option('outputs-file', { type: 'string', alias: 'O', desc: 'Path to file where stack outputs will be written as JSON', requiresArg: true }) .option('previous-parameters', { type: 'boolean', default: true, desc: 'Use previous values for existing parameters (you must specify all parameters on every deployment if this is disabled)' }) - .option('progress', { type: 'string', choices: [StackActivityProgress.BAR, StackActivityProgress.EVENTS], desc: 'Display mode for stack activity events.' }) - .option('bundling', { type: 'array', alias: 'b', desc: 'Run bundling only for given stacks (defaults to STACKS if `exclusively` is used, all stacks otherwise)' }), + .option('progress', { type: 'string', choices: [StackActivityProgress.BAR, StackActivityProgress.EVENTS], desc: 'Display mode for stack activity events.' }), ) .command('destroy [STACKS..]', 'Destroy the stack(s) named STACKS', yargs => yargs .option('exclusively', { type: 'boolean', alias: 'e', desc: 'Only destroy requested stacks, don\'t include dependees' }) - .option('force', { type: 'boolean', alias: 'f', desc: 'Do not ask for confirmation before destroying the stacks' }) - .option('bundling', { type: 'array', default: [], alias: 'b', desc: 'Run bundling only for given stacks (defaults to no stacks)' }), + .option('force', { type: 'boolean', alias: 'f', desc: 'Do not ask for confirmation before destroying the stacks' }), ) .command('diff [STACKS..]', 'Compares the specified stack with the deployed stack or a local template file, and returns with status 1 if any difference is found', yargs => yargs .option('exclusively', { type: 'boolean', alias: 'e', desc: 'Only diff requested stacks, don\'t include dependencies' }) .option('context-lines', { type: 'number', desc: 'Number of context lines to include in arbitrary JSON diff rendering', default: 3, requiresArg: true }) .option('template', { type: 'string', desc: 'The path to the CloudFormation template to compare with', requiresArg: true }) - .option('strict', { type: 'boolean', desc: 'Do not filter out AWS::CDK::Metadata resources', default: false }) - .option('bundling', { type: 'array', alias: 'b', desc: 'Run bundling only for given stacks (defaults to STACKS if `exclusively` is used, all stacks otherwise)' }), + .option('strict', { type: 'boolean', desc: 'Do not filter out AWS::CDK::Metadata resources', default: false }), ) .option('fail', { type: 'boolean', desc: 'Fail with exit code 1 in case of diff', default: false }) .command('metadata [STACK]', 'Returns all metadata associated with this stack') diff --git a/packages/aws-cdk/lib/api/cxapp/exec.ts b/packages/aws-cdk/lib/api/cxapp/exec.ts index 6e5c2cbad9d0f..735e9a7622e19 100644 --- a/packages/aws-cdk/lib/api/cxapp/exec.ts +++ b/packages/aws-cdk/lib/api/cxapp/exec.ts @@ -39,7 +39,7 @@ export async function execProgram(aws: SdkProvider, config: Configuration): Prom context[cxapi.DISABLE_ASSET_STAGING_CONTEXT] = true; } - const bundlingStacks = config.settings.get(['bundling']) ?? ['*']; + const bundlingStacks = config.settings.get(['bundlingStacks']) ?? ['*']; context[cxapi.BUNDLING_STACKS] = bundlingStacks; debug('context:', context); diff --git a/packages/aws-cdk/lib/settings.ts b/packages/aws-cdk/lib/settings.ts index 22065e2251398..1fbc35150478a 100644 --- a/packages/aws-cdk/lib/settings.ts +++ b/packages/aws-cdk/lib/settings.ts @@ -18,7 +18,7 @@ export const TRANSIENT_CONTEXT_KEY = '$dontSaveContext'; const CONTEXT_KEY = 'context'; -const CUSTOM_BUNDLING_DEFAULT_COMMANDS = ['deploy', 'diff', 'synth', 'synthesize']; +const BUNDLING_COMMANDS = ['deploy', 'diff', 'synth', 'synthesize']; export type Arguments = { readonly [name: string]: unknown, readonly _: string[] }; @@ -187,15 +187,16 @@ export class Settings { const context = this.parseStringContextListToObject(argv); const tags = this.parseStringTagsListToObject(argv); - // Custom `bundling` default. If we deploy, diff or synth a list of stacks - // exclusively we skip bundling for all other stacks. - let bundling = argv.bundling; - if (!bundling) { - if (CUSTOM_BUNDLING_DEFAULT_COMMANDS.includes(argv._[0]) && argv.exclusively) { - bundling = argv.STACKS ?? []; - } else { - bundling = ['*']; - } + // Determine bundling stacks + let bundlingStacks: string[]; + if (BUNDLING_COMMANDS.includes(argv._[0])) { + // If we deploy, diff or synth a list of stacks exclusively we skip + // bundling for all other stacks. + bundlingStacks = argv.exclusively + ? argv.STACKS as string[] ?? ['*'] + : ['*']; + } else { // Skip bundling for all stacks + bundlingStacks = []; } return new Settings({ @@ -218,7 +219,7 @@ export class Settings { staging: argv.staging, output: argv.output, progress: argv.progress, - bundling, + bundlingStacks, }); } diff --git a/packages/aws-cdk/test/settings.test.ts b/packages/aws-cdk/test/settings.test.ts index 4cc5b62dd64b9..9a0879ddaf83f 100644 --- a/packages/aws-cdk/test/settings.test.ts +++ b/packages/aws-cdk/test/settings.test.ts @@ -80,37 +80,34 @@ test('can parse string context from command line arguments with equals sign in v expect(settings2.get(['context']).foo).toEqual( 'bar='); }); -test('custom default for bundling in case of deploy', () => { +test('bundling stacks defaults to an empty list', () => { // GIVEN const settings = Settings.fromCommandLineArguments({ - _: ['deploy'], - exclusively: true, - STACKS: ['cool-stack'], + _: ['command'], }); // THEN - expect(settings.get(['bundling'])).toEqual(['cool-stack']); + expect(settings.get(['bundlingStacks'])).toEqual([]); }); -test('bundling defaults to *', () => { +test('bundling stacks defaults to * for deploy', () => { // GIVEN const settings = Settings.fromCommandLineArguments({ - _: ['command'], + _: ['deploy'], }); // THEN - expect(settings.get(['bundling'])).toEqual(['*']); + expect(settings.get(['bundlingStacks'])).toEqual(['*']); }); -test('deploy with bundling specified', () => { +test('bundling stacks with deploy exclusively', () => { // GIVEN const settings = Settings.fromCommandLineArguments({ _: ['deploy'], exclusively: true, STACKS: ['cool-stack'], - bundling: ['other-stack', 'cool-stack'], }); // THEN - expect(settings.get(['bundling'])).toEqual(['other-stack', 'cool-stack']); + expect(settings.get(['bundlingStacks'])).toEqual(['cool-stack']); }); From bd704f4cc58ee7083a9e5dd8924df09787004fd8 Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Wed, 2 Sep 2020 11:50:11 +0200 Subject: [PATCH 09/11] dummy hash in case of BUNDLE --- packages/@aws-cdk/core/lib/asset-staging.ts | 4 +++- packages/@aws-cdk/core/test/test.staging.ts | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/core/lib/asset-staging.ts b/packages/@aws-cdk/core/lib/asset-staging.ts index 2c03f345091fd..dc49750a46f2f 100644 --- a/packages/@aws-cdk/core/lib/asset-staging.ts +++ b/packages/@aws-cdk/core/lib/asset-staging.ts @@ -113,7 +113,9 @@ export class AssetStaging extends Construct { this.relativePath = renderAssetFilename(this.assetHash); this.stagedPath = this.relativePath; } else { // Bundling is skipped - this.assetHash = this.calculateHash(AssetHashType.CUSTOM, this.node.path); // Use node path as dummy hash + this.assetHash = props.assetHashType === AssetHashType.BUNDLE + ? this.calculateHash(AssetHashType.CUSTOM, this.node.path) // Use node path as dummy hash because we're not bundling + : this.calculateHash(hashType, props.assetHash); this.stagedPath = this.sourcePath; } } else { diff --git a/packages/@aws-cdk/core/test/test.staging.ts b/packages/@aws-cdk/core/test/test.staging.ts index 16a4284be849a..ff7279172bb00 100644 --- a/packages/@aws-cdk/core/test/test.staging.ts +++ b/packages/@aws-cdk/core/test/test.staging.ts @@ -591,13 +591,14 @@ export = { // WHEN const asset = new AssetStaging(stack, 'Asset', { sourcePath: directory, + assetHashType: AssetHashType.BUNDLE, bundling: { image: BundlingDockerImage.fromRegistry('alpine'), command: [DockerStubCommand.SUCCESS], }, }); - test.throws(() => readDockerStubInput()); + test.throws(() => readDockerStubInput()); // Bundling did not run test.equal(asset.assetHash, '3d96e735e26b857743a7c44523c9160c285c2d3ccf273d80fa38a1e674c32cb3'); // hash of MyStack/Asset test.equal(asset.sourcePath, directory); test.equal(stack.resolve(asset.stagedPath), directory); From 98493583338981f9f9fcb459fe0163b06c899fd5 Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Wed, 2 Sep 2020 11:52:13 +0200 Subject: [PATCH 10/11] revert changes in bin/cdk.ts --- packages/aws-cdk/bin/cdk.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/aws-cdk/bin/cdk.ts b/packages/aws-cdk/bin/cdk.ts index b401977085593..89c4287ff3918 100644 --- a/packages/aws-cdk/bin/cdk.ts +++ b/packages/aws-cdk/bin/cdk.ts @@ -66,8 +66,7 @@ async function parseCommandLineArguments() { .option('long', { type: 'boolean', default: false, alias: 'l', desc: 'Display environment information for each stack' }), ) .command(['synthesize [STACKS..]', 'synth [STACKS..]'], 'Synthesizes and prints the CloudFormation template for this stack', yargs => yargs - .option('exclusively', { type: 'boolean', alias: 'e', desc: 'Only synthesize requested stacks, don\'t include dependencies' }), - ) + .option('exclusively', { type: 'boolean', alias: 'e', desc: 'Only synthesize requested stacks, don\'t include dependencies' })) .command('bootstrap [ENVIRONMENTS..]', 'Deploys the CDK toolkit stack into an AWS environment', yargs => yargs .option('bootstrap-bucket-name', { type: 'string', alias: ['b', 'toolkit-bucket-name'], desc: 'The name of the CDK toolkit bucket; bucket will be created and must not exist', default: undefined }) .option('bootstrap-kms-key-id', { type: 'string', desc: 'AWS KMS master key ID used for the SSE-KMS encryption', default: undefined }) @@ -98,14 +97,12 @@ async function parseCommandLineArguments() { ) .command('destroy [STACKS..]', 'Destroy the stack(s) named STACKS', yargs => yargs .option('exclusively', { type: 'boolean', alias: 'e', desc: 'Only destroy requested stacks, don\'t include dependees' }) - .option('force', { type: 'boolean', alias: 'f', desc: 'Do not ask for confirmation before destroying the stacks' }), - ) + .option('force', { type: 'boolean', alias: 'f', desc: 'Do not ask for confirmation before destroying the stacks' })) .command('diff [STACKS..]', 'Compares the specified stack with the deployed stack or a local template file, and returns with status 1 if any difference is found', yargs => yargs .option('exclusively', { type: 'boolean', alias: 'e', desc: 'Only diff requested stacks, don\'t include dependencies' }) .option('context-lines', { type: 'number', desc: 'Number of context lines to include in arbitrary JSON diff rendering', default: 3, requiresArg: true }) .option('template', { type: 'string', desc: 'The path to the CloudFormation template to compare with', requiresArg: true }) - .option('strict', { type: 'boolean', desc: 'Do not filter out AWS::CDK::Metadata resources', default: false }), - ) + .option('strict', { type: 'boolean', desc: 'Do not filter out AWS::CDK::Metadata resources', default: false })) .option('fail', { type: 'boolean', desc: 'Fail with exit code 1 in case of diff', default: false }) .command('metadata [STACK]', 'Returns all metadata associated with this stack') .command('init [TEMPLATE]', 'Create a new, empty CDK project from a template. Invoked without TEMPLATE, the app template will be used.', yargs => yargs From 6132e72f337e8e25879025664a6e4efe7f3ef5d4 Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Wed, 16 Sep 2020 15:17:31 +0200 Subject: [PATCH 11/11] improve typing --- packages/aws-cdk/bin/cdk.ts | 7 ++++-- packages/aws-cdk/lib/settings.ts | 32 ++++++++++++++++++++++---- packages/aws-cdk/test/settings.test.ts | 16 ++++++------- 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/packages/aws-cdk/bin/cdk.ts b/packages/aws-cdk/bin/cdk.ts index 8a7f89911a6a6..8966cd37f517a 100644 --- a/packages/aws-cdk/bin/cdk.ts +++ b/packages/aws-cdk/bin/cdk.ts @@ -17,7 +17,7 @@ import { availableInitLanguages, cliInit, printAvailableTemplates } from '../lib import { data, debug, error, print, setLogLevel } from '../lib/logging'; import { PluginHost } from '../lib/plugin'; import { serializeStructure } from '../lib/serialize'; -import { Configuration, Settings } from '../lib/settings'; +import { Command, Configuration, Settings } from '../lib/settings'; import * as version from '../lib/version'; /* eslint-disable max-len */ @@ -136,7 +136,10 @@ async function initCommandLine() { debug('CDK toolkit version:', version.DISPLAY_VERSION); debug('Command line arguments:', argv); - const configuration = new Configuration(argv); + const configuration = new Configuration({ + ...argv, + _: argv._ as [Command, ...string[]], // TypeScript at its best + }); await configuration.load(); const sdkProvider = await SdkProvider.withAwsCliCompatibleDefaults({ diff --git a/packages/aws-cdk/lib/settings.ts b/packages/aws-cdk/lib/settings.ts index 75bbdd1b5e644..af9193d9a6456 100644 --- a/packages/aws-cdk/lib/settings.ts +++ b/packages/aws-cdk/lib/settings.ts @@ -18,9 +18,33 @@ export const TRANSIENT_CONTEXT_KEY = '$dontSaveContext'; const CONTEXT_KEY = 'context'; -const BUNDLING_COMMANDS = ['deploy', 'diff', 'synth', 'synthesize']; +export enum Command { + LS = 'ls', + LIST = 'list', + DIFF = 'diff', + BOOTSTRAP = 'bootstrap', + DEPLOY = 'deploy', + DESTROY = 'destroy', + SYNTHESIZE = 'synthesize', + SYNTH = 'synth', + METADATA = 'metadata', + INIT = 'init', + VERSION = 'version', +} + +const BUNDLING_COMMANDS = [ + Command.DEPLOY, + Command.DIFF, + Command.SYNTH, + Command.SYNTHESIZE, +]; -export type Arguments = { readonly [name: string]: unknown, readonly _: string[] }; +export type Arguments = { + readonly _: [Command, ...string[]]; + readonly exclusively?: boolean; + readonly STACKS?: string[]; + readonly [name: string]: unknown; +}; /** * All sources of settings combined @@ -193,7 +217,7 @@ export class Settings { // If we deploy, diff or synth a list of stacks exclusively we skip // bundling for all other stacks. bundlingStacks = argv.exclusively - ? argv.STACKS as string[] ?? ['*'] + ? argv.STACKS ?? ['*'] : ['*']; } else { // Skip bundling for all stacks bundlingStacks = []; @@ -411,4 +435,4 @@ function expectStringList(x: unknown): string[] | undefined { throw new Error(`Expected list of strings, found ${nonStrings}`); } return x; -} \ No newline at end of file +} diff --git a/packages/aws-cdk/test/settings.test.ts b/packages/aws-cdk/test/settings.test.ts index 9a0879ddaf83f..b3bc9dded811c 100644 --- a/packages/aws-cdk/test/settings.test.ts +++ b/packages/aws-cdk/test/settings.test.ts @@ -1,4 +1,4 @@ -import { Context, Settings } from '../lib/settings'; +import { Command, Context, Settings } from '../lib/settings'; test('can delete values from Context object', () => { // GIVEN @@ -62,8 +62,8 @@ test('can clear all values in all objects', () => { test('can parse string context from command line arguments', () => { // GIVEN - const settings1 = Settings.fromCommandLineArguments({ context: ['foo=bar'], _: ['command'] }); - const settings2 = Settings.fromCommandLineArguments({ context: ['foo='], _: ['command'] }); + const settings1 = Settings.fromCommandLineArguments({ context: ['foo=bar'], _: [Command.DEPLOY] }); + const settings2 = Settings.fromCommandLineArguments({ context: ['foo='], _: [Command.DEPLOY] }); // THEN expect(settings1.get(['context']).foo).toEqual( 'bar'); @@ -72,8 +72,8 @@ test('can parse string context from command line arguments', () => { test('can parse string context from command line arguments with equals sign in value', () => { // GIVEN - const settings1 = Settings.fromCommandLineArguments({ context: ['foo==bar='], _: ['command'] }); - const settings2 = Settings.fromCommandLineArguments({ context: ['foo=bar='], _: ['command'] }); + const settings1 = Settings.fromCommandLineArguments({ context: ['foo==bar='], _: [Command.DEPLOY] }); + const settings2 = Settings.fromCommandLineArguments({ context: ['foo=bar='], _: [Command.DEPLOY] }); // THEN expect(settings1.get(['context']).foo).toEqual( '=bar='); @@ -83,7 +83,7 @@ test('can parse string context from command line arguments with equals sign in v test('bundling stacks defaults to an empty list', () => { // GIVEN const settings = Settings.fromCommandLineArguments({ - _: ['command'], + _: [Command.LIST], }); // THEN @@ -93,7 +93,7 @@ test('bundling stacks defaults to an empty list', () => { test('bundling stacks defaults to * for deploy', () => { // GIVEN const settings = Settings.fromCommandLineArguments({ - _: ['deploy'], + _: [Command.DEPLOY], }); // THEN @@ -103,7 +103,7 @@ test('bundling stacks defaults to * for deploy', () => { test('bundling stacks with deploy exclusively', () => { // GIVEN const settings = Settings.fromCommandLineArguments({ - _: ['deploy'], + _: [Command.DEPLOY], exclusively: true, STACKS: ['cool-stack'], });