Skip to content

Commit

Permalink
fix undefined bundling
Browse files Browse the repository at this point in the history
  • Loading branch information
iankhou committed Feb 12, 2025
1 parent 0e5c60a commit e7004e7
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions packages/aws-cdk/lib/cli/user-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ const CONTEXT_KEY = 'context';
* All available CDK commands.
*/
export enum Command {
// List operations
// List operations (no bundling)
LS = 'ls',
LIST = 'list',

// Stack modification operations
// Stack modification operations (require bundling)
DIFF = 'diff',
DEPLOY = 'deploy',
SYNTHESIZE = 'synthesize',
SYNTH = 'synth',
WATCH = 'watch',
IMPORT = 'import',

// Management operations
// Management operations (no bundling)
BOOTSTRAP = 'bootstrap',
DESTROY = 'destroy',
METADATA = 'metadata',
Expand All @@ -43,23 +43,12 @@ export enum Command {
DOCTOR = 'doctor',
}

interface ConfiguredCommand {
bundling: boolean;
}

type CommandType = {
[K in Command]: ConfiguredCommand;
};

/**
* Available commands and their bundling configurations.
* The bundling property is determined by the command's categorization.
*
* @example
* ConfiguredCommands[Command.DEPLOY].bundling; // true
* ConfiguredCommands[Command.LS].bundling; // false
* Metadata for each command specifying if it requires bundling.
* This must be kept in sync with the Command enum.
* TypeScript will enforce this by checking that all enum values are covered.
*/
const ConfiguredCommands: CommandType = {
export const CommandMetadata: { [K in Command]: { bundling: boolean } } = {
// List operations (no bundling)
[Command.LS]: { bundling: false },
[Command.LIST]: { bundling: false },
Expand Down Expand Up @@ -90,6 +79,29 @@ const ConfiguredCommands: CommandType = {
[Command.DOCTOR]: { bundling: false },
};

export interface ConfiguredCommand {
bundling: boolean;
}

type CommandType = {
[key: string]: ConfiguredCommand;
};

/**
* Available commands and their bundling configurations.
* Generated from CommandMetadata to ensure consistency.
*
* @example
* ConfiguredCommands['deploy'].bundling; // true
* ConfiguredCommands['ls'].bundling; // false
*/
export const ConfiguredCommands: CommandType = Object.entries(Command)
.filter(([key]) => isNaN(Number(key))) // Filter out reverse mapping
.reduce((acc, [_, value]) => ({
...acc,
[value]: CommandMetadata[value as Command],
}), {});

export type Arguments = {
readonly _: [keyof typeof ConfiguredCommands, ...string[]];
readonly exclusively?: boolean;
Expand Down

0 comments on commit e7004e7

Please sign in to comment.