From 82929ad63dd7cb74069bc770e34f7f8ba35a152b Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Tue, 27 Nov 2018 11:32:47 +0100 Subject: [PATCH] fix(cdk): don't use instanceof in App Make the Stack instance test no longer use instanceof, which doesn't work properly in case of multiple installed copies of the library. This does not resolve but helps with #1245. --- packages/@aws-cdk/cdk/lib/app.ts | 6 +++--- packages/@aws-cdk/cdk/lib/cloudformation/stack.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/@aws-cdk/cdk/lib/app.ts b/packages/@aws-cdk/cdk/lib/app.ts index f3e7c6a90ff8a..3892bd72bdc1d 100644 --- a/packages/@aws-cdk/cdk/lib/app.ts +++ b/packages/@aws-cdk/cdk/lib/app.ts @@ -1,7 +1,7 @@ import cxapi = require('@aws-cdk/cx-api'); import fs = require('fs'); import path = require('path'); -import { Stack } from './cloudformation/stack'; +import { isStack, Stack } from './cloudformation/stack'; import { Construct, MetadataEntry, PATH_SEP, Root } from './core/construct'; import { resolve } from './core/tokens'; @@ -21,8 +21,8 @@ export class App extends Root { private get stacks() { const out: { [name: string]: Stack } = { }; for (const child of this.children) { - if (!(child instanceof Stack)) { - throw new Error(`The child ${child.toString()} of Program must be a Stack`); + if (!isStack(child)) { + throw new Error(`The child ${child.toString()} of App must be a Stack`); } out[child.id] = child as Stack; diff --git a/packages/@aws-cdk/cdk/lib/cloudformation/stack.ts b/packages/@aws-cdk/cdk/lib/cloudformation/stack.ts index 5e97d935a8ed6..04182776660cb 100644 --- a/packages/@aws-cdk/cdk/lib/cloudformation/stack.ts +++ b/packages/@aws-cdk/cdk/lib/cloudformation/stack.ts @@ -438,7 +438,7 @@ export abstract class Referenceable extends StackElement { * * We do attribute detection since we can't reliably use 'instanceof'. */ -function isStack(construct: Construct): construct is Stack { +export function isStack(construct: Construct): construct is Stack { return (construct as any).isStack; }