From 19d2e4130c9950ee8d0e0f2d884222fa3486d243 Mon Sep 17 00:00:00 2001 From: Kaizen Conroy Date: Mon, 6 Jan 2025 15:28:58 -0500 Subject: [PATCH 01/14] chore(cli): cli arguments with "count: true" are generated as number types --- packages/aws-cdk/lib/cli-arguments.ts | 2 +- tools/@aws-cdk/cli-args-gen/lib/cli-args-gen.ts | 8 ++++---- .../@aws-cdk/cli-args-gen/test/cli-args-gen.test.ts | 12 ++++++++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/packages/aws-cdk/lib/cli-arguments.ts b/packages/aws-cdk/lib/cli-arguments.ts index 8dc3afcc24c09..665f81b2ce9d1 100644 --- a/packages/aws-cdk/lib/cli-arguments.ts +++ b/packages/aws-cdk/lib/cli-arguments.ts @@ -194,7 +194,7 @@ export interface GlobalOptions { * * @default - false */ - readonly verbose?: boolean; + readonly verbose?: number; /** * Debug the CDK app. Log additional information during synthesis, such as creation stack traces of tokens (sets CDK_DEBUG, will slow down synthesis) diff --git a/tools/@aws-cdk/cli-args-gen/lib/cli-args-gen.ts b/tools/@aws-cdk/cli-args-gen/lib/cli-args-gen.ts index 859319d028661..da469e5cb9dc0 100644 --- a/tools/@aws-cdk/cli-args-gen/lib/cli-args-gen.ts +++ b/tools/@aws-cdk/cli-args-gen/lib/cli-args-gen.ts @@ -43,7 +43,7 @@ export async function renderCliArgsType(config: CliConfig): Promise { for (const [optionName, option] of Object.entries(config.globalOptions)) { globalOptionType.addProperty({ name: kebabToCamelCase(optionName), - type: convertType(option.type), + type: convertType(option.type, option.count), docs: { default: normalizeDefault(option.default, option.type), summary: option.desc, @@ -77,7 +77,7 @@ export async function renderCliArgsType(config: CliConfig): Promise { for (const [optionName, option] of Object.entries(command.options ?? {})) { commandType.addProperty({ name: kebabToCamelCase(optionName), - type: convertType(option.type), + type: convertType(option.type, option.count), docs: { // Notification Arns is a special property where undefined and [] mean different things default: optionName === 'notification-arns' ? 'undefined' : normalizeDefault(option.default, option.type), @@ -124,10 +124,10 @@ export async function renderCliArgsType(config: CliConfig): Promise { }); } -function convertType(type: 'string' | 'array' | 'number' | 'boolean' | 'count'): Type { +function convertType(type: 'string' | 'array' | 'number' | 'boolean' | 'count', count?: boolean): Type { switch (type) { case 'boolean': - return Type.BOOLEAN; + return count ? Type.NUMBER : Type.BOOLEAN; case 'string': return Type.STRING; case 'number': diff --git a/tools/@aws-cdk/cli-args-gen/test/cli-args-gen.test.ts b/tools/@aws-cdk/cli-args-gen/test/cli-args-gen.test.ts index a323974bee1e8..341931d53e8f8 100644 --- a/tools/@aws-cdk/cli-args-gen/test/cli-args-gen.test.ts +++ b/tools/@aws-cdk/cli-args-gen/test/cli-args-gen.test.ts @@ -13,6 +13,11 @@ describe('render', () => { desc: 'Enable debug logging', default: false, }, + verbose: { + type: 'boolean', + count: true, + desc: 'Increase logging verbosity', + }, context: { default: [], type: 'array', @@ -88,6 +93,13 @@ describe('render', () => { */ readonly debug?: boolean; + /** + * Increase logging verbosity + * + * @default - undefined + */ + readonly verbose?: number; + /** * context values * From 2cc8fbab1a94a18f664061ede75df4eca674c52b Mon Sep 17 00:00:00 2001 From: Kaizen Conroy Date: Mon, 6 Jan 2025 17:19:08 -0500 Subject: [PATCH 02/14] chore(cli): refactor cli.ts to use CliArguments --- packages/aws-cdk/lib/cdk-toolkit.ts | 7 +- packages/aws-cdk/lib/cli.ts | 317 +++++++++++++++------------- packages/aws-cdk/lib/settings.ts | 13 +- 3 files changed, 178 insertions(+), 159 deletions(-) diff --git a/packages/aws-cdk/lib/cdk-toolkit.ts b/packages/aws-cdk/lib/cdk-toolkit.ts index 32f6616e5cdb6..c6438e2400f3d 100644 --- a/packages/aws-cdk/lib/cdk-toolkit.ts +++ b/packages/aws-cdk/lib/cdk-toolkit.ts @@ -1729,6 +1729,9 @@ export interface DestroyOptions { readonly ci?: boolean; } +export type ActionType = 'print' | 'tag' | 'delete-tagged' | 'full'; +export type TypeType = 's3' | 'ecr' | 'all'; + /** * Options for the garbage collection */ @@ -1738,14 +1741,14 @@ export interface GarbageCollectionOptions { * * @default 'full' */ - readonly action: 'print' | 'tag' | 'delete-tagged' | 'full'; + readonly action: ActionType; /** * The type of the assets to be garbage collected. * * @default 'all' */ - readonly type: 's3' | 'ecr' | 'all'; + readonly type: TypeType; /** * Elapsed time between an asset being marked as isolated and actually deleted. diff --git a/packages/aws-cdk/lib/cli.ts b/packages/aws-cdk/lib/cli.ts index d763eb924b0fc..84e30a1705da0 100644 --- a/packages/aws-cdk/lib/cli.ts +++ b/packages/aws-cdk/lib/cli.ts @@ -16,7 +16,7 @@ import { execProgram } from '../lib/api/cxapp/exec'; import { Deployments } from '../lib/api/deployments'; import { PluginHost } from '../lib/api/plugin'; import { ToolkitInfo } from '../lib/api/toolkit-info'; -import { CdkToolkit, AssetBuildTime } from '../lib/cdk-toolkit'; +import { CdkToolkit, AssetBuildTime, ActionType, TypeType } from '../lib/cdk-toolkit'; import { contextHandler as context } from '../lib/commands/context'; import { docs } from '../lib/commands/docs'; import { doctor } from '../lib/commands/doctor'; @@ -28,6 +28,9 @@ import { Command, Configuration, Settings } from '../lib/settings'; import * as version from '../lib/version'; import { SdkToCliLogger } from './api/aws-auth/sdk-logger'; import { ToolkitError } from './toolkit/error'; +import { convertToCliArgs } from './convert-to-cli-args'; +import { CliArguments } from './cli-arguments'; +import { StringWithoutPlaceholders } from './api/util/placeholders'; /* eslint-disable max-len */ /* eslint-disable @typescript-eslint/no-shadow */ // yargs @@ -38,13 +41,13 @@ if (!process.stdout.isTTY) { } export async function exec(args: string[], synthesizer?: Synthesizer): Promise { - const argv = await parseCommandLineArguments(args); + const argv: CliArguments = convertToCliArgs(await parseCommandLineArguments(args)); // if one -v, log at a DEBUG level // if 2 -v, log at a TRACE level - if (argv.verbose) { + if (argv.globalOptions?.verbose) { let logLevel: LogLevel; - switch (argv.verbose) { + switch (argv.globalOptions.verbose) { case 1: logLevel = LogLevel.DEBUG; break; @@ -57,11 +60,11 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise 2) { + if (argv.globalOptions?.debug || (argv.globalOptions?.verbose ?? 0) > 2) { enableTracing(true); } - if (argv.ci) { + if (argv.globalOptions?.ci) { setCI(true); } @@ -75,10 +78,7 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise { + async function main(command: string, argv: CliArguments): Promise { const toolkitStackName: string = ToolkitInfo.determineName(configuration.settings.get(['toolkitStackName'])); debug(`Toolkit stack: ${chalk.bold(toolkitStackName)}`); - const cloudFormation = new Deployments({ sdkProvider, toolkitStackName }); - - if (args.all && args.STACKS) { - throw new ToolkitError('You must either specify a list of Stacks or the `--all` argument'); - } - - args.STACKS = args.STACKS ?? (args.STACK ? [args.STACK] : []); - args.ENVIRONMENTS = args.ENVIRONMENTS ?? []; + const globalOptions = argv.globalOptions ?? {}; - const selector: StackSelector = { - allTopLevel: args.all, - patterns: args.STACKS, - }; + const cloudFormation = new Deployments({ sdkProvider, toolkitStackName }); const cli = new CdkToolkit({ cloudExecutable, deployments: cloudFormation, - verbose: argv.trace || argv.verbose > 0, - ignoreErrors: argv['ignore-errors'], - strict: argv.strict, + verbose: globalOptions.trace || (globalOptions.verbose ?? 0) > 0, + ignoreErrors: globalOptions.ignoreErrors, + strict: globalOptions.strict, configuration, sdkProvider, }); switch (command) { case 'context': + const contextOptions = argv.context ?? {}; return context({ context: configuration.context, - clear: argv.clear, - json: argv.json, - force: argv.force, - reset: argv.reset, + clear: contextOptions.clear, + json: globalOptions.json, + force: contextOptions.force, + reset: contextOptions.reset, }); case 'docs': @@ -219,80 +210,88 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise Date: Tue, 7 Jan 2025 14:46:18 -0500 Subject: [PATCH 03/14] builds with test failures --- packages/aws-cdk/lib/api/cxapp/exec.ts | 24 +++- packages/aws-cdk/lib/cli.ts | 49 +++++-- packages/aws-cdk/lib/settings.ts | 176 +++++++------------------ packages/aws-cdk/test/settings.test.ts | 45 +++---- 4 files changed, 132 insertions(+), 162 deletions(-) diff --git a/packages/aws-cdk/lib/api/cxapp/exec.ts b/packages/aws-cdk/lib/api/cxapp/exec.ts index b02ad38445a07..142340b3a501e 100644 --- a/packages/aws-cdk/lib/api/cxapp/exec.ts +++ b/packages/aws-cdk/lib/api/cxapp/exec.ts @@ -6,7 +6,7 @@ import * as cxapi from '@aws-cdk/cx-api'; import * as fs from 'fs-extra'; import * as semver from 'semver'; import { debug, warning } from '../../logging'; -import { Configuration, PROJECT_CONFIG, USER_DEFAULTS } from '../../settings'; +import { Command, Configuration, PROJECT_CONFIG, USER_DEFAULTS } from '../../settings'; import { ToolkitError } from '../../toolkit/error'; import { loadTree, some } from '../../tree'; import { splitBySize } from '../../util/objects'; @@ -214,7 +214,7 @@ export async function prepareContext(config: Configuration, env: { [key: string] context[cxapi.DISABLE_ASSET_STAGING_CONTEXT] = true; } - const bundlingStacks = config.settings.get(['bundlingStacks']) ?? ['**']; + const bundlingStacks = setBundlingStacks(config); context[cxapi.BUNDLING_STACKS] = bundlingStacks; debug('context:', context); @@ -222,6 +222,26 @@ export async function prepareContext(config: Configuration, env: { [key: string] return context; } +function setBundlingStacks(config: Configuration) { + let bundlingStacks: string[]; + if (config.command && [ + Command.DEPLOY, + Command.DIFF, + Command.SYNTH, + Command.SYNTHESIZE, + Command.WATCH, + ].includes(config.command)) { + // If we deploy, diff, synth or watch a list of stacks exclusively we skip + // bundling for all other stacks. + bundlingStacks = config.settings.get(['exclusively']) + ? config.settings.get(['STACKS']) ?? ['**'] + : ['**']; + } else { // Skip bundling for all stacks + bundlingStacks = []; + } + return bundlingStacks; +} + /** * Make sure the 'app' is an array * diff --git a/packages/aws-cdk/lib/cli.ts b/packages/aws-cdk/lib/cli.ts index 84e30a1705da0..360855b01e95e 100644 --- a/packages/aws-cdk/lib/cli.ts +++ b/packages/aws-cdk/lib/cli.ts @@ -5,6 +5,8 @@ import * as chalk from 'chalk'; import { DeploymentMethod } from './api'; import { HotswapMode } from './api/hotswap/common'; import { ILock } from './api/util/rwlock'; +import { CliArguments } from './cli-arguments'; +import { convertToCliArgs } from './convert-to-cli-args'; import { parseCommandLineArguments } from './parse-command-line-arguments'; import { checkForPlatformWarnings } from './platform-warnings'; import { enableTracing } from './util/tracing'; @@ -16,21 +18,19 @@ import { execProgram } from '../lib/api/cxapp/exec'; import { Deployments } from '../lib/api/deployments'; import { PluginHost } from '../lib/api/plugin'; import { ToolkitInfo } from '../lib/api/toolkit-info'; -import { CdkToolkit, AssetBuildTime, ActionType, TypeType } from '../lib/cdk-toolkit'; +import { CdkToolkit, AssetBuildTime, ActionType, TypeType, Tag } from '../lib/cdk-toolkit'; import { contextHandler as context } from '../lib/commands/context'; import { docs } from '../lib/commands/docs'; import { doctor } from '../lib/commands/doctor'; import { getMigrateScanType } from '../lib/commands/migrate'; import { cliInit, printAvailableTemplates } from '../lib/init'; -import { data, debug, error, print, setCI, setLogLevel, LogLevel } from '../lib/logging'; +import { data, debug, error, print, setCI, setLogLevel, LogLevel, warning } from '../lib/logging'; import { Notices } from '../lib/notices'; -import { Command, Configuration, Settings } from '../lib/settings'; +import { Configuration, Settings } from '../lib/settings'; import * as version from '../lib/version'; import { SdkToCliLogger } from './api/aws-auth/sdk-logger'; -import { ToolkitError } from './toolkit/error'; -import { convertToCliArgs } from './convert-to-cli-args'; -import { CliArguments } from './cli-arguments'; import { StringWithoutPlaceholders } from './api/util/placeholders'; +import { ToolkitError } from './toolkit/error'; /* eslint-disable max-len */ /* eslint-disable @typescript-eslint/no-shadow */ // yargs @@ -86,12 +86,12 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise t !== ''); + if (nonEmptyTags.length === 0) { return []; } + + const tags: Tag[] = []; + + for (const assignment of nonEmptyTags) { + const parts = assignment.split(/=(.*)/, 2); + if (parts.length === 2) { + debug('CLI argument tags: %s=%s', parts[0], parts[1]); + tags.push({ + Key: parts[0], + Value: parts[1], + }); + } else { + warning('Tags argument is not an assignment (key=value): %s', assignment); + } + } + return tags.length > 0 ? tags : undefined; +} diff --git a/packages/aws-cdk/lib/settings.ts b/packages/aws-cdk/lib/settings.ts index b6712fe0c81ad..4f54e824d8820 100644 --- a/packages/aws-cdk/lib/settings.ts +++ b/packages/aws-cdk/lib/settings.ts @@ -1,11 +1,11 @@ import * as os from 'os'; import * as fs_path from 'path'; import * as fs from 'fs-extra'; -import { Tag } from './cdk-toolkit'; +import { CliArguments } from './cli-arguments'; +import { convertToCliArgs } from './convert-to-cli-args'; import { debug, warning } from './logging'; import { ToolkitError } from './toolkit/error'; import * as util from './util'; -import { CliArguments } from './cli-arguments'; export type SettingsMap = {[key: string]: any}; @@ -44,14 +44,6 @@ export enum Command { DOCTOR = 'doctor', } -const BUNDLING_COMMANDS = [ - Command.DEPLOY, - Command.DIFF, - Command.SYNTH, - Command.SYNTHESIZE, - Command.WATCH, -]; - export interface ConfigurationProps { /** * Configuration passed via command line arguments @@ -74,6 +66,7 @@ export interface ConfigurationProps { export class Configuration { public settings = new Settings(); public context = new Context(); + public command?: Command; public readonly defaultConfig = new Settings({ versionReporting: true, @@ -89,6 +82,7 @@ export class Configuration { private loaded = false; constructor(private readonly props: ConfigurationProps = {}) { + this.command = props.commandLineArguments?._; this.commandLineArguments = props.commandLineArguments ? Settings.fromCommandLineArguments(props.commandLineArguments) : new Settings(); @@ -119,15 +113,12 @@ export class Configuration { const readUserContext = this.props.readUserContext ?? true; - if (userConfig.get(['build'])) { - throw new ToolkitError('The `build` key cannot be specified in the user config (~/.cdk.json), specify it in the project config (cdk.json) instead'); - } - const contextSources = [ { bag: this.commandLineContext }, { fileName: PROJECT_CONFIG, bag: this.projectConfig.subSettings([CONTEXT_KEY]).makeReadOnly() }, { fileName: PROJECT_CONTEXT, bag: this.projectContext }, ]; + if (readUserContext) { contextSources.push({ fileName: USER_DEFAULTS, bag: userConfig.subSettings([CONTEXT_KEY]).makeReadOnly() }); } @@ -267,6 +258,25 @@ export class Context { } } +// cdk.json is gonna look like this: +// { +// 'someGlobalOption': true, +// 'deploy': { +// 'someDeployOption': true, +// } +// } +// for backwards compat we will allow existing options to be specified at the base rather than within command +// this will translate to +// cliArguments: { +// command: Command.ALL, +// globalOptions: { +// someGlobalOption: true, +// } +// deploy: { +// someDeployOption: true, +// } +// } + /** * A single bag of settings */ @@ -285,61 +295,7 @@ export class Settings { * @returns a new Settings object. */ public static fromCommandLineArguments(argv: CliArguments): Settings { - const context = this.parseStringContextListToObject(argv); - const tags = this.parseStringTagsListToObject(expectStringList(argv.tags)); - - // Determine bundling stacks - let bundlingStacks: string[]; - if (BUNDLING_COMMANDS.includes(argv._[0])) { - // If we deploy, diff, synth or watch a list of stacks exclusively we skip - // bundling for all other stacks. - bundlingStacks = argv.exclusively - ? argv.STACKS ?? ['**'] - : ['**']; - } else { // Skip bundling for all stacks - bundlingStacks = []; - } - - return new Settings({ - app: argv.app, - browser: argv.browser, - build: argv.build, - caBundlePath: argv.caBundlePath, - context, - debug: argv.debug, - tags, - language: argv.language, - pathMetadata: argv.pathMetadata, - assetMetadata: argv.assetMetadata, - profile: argv.profile, - plugin: argv.plugin, - requireApproval: argv.requireApproval, - toolkitStackName: argv.toolkitStackName, - toolkitBucket: { - bucketName: argv.bootstrapBucketName, - kmsKeyId: argv.bootstrapKmsKeyId, - }, - versionReporting: argv.versionReporting, - staging: argv.staging, - output: argv.output, - outputsFile: argv.outputsFile, - progress: argv.progress, - proxy: argv.proxy, - bundlingStacks, - lookups: argv.lookups, - rollback: argv.rollback, - notices: argv.notices, - assetParallelism: argv['asset-parallelism'], - assetPrebuild: argv['asset-prebuild'], - ignoreNoStacks: argv['ignore-no-stacks'], - hotswap: { - ecs: { - minimumEcsHealthyPercent: argv.minimumEcsHealthyPercent, - maximumEcsHealthyPercent: argv.maximumEcsHealthyPercent, - }, - }, - unstable: argv.unstable, - }); + return new Settings(argv); } public static mergeAll(...settings: Settings[]): Settings { @@ -350,53 +306,6 @@ export class Settings { return ret; } - private static parseStringContextListToObject(argv: Arguments): any { - const context: any = {}; - - for (const assignment of ((argv as any).context || [])) { - const parts = assignment.split(/=(.*)/, 2); - if (parts.length === 2) { - debug('CLI argument context: %s=%s', parts[0], parts[1]); - if (parts[0].match(/^aws:.+/)) { - throw new ToolkitError(`User-provided context cannot use keys prefixed with 'aws:', but ${parts[0]} was provided.`); - } - context[parts[0]] = parts[1]; - } else { - warning('Context argument is not an assignment (key=value): %s', assignment); - } - } - return context; - } - - /** - * Parse tags out of arguments - * - * Return undefined if no tags were provided, return an empty array if only empty - * strings were provided - */ - private static parseStringTagsListToObject(argTags: string[] | undefined): Tag[] | undefined { - if (argTags === undefined) { return undefined; } - if (argTags.length === 0) { return undefined; } - const nonEmptyTags = argTags.filter(t => t !== ''); - if (nonEmptyTags.length === 0) { return []; } - - const tags: Tag[] = []; - - for (const assignment of nonEmptyTags) { - const parts = assignment.split(/=(.*)/, 2); - if (parts.length === 2) { - debug('CLI argument tags: %s=%s', parts[0], parts[1]); - tags.push({ - Key: parts[0], - Value: parts[1], - }); - } else { - warning('Tags argument is not an assignment (key=value): %s', assignment); - } - } - return tags.length > 0 ? tags : undefined; - } - constructor(private settings: SettingsMap = {}, public readonly readOnly = false) {} public async load(fileName: string): Promise { @@ -491,6 +400,29 @@ export class Settings { } } +export class ArgumentSettings extends Settings { + /** + * Parse Settings out of CLI arguments. + * + * CLI arguments in must be accessed in the CLI code via + * `configuration.settings.get(['argName'])` instead of via `args.argName`. + * + * The advantage is that they can be configured via `cdk.json` and + * `$HOME/.cdk.json`. Arguments not listed below and accessed via this object + * can only be specified on the command line. + * + * @param argv the received CLI arguments. + * @returns a new Settings object. + */ + public static fromCommandLineArguments(argv: CliArguments): ArgumentSettings { + return new ArgumentSettings(argv); + } + + public static fromConfigFileArguments(argv: any): ArgumentSettings { + return new ArgumentSettings(convertToCliArgs(argv)); + } +} + function expandHomeDir(x: string) { if (x.startsWith('~')) { return fs_path.join(os.homedir(), x.slice(1)); @@ -519,15 +451,3 @@ function stripTransientValues(obj: {[key: string]: any}) { function isTransientValue(value: any) { return typeof value === 'object' && value !== null && (value as any)[TRANSIENT_CONTEXT_KEY]; } - -function expectStringList(x: unknown): string[] | undefined { - if (x === undefined) { return undefined; } - if (!Array.isArray(x)) { - throw new ToolkitError(`Expected array, got '${x}'`); - } - const nonStrings = x.filter(e => typeof e !== 'string'); - if (nonStrings.length > 0) { - throw new ToolkitError(`Expected list of strings, found ${nonStrings}`); - } - return x; -} diff --git a/packages/aws-cdk/test/settings.test.ts b/packages/aws-cdk/test/settings.test.ts index 7edc2e9b487a2..342effdf9c905 100644 --- a/packages/aws-cdk/test/settings.test.ts +++ b/packages/aws-cdk/test/settings.test.ts @@ -1,6 +1,7 @@ /* eslint-disable import/order */ import { Command, Context, Settings } from '../lib/settings'; import { Tag } from '../lib/cdk-toolkit'; +import { convertToCliArgs } from '../lib/convert-to-cli-args'; test('can delete values from Context object', () => { // GIVEN @@ -64,8 +65,8 @@ test('can clear all values in all objects', () => { test('can parse string context from command line arguments', () => { // GIVEN - const settings1 = Settings.fromCommandLineArguments({ context: ['foo=bar'], _: [Command.DEPLOY] }); - const settings2 = Settings.fromCommandLineArguments({ context: ['foo='], _: [Command.DEPLOY] }); + const settings1 = Settings.fromCommandLineArguments(convertToCliArgs({ context: ['foo=bar'], _: [Command.DEPLOY] })); + const settings2 = Settings.fromCommandLineArguments(convertToCliArgs({ context: ['foo='], _: [Command.DEPLOY] })); // THEN expect(settings1.get(['context']).foo).toEqual( 'bar'); @@ -74,8 +75,8 @@ test('can parse string context from command line arguments', () => { test('can parse string context from command line arguments with equals sign in value', () => { // GIVEN - const settings1 = Settings.fromCommandLineArguments({ context: ['foo==bar='], _: [Command.DEPLOY] }); - const settings2 = Settings.fromCommandLineArguments({ context: ['foo=bar='], _: [Command.DEPLOY] }); + const settings1 = Settings.fromCommandLineArguments(convertToCliArgs({ context: ['foo==bar='], _: [Command.DEPLOY] })); + const settings2 = Settings.fromCommandLineArguments(convertToCliArgs({ context: ['foo=bar='], _: [Command.DEPLOY] })); // THEN expect(settings1.get(['context']).foo).toEqual( '=bar='); @@ -84,8 +85,8 @@ test('can parse string context from command line arguments with equals sign in v test('can parse tag values from command line arguments', () => { // GIVEN - const settings1 = Settings.fromCommandLineArguments({ tags: ['foo=bar'], _: [Command.DEPLOY] }); - const settings2 = Settings.fromCommandLineArguments({ tags: ['foo='], _: [Command.DEPLOY] }); + const settings1 = Settings.fromCommandLineArguments(convertToCliArgs({ tags: ['foo=bar'], _: [Command.DEPLOY] })); + const settings2 = Settings.fromCommandLineArguments(convertToCliArgs({ tags: ['foo='], _: [Command.DEPLOY] })); // THEN expect(settings1.get(['tags']).find((tag: Tag) => tag.Key === 'foo').Value).toEqual('bar'); @@ -94,8 +95,8 @@ test('can parse tag values from command line arguments', () => { test('can parse tag values from command line arguments with equals sign in value', () => { // GIVEN - const settings1 = Settings.fromCommandLineArguments({ tags: ['foo==bar='], _: [Command.DEPLOY] }); - const settings2 = Settings.fromCommandLineArguments({ tags: ['foo=bar='], _: [Command.DEPLOY] }); + const settings1 = Settings.fromCommandLineArguments(convertToCliArgs({ tags: ['foo==bar='], _: [Command.DEPLOY] })); + const settings2 = Settings.fromCommandLineArguments(convertToCliArgs({ tags: ['foo=bar='], _: [Command.DEPLOY] })); // THEN expect(settings1.get(['tags']).find((tag: Tag) => tag.Key === 'foo').Value).toEqual('=bar='); @@ -104,9 +105,9 @@ test('can parse tag values from command line arguments with equals sign in value test('bundling stacks defaults to an empty list', () => { // GIVEN - const settings = Settings.fromCommandLineArguments({ + const settings = Settings.fromCommandLineArguments(convertToCliArgs({ _: [Command.LIST], - }); + })); // THEN expect(settings.get(['bundlingStacks'])).toEqual([]); @@ -114,9 +115,9 @@ test('bundling stacks defaults to an empty list', () => { test('bundling stacks defaults to ** for deploy', () => { // GIVEN - const settings = Settings.fromCommandLineArguments({ + const settings = Settings.fromCommandLineArguments(convertToCliArgs({ _: [Command.DEPLOY], - }); + })); // THEN expect(settings.get(['bundlingStacks'])).toEqual(['**']); @@ -124,9 +125,9 @@ test('bundling stacks defaults to ** for deploy', () => { test('bundling stacks defaults to ** for watch', () => { // GIVEN - const settings = Settings.fromCommandLineArguments({ + const settings = Settings.fromCommandLineArguments(convertToCliArgs({ _: [Command.WATCH], - }); + })); // THEN expect(settings.get(['bundlingStacks'])).toEqual(['**']); @@ -134,11 +135,11 @@ test('bundling stacks defaults to ** for watch', () => { test('bundling stacks with deploy exclusively', () => { // GIVEN - const settings = Settings.fromCommandLineArguments({ + const settings = Settings.fromCommandLineArguments(convertToCliArgs({ _: [Command.DEPLOY], exclusively: true, STACKS: ['cool-stack'], - }); + })); // THEN expect(settings.get(['bundlingStacks'])).toEqual(['cool-stack']); @@ -146,11 +147,11 @@ test('bundling stacks with deploy exclusively', () => { test('bundling stacks with watch exclusively', () => { // GIVEN - const settings = Settings.fromCommandLineArguments({ + const settings = Settings.fromCommandLineArguments(convertToCliArgs({ _: [Command.WATCH], exclusively: true, STACKS: ['cool-stack'], - }); + })); // THEN expect(settings.get(['bundlingStacks'])).toEqual(['cool-stack']); @@ -158,10 +159,10 @@ test('bundling stacks with watch exclusively', () => { test('should include outputs-file in settings', () => { // GIVEN - const settings = Settings.fromCommandLineArguments({ + const settings = Settings.fromCommandLineArguments(convertToCliArgs({ _: [Command.DEPLOY], outputsFile: 'my-outputs-file.json', - }); + })); // THEN expect(settings.get(['outputsFile'])).toEqual('my-outputs-file.json'); @@ -169,10 +170,10 @@ test('should include outputs-file in settings', () => { test('providing a build arg', () => { // GIVEN - const settings = Settings.fromCommandLineArguments({ + const settings = Settings.fromCommandLineArguments(convertToCliArgs({ _: [Command.SYNTH], build: 'mvn package', - }); + })); // THEN expect(settings.get(['build'])).toEqual('mvn package'); From b4757bfc74987fbd6f0d2aced1f4b0b0eeba0e0d Mon Sep 17 00:00:00 2001 From: Kaizen Conroy Date: Tue, 7 Jan 2025 15:04:21 -0500 Subject: [PATCH 04/14] still builds --- packages/aws-cdk/lib/settings.ts | 44 +++++++++++--------------- packages/aws-cdk/test/settings.test.ts | 32 +++++++++---------- 2 files changed, 34 insertions(+), 42 deletions(-) diff --git a/packages/aws-cdk/lib/settings.ts b/packages/aws-cdk/lib/settings.ts index 4f54e824d8820..7007ab830218a 100644 --- a/packages/aws-cdk/lib/settings.ts +++ b/packages/aws-cdk/lib/settings.ts @@ -64,18 +64,20 @@ export interface ConfigurationProps { * All sources of settings combined */ export class Configuration { - public settings = new Settings(); + public settings = new ArgumentSettings(); public context = new Context(); public command?: Command; - public readonly defaultConfig = new Settings({ - versionReporting: true, - assetMetadata: true, - pathMetadata: true, - output: 'cdk.out', + public readonly defaultConfig = new ArgumentSettings({ + globalOptions: { + versionReporting: true, + assetMetadata: true, + pathMetadata: true, + output: 'cdk.out', + }, }); - private readonly commandLineArguments: Settings; + private readonly commandLineArguments: ArgumentSettings; private readonly commandLineContext: Settings; private _projectConfig?: Settings; private _projectContext?: Settings; @@ -84,8 +86,8 @@ export class Configuration { constructor(private readonly props: ConfigurationProps = {}) { this.command = props.commandLineArguments?._; this.commandLineArguments = props.commandLineArguments - ? Settings.fromCommandLineArguments(props.commandLineArguments) - : new Settings(); + ? ArgumentSettings.fromCommandLineArguments(props.commandLineArguments) + : new ArgumentSettings(); this.commandLineContext = this.commandLineArguments.subSettings([CONTEXT_KEY]).makeReadOnly(); } @@ -281,23 +283,6 @@ export class Context { * A single bag of settings */ export class Settings { - /** - * Parse Settings out of CLI arguments. - * - * CLI arguments in must be accessed in the CLI code via - * `configuration.settings.get(['argName'])` instead of via `args.argName`. - * - * The advantage is that they can be configured via `cdk.json` and - * `$HOME/.cdk.json`. Arguments not listed below and accessed via this object - * can only be specified on the command line. - * - * @param argv the received CLI arguments. - * @returns a new Settings object. - */ - public static fromCommandLineArguments(argv: CliArguments): Settings { - return new Settings(argv); - } - public static mergeAll(...settings: Settings[]): Settings { let ret = new Settings(); for (const setting of settings) { @@ -400,6 +385,9 @@ export class Settings { } } +/** + * A specific bag of settings related to Arguments specified via CLI or cdk.json + */ export class ArgumentSettings extends Settings { /** * Parse Settings out of CLI arguments. @@ -421,6 +409,10 @@ export class ArgumentSettings extends Settings { public static fromConfigFileArguments(argv: any): ArgumentSettings { return new ArgumentSettings(convertToCliArgs(argv)); } + + public constructor(args: Partial = {}) { + super(args); + } } function expandHomeDir(x: string) { diff --git a/packages/aws-cdk/test/settings.test.ts b/packages/aws-cdk/test/settings.test.ts index 342effdf9c905..67f92b105df63 100644 --- a/packages/aws-cdk/test/settings.test.ts +++ b/packages/aws-cdk/test/settings.test.ts @@ -1,5 +1,5 @@ /* eslint-disable import/order */ -import { Command, Context, Settings } from '../lib/settings'; +import { Command, Context, ArgumentSettings, Settings } from '../lib/settings'; import { Tag } from '../lib/cdk-toolkit'; import { convertToCliArgs } from '../lib/convert-to-cli-args'; @@ -65,8 +65,8 @@ test('can clear all values in all objects', () => { test('can parse string context from command line arguments', () => { // GIVEN - const settings1 = Settings.fromCommandLineArguments(convertToCliArgs({ context: ['foo=bar'], _: [Command.DEPLOY] })); - const settings2 = Settings.fromCommandLineArguments(convertToCliArgs({ context: ['foo='], _: [Command.DEPLOY] })); + const settings1 = ArgumentSettings.fromCommandLineArguments(convertToCliArgs({ context: ['foo=bar'], _: [Command.DEPLOY] })); + const settings2 = ArgumentSettings.fromCommandLineArguments(convertToCliArgs({ context: ['foo='], _: [Command.DEPLOY] })); // THEN expect(settings1.get(['context']).foo).toEqual( 'bar'); @@ -75,8 +75,8 @@ test('can parse string context from command line arguments', () => { test('can parse string context from command line arguments with equals sign in value', () => { // GIVEN - const settings1 = Settings.fromCommandLineArguments(convertToCliArgs({ context: ['foo==bar='], _: [Command.DEPLOY] })); - const settings2 = Settings.fromCommandLineArguments(convertToCliArgs({ context: ['foo=bar='], _: [Command.DEPLOY] })); + const settings1 = ArgumentSettings.fromCommandLineArguments(convertToCliArgs({ context: ['foo==bar='], _: [Command.DEPLOY] })); + const settings2 = ArgumentSettings.fromCommandLineArguments(convertToCliArgs({ context: ['foo=bar='], _: [Command.DEPLOY] })); // THEN expect(settings1.get(['context']).foo).toEqual( '=bar='); @@ -85,8 +85,8 @@ test('can parse string context from command line arguments with equals sign in v test('can parse tag values from command line arguments', () => { // GIVEN - const settings1 = Settings.fromCommandLineArguments(convertToCliArgs({ tags: ['foo=bar'], _: [Command.DEPLOY] })); - const settings2 = Settings.fromCommandLineArguments(convertToCliArgs({ tags: ['foo='], _: [Command.DEPLOY] })); + const settings1 = ArgumentSettings.fromCommandLineArguments(convertToCliArgs({ tags: ['foo=bar'], _: [Command.DEPLOY] })); + const settings2 = ArgumentSettings.fromCommandLineArguments(convertToCliArgs({ tags: ['foo='], _: [Command.DEPLOY] })); // THEN expect(settings1.get(['tags']).find((tag: Tag) => tag.Key === 'foo').Value).toEqual('bar'); @@ -95,8 +95,8 @@ test('can parse tag values from command line arguments', () => { test('can parse tag values from command line arguments with equals sign in value', () => { // GIVEN - const settings1 = Settings.fromCommandLineArguments(convertToCliArgs({ tags: ['foo==bar='], _: [Command.DEPLOY] })); - const settings2 = Settings.fromCommandLineArguments(convertToCliArgs({ tags: ['foo=bar='], _: [Command.DEPLOY] })); + const settings1 = ArgumentSettings.fromCommandLineArguments(convertToCliArgs({ tags: ['foo==bar='], _: [Command.DEPLOY] })); + const settings2 = ArgumentSettings.fromCommandLineArguments(convertToCliArgs({ tags: ['foo=bar='], _: [Command.DEPLOY] })); // THEN expect(settings1.get(['tags']).find((tag: Tag) => tag.Key === 'foo').Value).toEqual('=bar='); @@ -105,7 +105,7 @@ test('can parse tag values from command line arguments with equals sign in value test('bundling stacks defaults to an empty list', () => { // GIVEN - const settings = Settings.fromCommandLineArguments(convertToCliArgs({ + const settings = ArgumentSettings.fromCommandLineArguments(convertToCliArgs({ _: [Command.LIST], })); @@ -115,7 +115,7 @@ test('bundling stacks defaults to an empty list', () => { test('bundling stacks defaults to ** for deploy', () => { // GIVEN - const settings = Settings.fromCommandLineArguments(convertToCliArgs({ + const settings = ArgumentSettings.fromCommandLineArguments(convertToCliArgs({ _: [Command.DEPLOY], })); @@ -125,7 +125,7 @@ test('bundling stacks defaults to ** for deploy', () => { test('bundling stacks defaults to ** for watch', () => { // GIVEN - const settings = Settings.fromCommandLineArguments(convertToCliArgs({ + const settings = ArgumentSettings.fromCommandLineArguments(convertToCliArgs({ _: [Command.WATCH], })); @@ -135,7 +135,7 @@ test('bundling stacks defaults to ** for watch', () => { test('bundling stacks with deploy exclusively', () => { // GIVEN - const settings = Settings.fromCommandLineArguments(convertToCliArgs({ + const settings = ArgumentSettings.fromCommandLineArguments(convertToCliArgs({ _: [Command.DEPLOY], exclusively: true, STACKS: ['cool-stack'], @@ -147,7 +147,7 @@ test('bundling stacks with deploy exclusively', () => { test('bundling stacks with watch exclusively', () => { // GIVEN - const settings = Settings.fromCommandLineArguments(convertToCliArgs({ + const settings = ArgumentSettings.fromCommandLineArguments(convertToCliArgs({ _: [Command.WATCH], exclusively: true, STACKS: ['cool-stack'], @@ -159,7 +159,7 @@ test('bundling stacks with watch exclusively', () => { test('should include outputs-file in settings', () => { // GIVEN - const settings = Settings.fromCommandLineArguments(convertToCliArgs({ + const settings = ArgumentSettings.fromCommandLineArguments(convertToCliArgs({ _: [Command.DEPLOY], outputsFile: 'my-outputs-file.json', })); @@ -170,7 +170,7 @@ test('should include outputs-file in settings', () => { test('providing a build arg', () => { // GIVEN - const settings = Settings.fromCommandLineArguments(convertToCliArgs({ + const settings = ArgumentSettings.fromCommandLineArguments(convertToCliArgs({ _: [Command.SYNTH], build: 'mvn package', })); From 957f07963ed167c9cf110d8d3319cf2baf2a5192 Mon Sep 17 00:00:00 2001 From: Kaizen Conroy Date: Wed, 8 Jan 2025 18:12:58 -0500 Subject: [PATCH 05/14] more building --- packages/aws-cdk/lib/api/cxapp/exec.ts | 3 +- packages/aws-cdk/lib/cli-arguments.ts | 2 +- packages/aws-cdk/lib/cli.ts | 4 +- packages/aws-cdk/lib/command.ts | 24 +++ packages/aws-cdk/lib/convert-to-cli-args.ts | 199 +++++++++++++++++- packages/aws-cdk/lib/settings.ts | 41 +--- packages/aws-cdk/test/cli-arguments.test.ts | 8 +- packages/aws-cdk/test/settings.test.ts | 35 +-- .../cli-args-gen/lib/cli-args-function-gen.ts | 49 ++++- .../@aws-cdk/cli-args-gen/lib/cli-args-gen.ts | 2 +- .../test/cli-args-function-gen.test.ts | 2 +- 11 files changed, 308 insertions(+), 61 deletions(-) create mode 100644 packages/aws-cdk/lib/command.ts diff --git a/packages/aws-cdk/lib/api/cxapp/exec.ts b/packages/aws-cdk/lib/api/cxapp/exec.ts index 142340b3a501e..4a5ea9f55f3fd 100644 --- a/packages/aws-cdk/lib/api/cxapp/exec.ts +++ b/packages/aws-cdk/lib/api/cxapp/exec.ts @@ -5,8 +5,9 @@ import * as cxschema from '@aws-cdk/cloud-assembly-schema'; import * as cxapi from '@aws-cdk/cx-api'; import * as fs from 'fs-extra'; import * as semver from 'semver'; +import { Command } from '../../command'; import { debug, warning } from '../../logging'; -import { Command, Configuration, PROJECT_CONFIG, USER_DEFAULTS } from '../../settings'; +import { Configuration, PROJECT_CONFIG, USER_DEFAULTS } from '../../settings'; import { ToolkitError } from '../../toolkit/error'; import { loadTree, some } from '../../tree'; import { splitBySize } from '../../util/objects'; diff --git a/packages/aws-cdk/lib/cli-arguments.ts b/packages/aws-cdk/lib/cli-arguments.ts index 665f81b2ce9d1..f3e80628b9d29 100644 --- a/packages/aws-cdk/lib/cli-arguments.ts +++ b/packages/aws-cdk/lib/cli-arguments.ts @@ -3,7 +3,7 @@ // Do not edit by hand; all changes will be overwritten at build time from the config file. // ------------------------------------------------------------------------------------------- /* eslint-disable @stylistic/max-len */ -import { Command } from './settings'; +import { Command } from './command'; /** * The structure of the CLI configuration, generated from packages/aws-cdk/lib/config.ts diff --git a/packages/aws-cdk/lib/cli.ts b/packages/aws-cdk/lib/cli.ts index 360855b01e95e..f455655cf4e2b 100644 --- a/packages/aws-cdk/lib/cli.ts +++ b/packages/aws-cdk/lib/cli.ts @@ -6,7 +6,7 @@ import { DeploymentMethod } from './api'; import { HotswapMode } from './api/hotswap/common'; import { ILock } from './api/util/rwlock'; import { CliArguments } from './cli-arguments'; -import { convertToCliArgs } from './convert-to-cli-args'; +import { convertYargsToCliArgs } from './convert-to-cli-args'; import { parseCommandLineArguments } from './parse-command-line-arguments'; import { checkForPlatformWarnings } from './platform-warnings'; import { enableTracing } from './util/tracing'; @@ -41,7 +41,7 @@ if (!process.stdout.isTTY) { } export async function exec(args: string[], synthesizer?: Synthesizer): Promise { - const argv: CliArguments = convertToCliArgs(await parseCommandLineArguments(args)); + const argv: CliArguments = convertYargsToCliArgs(await parseCommandLineArguments(args)); // if one -v, log at a DEBUG level // if 2 -v, log at a TRACE level diff --git a/packages/aws-cdk/lib/command.ts b/packages/aws-cdk/lib/command.ts new file mode 100644 index 0000000000000..650c9759c18fb --- /dev/null +++ b/packages/aws-cdk/lib/command.ts @@ -0,0 +1,24 @@ +export enum Command { + LS = 'ls', + LIST = 'list', + DIFF = 'diff', + BOOTSTRAP = 'bootstrap', + DEPLOY = 'deploy', + DESTROY = 'destroy', + SYNTHESIZE = 'synthesize', + SYNTH = 'synth', + METADATA = 'metadata', + INIT = 'init', + VERSION = 'version', + WATCH = 'watch', + GC = 'gc', + ROLLBACK = 'rollback', + IMPORT = 'import', + ACKNOWLEDGE = 'acknowledge', + NOTICES = 'notices', + MIGRATE = 'migrate', + CONTEXT = 'context', + DOCS = 'docs', + DOCTOR = 'doctor', + SOME = 'some', +} diff --git a/packages/aws-cdk/lib/convert-to-cli-args.ts b/packages/aws-cdk/lib/convert-to-cli-args.ts index 3fc1b9a2bc541..63f731555eda1 100644 --- a/packages/aws-cdk/lib/convert-to-cli-args.ts +++ b/packages/aws-cdk/lib/convert-to-cli-args.ts @@ -4,10 +4,10 @@ // ------------------------------------------------------------------------------------------- /* eslint-disable @stylistic/max-len */ import { CliArguments, GlobalOptions } from './cli-arguments'; -import { Command } from './settings'; +import { Command } from './command'; // @ts-ignore TS6133 -export function convertToCliArgs(args: any): CliArguments { +export function convertYargsToCliArgs(args: any): CliArguments { const globalOptions: GlobalOptions = { app: args.app, build: args.build, @@ -254,3 +254,198 @@ export function convertToCliArgs(args: any): CliArguments { return cliArguments; } + +// @ts-ignore TS6133 +export function convertConfigToCliArgs(args: any): CliArguments { + const globalOptions: GlobalOptions = { + app: args.app, + build: args.build, + context: args.context, + plugin: args.plugin, + trace: args.trace, + strict: args.strict, + lookups: args.lookups, + ignoreErrors: args.ignoreErrors, + json: args.json, + verbose: args.verbose, + debug: args.debug, + profile: args.profile, + proxy: args.proxy, + caBundlePath: args.caBundlePath, + ec2creds: args.ec2creds, + versionReporting: args.versionReporting, + pathMetadata: args.pathMetadata, + assetMetadata: args.assetMetadata, + roleArn: args.roleArn, + staging: args.staging, + output: args.output, + notices: args.notices, + noColor: args.noColor, + ci: args.ci, + unstable: args.unstable, + }; + const listOptions = { + long: args.long, + showDependencies: args.showDependencies, + }; + const synthesizeOptions = { + exclusively: args.exclusively, + validation: args.validation, + quiet: args.quiet, + }; + const bootstrapOptions = { + bootstrapBucketName: args.bootstrapBucketName, + bootstrapKmsKeyId: args.bootstrapKmsKeyId, + examplePermissionsBoundary: args.examplePermissionsBoundary, + customPermissionsBoundary: args.customPermissionsBoundary, + bootstrapCustomerKey: args.bootstrapCustomerKey, + qualifier: args.qualifier, + publicAccessBlockConfiguration: args.publicAccessBlockConfiguration, + tags: args.tags, + execute: args.execute, + trust: args.trust, + trustForLookup: args.trustForLookup, + cloudformationExecutionPolicies: args.cloudformationExecutionPolicies, + force: args.force, + terminationProtection: args.terminationProtection, + showTemplate: args.showTemplate, + toolkitStackName: args.toolkitStackName, + template: args.template, + previousParameters: args.previousParameters, + }; + const gcOptions = { + action: args.action, + type: args.type, + rollbackBufferDays: args.rollbackBufferDays, + createdBufferDays: args.createdBufferDays, + confirm: args.confirm, + bootstrapStackName: args.bootstrapStackName, + }; + const deployOptions = { + all: args.all, + buildExclude: args.buildExclude, + exclusively: args.exclusively, + requireApproval: args.requireApproval, + notificationArns: args.notificationArns, + tags: args.tags, + execute: args.execute, + changeSetName: args.changeSetName, + method: args.method, + importExistingResources: args.importExistingResources, + force: args.force, + parameters: args.parameters, + outputsFile: args.outputsFile, + previousParameters: args.previousParameters, + toolkitStackName: args.toolkitStackName, + progress: args.progress, + rollback: args.rollback, + hotswap: args.hotswap, + hotswapFallback: args.hotswapFallback, + watch: args.watch, + logs: args.logs, + concurrency: args.concurrency, + assetParallelism: args.assetParallelism, + assetPrebuild: args.assetPrebuild, + ignoreNoStacks: args.ignoreNoStacks, + }; + const rollbackOptions = { + all: args.all, + toolkitStackName: args.toolkitStackName, + force: args.force, + validateBootstrapVersion: args.validateBootstrapVersion, + orphan: args.orphan, + }; + const importOptions = { + execute: args.execute, + changeSetName: args.changeSetName, + toolkitStackName: args.toolkitStackName, + rollback: args.rollback, + force: args.force, + recordResourceMapping: args.recordResourceMapping, + resourceMapping: args.resourceMapping, + }; + const watchOptions = { + buildExclude: args.buildExclude, + exclusively: args.exclusively, + changeSetName: args.changeSetName, + force: args.force, + toolkitStackName: args.toolkitStackName, + progress: args.progress, + rollback: args.rollback, + hotswap: args.hotswap, + hotswapFallback: args.hotswapFallback, + logs: args.logs, + concurrency: args.concurrency, + }; + const destroyOptions = { + all: args.all, + exclusively: args.exclusively, + force: args.force, + }; + const diffOptions = { + exclusively: args.exclusively, + contextLines: args.contextLines, + template: args.template, + strict: args.strict, + securityOnly: args.securityOnly, + fail: args.fail, + processed: args.processed, + quiet: args.quiet, + changeSet: args.changeSet, + }; + const metadataOptions = {}; + const acknowledgeOptions = {}; + const noticesOptions = { + unacknowledged: args.unacknowledged, + }; + const initOptions = { + language: args.language, + list: args.list, + generateOnly: args.generateOnly, + }; + const migrateOptions = { + stackName: args.stackName, + language: args.language, + account: args.account, + region: args.region, + fromPath: args.fromPath, + fromStack: args.fromStack, + outputPath: args.outputPath, + fromScan: args.fromScan, + filter: args.filter, + compress: args.compress, + }; + const contextOptions = { + reset: args.reset, + force: args.force, + clear: args.clear, + }; + const docsOptions = { + browser: args.browser, + }; + const doctorOptions = {}; + const cliArguments: CliArguments = { + _: Command.SOME, + globalOptions, + list: listOptions, + synthesize: synthesizeOptions, + bootstrap: bootstrapOptions, + gc: gcOptions, + deploy: deployOptions, + rollback: rollbackOptions, + import: importOptions, + watch: watchOptions, + destroy: destroyOptions, + diff: diffOptions, + metadata: metadataOptions, + acknowledge: acknowledgeOptions, + notices: noticesOptions, + init: initOptions, + migrate: migrateOptions, + context: contextOptions, + docs: docsOptions, + doctor: doctorOptions, + }; + + return cliArguments; +} diff --git a/packages/aws-cdk/lib/settings.ts b/packages/aws-cdk/lib/settings.ts index 7007ab830218a..54f247c7bc6e7 100644 --- a/packages/aws-cdk/lib/settings.ts +++ b/packages/aws-cdk/lib/settings.ts @@ -2,7 +2,8 @@ import * as os from 'os'; import * as fs_path from 'path'; import * as fs from 'fs-extra'; import { CliArguments } from './cli-arguments'; -import { convertToCliArgs } from './convert-to-cli-args'; +import { Command } from './command'; +import { convertConfigToCliArgs } from './convert-to-cli-args'; import { debug, warning } from './logging'; import { ToolkitError } from './toolkit/error'; import * as util from './util'; @@ -20,30 +21,6 @@ export const TRANSIENT_CONTEXT_KEY = '$dontSaveContext'; const CONTEXT_KEY = 'context'; -export enum Command { - LS = 'ls', - LIST = 'list', - DIFF = 'diff', - BOOTSTRAP = 'bootstrap', - DEPLOY = 'deploy', - DESTROY = 'destroy', - SYNTHESIZE = 'synthesize', - SYNTH = 'synth', - METADATA = 'metadata', - INIT = 'init', - VERSION = 'version', - WATCH = 'watch', - GC = 'gc', - ROLLBACK = 'rollback', - IMPORT = 'import', - ACKNOWLEDGE = 'acknowledge', - NOTICES = 'notices', - MIGRATE = 'migrate', - CONTEXT = 'context', - DOCS = 'docs', - DOCTOR = 'doctor', -} - export interface ConfigurationProps { /** * Configuration passed via command line arguments @@ -129,8 +106,8 @@ export class Configuration { // Build settings from what's left this.settings = this.defaultConfig - .merge(userConfig) - .merge(this.projectConfig) + .merge(new ArgumentSettings(convertConfigToCliArgs(userConfig.all))) + .merge(new ArgumentSettings(convertConfigToCliArgs(this.projectConfig.all))) .merge(this.commandLineArguments) .makeReadOnly(); @@ -291,7 +268,7 @@ export class Settings { return ret; } - constructor(private settings: SettingsMap = {}, public readonly readOnly = false) {} + constructor(protected settings: SettingsMap = {}, public readonly readOnly = false) {} public async load(fileName: string): Promise { if (this.readOnly) { @@ -406,13 +383,17 @@ export class ArgumentSettings extends Settings { return new ArgumentSettings(argv); } - public static fromConfigFileArguments(argv: any): ArgumentSettings { - return new ArgumentSettings(convertToCliArgs(argv)); + public static fromConfigFileArguments(argv: CliArguments): ArgumentSettings { + return new ArgumentSettings(argv); } public constructor(args: Partial = {}) { super(args); } + + public merge(other: ArgumentSettings): ArgumentSettings { + return new ArgumentSettings(util.deepMerge(this.settings, other.settings)); + } } function expandHomeDir(x: string) { diff --git a/packages/aws-cdk/test/cli-arguments.test.ts b/packages/aws-cdk/test/cli-arguments.test.ts index 3024bfaae524a..9bfe03279f9a1 100644 --- a/packages/aws-cdk/test/cli-arguments.test.ts +++ b/packages/aws-cdk/test/cli-arguments.test.ts @@ -1,10 +1,10 @@ -import { convertToCliArgs } from '../lib/convert-to-cli-args'; +import { convertYargsToCliArgs } from '../lib/convert-to-cli-args'; import { parseCommandLineArguments } from '../lib/parse-command-line-arguments'; test('yargs object can be converted to cli arguments', async () => { const input = await parseCommandLineArguments(['deploy', '-R', '-v', '--ci']); - const result = convertToCliArgs(input); + const result = convertYargsToCliArgs(input); expect(result).toEqual({ _: 'deploy', @@ -69,7 +69,7 @@ test('yargs object can be converted to cli arguments', async () => { test('positional argument is correctly passed through -- variadic', async () => { const input = await parseCommandLineArguments(['deploy', 'stack1', 'stack2', '-R', '-v', '--ci']); - const result = convertToCliArgs(input); + const result = convertYargsToCliArgs(input); expect(result).toEqual({ _: 'deploy', @@ -83,7 +83,7 @@ test('positional argument is correctly passed through -- variadic', async () => test('positional argument is correctly passed through -- single', async () => { const input = await parseCommandLineArguments(['acknowledge', 'id1', '-v', '--ci']); - const result = convertToCliArgs(input); + const result = convertYargsToCliArgs(input); expect(result).toEqual({ _: 'acknowledge', diff --git a/packages/aws-cdk/test/settings.test.ts b/packages/aws-cdk/test/settings.test.ts index 67f92b105df63..d4f868bff3f82 100644 --- a/packages/aws-cdk/test/settings.test.ts +++ b/packages/aws-cdk/test/settings.test.ts @@ -1,7 +1,8 @@ /* eslint-disable import/order */ -import { Command, Context, ArgumentSettings, Settings } from '../lib/settings'; +import { Context, ArgumentSettings, Settings } from '../lib/settings'; import { Tag } from '../lib/cdk-toolkit'; -import { convertToCliArgs } from '../lib/convert-to-cli-args'; +import { convertYargsToCliArgs } from '../lib/convert-to-cli-args'; +import { Command } from '../lib/command'; test('can delete values from Context object', () => { // GIVEN @@ -65,8 +66,8 @@ test('can clear all values in all objects', () => { test('can parse string context from command line arguments', () => { // GIVEN - const settings1 = ArgumentSettings.fromCommandLineArguments(convertToCliArgs({ context: ['foo=bar'], _: [Command.DEPLOY] })); - const settings2 = ArgumentSettings.fromCommandLineArguments(convertToCliArgs({ context: ['foo='], _: [Command.DEPLOY] })); + const settings1 = ArgumentSettings.fromCommandLineArguments(convertYargsToCliArgs({ context: ['foo=bar'], _: [Command.DEPLOY] })); + const settings2 = ArgumentSettings.fromCommandLineArguments(convertYargsToCliArgs({ context: ['foo='], _: [Command.DEPLOY] })); // THEN expect(settings1.get(['context']).foo).toEqual( 'bar'); @@ -75,8 +76,8 @@ test('can parse string context from command line arguments', () => { test('can parse string context from command line arguments with equals sign in value', () => { // GIVEN - const settings1 = ArgumentSettings.fromCommandLineArguments(convertToCliArgs({ context: ['foo==bar='], _: [Command.DEPLOY] })); - const settings2 = ArgumentSettings.fromCommandLineArguments(convertToCliArgs({ context: ['foo=bar='], _: [Command.DEPLOY] })); + const settings1 = ArgumentSettings.fromCommandLineArguments(convertYargsToCliArgs({ context: ['foo==bar='], _: [Command.DEPLOY] })); + const settings2 = ArgumentSettings.fromCommandLineArguments(convertYargsToCliArgs({ context: ['foo=bar='], _: [Command.DEPLOY] })); // THEN expect(settings1.get(['context']).foo).toEqual( '=bar='); @@ -85,8 +86,8 @@ test('can parse string context from command line arguments with equals sign in v test('can parse tag values from command line arguments', () => { // GIVEN - const settings1 = ArgumentSettings.fromCommandLineArguments(convertToCliArgs({ tags: ['foo=bar'], _: [Command.DEPLOY] })); - const settings2 = ArgumentSettings.fromCommandLineArguments(convertToCliArgs({ tags: ['foo='], _: [Command.DEPLOY] })); + const settings1 = ArgumentSettings.fromCommandLineArguments(convertYargsToCliArgs({ tags: ['foo=bar'], _: [Command.DEPLOY] })); + const settings2 = ArgumentSettings.fromCommandLineArguments(convertYargsToCliArgs({ tags: ['foo='], _: [Command.DEPLOY] })); // THEN expect(settings1.get(['tags']).find((tag: Tag) => tag.Key === 'foo').Value).toEqual('bar'); @@ -95,8 +96,8 @@ test('can parse tag values from command line arguments', () => { test('can parse tag values from command line arguments with equals sign in value', () => { // GIVEN - const settings1 = ArgumentSettings.fromCommandLineArguments(convertToCliArgs({ tags: ['foo==bar='], _: [Command.DEPLOY] })); - const settings2 = ArgumentSettings.fromCommandLineArguments(convertToCliArgs({ tags: ['foo=bar='], _: [Command.DEPLOY] })); + const settings1 = ArgumentSettings.fromCommandLineArguments(convertYargsToCliArgs({ tags: ['foo==bar='], _: [Command.DEPLOY] })); + const settings2 = ArgumentSettings.fromCommandLineArguments(convertYargsToCliArgs({ tags: ['foo=bar='], _: [Command.DEPLOY] })); // THEN expect(settings1.get(['tags']).find((tag: Tag) => tag.Key === 'foo').Value).toEqual('=bar='); @@ -105,7 +106,7 @@ test('can parse tag values from command line arguments with equals sign in value test('bundling stacks defaults to an empty list', () => { // GIVEN - const settings = ArgumentSettings.fromCommandLineArguments(convertToCliArgs({ + const settings = ArgumentSettings.fromCommandLineArguments(convertYargsToCliArgs({ _: [Command.LIST], })); @@ -115,7 +116,7 @@ test('bundling stacks defaults to an empty list', () => { test('bundling stacks defaults to ** for deploy', () => { // GIVEN - const settings = ArgumentSettings.fromCommandLineArguments(convertToCliArgs({ + const settings = ArgumentSettings.fromCommandLineArguments(convertYargsToCliArgs({ _: [Command.DEPLOY], })); @@ -125,7 +126,7 @@ test('bundling stacks defaults to ** for deploy', () => { test('bundling stacks defaults to ** for watch', () => { // GIVEN - const settings = ArgumentSettings.fromCommandLineArguments(convertToCliArgs({ + const settings = ArgumentSettings.fromCommandLineArguments(convertYargsToCliArgs({ _: [Command.WATCH], })); @@ -135,7 +136,7 @@ test('bundling stacks defaults to ** for watch', () => { test('bundling stacks with deploy exclusively', () => { // GIVEN - const settings = ArgumentSettings.fromCommandLineArguments(convertToCliArgs({ + const settings = ArgumentSettings.fromCommandLineArguments(convertYargsToCliArgs({ _: [Command.DEPLOY], exclusively: true, STACKS: ['cool-stack'], @@ -147,7 +148,7 @@ test('bundling stacks with deploy exclusively', () => { test('bundling stacks with watch exclusively', () => { // GIVEN - const settings = ArgumentSettings.fromCommandLineArguments(convertToCliArgs({ + const settings = ArgumentSettings.fromCommandLineArguments(convertYargsToCliArgs({ _: [Command.WATCH], exclusively: true, STACKS: ['cool-stack'], @@ -159,7 +160,7 @@ test('bundling stacks with watch exclusively', () => { test('should include outputs-file in settings', () => { // GIVEN - const settings = ArgumentSettings.fromCommandLineArguments(convertToCliArgs({ + const settings = ArgumentSettings.fromCommandLineArguments(convertYargsToCliArgs({ _: [Command.DEPLOY], outputsFile: 'my-outputs-file.json', })); @@ -170,7 +171,7 @@ test('should include outputs-file in settings', () => { test('providing a build arg', () => { // GIVEN - const settings = ArgumentSettings.fromCommandLineArguments(convertToCliArgs({ + const settings = ArgumentSettings.fromCommandLineArguments(convertYargsToCliArgs({ _: [Command.SYNTH], build: 'mvn package', })); diff --git a/tools/@aws-cdk/cli-args-gen/lib/cli-args-function-gen.ts b/tools/@aws-cdk/cli-args-gen/lib/cli-args-function-gen.ts index cb7e6a6dd22d4..618824d87c32b 100644 --- a/tools/@aws-cdk/cli-args-gen/lib/cli-args-function-gen.ts +++ b/tools/@aws-cdk/cli-args-gen/lib/cli-args-function-gen.ts @@ -15,10 +15,10 @@ export async function renderCliArgsFunc(config: CliConfig): Promise { scope.addImport(new SelectiveModuleImport(scope, './cli-arguments', ['CliArguments', 'GlobalOptions'])); const cliArgType = Type.fromName(scope, 'CliArguments'); - scope.addImport(new SelectiveModuleImport(scope, './settings', ['Command'])); + scope.addImport(new SelectiveModuleImport(scope, './command', ['Command'])); const createCliArguments = new FreeFunction(scope, { - name: 'convertToCliArgs', + name: 'convertYargsToCliArgs', export: true, returnType: cliArgType, parameters: [ @@ -27,6 +27,16 @@ export async function renderCliArgsFunc(config: CliConfig): Promise { }); createCliArguments.addBody(code.expr.directCode(buildCliArgsFunction(config))); + const createConfigArguments = new FreeFunction(scope, { + name: 'convertConfigToCliArgs', + export: true, + returnType: cliArgType, + parameters: [ + { name: 'args', type: Type.ANY }, + ], + }); + createConfigArguments.addBody(code.expr.directCode(buildConfigArgsFunction(config))); + const ts = new TypeScriptRenderer({ disabledEsLintRules: [EsLintRules.MAX_LEN], // the default disabled rules result in 'Definition for rule 'prettier/prettier' was not found' }).render(scope); @@ -50,6 +60,17 @@ function buildCliArgsFunction(config: CliConfig): string { ].join('\n'); } +function buildConfigArgsFunction(config: CliConfig): string { + const globalOptions = buildGlobalOptions(config); + const commandList = buildCommandsList(config); + const configArgs = buildConfigArgs(config); + return [ + globalOptions, + commandList, + configArgs, + ].join('\n'); +} + function buildGlobalOptions(config: CliConfig): string { const globalOptionExprs = ['const globalOptions: GlobalOptions = {']; for (const optionName of Object.keys(config.globalOptions)) { @@ -60,6 +81,16 @@ function buildGlobalOptions(config: CliConfig): string { return globalOptionExprs.join('\n'); } +function buildCommandsList(config: CliConfig): string { + const commandOptions = []; + for (const commandName of Object.keys(config.commands)) { + commandOptions.push(`const ${kebabToCamelCase(commandName)}Options = {`); + commandOptions.push(...buildCommandOptions(config.commands[commandName])); + commandOptions.push('}'); + } + return commandOptions.join('\n'); +} + function buildCommandSwitch(config: CliConfig): string { const commandSwitchExprs = ['let commandOptions;', 'switch (args._[0] as Command) {']; for (const commandName of Object.keys(config.commands)) { @@ -103,3 +134,17 @@ function buildCliArgs(): string { 'return cliArguments', ].join('\n'); } + +function buildConfigArgs(config: CliConfig): string { + return [ + 'const cliArguments: CliArguments = {', + '_: Command.SOME,', + 'globalOptions,', + ...(Object.keys(config.commands).map((commandName) => { + return `'${commandName}': ${kebabToCamelCase(commandName)}Options,`; + })), + '}', + '', + 'return cliArguments', + ].join('\n'); +} diff --git a/tools/@aws-cdk/cli-args-gen/lib/cli-args-gen.ts b/tools/@aws-cdk/cli-args-gen/lib/cli-args-gen.ts index da469e5cb9dc0..92b837cff4679 100644 --- a/tools/@aws-cdk/cli-args-gen/lib/cli-args-gen.ts +++ b/tools/@aws-cdk/cli-args-gen/lib/cli-args-gen.ts @@ -21,7 +21,7 @@ export async function renderCliArgsType(config: CliConfig): Promise { }); // add required command - scope.addImport(new SelectiveModuleImport(scope, './settings', ['Command'])); + scope.addImport(new SelectiveModuleImport(scope, './command', ['Command'])); const commandEnum = Type.fromName(scope, 'Command'); cliArgType.addProperty({ diff --git a/tools/@aws-cdk/cli-args-gen/test/cli-args-function-gen.test.ts b/tools/@aws-cdk/cli-args-gen/test/cli-args-function-gen.test.ts index 24b92c7fe291e..1a642c00e0cfd 100644 --- a/tools/@aws-cdk/cli-args-gen/test/cli-args-function-gen.test.ts +++ b/tools/@aws-cdk/cli-args-gen/test/cli-args-function-gen.test.ts @@ -52,7 +52,7 @@ describe('render', () => { import { Command } from './settings'; // @ts-ignore TS6133 - export function convertToCliArgs(args: any): CliArguments { + export function convertYargsToCliArgs(args: any): CliArguments { const globalOptions: GlobalOptions = { app: args.app, debug: args.debug, From 2ea41813c349331f900b09404e9294e95903d2f3 Mon Sep 17 00:00:00 2001 From: Kaizen Conroy Date: Wed, 8 Jan 2025 19:02:49 -0500 Subject: [PATCH 06/14] use settinsg --- packages/aws-cdk/lib/cli.ts | 118 ++++++++++++++++--------------- packages/aws-cdk/lib/settings.ts | 4 ++ 2 files changed, 65 insertions(+), 57 deletions(-) diff --git a/packages/aws-cdk/lib/cli.ts b/packages/aws-cdk/lib/cli.ts index f455655cf4e2b..a9c05e6890ed0 100644 --- a/packages/aws-cdk/lib/cli.ts +++ b/packages/aws-cdk/lib/cli.ts @@ -43,11 +43,19 @@ if (!process.stdout.isTTY) { export async function exec(args: string[], synthesizer?: Synthesizer): Promise { const argv: CliArguments = convertYargsToCliArgs(await parseCommandLineArguments(args)); + debug('Command line arguments:', argv); + + const configuration = new Configuration({ + commandLineArguments: argv, + }); + await configuration.load(); + const settings = configuration.settings.all; + // if one -v, log at a DEBUG level // if 2 -v, log at a TRACE level - if (argv.globalOptions?.verbose) { + if (settings.globalOptions?.verbose) { let logLevel: LogLevel; - switch (argv.globalOptions.verbose) { + switch (settings.globalOptions.verbose) { case 1: logLevel = LogLevel.DEBUG; break; @@ -60,11 +68,11 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise 2) { + if (settings.globalOptions?.debug || (settings.globalOptions?.verbose ?? 0) > 2) { enableTracing(true); } - if (argv.globalOptions?.ci) { + if (settings.globalOptions?.ci) { setCI(true); } @@ -75,32 +83,27 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise { + async function main(command: string, settings: CliArguments): Promise { const toolkitStackName: string = ToolkitInfo.determineName(configuration.settings.get(['toolkitStackName'])); debug(`Toolkit stack: ${chalk.bold(toolkitStackName)}`); - const globalOptions = argv.globalOptions ?? {}; + const globalOptions = settings.globalOptions ?? {}; const cloudFormation = new Deployments({ sdkProvider, toolkitStackName }); @@ -193,7 +196,7 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise { if (typeof value === 'number') { diff --git a/packages/aws-cdk/lib/settings.ts b/packages/aws-cdk/lib/settings.ts index 54f247c7bc6e7..5ebe8e46fd42c 100644 --- a/packages/aws-cdk/lib/settings.ts +++ b/packages/aws-cdk/lib/settings.ts @@ -394,6 +394,10 @@ export class ArgumentSettings extends Settings { public merge(other: ArgumentSettings): ArgumentSettings { return new ArgumentSettings(util.deepMerge(this.settings, other.settings)); } + + public get all(): CliArguments { + return this.get([]); + } } function expandHomeDir(x: string) { From a5e6e8c41a05924968c401757677a9f3652cc6c0 Mon Sep 17 00:00:00 2001 From: Kaizen Conroy Date: Wed, 8 Jan 2025 19:49:41 -0500 Subject: [PATCH 07/14] small chagne --- packages/aws-cdk/lib/cli.ts | 4 +- packages/aws-cdk/lib/convert-to-cli-args.ts | 214 +++++++++--------- .../cli-args-gen/lib/cli-args-function-gen.ts | 10 +- 3 files changed, 116 insertions(+), 112 deletions(-) diff --git a/packages/aws-cdk/lib/cli.ts b/packages/aws-cdk/lib/cli.ts index a9c05e6890ed0..270dd77bc60b4 100644 --- a/packages/aws-cdk/lib/cli.ts +++ b/packages/aws-cdk/lib/cli.ts @@ -177,7 +177,7 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise { - const toolkitStackName: string = ToolkitInfo.determineName(configuration.settings.get(['toolkitStackName'])); + const toolkitStackName: string = ToolkitInfo.determineName(settings.bootstrap?.toolkitStackName); // TODO, mroe than bootstrap has toolkitstackname debug(`Toolkit stack: ${chalk.bold(toolkitStackName)}`); const globalOptions = settings.globalOptions ?? {}; @@ -554,7 +554,7 @@ function determineHotswapMode(hotswap?: boolean, hotswapFallback?: boolean, watc } /* istanbul ignore next: we never call this in unit tests */ -export function cli(args: string[] = process.settings.slice(2)) { +export function cli(args: string[] = process.argv.slice(2)) { exec(args) .then(async (value) => { if (typeof value === 'number') { diff --git a/packages/aws-cdk/lib/convert-to-cli-args.ts b/packages/aws-cdk/lib/convert-to-cli-args.ts index 63f731555eda1..53b5ac76d81b2 100644 --- a/packages/aws-cdk/lib/convert-to-cli-args.ts +++ b/packages/aws-cdk/lib/convert-to-cli-args.ts @@ -285,143 +285,143 @@ export function convertConfigToCliArgs(args: any): CliArguments { unstable: args.unstable, }; const listOptions = { - long: args.long, - showDependencies: args.showDependencies, + long: args.list.long, + showDependencies: args.list.showDependencies, }; const synthesizeOptions = { - exclusively: args.exclusively, - validation: args.validation, - quiet: args.quiet, + exclusively: args.synthesize.exclusively, + validation: args.synthesize.validation, + quiet: args.synthesize.quiet, }; const bootstrapOptions = { - bootstrapBucketName: args.bootstrapBucketName, - bootstrapKmsKeyId: args.bootstrapKmsKeyId, - examplePermissionsBoundary: args.examplePermissionsBoundary, - customPermissionsBoundary: args.customPermissionsBoundary, - bootstrapCustomerKey: args.bootstrapCustomerKey, - qualifier: args.qualifier, - publicAccessBlockConfiguration: args.publicAccessBlockConfiguration, - tags: args.tags, - execute: args.execute, - trust: args.trust, - trustForLookup: args.trustForLookup, - cloudformationExecutionPolicies: args.cloudformationExecutionPolicies, - force: args.force, - terminationProtection: args.terminationProtection, - showTemplate: args.showTemplate, - toolkitStackName: args.toolkitStackName, - template: args.template, - previousParameters: args.previousParameters, + bootstrapBucketName: args.bootstrap.bootstrapBucketName, + bootstrapKmsKeyId: args.bootstrap.bootstrapKmsKeyId, + examplePermissionsBoundary: args.bootstrap.examplePermissionsBoundary, + customPermissionsBoundary: args.bootstrap.customPermissionsBoundary, + bootstrapCustomerKey: args.bootstrap.bootstrapCustomerKey, + qualifier: args.bootstrap.qualifier, + publicAccessBlockConfiguration: args.bootstrap.publicAccessBlockConfiguration, + tags: args.bootstrap.tags, + execute: args.bootstrap.execute, + trust: args.bootstrap.trust, + trustForLookup: args.bootstrap.trustForLookup, + cloudformationExecutionPolicies: args.bootstrap.cloudformationExecutionPolicies, + force: args.bootstrap.force, + terminationProtection: args.bootstrap.terminationProtection, + showTemplate: args.bootstrap.showTemplate, + toolkitStackName: args.bootstrap.toolkitStackName, + template: args.bootstrap.template, + previousParameters: args.bootstrap.previousParameters, }; const gcOptions = { - action: args.action, - type: args.type, - rollbackBufferDays: args.rollbackBufferDays, - createdBufferDays: args.createdBufferDays, - confirm: args.confirm, - bootstrapStackName: args.bootstrapStackName, + action: args.gc.action, + type: args.gc.type, + rollbackBufferDays: args.gc.rollbackBufferDays, + createdBufferDays: args.gc.createdBufferDays, + confirm: args.gc.confirm, + bootstrapStackName: args.gc.bootstrapStackName, }; const deployOptions = { - all: args.all, - buildExclude: args.buildExclude, - exclusively: args.exclusively, - requireApproval: args.requireApproval, - notificationArns: args.notificationArns, - tags: args.tags, - execute: args.execute, - changeSetName: args.changeSetName, - method: args.method, - importExistingResources: args.importExistingResources, - force: args.force, - parameters: args.parameters, - outputsFile: args.outputsFile, - previousParameters: args.previousParameters, - toolkitStackName: args.toolkitStackName, - progress: args.progress, - rollback: args.rollback, - hotswap: args.hotswap, - hotswapFallback: args.hotswapFallback, - watch: args.watch, - logs: args.logs, - concurrency: args.concurrency, - assetParallelism: args.assetParallelism, - assetPrebuild: args.assetPrebuild, - ignoreNoStacks: args.ignoreNoStacks, + all: args.deploy.all, + buildExclude: args.deploy.buildExclude, + exclusively: args.deploy.exclusively, + requireApproval: args.deploy.requireApproval, + notificationArns: args.deploy.notificationArns, + tags: args.deploy.tags, + execute: args.deploy.execute, + changeSetName: args.deploy.changeSetName, + method: args.deploy.method, + importExistingResources: args.deploy.importExistingResources, + force: args.deploy.force, + parameters: args.deploy.parameters, + outputsFile: args.deploy.outputsFile, + previousParameters: args.deploy.previousParameters, + toolkitStackName: args.deploy.toolkitStackName, + progress: args.deploy.progress, + rollback: args.deploy.rollback, + hotswap: args.deploy.hotswap, + hotswapFallback: args.deploy.hotswapFallback, + watch: args.deploy.watch, + logs: args.deploy.logs, + concurrency: args.deploy.concurrency, + assetParallelism: args.deploy.assetParallelism, + assetPrebuild: args.deploy.assetPrebuild, + ignoreNoStacks: args.deploy.ignoreNoStacks, }; const rollbackOptions = { - all: args.all, - toolkitStackName: args.toolkitStackName, - force: args.force, - validateBootstrapVersion: args.validateBootstrapVersion, - orphan: args.orphan, + all: args.rollback.all, + toolkitStackName: args.rollback.toolkitStackName, + force: args.rollback.force, + validateBootstrapVersion: args.rollback.validateBootstrapVersion, + orphan: args.rollback.orphan, }; const importOptions = { - execute: args.execute, - changeSetName: args.changeSetName, - toolkitStackName: args.toolkitStackName, - rollback: args.rollback, - force: args.force, - recordResourceMapping: args.recordResourceMapping, - resourceMapping: args.resourceMapping, + execute: args.import.execute, + changeSetName: args.import.changeSetName, + toolkitStackName: args.import.toolkitStackName, + rollback: args.import.rollback, + force: args.import.force, + recordResourceMapping: args.import.recordResourceMapping, + resourceMapping: args.import.resourceMapping, }; const watchOptions = { - buildExclude: args.buildExclude, - exclusively: args.exclusively, - changeSetName: args.changeSetName, - force: args.force, - toolkitStackName: args.toolkitStackName, - progress: args.progress, - rollback: args.rollback, - hotswap: args.hotswap, - hotswapFallback: args.hotswapFallback, - logs: args.logs, - concurrency: args.concurrency, + buildExclude: args.watch.buildExclude, + exclusively: args.watch.exclusively, + changeSetName: args.watch.changeSetName, + force: args.watch.force, + toolkitStackName: args.watch.toolkitStackName, + progress: args.watch.progress, + rollback: args.watch.rollback, + hotswap: args.watch.hotswap, + hotswapFallback: args.watch.hotswapFallback, + logs: args.watch.logs, + concurrency: args.watch.concurrency, }; const destroyOptions = { - all: args.all, - exclusively: args.exclusively, - force: args.force, + all: args.destroy.all, + exclusively: args.destroy.exclusively, + force: args.destroy.force, }; const diffOptions = { - exclusively: args.exclusively, - contextLines: args.contextLines, - template: args.template, - strict: args.strict, - securityOnly: args.securityOnly, - fail: args.fail, - processed: args.processed, - quiet: args.quiet, - changeSet: args.changeSet, + exclusively: args.diff.exclusively, + contextLines: args.diff.contextLines, + template: args.diff.template, + strict: args.diff.strict, + securityOnly: args.diff.securityOnly, + fail: args.diff.fail, + processed: args.diff.processed, + quiet: args.diff.quiet, + changeSet: args.diff.changeSet, }; const metadataOptions = {}; const acknowledgeOptions = {}; const noticesOptions = { - unacknowledged: args.unacknowledged, + unacknowledged: args.notices.unacknowledged, }; const initOptions = { - language: args.language, - list: args.list, - generateOnly: args.generateOnly, + language: args.init.language, + list: args.init.list, + generateOnly: args.init.generateOnly, }; const migrateOptions = { - stackName: args.stackName, - language: args.language, - account: args.account, - region: args.region, - fromPath: args.fromPath, - fromStack: args.fromStack, - outputPath: args.outputPath, - fromScan: args.fromScan, - filter: args.filter, - compress: args.compress, + stackName: args.migrate.stackName, + language: args.migrate.language, + account: args.migrate.account, + region: args.migrate.region, + fromPath: args.migrate.fromPath, + fromStack: args.migrate.fromStack, + outputPath: args.migrate.outputPath, + fromScan: args.migrate.fromScan, + filter: args.migrate.filter, + compress: args.migrate.compress, }; const contextOptions = { - reset: args.reset, - force: args.force, - clear: args.clear, + reset: args.context.reset, + force: args.context.force, + clear: args.context.clear, }; const docsOptions = { - browser: args.browser, + browser: args.docs.browser, }; const doctorOptions = {}; const cliArguments: CliArguments = { diff --git a/tools/@aws-cdk/cli-args-gen/lib/cli-args-function-gen.ts b/tools/@aws-cdk/cli-args-gen/lib/cli-args-function-gen.ts index 618824d87c32b..34254d4d8b18b 100644 --- a/tools/@aws-cdk/cli-args-gen/lib/cli-args-function-gen.ts +++ b/tools/@aws-cdk/cli-args-gen/lib/cli-args-function-gen.ts @@ -85,7 +85,7 @@ function buildCommandsList(config: CliConfig): string { const commandOptions = []; for (const commandName of Object.keys(config.commands)) { commandOptions.push(`const ${kebabToCamelCase(commandName)}Options = {`); - commandOptions.push(...buildCommandOptions(config.commands[commandName])); + commandOptions.push(...buildCommandOptions(config.commands[commandName], kebabToCamelCase(commandName))); commandOptions.push('}'); } return commandOptions.join('\n'); @@ -107,11 +107,15 @@ function buildCommandSwitch(config: CliConfig): string { return commandSwitchExprs.join('\n'); } -function buildCommandOptions(options: CliAction): string[] { +function buildCommandOptions(options: CliAction, prefix?: string): string[] { const commandOptions: string[] = []; for (const optionName of Object.keys(options.options ?? {})) { const name = kebabToCamelCase(optionName); - commandOptions.push(`'${name}': args.${name},`); + if (prefix) { + commandOptions.push(`'${name}': args.${prefix}.${name},`); + } else { + commandOptions.push(`'${name}': args.${name},`); + } } return commandOptions; } From ed197319e825c56b132e71345bed81fc90471f07 Mon Sep 17 00:00:00 2001 From: Kaizen Conroy Date: Wed, 8 Jan 2025 23:06:42 -0500 Subject: [PATCH 08/14] oneline --- tools/@aws-cdk/cli-args-gen/lib/cli-args-function-gen.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/@aws-cdk/cli-args-gen/lib/cli-args-function-gen.ts b/tools/@aws-cdk/cli-args-gen/lib/cli-args-function-gen.ts index 34254d4d8b18b..23950a0a093c0 100644 --- a/tools/@aws-cdk/cli-args-gen/lib/cli-args-function-gen.ts +++ b/tools/@aws-cdk/cli-args-gen/lib/cli-args-function-gen.ts @@ -112,7 +112,7 @@ function buildCommandOptions(options: CliAction, prefix?: string): string[] { for (const optionName of Object.keys(options.options ?? {})) { const name = kebabToCamelCase(optionName); if (prefix) { - commandOptions.push(`'${name}': args.${prefix}.${name},`); + commandOptions.push(`'${name}': args.${prefix}?.${name},`); } else { commandOptions.push(`'${name}': args.${name},`); } From 85641095ea1cb9bda925ca76e6af4269a57f11e7 Mon Sep 17 00:00:00 2001 From: Kaizen Conroy Date: Wed, 8 Jan 2025 23:07:09 -0500 Subject: [PATCH 09/14] updates --- packages/aws-cdk/lib/convert-to-cli-args.ts | 214 ++++++++++---------- 1 file changed, 107 insertions(+), 107 deletions(-) diff --git a/packages/aws-cdk/lib/convert-to-cli-args.ts b/packages/aws-cdk/lib/convert-to-cli-args.ts index 53b5ac76d81b2..a6fb17321f691 100644 --- a/packages/aws-cdk/lib/convert-to-cli-args.ts +++ b/packages/aws-cdk/lib/convert-to-cli-args.ts @@ -285,143 +285,143 @@ export function convertConfigToCliArgs(args: any): CliArguments { unstable: args.unstable, }; const listOptions = { - long: args.list.long, - showDependencies: args.list.showDependencies, + long: args.list?.long, + showDependencies: args.list?.showDependencies, }; const synthesizeOptions = { - exclusively: args.synthesize.exclusively, - validation: args.synthesize.validation, - quiet: args.synthesize.quiet, + exclusively: args.synthesize?.exclusively, + validation: args.synthesize?.validation, + quiet: args.synthesize?.quiet, }; const bootstrapOptions = { - bootstrapBucketName: args.bootstrap.bootstrapBucketName, - bootstrapKmsKeyId: args.bootstrap.bootstrapKmsKeyId, - examplePermissionsBoundary: args.bootstrap.examplePermissionsBoundary, - customPermissionsBoundary: args.bootstrap.customPermissionsBoundary, - bootstrapCustomerKey: args.bootstrap.bootstrapCustomerKey, - qualifier: args.bootstrap.qualifier, - publicAccessBlockConfiguration: args.bootstrap.publicAccessBlockConfiguration, - tags: args.bootstrap.tags, - execute: args.bootstrap.execute, - trust: args.bootstrap.trust, - trustForLookup: args.bootstrap.trustForLookup, - cloudformationExecutionPolicies: args.bootstrap.cloudformationExecutionPolicies, - force: args.bootstrap.force, - terminationProtection: args.bootstrap.terminationProtection, - showTemplate: args.bootstrap.showTemplate, - toolkitStackName: args.bootstrap.toolkitStackName, - template: args.bootstrap.template, - previousParameters: args.bootstrap.previousParameters, + bootstrapBucketName: args.bootstrap?.bootstrapBucketName, + bootstrapKmsKeyId: args.bootstrap?.bootstrapKmsKeyId, + examplePermissionsBoundary: args.bootstrap?.examplePermissionsBoundary, + customPermissionsBoundary: args.bootstrap?.customPermissionsBoundary, + bootstrapCustomerKey: args.bootstrap?.bootstrapCustomerKey, + qualifier: args.bootstrap?.qualifier, + publicAccessBlockConfiguration: args.bootstrap?.publicAccessBlockConfiguration, + tags: args.bootstrap?.tags, + execute: args.bootstrap?.execute, + trust: args.bootstrap?.trust, + trustForLookup: args.bootstrap?.trustForLookup, + cloudformationExecutionPolicies: args.bootstrap?.cloudformationExecutionPolicies, + force: args.bootstrap?.force, + terminationProtection: args.bootstrap?.terminationProtection, + showTemplate: args.bootstrap?.showTemplate, + toolkitStackName: args.bootstrap?.toolkitStackName, + template: args.bootstrap?.template, + previousParameters: args.bootstrap?.previousParameters, }; const gcOptions = { - action: args.gc.action, - type: args.gc.type, - rollbackBufferDays: args.gc.rollbackBufferDays, - createdBufferDays: args.gc.createdBufferDays, - confirm: args.gc.confirm, - bootstrapStackName: args.gc.bootstrapStackName, + action: args.gc?.action, + type: args.gc?.type, + rollbackBufferDays: args.gc?.rollbackBufferDays, + createdBufferDays: args.gc?.createdBufferDays, + confirm: args.gc?.confirm, + bootstrapStackName: args.gc?.bootstrapStackName, }; const deployOptions = { - all: args.deploy.all, - buildExclude: args.deploy.buildExclude, - exclusively: args.deploy.exclusively, - requireApproval: args.deploy.requireApproval, - notificationArns: args.deploy.notificationArns, - tags: args.deploy.tags, - execute: args.deploy.execute, - changeSetName: args.deploy.changeSetName, - method: args.deploy.method, - importExistingResources: args.deploy.importExistingResources, - force: args.deploy.force, - parameters: args.deploy.parameters, - outputsFile: args.deploy.outputsFile, - previousParameters: args.deploy.previousParameters, - toolkitStackName: args.deploy.toolkitStackName, - progress: args.deploy.progress, - rollback: args.deploy.rollback, - hotswap: args.deploy.hotswap, - hotswapFallback: args.deploy.hotswapFallback, - watch: args.deploy.watch, - logs: args.deploy.logs, - concurrency: args.deploy.concurrency, - assetParallelism: args.deploy.assetParallelism, - assetPrebuild: args.deploy.assetPrebuild, - ignoreNoStacks: args.deploy.ignoreNoStacks, + all: args.deploy?.all, + buildExclude: args.deploy?.buildExclude, + exclusively: args.deploy?.exclusively, + requireApproval: args.deploy?.requireApproval, + notificationArns: args.deploy?.notificationArns, + tags: args.deploy?.tags, + execute: args.deploy?.execute, + changeSetName: args.deploy?.changeSetName, + method: args.deploy?.method, + importExistingResources: args.deploy?.importExistingResources, + force: args.deploy?.force, + parameters: args.deploy?.parameters, + outputsFile: args.deploy?.outputsFile, + previousParameters: args.deploy?.previousParameters, + toolkitStackName: args.deploy?.toolkitStackName, + progress: args.deploy?.progress, + rollback: args.deploy?.rollback, + hotswap: args.deploy?.hotswap, + hotswapFallback: args.deploy?.hotswapFallback, + watch: args.deploy?.watch, + logs: args.deploy?.logs, + concurrency: args.deploy?.concurrency, + assetParallelism: args.deploy?.assetParallelism, + assetPrebuild: args.deploy?.assetPrebuild, + ignoreNoStacks: args.deploy?.ignoreNoStacks, }; const rollbackOptions = { - all: args.rollback.all, - toolkitStackName: args.rollback.toolkitStackName, - force: args.rollback.force, - validateBootstrapVersion: args.rollback.validateBootstrapVersion, - orphan: args.rollback.orphan, + all: args.rollback?.all, + toolkitStackName: args.rollback?.toolkitStackName, + force: args.rollback?.force, + validateBootstrapVersion: args.rollback?.validateBootstrapVersion, + orphan: args.rollback?.orphan, }; const importOptions = { - execute: args.import.execute, - changeSetName: args.import.changeSetName, - toolkitStackName: args.import.toolkitStackName, - rollback: args.import.rollback, - force: args.import.force, - recordResourceMapping: args.import.recordResourceMapping, - resourceMapping: args.import.resourceMapping, + execute: args.import?.execute, + changeSetName: args.import?.changeSetName, + toolkitStackName: args.import?.toolkitStackName, + rollback: args.import?.rollback, + force: args.import?.force, + recordResourceMapping: args.import?.recordResourceMapping, + resourceMapping: args.import?.resourceMapping, }; const watchOptions = { - buildExclude: args.watch.buildExclude, - exclusively: args.watch.exclusively, - changeSetName: args.watch.changeSetName, - force: args.watch.force, - toolkitStackName: args.watch.toolkitStackName, - progress: args.watch.progress, - rollback: args.watch.rollback, - hotswap: args.watch.hotswap, - hotswapFallback: args.watch.hotswapFallback, - logs: args.watch.logs, - concurrency: args.watch.concurrency, + buildExclude: args.watch?.buildExclude, + exclusively: args.watch?.exclusively, + changeSetName: args.watch?.changeSetName, + force: args.watch?.force, + toolkitStackName: args.watch?.toolkitStackName, + progress: args.watch?.progress, + rollback: args.watch?.rollback, + hotswap: args.watch?.hotswap, + hotswapFallback: args.watch?.hotswapFallback, + logs: args.watch?.logs, + concurrency: args.watch?.concurrency, }; const destroyOptions = { - all: args.destroy.all, - exclusively: args.destroy.exclusively, - force: args.destroy.force, + all: args.destroy?.all, + exclusively: args.destroy?.exclusively, + force: args.destroy?.force, }; const diffOptions = { - exclusively: args.diff.exclusively, - contextLines: args.diff.contextLines, - template: args.diff.template, - strict: args.diff.strict, - securityOnly: args.diff.securityOnly, - fail: args.diff.fail, - processed: args.diff.processed, - quiet: args.diff.quiet, - changeSet: args.diff.changeSet, + exclusively: args.diff?.exclusively, + contextLines: args.diff?.contextLines, + template: args.diff?.template, + strict: args.diff?.strict, + securityOnly: args.diff?.securityOnly, + fail: args.diff?.fail, + processed: args.diff?.processed, + quiet: args.diff?.quiet, + changeSet: args.diff?.changeSet, }; const metadataOptions = {}; const acknowledgeOptions = {}; const noticesOptions = { - unacknowledged: args.notices.unacknowledged, + unacknowledged: args.notices?.unacknowledged, }; const initOptions = { - language: args.init.language, - list: args.init.list, - generateOnly: args.init.generateOnly, + language: args.init?.language, + list: args.init?.list, + generateOnly: args.init?.generateOnly, }; const migrateOptions = { - stackName: args.migrate.stackName, - language: args.migrate.language, - account: args.migrate.account, - region: args.migrate.region, - fromPath: args.migrate.fromPath, - fromStack: args.migrate.fromStack, - outputPath: args.migrate.outputPath, - fromScan: args.migrate.fromScan, - filter: args.migrate.filter, - compress: args.migrate.compress, + stackName: args.migrate?.stackName, + language: args.migrate?.language, + account: args.migrate?.account, + region: args.migrate?.region, + fromPath: args.migrate?.fromPath, + fromStack: args.migrate?.fromStack, + outputPath: args.migrate?.outputPath, + fromScan: args.migrate?.fromScan, + filter: args.migrate?.filter, + compress: args.migrate?.compress, }; const contextOptions = { - reset: args.context.reset, - force: args.context.force, - clear: args.context.clear, + reset: args.context?.reset, + force: args.context?.force, + clear: args.context?.clear, }; const docsOptions = { - browser: args.docs.browser, + browser: args.docs?.browser, }; const doctorOptions = {}; const cliArguments: CliArguments = { From 64e44040b71bd94396a66e6121a0020f34b15d25 Mon Sep 17 00:00:00 2001 From: Kaizen Conroy Date: Fri, 10 Jan 2025 15:04:07 -0500 Subject: [PATCH 10/14] delete extra file --- packages/aws-cdk/lib/convert-to-cli-args.ts | 451 -------------------- 1 file changed, 451 deletions(-) delete mode 100644 packages/aws-cdk/lib/convert-to-cli-args.ts diff --git a/packages/aws-cdk/lib/convert-to-cli-args.ts b/packages/aws-cdk/lib/convert-to-cli-args.ts deleted file mode 100644 index a6fb17321f691..0000000000000 --- a/packages/aws-cdk/lib/convert-to-cli-args.ts +++ /dev/null @@ -1,451 +0,0 @@ -// ------------------------------------------------------------------------------------------- -// GENERATED FROM packages/aws-cdk/lib/config.ts. -// Do not edit by hand; all changes will be overwritten at build time from the config file. -// ------------------------------------------------------------------------------------------- -/* eslint-disable @stylistic/max-len */ -import { CliArguments, GlobalOptions } from './cli-arguments'; -import { Command } from './command'; - -// @ts-ignore TS6133 -export function convertYargsToCliArgs(args: any): CliArguments { - const globalOptions: GlobalOptions = { - app: args.app, - build: args.build, - context: args.context, - plugin: args.plugin, - trace: args.trace, - strict: args.strict, - lookups: args.lookups, - ignoreErrors: args.ignoreErrors, - json: args.json, - verbose: args.verbose, - debug: args.debug, - profile: args.profile, - proxy: args.proxy, - caBundlePath: args.caBundlePath, - ec2creds: args.ec2creds, - versionReporting: args.versionReporting, - pathMetadata: args.pathMetadata, - assetMetadata: args.assetMetadata, - roleArn: args.roleArn, - staging: args.staging, - output: args.output, - notices: args.notices, - noColor: args.noColor, - ci: args.ci, - unstable: args.unstable, - }; - let commandOptions; - switch (args._[0] as Command) { - case 'list': - commandOptions = { - long: args.long, - showDependencies: args.showDependencies, - STACKS: args.STACKS, - }; - break; - - case 'synthesize': - commandOptions = { - exclusively: args.exclusively, - validation: args.validation, - quiet: args.quiet, - STACKS: args.STACKS, - }; - break; - - case 'bootstrap': - commandOptions = { - bootstrapBucketName: args.bootstrapBucketName, - bootstrapKmsKeyId: args.bootstrapKmsKeyId, - examplePermissionsBoundary: args.examplePermissionsBoundary, - customPermissionsBoundary: args.customPermissionsBoundary, - bootstrapCustomerKey: args.bootstrapCustomerKey, - qualifier: args.qualifier, - publicAccessBlockConfiguration: args.publicAccessBlockConfiguration, - tags: args.tags, - execute: args.execute, - trust: args.trust, - trustForLookup: args.trustForLookup, - cloudformationExecutionPolicies: args.cloudformationExecutionPolicies, - force: args.force, - terminationProtection: args.terminationProtection, - showTemplate: args.showTemplate, - toolkitStackName: args.toolkitStackName, - template: args.template, - previousParameters: args.previousParameters, - ENVIRONMENTS: args.ENVIRONMENTS, - }; - break; - - case 'gc': - commandOptions = { - action: args.action, - type: args.type, - rollbackBufferDays: args.rollbackBufferDays, - createdBufferDays: args.createdBufferDays, - confirm: args.confirm, - bootstrapStackName: args.bootstrapStackName, - ENVIRONMENTS: args.ENVIRONMENTS, - }; - break; - - case 'deploy': - commandOptions = { - all: args.all, - buildExclude: args.buildExclude, - exclusively: args.exclusively, - requireApproval: args.requireApproval, - notificationArns: args.notificationArns, - tags: args.tags, - execute: args.execute, - changeSetName: args.changeSetName, - method: args.method, - importExistingResources: args.importExistingResources, - force: args.force, - parameters: args.parameters, - outputsFile: args.outputsFile, - previousParameters: args.previousParameters, - toolkitStackName: args.toolkitStackName, - progress: args.progress, - rollback: args.rollback, - hotswap: args.hotswap, - hotswapFallback: args.hotswapFallback, - watch: args.watch, - logs: args.logs, - concurrency: args.concurrency, - assetParallelism: args.assetParallelism, - assetPrebuild: args.assetPrebuild, - ignoreNoStacks: args.ignoreNoStacks, - STACKS: args.STACKS, - }; - break; - - case 'rollback': - commandOptions = { - all: args.all, - toolkitStackName: args.toolkitStackName, - force: args.force, - validateBootstrapVersion: args.validateBootstrapVersion, - orphan: args.orphan, - STACKS: args.STACKS, - }; - break; - - case 'import': - commandOptions = { - execute: args.execute, - changeSetName: args.changeSetName, - toolkitStackName: args.toolkitStackName, - rollback: args.rollback, - force: args.force, - recordResourceMapping: args.recordResourceMapping, - resourceMapping: args.resourceMapping, - STACK: args.STACK, - }; - break; - - case 'watch': - commandOptions = { - buildExclude: args.buildExclude, - exclusively: args.exclusively, - changeSetName: args.changeSetName, - force: args.force, - toolkitStackName: args.toolkitStackName, - progress: args.progress, - rollback: args.rollback, - hotswap: args.hotswap, - hotswapFallback: args.hotswapFallback, - logs: args.logs, - concurrency: args.concurrency, - STACKS: args.STACKS, - }; - break; - - case 'destroy': - commandOptions = { - all: args.all, - exclusively: args.exclusively, - force: args.force, - STACKS: args.STACKS, - }; - break; - - case 'diff': - commandOptions = { - exclusively: args.exclusively, - contextLines: args.contextLines, - template: args.template, - strict: args.strict, - securityOnly: args.securityOnly, - fail: args.fail, - processed: args.processed, - quiet: args.quiet, - changeSet: args.changeSet, - STACKS: args.STACKS, - }; - break; - - case 'metadata': - commandOptions = { - STACK: args.STACK, - }; - break; - - case 'acknowledge': - commandOptions = { - ID: args.ID, - }; - break; - - case 'notices': - commandOptions = { - unacknowledged: args.unacknowledged, - }; - break; - - case 'init': - commandOptions = { - language: args.language, - list: args.list, - generateOnly: args.generateOnly, - TEMPLATE: args.TEMPLATE, - }; - break; - - case 'migrate': - commandOptions = { - stackName: args.stackName, - language: args.language, - account: args.account, - region: args.region, - fromPath: args.fromPath, - fromStack: args.fromStack, - outputPath: args.outputPath, - fromScan: args.fromScan, - filter: args.filter, - compress: args.compress, - }; - break; - - case 'context': - commandOptions = { - reset: args.reset, - force: args.force, - clear: args.clear, - }; - break; - - case 'docs': - commandOptions = { - browser: args.browser, - }; - break; - - case 'doctor': - commandOptions = {}; - break; - } - const cliArguments: CliArguments = { - _: args._[0], - globalOptions, - [args._[0]]: commandOptions, - }; - - return cliArguments; -} - -// @ts-ignore TS6133 -export function convertConfigToCliArgs(args: any): CliArguments { - const globalOptions: GlobalOptions = { - app: args.app, - build: args.build, - context: args.context, - plugin: args.plugin, - trace: args.trace, - strict: args.strict, - lookups: args.lookups, - ignoreErrors: args.ignoreErrors, - json: args.json, - verbose: args.verbose, - debug: args.debug, - profile: args.profile, - proxy: args.proxy, - caBundlePath: args.caBundlePath, - ec2creds: args.ec2creds, - versionReporting: args.versionReporting, - pathMetadata: args.pathMetadata, - assetMetadata: args.assetMetadata, - roleArn: args.roleArn, - staging: args.staging, - output: args.output, - notices: args.notices, - noColor: args.noColor, - ci: args.ci, - unstable: args.unstable, - }; - const listOptions = { - long: args.list?.long, - showDependencies: args.list?.showDependencies, - }; - const synthesizeOptions = { - exclusively: args.synthesize?.exclusively, - validation: args.synthesize?.validation, - quiet: args.synthesize?.quiet, - }; - const bootstrapOptions = { - bootstrapBucketName: args.bootstrap?.bootstrapBucketName, - bootstrapKmsKeyId: args.bootstrap?.bootstrapKmsKeyId, - examplePermissionsBoundary: args.bootstrap?.examplePermissionsBoundary, - customPermissionsBoundary: args.bootstrap?.customPermissionsBoundary, - bootstrapCustomerKey: args.bootstrap?.bootstrapCustomerKey, - qualifier: args.bootstrap?.qualifier, - publicAccessBlockConfiguration: args.bootstrap?.publicAccessBlockConfiguration, - tags: args.bootstrap?.tags, - execute: args.bootstrap?.execute, - trust: args.bootstrap?.trust, - trustForLookup: args.bootstrap?.trustForLookup, - cloudformationExecutionPolicies: args.bootstrap?.cloudformationExecutionPolicies, - force: args.bootstrap?.force, - terminationProtection: args.bootstrap?.terminationProtection, - showTemplate: args.bootstrap?.showTemplate, - toolkitStackName: args.bootstrap?.toolkitStackName, - template: args.bootstrap?.template, - previousParameters: args.bootstrap?.previousParameters, - }; - const gcOptions = { - action: args.gc?.action, - type: args.gc?.type, - rollbackBufferDays: args.gc?.rollbackBufferDays, - createdBufferDays: args.gc?.createdBufferDays, - confirm: args.gc?.confirm, - bootstrapStackName: args.gc?.bootstrapStackName, - }; - const deployOptions = { - all: args.deploy?.all, - buildExclude: args.deploy?.buildExclude, - exclusively: args.deploy?.exclusively, - requireApproval: args.deploy?.requireApproval, - notificationArns: args.deploy?.notificationArns, - tags: args.deploy?.tags, - execute: args.deploy?.execute, - changeSetName: args.deploy?.changeSetName, - method: args.deploy?.method, - importExistingResources: args.deploy?.importExistingResources, - force: args.deploy?.force, - parameters: args.deploy?.parameters, - outputsFile: args.deploy?.outputsFile, - previousParameters: args.deploy?.previousParameters, - toolkitStackName: args.deploy?.toolkitStackName, - progress: args.deploy?.progress, - rollback: args.deploy?.rollback, - hotswap: args.deploy?.hotswap, - hotswapFallback: args.deploy?.hotswapFallback, - watch: args.deploy?.watch, - logs: args.deploy?.logs, - concurrency: args.deploy?.concurrency, - assetParallelism: args.deploy?.assetParallelism, - assetPrebuild: args.deploy?.assetPrebuild, - ignoreNoStacks: args.deploy?.ignoreNoStacks, - }; - const rollbackOptions = { - all: args.rollback?.all, - toolkitStackName: args.rollback?.toolkitStackName, - force: args.rollback?.force, - validateBootstrapVersion: args.rollback?.validateBootstrapVersion, - orphan: args.rollback?.orphan, - }; - const importOptions = { - execute: args.import?.execute, - changeSetName: args.import?.changeSetName, - toolkitStackName: args.import?.toolkitStackName, - rollback: args.import?.rollback, - force: args.import?.force, - recordResourceMapping: args.import?.recordResourceMapping, - resourceMapping: args.import?.resourceMapping, - }; - const watchOptions = { - buildExclude: args.watch?.buildExclude, - exclusively: args.watch?.exclusively, - changeSetName: args.watch?.changeSetName, - force: args.watch?.force, - toolkitStackName: args.watch?.toolkitStackName, - progress: args.watch?.progress, - rollback: args.watch?.rollback, - hotswap: args.watch?.hotswap, - hotswapFallback: args.watch?.hotswapFallback, - logs: args.watch?.logs, - concurrency: args.watch?.concurrency, - }; - const destroyOptions = { - all: args.destroy?.all, - exclusively: args.destroy?.exclusively, - force: args.destroy?.force, - }; - const diffOptions = { - exclusively: args.diff?.exclusively, - contextLines: args.diff?.contextLines, - template: args.diff?.template, - strict: args.diff?.strict, - securityOnly: args.diff?.securityOnly, - fail: args.diff?.fail, - processed: args.diff?.processed, - quiet: args.diff?.quiet, - changeSet: args.diff?.changeSet, - }; - const metadataOptions = {}; - const acknowledgeOptions = {}; - const noticesOptions = { - unacknowledged: args.notices?.unacknowledged, - }; - const initOptions = { - language: args.init?.language, - list: args.init?.list, - generateOnly: args.init?.generateOnly, - }; - const migrateOptions = { - stackName: args.migrate?.stackName, - language: args.migrate?.language, - account: args.migrate?.account, - region: args.migrate?.region, - fromPath: args.migrate?.fromPath, - fromStack: args.migrate?.fromStack, - outputPath: args.migrate?.outputPath, - fromScan: args.migrate?.fromScan, - filter: args.migrate?.filter, - compress: args.migrate?.compress, - }; - const contextOptions = { - reset: args.context?.reset, - force: args.context?.force, - clear: args.context?.clear, - }; - const docsOptions = { - browser: args.docs?.browser, - }; - const doctorOptions = {}; - const cliArguments: CliArguments = { - _: Command.SOME, - globalOptions, - list: listOptions, - synthesize: synthesizeOptions, - bootstrap: bootstrapOptions, - gc: gcOptions, - deploy: deployOptions, - rollback: rollbackOptions, - import: importOptions, - watch: watchOptions, - destroy: destroyOptions, - diff: diffOptions, - metadata: metadataOptions, - acknowledge: acknowledgeOptions, - notices: noticesOptions, - init: initOptions, - migrate: migrateOptions, - context: contextOptions, - docs: docsOptions, - doctor: doctorOptions, - }; - - return cliArguments; -} From 3da904c79ebb95b5d1649fb831919fb61b733c2c Mon Sep 17 00:00:00 2001 From: Kaizen Conroy Date: Fri, 10 Jan 2025 15:14:54 -0500 Subject: [PATCH 11/14] builds now --- packages/aws-cdk/lib/cli.ts | 10 +++--- packages/aws-cdk/lib/command.ts | 2 ++ packages/aws-cdk/lib/convert-to-user-input.ts | 2 +- packages/aws-cdk/lib/settings.ts | 6 ++-- packages/aws-cdk/test/settings.test.ts | 32 +++++++++---------- .../lib/convert-to-user-input-gen.ts | 2 +- .../test/convert-to-user-input-gen.test.ts | 2 +- .../test/user-input-gen.test.ts | 6 ++-- 8 files changed, 32 insertions(+), 30 deletions(-) diff --git a/packages/aws-cdk/lib/cli.ts b/packages/aws-cdk/lib/cli.ts index 270dd77bc60b4..ccbaa7255ec6b 100644 --- a/packages/aws-cdk/lib/cli.ts +++ b/packages/aws-cdk/lib/cli.ts @@ -5,8 +5,7 @@ import * as chalk from 'chalk'; import { DeploymentMethod } from './api'; import { HotswapMode } from './api/hotswap/common'; import { ILock } from './api/util/rwlock'; -import { CliArguments } from './cli-arguments'; -import { convertYargsToCliArgs } from './convert-to-cli-args'; +import { convertYargsToUserInput } from './convert-to-user-input'; import { parseCommandLineArguments } from './parse-command-line-arguments'; import { checkForPlatformWarnings } from './platform-warnings'; import { enableTracing } from './util/tracing'; @@ -31,6 +30,7 @@ import * as version from '../lib/version'; import { SdkToCliLogger } from './api/aws-auth/sdk-logger'; import { StringWithoutPlaceholders } from './api/util/placeholders'; import { ToolkitError } from './toolkit/error'; +import { UserInput } from './user-input'; /* eslint-disable max-len */ /* eslint-disable @typescript-eslint/no-shadow */ // yargs @@ -41,7 +41,7 @@ if (!process.stdout.isTTY) { } export async function exec(args: string[], synthesizer?: Synthesizer): Promise { - const argv: CliArguments = convertYargsToCliArgs(await parseCommandLineArguments(args)); + const argv: UserInput = convertYargsToUserInput(await parseCommandLineArguments(args)); debug('Command line arguments:', argv); @@ -176,7 +176,7 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise { + async function main(command: string, settings: UserInput): Promise { const toolkitStackName: string = ToolkitInfo.determineName(settings.bootstrap?.toolkitStackName); // TODO, mroe than bootstrap has toolkitstackname debug(`Toolkit stack: ${chalk.bold(toolkitStackName)}`); @@ -438,7 +438,7 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise { @@ -66,8 +66,8 @@ test('can clear all values in all objects', () => { test('can parse string context from command line arguments', () => { // GIVEN - const settings1 = ArgumentSettings.fromCommandLineArguments(convertYargsToCliArgs({ context: ['foo=bar'], _: [Command.DEPLOY] })); - const settings2 = ArgumentSettings.fromCommandLineArguments(convertYargsToCliArgs({ context: ['foo='], _: [Command.DEPLOY] })); + const settings1 = ArgumentSettings.fromCommandLineArguments(convertYargsToUserInput({ context: ['foo=bar'], _: [Command.DEPLOY] })); + const settings2 = ArgumentSettings.fromCommandLineArguments(convertYargsToUserInput({ context: ['foo='], _: [Command.DEPLOY] })); // THEN expect(settings1.get(['context']).foo).toEqual( 'bar'); @@ -76,8 +76,8 @@ test('can parse string context from command line arguments', () => { test('can parse string context from command line arguments with equals sign in value', () => { // GIVEN - const settings1 = ArgumentSettings.fromCommandLineArguments(convertYargsToCliArgs({ context: ['foo==bar='], _: [Command.DEPLOY] })); - const settings2 = ArgumentSettings.fromCommandLineArguments(convertYargsToCliArgs({ context: ['foo=bar='], _: [Command.DEPLOY] })); + const settings1 = ArgumentSettings.fromCommandLineArguments(convertYargsToUserInput({ context: ['foo==bar='], _: [Command.DEPLOY] })); + const settings2 = ArgumentSettings.fromCommandLineArguments(convertYargsToUserInput({ context: ['foo=bar='], _: [Command.DEPLOY] })); // THEN expect(settings1.get(['context']).foo).toEqual( '=bar='); @@ -86,8 +86,8 @@ test('can parse string context from command line arguments with equals sign in v test('can parse tag values from command line arguments', () => { // GIVEN - const settings1 = ArgumentSettings.fromCommandLineArguments(convertYargsToCliArgs({ tags: ['foo=bar'], _: [Command.DEPLOY] })); - const settings2 = ArgumentSettings.fromCommandLineArguments(convertYargsToCliArgs({ tags: ['foo='], _: [Command.DEPLOY] })); + const settings1 = ArgumentSettings.fromCommandLineArguments(convertYargsToUserInput({ tags: ['foo=bar'], _: [Command.DEPLOY] })); + const settings2 = ArgumentSettings.fromCommandLineArguments(convertYargsToUserInput({ tags: ['foo='], _: [Command.DEPLOY] })); // THEN expect(settings1.get(['tags']).find((tag: Tag) => tag.Key === 'foo').Value).toEqual('bar'); @@ -96,8 +96,8 @@ test('can parse tag values from command line arguments', () => { test('can parse tag values from command line arguments with equals sign in value', () => { // GIVEN - const settings1 = ArgumentSettings.fromCommandLineArguments(convertYargsToCliArgs({ tags: ['foo==bar='], _: [Command.DEPLOY] })); - const settings2 = ArgumentSettings.fromCommandLineArguments(convertYargsToCliArgs({ tags: ['foo=bar='], _: [Command.DEPLOY] })); + const settings1 = ArgumentSettings.fromCommandLineArguments(convertYargsToUserInput({ tags: ['foo==bar='], _: [Command.DEPLOY] })); + const settings2 = ArgumentSettings.fromCommandLineArguments(convertYargsToUserInput({ tags: ['foo=bar='], _: [Command.DEPLOY] })); // THEN expect(settings1.get(['tags']).find((tag: Tag) => tag.Key === 'foo').Value).toEqual('=bar='); @@ -106,7 +106,7 @@ test('can parse tag values from command line arguments with equals sign in value test('bundling stacks defaults to an empty list', () => { // GIVEN - const settings = ArgumentSettings.fromCommandLineArguments(convertYargsToCliArgs({ + const settings = ArgumentSettings.fromCommandLineArguments(convertYargsToUserInput({ _: [Command.LIST], })); @@ -116,7 +116,7 @@ test('bundling stacks defaults to an empty list', () => { test('bundling stacks defaults to ** for deploy', () => { // GIVEN - const settings = ArgumentSettings.fromCommandLineArguments(convertYargsToCliArgs({ + const settings = ArgumentSettings.fromCommandLineArguments(convertYargsToUserInput({ _: [Command.DEPLOY], })); @@ -126,7 +126,7 @@ test('bundling stacks defaults to ** for deploy', () => { test('bundling stacks defaults to ** for watch', () => { // GIVEN - const settings = ArgumentSettings.fromCommandLineArguments(convertYargsToCliArgs({ + const settings = ArgumentSettings.fromCommandLineArguments(convertYargsToUserInput({ _: [Command.WATCH], })); @@ -136,7 +136,7 @@ test('bundling stacks defaults to ** for watch', () => { test('bundling stacks with deploy exclusively', () => { // GIVEN - const settings = ArgumentSettings.fromCommandLineArguments(convertYargsToCliArgs({ + const settings = ArgumentSettings.fromCommandLineArguments(convertYargsToUserInput({ _: [Command.DEPLOY], exclusively: true, STACKS: ['cool-stack'], @@ -148,7 +148,7 @@ test('bundling stacks with deploy exclusively', () => { test('bundling stacks with watch exclusively', () => { // GIVEN - const settings = ArgumentSettings.fromCommandLineArguments(convertYargsToCliArgs({ + const settings = ArgumentSettings.fromCommandLineArguments(convertYargsToUserInput({ _: [Command.WATCH], exclusively: true, STACKS: ['cool-stack'], @@ -160,7 +160,7 @@ test('bundling stacks with watch exclusively', () => { test('should include outputs-file in settings', () => { // GIVEN - const settings = ArgumentSettings.fromCommandLineArguments(convertYargsToCliArgs({ + const settings = ArgumentSettings.fromCommandLineArguments(convertYargsToUserInput({ _: [Command.DEPLOY], outputsFile: 'my-outputs-file.json', })); @@ -171,7 +171,7 @@ test('should include outputs-file in settings', () => { test('providing a build arg', () => { // GIVEN - const settings = ArgumentSettings.fromCommandLineArguments(convertYargsToCliArgs({ + const settings = ArgumentSettings.fromCommandLineArguments(convertYargsToUserInput({ _: [Command.SYNTH], build: 'mvn package', })); diff --git a/tools/@aws-cdk/user-input-gen/lib/convert-to-user-input-gen.ts b/tools/@aws-cdk/user-input-gen/lib/convert-to-user-input-gen.ts index b348059eff33e..c7dc010328864 100644 --- a/tools/@aws-cdk/user-input-gen/lib/convert-to-user-input-gen.ts +++ b/tools/@aws-cdk/user-input-gen/lib/convert-to-user-input-gen.ts @@ -15,7 +15,7 @@ export async function renderUserInputFuncs(config: CliConfig): Promise { scope.documentation.push('Do not edit by hand; all changes will be overwritten at build time from the config file.'); scope.documentation.push('-------------------------------------------------------------------------------------------'); - scope.addImport(new SelectiveModuleImport(scope, './settings', ['Command'])); + scope.addImport(new SelectiveModuleImport(scope, './command', ['Command'])); scope.addImport(new SelectiveModuleImport(scope, './user-input', ['UserInput', 'GlobalOptions'])); const userInputType = Type.fromName(scope, 'UserInput'); diff --git a/tools/@aws-cdk/user-input-gen/test/convert-to-user-input-gen.test.ts b/tools/@aws-cdk/user-input-gen/test/convert-to-user-input-gen.test.ts index 6afc40e224592..f860985c10beb 100644 --- a/tools/@aws-cdk/user-input-gen/test/convert-to-user-input-gen.test.ts +++ b/tools/@aws-cdk/user-input-gen/test/convert-to-user-input-gen.test.ts @@ -49,7 +49,7 @@ describe('render', () => { // Do not edit by hand; all changes will be overwritten at build time from the config file. // ------------------------------------------------------------------------------------------- /* eslint-disable @stylistic/max-len */ - import { Command } from './settings'; + import { Command } from './command'; import { UserInput, GlobalOptions } from './user-input'; // @ts-ignore TS6133 diff --git a/tools/@aws-cdk/user-input-gen/test/user-input-gen.test.ts b/tools/@aws-cdk/user-input-gen/test/user-input-gen.test.ts index f88360f34f1d7..72253f935f3ce 100644 --- a/tools/@aws-cdk/user-input-gen/test/user-input-gen.test.ts +++ b/tools/@aws-cdk/user-input-gen/test/user-input-gen.test.ts @@ -49,7 +49,7 @@ describe('render', () => { // Do not edit by hand; all changes will be overwritten at build time from the config file. // ------------------------------------------------------------------------------------------- /* eslint-disable @stylistic/max-len */ - import { Command } from './settings'; + import { Command } from './command'; /** * The structure of the user input -- either CLI options or cdk.json -- generated from packages/aws-cdk/lib/config.ts @@ -158,7 +158,7 @@ describe('render', () => { // Do not edit by hand; all changes will be overwritten at build time from the config file. // ------------------------------------------------------------------------------------------- /* eslint-disable @stylistic/max-len */ - import { Command } from './settings'; + import { Command } from './command'; /** * The structure of the user input -- either CLI options or cdk.json -- generated from packages/aws-cdk/lib/config.ts @@ -240,7 +240,7 @@ describe('render', () => { // Do not edit by hand; all changes will be overwritten at build time from the config file. // ------------------------------------------------------------------------------------------- /* eslint-disable @stylistic/max-len */ - import { Command } from './settings'; + import { Command } from './command'; /** * The structure of the user input -- either CLI options or cdk.json -- generated from packages/aws-cdk/lib/config.ts From ecef343dd98b6647ba5ee7ba99380a50737f82f8 Mon Sep 17 00:00:00 2001 From: Kaizen Conroy Date: Fri, 10 Jan 2025 15:45:54 -0500 Subject: [PATCH 12/14] fixes the build --- packages/aws-cdk/lib/api/cxapp/exec.ts | 26 +++++++++++++++++--------- packages/aws-cdk/lib/cdk-toolkit.ts | 7 ++----- packages/aws-cdk/lib/cli.ts | 8 ++++---- packages/aws-cdk/lib/settings.ts | 16 ++++++++-------- 4 files changed, 31 insertions(+), 26 deletions(-) diff --git a/packages/aws-cdk/lib/api/cxapp/exec.ts b/packages/aws-cdk/lib/api/cxapp/exec.ts index 4a5ea9f55f3fd..aad74c640f502 100644 --- a/packages/aws-cdk/lib/api/cxapp/exec.ts +++ b/packages/aws-cdk/lib/api/cxapp/exec.ts @@ -224,23 +224,31 @@ export async function prepareContext(config: Configuration, env: { [key: string] } function setBundlingStacks(config: Configuration) { - let bundlingStacks: string[]; - if (config.command && [ + // Command may not exist if we are not executing a CLI command + if (!config.command) { + return []; + } + + const stackCommands = [ Command.DEPLOY, Command.DIFF, Command.SYNTH, Command.SYNTHESIZE, Command.WATCH, - ].includes(config.command)) { + ]; + + // command doesn't operate on a stack selection + if (!stackCommands.includes(config.command)) { + return []; + } + // If we deploy, diff, synth or watch a list of stacks exclusively we skip // bundling for all other stacks. - bundlingStacks = config.settings.get(['exclusively']) - ? config.settings.get(['STACKS']) ?? ['**'] - : ['**']; - } else { // Skip bundling for all stacks - bundlingStacks = []; + if (config.settings.get(['exclusively']) && config.settings.get(['STACKS'])) { + return config.settings.get(['STACKS']); } - return bundlingStacks; + + return ['**']; } /** diff --git a/packages/aws-cdk/lib/cdk-toolkit.ts b/packages/aws-cdk/lib/cdk-toolkit.ts index 4fe7a73b1220f..64fa955912e4d 100644 --- a/packages/aws-cdk/lib/cdk-toolkit.ts +++ b/packages/aws-cdk/lib/cdk-toolkit.ts @@ -1783,9 +1783,6 @@ export interface DestroyOptions { readonly ci?: boolean; } -export type ActionType = 'print' | 'tag' | 'delete-tagged' | 'full'; -export type TypeType = 's3' | 'ecr' | 'all'; - /** * Options for the garbage collection */ @@ -1795,14 +1792,14 @@ export interface GarbageCollectionOptions { * * @default 'full' */ - readonly action: ActionType; + readonly action: 'print' | 'tag' | 'delete-tagged' | 'full'; /** * The type of the assets to be garbage collected. * * @default 'all' */ - readonly type: TypeType; + readonly type: 's3' | 'ecr' | 'all'; /** * Elapsed time between an asset being marked as isolated and actually deleted. diff --git a/packages/aws-cdk/lib/cli.ts b/packages/aws-cdk/lib/cli.ts index ccbaa7255ec6b..d95e3544ab93c 100644 --- a/packages/aws-cdk/lib/cli.ts +++ b/packages/aws-cdk/lib/cli.ts @@ -17,7 +17,7 @@ import { execProgram } from '../lib/api/cxapp/exec'; import { Deployments } from '../lib/api/deployments'; import { PluginHost } from '../lib/api/plugin'; import { ToolkitInfo } from '../lib/api/toolkit-info'; -import { CdkToolkit, AssetBuildTime, ActionType, TypeType, Tag } from '../lib/cdk-toolkit'; +import { CdkToolkit, AssetBuildTime, Tag } from '../lib/cdk-toolkit'; import { contextHandler as context } from '../lib/commands/context'; import { docs } from '../lib/commands/docs'; import { doctor } from '../lib/commands/doctor'; @@ -85,7 +85,7 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise = {}) { + public constructor(args: UserInput = {}) { super(args); } @@ -395,7 +395,7 @@ export class ArgumentSettings extends Settings { return new ArgumentSettings(util.deepMerge(this.settings, other.settings)); } - public get all(): CliArguments { + public get all(): UserInput { return this.get([]); } } From ad76f1f3188328dda7cc99609e969b6c443dfb3a Mon Sep 17 00:00:00 2001 From: Kaizen Conroy Date: Mon, 13 Jan 2025 15:38:08 -0500 Subject: [PATCH 13/14] still builds, better refacotrs some places --- packages/aws-cdk/lib/api/cxapp/exec.ts | 20 ++++++++++---------- packages/aws-cdk/lib/cli.ts | 2 +- packages/aws-cdk/test/api/exec.test.ts | 2 +- packages/aws-cdk/test/usersettings.test.ts | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/aws-cdk/lib/api/cxapp/exec.ts b/packages/aws-cdk/lib/api/cxapp/exec.ts index aad74c640f502..0268e50d7f299 100644 --- a/packages/aws-cdk/lib/api/cxapp/exec.ts +++ b/packages/aws-cdk/lib/api/cxapp/exec.ts @@ -25,12 +25,12 @@ export async function execProgram(aws: SdkProvider, config: Configuration): Prom const env = await prepareDefaultEnvironment(aws); const context = await prepareContext(config, env); - const build = config.settings.get(['build']); + const build = config.settings.get(['globalOptions', 'build']); if (build) { await exec(build); } - const app = config.settings.get(['app']); + const app = config.settings.get(['globalOptions', 'app']); if (!app) { throw new ToolkitError(`--app is required either in command-line, in ${PROJECT_CONFIG} or in ${USER_DEFAULTS}`); } @@ -47,7 +47,7 @@ export async function execProgram(aws: SdkProvider, config: Configuration): Prom const commandLine = await guessExecutable(appToArray(app)); - const outdir = config.settings.get(['output']); + const outdir = config.settings.get(['globalOptions', 'output']); if (!outdir) { throw new ToolkitError('unexpected: --output is required'); } @@ -190,27 +190,27 @@ export async function prepareDefaultEnvironment(aws: SdkProvider): Promise<{ [ke export async function prepareContext(config: Configuration, env: { [key: string]: string | undefined}) { const context = config.context.all; - const debugMode: boolean = config.settings.get(['debug']) ?? true; + const debugMode: boolean = config.settings.get(['globalOptions', 'debug']) ?? true; if (debugMode) { env.CDK_DEBUG = 'true'; } - const pathMetadata: boolean = config.settings.get(['pathMetadata']) ?? true; + const pathMetadata: boolean = config.settings.get(['globalOptions', 'pathMetadata']) ?? true; if (pathMetadata) { context[cxapi.PATH_METADATA_ENABLE_CONTEXT] = true; } - const assetMetadata: boolean = config.settings.get(['assetMetadata']) ?? true; + const assetMetadata: boolean = config.settings.get(['globalOptions', 'assetMetadata']) ?? true; if (assetMetadata) { context[cxapi.ASSET_RESOURCE_METADATA_ENABLED_CONTEXT] = true; } - const versionReporting: boolean = config.settings.get(['versionReporting']) ?? true; + const versionReporting: boolean = config.settings.get(['globalOptions', 'versionReporting']) ?? true; if (versionReporting) { context[cxapi.ANALYTICS_REPORTING_ENABLED_CONTEXT] = true; } // We need to keep on doing this for framework version from before this flag was deprecated. if (!versionReporting) { context['aws:cdk:disable-version-reporting'] = true; } - const stagingEnabled = config.settings.get(['staging']) ?? true; + const stagingEnabled = config.settings.get(['globalOptions', 'staging']) ?? true; if (!stagingEnabled) { context[cxapi.DISABLE_ASSET_STAGING_CONTEXT] = true; } @@ -244,8 +244,8 @@ function setBundlingStacks(config: Configuration) { // If we deploy, diff, synth or watch a list of stacks exclusively we skip // bundling for all other stacks. - if (config.settings.get(['exclusively']) && config.settings.get(['STACKS'])) { - return config.settings.get(['STACKS']); + if (config.settings.get(['globalOptions', 'exclusively']) && config.settings.get([config.command, 'STACKS'])) { + return config.settings.get([config.command, 'STACKS']); } return ['**']; diff --git a/packages/aws-cdk/lib/cli.ts b/packages/aws-cdk/lib/cli.ts index d95e3544ab93c..748b752688f5c 100644 --- a/packages/aws-cdk/lib/cli.ts +++ b/packages/aws-cdk/lib/cli.ts @@ -177,7 +177,7 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise { - const toolkitStackName: string = ToolkitInfo.determineName(settings.bootstrap?.toolkitStackName); // TODO, mroe than bootstrap has toolkitstackname + const toolkitStackName: string = ToolkitInfo.determineName(configuration.settings.get([command, 'toolkitStackName'])); debug(`Toolkit stack: ${chalk.bold(toolkitStackName)}`); const globalOptions = settings.globalOptions ?? {}; diff --git a/packages/aws-cdk/test/api/exec.test.ts b/packages/aws-cdk/test/api/exec.test.ts index e67403dbb7680..8779dd2846595 100644 --- a/packages/aws-cdk/test/api/exec.test.ts +++ b/packages/aws-cdk/test/api/exec.test.ts @@ -261,7 +261,7 @@ test('cli releases the outdir lock when execProgram throws', async () => { // WHEN await expect(execProgram(sdkProvider, config)).rejects.toThrow(); - const output = config.settings.get(['output']); + const output = config.settings.get(['globalOptions', 'output']); expect(output).toBeDefined(); // check that the lock is released diff --git a/packages/aws-cdk/test/usersettings.test.ts b/packages/aws-cdk/test/usersettings.test.ts index 6f5e0fb4fb642..2113f0e749aa9 100644 --- a/packages/aws-cdk/test/usersettings.test.ts +++ b/packages/aws-cdk/test/usersettings.test.ts @@ -110,5 +110,5 @@ test('Can specify the `quiet` key in the user config', async () => { // THEN const config = await new Configuration().load(); - expect(config.settings.get(['quiet'])).toBe(true); + expect(config.settings.get(['globalOptions', 'quiet'])).toBe(true); }); From 03fe7d6eb2ba4e7811332ef18397cc11a740a115 Mon Sep 17 00:00:00 2001 From: Kaizen Conroy Date: Mon, 13 Jan 2025 16:00:01 -0500 Subject: [PATCH 14/14] more updates --- .../aws-cdk/lib/api/cxapp/cloud-executable.ts | 4 +-- packages/aws-cdk/lib/cdk-toolkit.ts | 2 +- packages/aws-cdk/lib/cli.ts | 28 +++++++++---------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/aws-cdk/lib/api/cxapp/cloud-executable.ts b/packages/aws-cdk/lib/api/cxapp/cloud-executable.ts index 5c0f1a2c2a289..7a26d7e253830 100644 --- a/packages/aws-cdk/lib/api/cxapp/cloud-executable.ts +++ b/packages/aws-cdk/lib/api/cxapp/cloud-executable.ts @@ -41,7 +41,7 @@ export class CloudExecutable { * Return whether there is an app command from the configuration */ public get hasApp() { - return !!this.props.configuration.settings.get(['app']); + return !!this.props.configuration.settings.get(['globalOptions', 'app']); } /** @@ -106,7 +106,7 @@ export class CloudExecutable { } private get canLookup() { - return !!(this.props.configuration.settings.get(['lookups']) ?? true); + return !!(this.props.configuration.settings.get(['globalOptions', 'lookups']) ?? true); } } diff --git a/packages/aws-cdk/lib/cdk-toolkit.ts b/packages/aws-cdk/lib/cdk-toolkit.ts index 64fa955912e4d..653d8244b6231 100644 --- a/packages/aws-cdk/lib/cdk-toolkit.ts +++ b/packages/aws-cdk/lib/cdk-toolkit.ts @@ -643,7 +643,7 @@ export class CdkToolkit { // 2. Any file whose name starts with a dot. // 3. Any directory's content whose name starts with a dot. // 4. Any node_modules and its content (even if it's not a JS/TS project, you might be using a local aws-cli package) - const outputDir = this.props.configuration.settings.get(['output']); + const outputDir = this.props.configuration.settings.get(['globalOptions', 'output']); const watchExcludes = this.patternsArrayForWatch(watchSettings.exclude, { rootDir, returnRootDirIfEmpty: false, diff --git a/packages/aws-cdk/lib/cli.ts b/packages/aws-cdk/lib/cli.ts index 748b752688f5c..8ca15a871a064 100644 --- a/packages/aws-cdk/lib/cli.ts +++ b/packages/aws-cdk/lib/cli.ts @@ -89,18 +89,18 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise