Skip to content

Commit

Permalink
fix(cdk): don't use instanceof in App
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rix0rrr committed Nov 27, 2018
1 parent 6a13a18 commit 82929ad
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/@aws-cdk/cdk/lib/app.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/cdk/lib/cloudformation/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 82929ad

Please sign in to comment.