Skip to content

Commit 76ac13c

Browse files
authored
fix: revert "retain type of context values and not convert them to string" (#630)
Some users are relying on context values always being a string. Fixes #629 and #626 --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
1 parent e9c24a6 commit 76ac13c

File tree

3 files changed

+3
-31
lines changed

3 files changed

+3
-31
lines changed

packages/@aws-cdk-testing/cli-integ/resources/cdk-apps/app/app.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,7 @@ class LambdaStack extends cdk.Stack {
453453
constructor(parent, id, props) {
454454
// sometimes we need to specify the custom bootstrap bucket to use
455455
// see the 'upgrade legacy bootstrap stack' test
456-
const useLegacy = [true, 'true'].includes(parent.node.tryGetContext('legacySynth'));
457-
const synthesizer = useLegacy ?
456+
const synthesizer = parent.node.tryGetContext('legacySynth') === 'true' ?
458457
new LegacyStackSynthesizer({
459458
fileAssetsBucketName: parent.node.tryGetContext('bootstrapBucket'),
460459
})
@@ -478,8 +477,7 @@ class LambdaStack extends cdk.Stack {
478477

479478
class DriftableStack extends cdk.Stack {
480479
constructor(parent, id, props) {
481-
const useLegacy = [true, 'true'].includes(parent.node.tryGetContext('legacySynth'));
482-
const synthesizer = useLegacy ?
480+
const synthesizer = parent.node.tryGetContext('legacySynth') === 'true' ?
483481
new LegacyStackSynthesizer({
484482
fileAssetsBucketName: parent.node.tryGetContext('bootstrapBucket'),
485483
})

packages/aws-cdk/lib/cli/user-configuration.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -341,13 +341,7 @@ function parseStringContextListToObject(argv: Arguments): any {
341341
`User-provided context cannot use keys prefixed with 'aws:', but ${parts[0]} was provided.`,
342342
);
343343
}
344-
let parsedValue: any = parts[1];
345-
try {
346-
parsedValue = JSON.parse(parts[1]);
347-
} catch {
348-
debug('Non-JSON context value for %s, leaving as string: %s', parts[0], parts[1]);
349-
}
350-
context[parts[0]] = parsedValue;
344+
context[parts[0]] = parts[1];
351345
} else {
352346
warning(
353347
'Context argument is not an assignment (key=value): %s',

packages/aws-cdk/test/cli/configuration.test.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -116,23 +116,3 @@ test('providing a build arg', () => {
116116
// THEN
117117
expect(settings.get(['build'])).toEqual('mvn package');
118118
});
119-
120-
test('can parse boolean context from command line arguments', () => {
121-
// GIVEN
122-
const settings1 = commandLineArgumentsToSettings({ context: ['foo=true'], _: [Command.DEPLOY] });
123-
const settings2 = commandLineArgumentsToSettings({ context: ['foo=false'], _: [Command.DEPLOY] });
124-
125-
// THEN
126-
expect(settings1.get(['context']).foo).toEqual( true );
127-
expect(settings2.get(['context']).foo).toEqual( false );
128-
});
129-
130-
test('can parse number context from command line arguments', () => {
131-
// GIVEN
132-
const settings1 = commandLineArgumentsToSettings({ context: ['foo=5'], _: [Command.DEPLOY] });
133-
const settings2 = commandLineArgumentsToSettings({ context: ['foo=3.14'], _: [Command.DEPLOY] });
134-
135-
// THEN
136-
expect(settings1.get(['context']).foo).toEqual( 5 );
137-
expect(settings2.get(['context']).foo).toEqual( 3.14 );
138-
});

0 commit comments

Comments
 (0)