From 929e8541776d8efcad495eb735dd3721e8b4525f Mon Sep 17 00:00:00 2001 From: Romain Marcadier-Muller Date: Tue, 5 Mar 2019 10:09:00 +0100 Subject: [PATCH] fix(awslint): Don't fail if the `@aws-cdk/cdk` module is not present (#1953) This simply means that no class may be a `Construct` or `Resource`, and that is a pretty valid thing to have. --- tools/awslint/lib/cfn-resources.ts | 6 +++++- tools/awslint/lib/util.ts | 8 ++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/awslint/lib/cfn-resources.ts b/tools/awslint/lib/cfn-resources.ts index 838a56978b9d5..a1ecda07eac8e 100644 --- a/tools/awslint/lib/cfn-resources.ts +++ b/tools/awslint/lib/cfn-resources.ts @@ -64,7 +64,11 @@ export function findCfnResources(assembly: reflect.Assembly): CfnResourceSpec[] } function isCfnResource(c: reflect.ClassType) { - const resourceBaseClass = c.system.findFqn('@aws-cdk/cdk.Resource'); + const cdkAssembly = '@aws-cdk/cdk'; + if (!c.system.includesAssembly(cdkAssembly)) { + return false; + } + const resourceBaseClass = c.system.findFqn(`${cdkAssembly}.Resource`); if (!isConstruct(c)) { return false; diff --git a/tools/awslint/lib/util.ts b/tools/awslint/lib/util.ts index 59b13085074ae..6302a19001770 100644 --- a/tools/awslint/lib/util.ts +++ b/tools/awslint/lib/util.ts @@ -1,9 +1,13 @@ import reflect = require('jsii-reflect'); -export const CONSTRUCT_FQN = '@aws-cdk/cdk.Construct'; -export const CONSTRUCT_INTERFACE_FQN = '@aws-cdk/cdk.IConstruct'; +export const CONSTRUCT_ASSEMBLY = '@aws-cdk/cdk'; +export const CONSTRUCT_FQN = `${CONSTRUCT_ASSEMBLY}.Construct`; +export const CONSTRUCT_INTERFACE_FQN = `${CONSTRUCT_ASSEMBLY}.IConstruct`; export function isConstruct(c: reflect.ClassType) { + if (!c.system.includesAssembly(CONSTRUCT_ASSEMBLY)) { + return false; + } const constructClass = c.system.findFqn(CONSTRUCT_FQN); const bases = c.getAncestors(); const root = bases[bases.length - 1];