@@ -3,10 +3,33 @@ import * as cxschema from '@aws-cdk/cloud-assembly-schema';
3
3
import { CloudArtifact } from '../cloud-artifact' ;
4
4
import { CloudAssembly } from '../cloud-assembly' ;
5
5
6
+ const ASSET_MANIFEST_ARTIFACT_SYM = Symbol . for ( '@aws-cdk/cx-api.AssetManifestArtifact' ) ;
7
+
6
8
/**
7
9
* Asset manifest is a description of a set of assets which need to be built and published
8
10
*/
9
11
export class AssetManifestArtifact extends CloudArtifact {
12
+ /**
13
+ * Checks if `art` is an instance of this class.
14
+ *
15
+ * Use this method instead of `instanceof` to properly detect `AssetManifestArtifact`
16
+ * instances, even when the construct library is symlinked.
17
+ *
18
+ * Explanation: in JavaScript, multiple copies of the `cx-api` library on
19
+ * disk are seen as independent, completely different libraries. As a
20
+ * consequence, the class `AssetManifestArtifact` in each copy of the `cx-api` library
21
+ * is seen as a different class, and an instance of one class will not test as
22
+ * `instanceof` the other class. `npm install` will not create installations
23
+ * like this, but users may manually symlink construct libraries together or
24
+ * use a monorepo tool: in those cases, multiple copies of the `cx-api`
25
+ * library can be accidentally installed, and `instanceof` will behave
26
+ * unpredictably. It is safest to avoid using `instanceof`, and using
27
+ * this type-testing method instead.
28
+ */
29
+ public static isAssetManifestArtifact ( art : any ) : art is AssetManifestArtifact {
30
+ return art && typeof art === 'object' && art [ ASSET_MANIFEST_ARTIFACT_SYM ] ;
31
+ }
32
+
10
33
/**
11
34
* The file name of the asset manifest
12
35
*/
@@ -36,3 +59,15 @@ export class AssetManifestArtifact extends CloudArtifact {
36
59
this . bootstrapStackVersionSsmParameter = properties . bootstrapStackVersionSsmParameter ;
37
60
}
38
61
}
62
+
63
+ /**
64
+ * Mark all instances of 'AssetManifestArtifact'
65
+ *
66
+ * Why not put this in the constructor? Because this is a class property,
67
+ * not an instance property. It applies to all instances of the class.
68
+ */
69
+ Object . defineProperty ( AssetManifestArtifact . prototype , ASSET_MANIFEST_ARTIFACT_SYM , {
70
+ value : true ,
71
+ enumerable : false ,
72
+ writable : false ,
73
+ } ) ;
0 commit comments