Skip to content

Commit f84826f

Browse files
authored
fix: not require aws-cdk to be a default dependency of amplify (#70)
In aws-amplify/amplify-backend#2614 Amplify is proposing to remove the app dependency on `aws-cdk` in favor of the new integration with `@aws-cdk/toolkit-lib`. This would cause our tests to fail, since we expected `aws-cdk` to be listed in the `default_packages.json` file. With this fix, we allow the dep to be there or not.
1 parent a1f91bc commit f84826f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

packages/@aws-cdk-testing/cli-integ/tests/tool-integrations/amplify.integtest.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ async function mutateAmplifyDepOnCdk(context: TemporaryDirectoryContext, cliVers
5656
assertIsObject(amplifyDepJson);
5757
assertIsStringArray(amplifyDepJson.defaultDevPackages);
5858

59-
replacePackageVersionIn('aws-cdk', cliVersion, amplifyDepJson.defaultDevPackages);
59+
// Amplify is removing the dependency on aws-cdk, since Amplify is now using the toolkit-lib
60+
// To prepare for this change, we need allow both situations: aws-cdk being listed and not being listed
61+
// Fix is to simply allow the replace operation to also NOT replace the version
62+
// @see https://github.com/aws-amplify/amplify-backend/pull/2614
63+
replacePackageVersionIn('aws-cdk', cliVersion, amplifyDepJson.defaultDevPackages, false);
6064
replacePackageVersionIn('aws-cdk-lib', libVersion, amplifyDepJson.defaultDevPackages);
6165

6266
await fs.writeFile(amplifyDepFile, JSON.stringify(amplifyDepJson, undefined, 2), { encoding: 'utf-8' });
@@ -80,9 +84,9 @@ async function mutateAmplifyDepOnCdk(context: TemporaryDirectoryContext, cliVers
8084
* ["package@version", "package@version", ...]
8185
* ```
8286
*
83-
* It's a failure if we don't find an entry to update.
87+
* It's a failure if we don't find an entry to update, unless we explicitly pass an option to say that's okay.
8488
*/
85-
function replacePackageVersionIn(packName: string, version: string, xs: string[]) {
89+
function replacePackageVersionIn(packName: string, version: string, xs: string[], failIfMissing = true) {
8690
let didUpdate = false;
8791
for (let i = 0; i < xs.length; i++) {
8892
if (xs[i].startsWith(`${packName}@`)) {
@@ -91,7 +95,7 @@ function replacePackageVersionIn(packName: string, version: string, xs: string[]
9195
}
9296
}
9397

94-
if (!didUpdate) {
98+
if (failIfMissing && !didUpdate) {
9599
throw new Error(`Did not find a package version to update for ${packName} in ${JSON.stringify(xs)}`);
96100
}
97101
}

0 commit comments

Comments
 (0)