aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 2.63 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0}),exports.constructInfoFromStack=exports.constructInfoFromConstruct=void 0;var app_1=()=>{var tmp=require("../app");return app_1=()=>tmp,tmp},stack_1=()=>{var tmp=require("../stack");return stack_1=()=>tmp,tmp},stage_1=()=>{var tmp=require("../stage");return stage_1=()=>tmp,tmp};const ALLOWED_FQN_PREFIXES=["@aws-cdk/","@aws-cdk-containers/","@aws-solutions-konstruk/","@aws-solutions-constructs/","@amzn/","@cdklabs/","aws-rfdk.","aws-cdk-lib.","cdk8s."],JSII_RUNTIME_SYMBOL=Symbol.for("jsii.rtti");function constructInfoFromConstruct(construct){const jsiiRuntimeInfo=Object.getPrototypeOf(construct).constructor[JSII_RUNTIME_SYMBOL];if(typeof jsiiRuntimeInfo=="object"&&jsiiRuntimeInfo!==null&&typeof jsiiRuntimeInfo.fqn=="string"&&typeof jsiiRuntimeInfo.version=="string")return{fqn:jsiiRuntimeInfo.fqn,version:jsiiRuntimeInfo.version};if(jsiiRuntimeInfo)throw new Error(`malformed jsii runtime info for construct: '${construct.node.path}'`)}exports.constructInfoFromConstruct=constructInfoFromConstruct;function addValidationPluginInfo(stack,allConstructInfos){let stage=stage_1().Stage.of(stack),done=!1;do app_1().App.isApp(stage)&&(done=!0),stage&&(allConstructInfos.push(...stage.policyValidationBeta1.map(plugin=>({fqn:pluginFqn(plugin),version:plugin.version??"0.0.0"}))),stage=stage_1().Stage.of(stage));while(!done&&stage)}function pluginFqn(plugin){return["policyValidation",plugin.name,plugin.ruleIds?.join("|")].filter(x=>x!=null).join(".")}function constructInfoFromStack(stack){const isDefined=value=>value!==void 0,allConstructInfos=constructsInStack(stack).map(construct=>constructInfoFromConstruct(construct)).filter(isDefined).filter(info=>ALLOWED_FQN_PREFIXES.find(prefix=>info.fqn.startsWith(prefix)));allConstructInfos.push({fqn:"jsii-runtime.Runtime",version:getJsiiAgentVersion()}),addValidationPluginInfo(stack,allConstructInfos);const uniqKeys=new Set;return allConstructInfos.filter(construct=>{const constructKey=`${construct.fqn}@${construct.version}`,isDuplicate=uniqKeys.has(constructKey);return uniqKeys.add(constructKey),!isDuplicate})}exports.constructInfoFromStack=constructInfoFromStack;function constructsInStack(construct){const constructs=[construct];return construct.node.children.filter(child=>!stage_1().Stage.isStage(child)&&!stack_1().Stack.isStack(child)).forEach(child=>constructs.push(...constructsInStack(child))),constructs}function getJsiiAgentVersion(){let jsiiAgent=process.env.JSII_AGENT;return jsiiAgent||(jsiiAgent=`node.js/${process.version}`),jsiiAgent=jsiiAgent.replace(/[^a-z0-9.-/=_]/gi,"-"),jsiiAgent}