Skip to content

Commit 38a9894

Browse files
author
Elad Ben-Israel
authored
fix(cx-api): improve compatibility messages for cli <=> app (#2676)
Emit a legacy manifest (cdk.out) to output directory with the new protocol version so that pre 0.33.0 CLI will emit a proper compatibility message which reads: CDK Toolkit >= 0.33.0 is required in order to interact with this program. Improve wording for the case where a new CLI is used with old apps: CDK CLI can only be used with apps created by CDK >= 0.33.0
1 parent ceaf54a commit 38a9894

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

packages/@aws-cdk/cdk/test/test.synthesis.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export = {
2525

2626
// THEN
2727
test.same(app.run(), session); // same session if we run() again
28-
test.deepEqual(list(session.directory), [ 'manifest.json' ]);
28+
test.deepEqual(list(session.directory), [ 'cdk.out', 'manifest.json' ]);
2929
test.deepEqual(readJson(session.directory, 'manifest.json').artifacts, {});
3030
test.done();
3131
},
@@ -40,6 +40,7 @@ export = {
4040

4141
// THEN
4242
test.deepEqual(list(session.directory), [
43+
'cdk.out',
4344
'manifest.json',
4445
'one-stack.template.json'
4546
]);
@@ -71,6 +72,7 @@ export = {
7172

7273
// THEN
7374
test.deepEqual(list(session.directory), [
75+
'cdk.out',
7476
'foo.json',
7577
'manifest.json',
7678
'one-stack.template.json'

packages/@aws-cdk/cx-api/lib/cloud-assembly.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export class CloudAssemblyBuilder {
117117

118118
// we leverage the fact that outdir is long-lived to avoid staging assets into it
119119
// that were already staged (copying can be expensive). this is achieved by the fact
120-
// that assets use a source hash as their name. other artifacts, and the manifest,
120+
// that assets use a source hash as their name. other artifacts, and the manifest itself,
121121
// will overwrite existing files as needed.
122122

123123
if (fs.existsSync(this.outdir)) {
@@ -143,6 +143,11 @@ export class CloudAssemblyBuilder {
143143
const manifestFilePath = path.join(this.outdir, MANIFEST_FILE);
144144
fs.writeFileSync(manifestFilePath, JSON.stringify(manifest, undefined, 2));
145145

146+
// "backwards compatibility": in order for the old CLI to tell the user they
147+
// need a new version, we'll emit the legacy manifest with only "version".
148+
// this will result in an error "CDK Toolkit >= 0.33.0 is required in order to interact with this program."
149+
fs.writeFileSync(path.join(this.outdir, 'cdk.out'), JSON.stringify({ version: CLOUD_ASSEMBLY_VERSION }));
150+
146151
return new CloudAssembly(this.outdir);
147152
}
148153
}
@@ -201,4 +206,4 @@ function filterUndefined(obj: any): any {
201206

202207
function ignore(_x: any) {
203208
return;
204-
}
209+
}

packages/@aws-cdk/cx-api/lib/versioning.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ export function verifyManifestVersion(manifetVersion: string) {
2727

2828
// if framework > cli, we require a newer cli version
2929
if (semver.gt(frameworkVersion, toolkitVersion)) {
30-
throw new Error(`CLI >= ${frameworkVersion} is required to interact with this app`);
30+
throw new Error(`CDK CLI >= ${frameworkVersion} is required to interact with this app`);
3131
}
3232

3333
// if framework < cli, we require a newer framework version
3434
if (semver.lt(frameworkVersion, toolkitVersion)) {
35-
throw new Error(`App used framework v${frameworkVersion} but it must be >= v${CLOUD_ASSEMBLY_VERSION} in order to interact with this CLI`);
35+
throw new Error(
36+
`CDK CLI can only be used with apps created by CDK >= ${CLOUD_ASSEMBLY_VERSION}`);
3637
}
3738
}
3839

packages/@aws-cdk/cx-api/test/cloud-assembly.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,6 @@ test('fails for invalid dependencies', () => {
9595

9696
test('verifyManifestVersion', () => {
9797
verifyManifestVersion('0.33.0');
98-
expect(() => verifyManifestVersion('0.31.0')).toThrow('App used framework v0.31.0 but it must be >= v0.33.0 in order to interact with this CLI');
99-
expect(() => verifyManifestVersion('0.34.0')).toThrow('CLI >= 0.34.0 is required to interact with this app');
98+
expect(() => verifyManifestVersion('0.31.0')).toThrow('CDK CLI can only be used with apps created by CDK >= 0.33.0');
99+
expect(() => verifyManifestVersion('0.34.0')).toThrow('CDK CLI >= 0.34.0 is required to interact with this app');
100100
});

0 commit comments

Comments
 (0)