UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

2 lines (1 loc) 1.97 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.constructInfoFromStack=exports.constructInfoFromConstruct=void 0;const stack_1=require("../stack"),stage_1=require("../stage"),ALLOWED_FQN_PREFIXES=["@aws-cdk/","@aws-cdk-containers/","@aws-solutions-konstruk/","@aws-solutions-constructs/","@amzn/","@cdklabs/","aws-rfdk.","aws-cdk-lib."],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 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()});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}