aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 1.76 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0}),exports.collectAnnotationReport=collectAnnotationReport;var path=()=>{var tmp=require("path");return path=()=>tmp,tmp},construct_iteration_1=()=>{var tmp=require("./construct-iteration");return construct_iteration_1=()=>tmp,tmp},cxschema=()=>{var tmp=require("../../../cloud-assembly-schema");return cxschema=()=>tmp,tmp},stack_1=()=>{var tmp=require("../stack");return stack_1=()=>tmp,tmp};const ANNOTATION_PLUGIN_NAME="Construct Annotations";function collectAnnotationReport(root,outdir){const violationMap=new Map;for(const construct of(0,construct_iteration_1().iterateDfsPreorder)(root))for(const entry of construct.node.metadata){if(entry.type!==cxschema().ArtifactMetadataEntryType.WARN&&entry.type!==cxschema().ArtifactMetadataEntryType.ERROR)continue;const message=entry.data,severity=entry.type===cxschema().ArtifactMetadataEntryType.ERROR?"error":"warning",ruleName=extractRuleName(message,severity);let templatePath;try{templatePath=path().join(outdir,stack_1().Stack.of(construct).templateFile)}catch{}const violatingResource={constructPath:construct.node.path,templatePath,locations:[]},key=`${ruleName}|${severity}|${message}`,existing=violationMap.get(key);existing?existing.violatingResources.push(violatingResource):violationMap.set(key,{ruleName,description:message,severity,violatingResources:[violatingResource]})}const violations=Array.from(violationMap.values());if(violations.length===0)return;const hasErrors=violations.some(v=>v.severity==="error");return{pluginName:ANNOTATION_PLUGIN_NAME,success:!hasErrors,violations}}function extractRuleName(message,severity){const ackMatch=message.match(/\[ack: ([^\]]+)\]/);return ackMatch?ackMatch[1]:`aws-cdk:${severity}`}