From 361bac902d1d2bc70ae481eab291def7f2e18fd0 Mon Sep 17 00:00:00 2001 From: Momo Kornher Date: Fri, 20 Dec 2024 23:29:47 +0100 Subject: [PATCH] chore(cli): remove v1 compat for stack selection --- .../aws-cdk/lib/api/cxapp/cloud-assembly.ts | 41 ++++++++----------- .../aws-cdk/test/api/cloud-assembly.test.ts | 3 -- packages/aws-cdk/test/cdk-toolkit.test.ts | 2 - 3 files changed, 17 insertions(+), 29 deletions(-) diff --git a/packages/aws-cdk/lib/api/cxapp/cloud-assembly.ts b/packages/aws-cdk/lib/api/cxapp/cloud-assembly.ts index 6b827d4a2e363..96843b706b005 100644 --- a/packages/aws-cdk/lib/api/cxapp/cloud-assembly.ts +++ b/packages/aws-cdk/lib/api/cxapp/cloud-assembly.ts @@ -4,7 +4,6 @@ import { minimatch } from 'minimatch'; import * as semver from 'semver'; import { error, print, warning } from '../../logging'; import { flatten } from '../../util'; -import { versionNumber } from '../../version'; export enum DefaultSelection { /** @@ -122,9 +121,11 @@ export class CloudAssembly { } } - private selectTopLevelStacks(stacks: cxapi.CloudFormationStackArtifact[], + private selectTopLevelStacks( + stacks: cxapi.CloudFormationStackArtifact[], topLevelStacks: cxapi.CloudFormationStackArtifact[], - extend: ExtendedStackSelection = ExtendedStackSelection.None): StackCollection { + extend: ExtendedStackSelection = ExtendedStackSelection.None, + ): StackCollection { if (topLevelStacks.length > 0) { return this.extendStacks(topLevelStacks, stacks, extend); } else { @@ -132,33 +133,23 @@ export class CloudAssembly { } } - private selectMatchingStacks(stacks: cxapi.CloudFormationStackArtifact[], + private selectMatchingStacks( + stacks: cxapi.CloudFormationStackArtifact[], patterns: string[], - extend: ExtendedStackSelection = ExtendedStackSelection.None): StackCollection { - - // cli tests use this to ensure tests do not depend on legacy behavior - // (otherwise they will fail in v2) - const disableLegacy = process.env.CXAPI_DISABLE_SELECT_BY_ID === '1'; - - const matchingPattern = (pattern: string) => (stack: cxapi.CloudFormationStackArtifact) => { - if (minimatch(stack.hierarchicalId, pattern)) { - return true; - } else if (!disableLegacy && stack.id === pattern && semver.major(versionNumber()) < 2) { - warning('Selecting stack by identifier "%s". This identifier is deprecated and will be removed in v2. Please use "%s" instead.', chalk.bold(stack.id), chalk.bold(stack.hierarchicalId)); - warning('Run "cdk ls" to see a list of all stack identifiers'); - return true; - } - return false; - }; + extend: ExtendedStackSelection = ExtendedStackSelection.None, + ): StackCollection { + const matchingPattern = (pattern: string) => (stack: cxapi.CloudFormationStackArtifact) => minimatch(stack.hierarchicalId, pattern); const matchedStacks = flatten(patterns.map(pattern => stacks.filter(matchingPattern(pattern)))); return this.extendStacks(matchedStacks, stacks, extend); } - private selectDefaultStacks(stacks: cxapi.CloudFormationStackArtifact[], + private selectDefaultStacks( + stacks: cxapi.CloudFormationStackArtifact[], topLevelStacks: cxapi.CloudFormationStackArtifact[], - defaultSelection: DefaultSelection) { + defaultSelection: DefaultSelection, + ) { switch (defaultSelection) { case DefaultSelection.MainAssembly: return new StackCollection(this, topLevelStacks); @@ -178,9 +169,11 @@ export class CloudAssembly { } } - private extendStacks(matched: cxapi.CloudFormationStackArtifact[], + private extendStacks( + matched: cxapi.CloudFormationStackArtifact[], all: cxapi.CloudFormationStackArtifact[], - extend: ExtendedStackSelection = ExtendedStackSelection.None) { + extend: ExtendedStackSelection = ExtendedStackSelection.None, + ) { const allStacks = new Map(); for (const stack of all) { allStacks.set(stack.hierarchicalId, stack); diff --git a/packages/aws-cdk/test/api/cloud-assembly.test.ts b/packages/aws-cdk/test/api/cloud-assembly.test.ts index 5654c6390f2dd..c97e6f4925d76 100644 --- a/packages/aws-cdk/test/api/cloud-assembly.test.ts +++ b/packages/aws-cdk/test/api/cloud-assembly.test.ts @@ -4,9 +4,6 @@ import { DefaultSelection } from '../../lib/api/cxapp/cloud-assembly'; import { MockCloudExecutable } from '../util'; import { cliAssemblyWithForcedVersion } from './assembly-versions'; -// behave like v2 -process.env.CXAPI_DISABLE_SELECT_BY_ID = '1'; - test('do not throw when selecting stack without errors', async () => { // GIVEN const cxasm = await testCloudAssembly(); diff --git a/packages/aws-cdk/test/cdk-toolkit.test.ts b/packages/aws-cdk/test/cdk-toolkit.test.ts index cba685fe15528..5e4081e66dcb5 100644 --- a/packages/aws-cdk/test/cdk-toolkit.test.ts +++ b/packages/aws-cdk/test/cdk-toolkit.test.ts @@ -95,8 +95,6 @@ import { flatten } from '../lib/util'; markTesting(); -process.env.CXAPI_DISABLE_SELECT_BY_ID = '1'; - const defaultBootstrapSource: BootstrapSource = { source: 'default' }; const bootstrapEnvironmentMock = jest.spyOn(Bootstrapper.prototype, 'bootstrapEnvironment'); let cloudExecutable: MockCloudExecutable;