aws-cdk-lib
Version:
Version 2 of the AWS Cloud Development Kit library
2 lines (1 loc) • 2.11 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0}),exports.prepareApp=prepareApp;var constructs_1=()=>{var tmp=require("constructs");return constructs_1=()=>tmp,tmp},refs_1=()=>{var tmp=require("./refs");return refs_1=()=>tmp,tmp},cfn_resource_1=()=>{var tmp=require("../cfn-resource");return cfn_resource_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},construct_iteration_1=()=>{var tmp=require("./construct-iteration");return construct_iteration_1=()=>tmp,tmp};function prepareApp(root){for(const dependency of findTransitiveDeps(root)){const targetCfnResources=findCfnResources(dependency.target),sourceCfnResources=Array.from(findCfnResources(dependency.source));for(const target of targetCfnResources)for(const source of sourceCfnResources)source.addDependency(target)}(0,refs_1().resolveReferences)(root);const queue=findAllNestedStacks(root);if(queue.length>0){for(;queue.length>0;){const nested=queue.shift();defineNestedStackAsset(nested)}(0,refs_1().resolveReferences)(root)}}function defineNestedStackAsset(nestedStack){nestedStack._prepareTemplateAsset()}function findAllNestedStacks(root){const result=new Array,includeStack=stack=>!stack_1().Stack.isStack(stack)||!stack.nested?!1:stage_1().Stage.of(stack)?stage_1().Stage.of(stack)===root:!0;for(const node of(0,construct_iteration_1().iterateDfsPostorder)(root))includeStack(node)&&result.push(node);return result}function*findCfnResources(root){for(const node of(0,construct_iteration_1().iterateDfsPreorder)(root))cfn_resource_1().CfnResource.isCfnResource(node)&&(yield node)}function findTransitiveDeps(root){const found=new Map,ret=new Array;for(const source of(0,construct_iteration_1().iterateDfsPreorder)(root))for(const dependable of source.node.dependencies)for(const target of constructs_1().Dependable.of(dependable).dependencyRoots){let foundTargets=found.get(source);foundTargets||found.set(source,foundTargets=new Set),foundTargets.has(target)||(ret.push({source,target}),foundTargets.add(target))}return ret}