Skip to content

Commit

Permalink
revert: "feat(cli): warn of non-existent stacks in cdk destroy" (#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
scanlonp authored Mar 25, 2024
1 parent 432f97d commit f60e6e9
Showing 1 changed file with 1 addition and 41 deletions.
42 changes: 1 addition & 41 deletions packages/aws-cdk/lib/cdk-toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import * as cxapi from '@aws-cdk/cx-api';
import * as chalk from 'chalk';
import * as chokidar from 'chokidar';
import * as fs from 'fs-extra';
import { minimatch } from 'minimatch';
import * as promptly from 'promptly';
import * as semver from 'semver';
import * as uuid from 'uuid';
import { DeploymentMethod } from './api';
import { SdkProvider } from './api/aws-auth';
Expand All @@ -31,7 +29,6 @@ import { validateSnsTopicArn } from './util/validate-notification-arn';
import { Concurrency, WorkGraph } from './util/work-graph';
import { WorkGraphBuilder } from './util/work-graph-builder';
import { AssetBuildNode, AssetPublishNode, StackNode } from './util/work-graph-types';
import { versionNumber } from './version';
import { environmentsFromDescriptors, globEnvironmentsFromStacks, looksLikeGlob } from '../lib/api/cxapp/environments';

export interface CdkToolkitProps {
Expand Down Expand Up @@ -617,9 +614,6 @@ export class CdkToolkit {
stacks = stacks.reversed();

if (!options.force) {
if (stacks.stackArtifacts.length === 0) {
return;
}
// eslint-disable-next-line max-len
const confirmed = await promptly.confirm(`Are you sure you want to delete: ${chalk.blue(stacks.stackArtifacts.map(s => s.hierarchicalId).join(', '))} (y/n)?`);
if (!confirmed) {
Expand Down Expand Up @@ -913,43 +907,9 @@ export class CdkToolkit {
extend: exclusively ? ExtendedStackSelection.None : ExtendedStackSelection.Downstream,
defaultBehavior: DefaultSelection.OnlySingle,
});
const selectorWithoutPatterns: StackSelector = {
...selector,
allTopLevel: true,
patterns: [],
};
const stacksWithoutPatterns = await assembly.selectStacks(selectorWithoutPatterns, {
extend: exclusively ? ExtendedStackSelection.None : ExtendedStackSelection.Downstream,
defaultBehavior: DefaultSelection.OnlySingle,
});

const patterns = selector.patterns.map(pattern => {
const notExist = !stacks.stackArtifacts.find(stack =>
minimatch(stack.hierarchicalId, pattern) || (stack.id === pattern && semver.major(versionNumber()) < 2),
);

const closelyMatched = notExist ? stacksWithoutPatterns.stackArtifacts.map(stack => {
if (minimatch(stack.hierarchicalId.toLowerCase(), pattern.toLowerCase())) {
return stack.hierarchicalId;
}
if (stack.id.toLowerCase() === pattern.toLowerCase() && semver.major(versionNumber()) < 2) {
return stack.id;
}
return;
}).filter((stack): stack is string => stack !== undefined) : [];
return {
pattern,
notExist,
closelyMatched,
};
});
// No validation

patterns.forEach(pattern => {
if (pattern.notExist) {
const closelyMatched = pattern.closelyMatched.length > 0 ? ` Do you mean ${pattern.closelyMatched.join(', ')}?` : '';
warning(`${pattern.pattern} does not exist.${closelyMatched}`);
}
});
return stacks;
}

Expand Down

0 comments on commit f60e6e9

Please sign in to comment.