@@ -16,7 +16,6 @@ import { Token } from '../token';
16
16
export class MetadataResource extends Construct {
17
17
constructor ( scope : Stack , id : string ) {
18
18
super ( scope , id ) ;
19
-
20
19
const metadataServiceExists = Token . isUnresolved ( scope . region ) || RegionInfo . get ( scope . region ) . cdkMetadataResourceAvailable ;
21
20
if ( metadataServiceExists ) {
22
21
const resource = new CfnResource ( this , 'Default' , {
@@ -51,22 +50,30 @@ function makeCdkMetadataAvailableCondition() {
51
50
class Trie extends Map < string , Trie > { }
52
51
53
52
/**
54
- * Formats a list of construct fully-qualified names (FQNs) and versions into a (possibly compressed) prefix-encoded string.
53
+ * Formats the analytics string which has 3 or 4 sections separated by colons (:)
54
+ *
55
+ * version:encoding:constructinfo OR version:encoding:constructinfo:appinfo
55
56
*
56
- * The list of ConstructInfos is logically formatted into:
57
- * ${version}!${fqn} (e.g., "1.90.0!aws-cdk-lib.Stack")
58
- * and then all of the construct-versions are grouped with common prefixes together, grouping common parts in '{}' and separating items with ','.
57
+ * The constructinfo section is a list of construct fully-qualified names (FQNs)
58
+ * and versions into a (possibly compressed) prefix-encoded string.
59
+ *
60
+ * The list of ConstructInfos is logically formatted into: ${version}!${fqn}
61
+ * (e.g., "1.90.0!aws-cdk-lib.Stack") and then all of the construct-versions are
62
+ * grouped with common prefixes together, grouping common parts in '{}' and
63
+ * separating items with ','.
59
64
*
60
65
* Example:
61
66
* [1.90.0!aws-cdk-lib.Stack, 1.90.0!aws-cdk-lib.Construct, 1.90.0!aws-cdk-lib.service.Resource, 0.42.1!aws-cdk-lib-experiments.NewStuff]
62
67
* Becomes:
63
68
* 1.90.0!aws-cdk-lib.{Stack,Construct,service.Resource},0.42.1!aws-cdk-lib-experiments.NewStuff
64
69
*
65
- * The whole thing is then either included directly as plaintext as:
66
- * v2:plaintext:{prefixEncodedList}
67
- * Or is compressed and base64-encoded, and then formatted as:
70
+ * The whole thing is then compressed and base64-encoded, and then formatted as:
68
71
* v2:deflate64:{prefixEncodedListCompressedAndEncoded}
69
72
*
73
+ * The appinfo section is optional, and currently only added if the app was generated using `cdk migrate`
74
+ * It is also compressed and base64-encoded. In this case, the string will be formatted as:
75
+ * v2:deflate64:{prefixEncodedListCompressedAndEncoded}:{'cdk-migrate'CompressedAndEncoded}
76
+ *
70
77
* Exported/visible for ease of testing.
71
78
*/
72
79
export function formatAnalytics ( infos : ConstructInfo [ ] ) {
@@ -81,7 +88,15 @@ export function formatAnalytics(infos: ConstructInfo[]) {
81
88
setGzipOperatingSystemToUnknown ( compressedConstructsBuffer ) ;
82
89
83
90
const compressedConstructs = compressedConstructsBuffer . toString ( 'base64' ) ;
84
- return `v2:deflate64:${ compressedConstructs } ` ;
91
+ const analyticsString = `v2:deflate64:${ compressedConstructs } ` ;
92
+
93
+ if ( process . env . CDK_CONTEXT_JSON && JSON . parse ( process . env . CDK_CONTEXT_JSON ) [ 'cdk-migrate' ] ) {
94
+ const compressedAppInfoBuffer = zlib . gzipSync ( Buffer . from ( 'cdk-migrate' ) ) ;
95
+ const compressedAppInfo = compressedAppInfoBuffer . toString ( 'base64' ) ;
96
+ analyticsString . concat ( ':' , compressedAppInfo ) ;
97
+ }
98
+
99
+ return analyticsString ;
85
100
}
86
101
87
102
/**
0 commit comments