diff --git a/CHANGELOG.v2.alpha.md b/CHANGELOG.v2.alpha.md index 6ad88cc237b01..cdcc281243a3c 100644 --- a/CHANGELOG.v2.alpha.md +++ b/CHANGELOG.v2.alpha.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [2.34.2-alpha.0](https://github.com/aws/aws-cdk/compare/v2.34.1-alpha.0...v2.34.2-alpha.0) (2022-07-29) + ## [2.34.1-alpha.0](https://github.com/aws/aws-cdk/compare/v2.34.0-alpha.0...v2.34.1-alpha.0) (2022-07-29) ### Bug Fixes diff --git a/CHANGELOG.v2.md b/CHANGELOG.v2.md index 09cb70054cb33..350acc9cf3102 100644 --- a/CHANGELOG.v2.md +++ b/CHANGELOG.v2.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [2.34.2](https://github.com/aws/aws-cdk/compare/v2.34.1...v2.34.2) (2022-07-29) + +### Bug Fixes + +* **cli:** context value type conversion causing parse failures ([21381](https://github.com/aws/aws-cdk/issues/21381)) + ## [2.34.1](https://github.com/aws/aws-cdk/compare/v2.34.0...v2.34.1) (2022-07-29) ### Bug Fixes diff --git a/packages/aws-cdk/lib/settings.ts b/packages/aws-cdk/lib/settings.ts index c9648236eb14b..adb467e49b798 100644 --- a/packages/aws-cdk/lib/settings.ts +++ b/packages/aws-cdk/lib/settings.ts @@ -300,35 +300,6 @@ export class Settings { return ret; } - /** - * Context can be passed as CLI arguments in the format - * --context foo=bar - * - * The context value can be of any type, but when it is parsed - * it is always a string. Here we attempt to determine the actual - * type of the value. - */ - private static parseContextValue(contextValue: string): any { - // If the value is a JSON object, then we try and parse it and return - // the object. - try { - return JSON.parse(contextValue); - } catch {} - const num = parseFloat(contextValue); - // parseFloat tries to convert any string to a number, but - // if the string begins with a number it will convert that and - // ignore the rest so only return a number if the number and the - // string are the same - if (!isNaN(num) && num.toString() === contextValue) { - return num; - } - // The string value 'false' is truthy so explicitely check for 'false' - if (contextValue === 'false') { - return false; - } - return contextValue; - } - private static parseStringContextListToObject(argv: Arguments): any { const context: any = {}; @@ -339,7 +310,7 @@ export class Settings { if (parts[0].match(/^aws:.+/)) { throw new Error(`User-provided context cannot use keys prefixed with 'aws:', but ${parts[0]} was provided.`); } - context[parts[0]] = this.parseContextValue(parts[1]); + context[parts[0]] = parts[1]; } else { warning('Context argument is not an assignment (key=value): %s', assignment); } @@ -347,7 +318,6 @@ export class Settings { return context; } - /** * Parse tags out of arguments * diff --git a/packages/aws-cdk/test/settings.test.ts b/packages/aws-cdk/test/settings.test.ts index 836b63a26d889..8c2c894ae4634 100644 --- a/packages/aws-cdk/test/settings.test.ts +++ b/packages/aws-cdk/test/settings.test.ts @@ -80,26 +80,6 @@ test('can parse string context from command line arguments with equals sign in v expect(settings2.get(['context']).foo).toEqual( 'bar='); }); -test('can parse context from command line arguments and convert value to correct type', () => { - // GIVEN - const settings1 = Settings.fromCommandLineArguments({ context: ['foo=false'], _: [Command.DEPLOY] }); - const settings2 = Settings.fromCommandLineArguments({ context: ['foo=0'], _: [Command.DEPLOY] }); - const settings3 = Settings.fromCommandLineArguments({ context: ['foo=true'], _: [Command.DEPLOY] }); - const settings4 = Settings.fromCommandLineArguments({ context: ['foo={"a": "b", "c": true, "d": ["a", "b"]}'], _: [Command.DEPLOY] }); - const settings5 = Settings.fromCommandLineArguments({ context: ['foo=34'], _: [Command.DEPLOY] }); - const settings6 = Settings.fromCommandLineArguments({ context: ['foo=34 35'], _: [Command.DEPLOY] }); - const settings7 = Settings.fromCommandLineArguments({ context: ['foo=0x22'], _: [Command.DEPLOY] }); - - // THEN - expect(settings1.get(['context']).foo).toEqual(false); - expect(settings2.get(['context']).foo).toEqual(0); - expect(settings3.get(['context']).foo).toEqual(true); - expect(settings4.get(['context']).foo).toEqual({ a: 'b', c: true, d: ['a', 'b'] }); - expect(settings5.get(['context']).foo).toEqual(34); - expect(settings6.get(['context']).foo).toEqual('34 35'); - expect(settings7.get(['context']).foo).toEqual('0x22'); -}); - test('bundling stacks defaults to an empty list', () => { // GIVEN const settings = Settings.fromCommandLineArguments({ @@ -174,4 +154,4 @@ test('providing a build arg', () => { // THEN expect(settings.get(['build'])).toEqual('mvn package'); -}); +}); \ No newline at end of file diff --git a/version.v2.json b/version.v2.json index 2a42587c09356..7756ec057f0cd 100644 --- a/version.v2.json +++ b/version.v2.json @@ -1,4 +1,4 @@ { - "version": "2.34.1", - "alphaVersion": "2.34.1-alpha.0" -} + "version": "2.34.2", + "alphaVersion": "2.34.2-alpha.0" +} \ No newline at end of file