From 8f31a2293a56ec3c545d5e824592356ffcc6378e Mon Sep 17 00:00:00 2001 From: Awesome YAMAUCHI Date: Fri, 19 Jun 2026 00:50:39 +0900 Subject: [PATCH 1/2] fix(aws-cdk): correct project-name argument mapping in cdk init The --project-name (-n) option for `cdk init` was silently ignored because the legacy code path in cli.ts referenced `args.name` (a non-existent property) instead of `args.projectName`. Yargs automatically converts the kebab-case option `--project-name` to `args.projectName` via camelCase conversion, but the mapping incorrectly used `args.name`, causing the value to always be undefined and falling back to the directory name. Also fixes the test description that incorrectly referred to the option as `--name` instead of `--project-name`. --- packages/aws-cdk/lib/cli/cli.ts | 2 +- packages/aws-cdk/test/cli/cli-arguments.test.ts | 15 +++++++++++++++ packages/aws-cdk/test/commands/init.test.ts | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/aws-cdk/lib/cli/cli.ts b/packages/aws-cdk/lib/cli/cli.ts index 6966f1420..58867c496 100644 --- a/packages/aws-cdk/lib/cli/cli.ts +++ b/packages/aws-cdk/lib/cli/cli.ts @@ -642,7 +642,7 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise { globalOptions: expect.anything(), }); }); + + test('init --project-name is correctly passed through', async () => { + const input = await parseCommandLineArguments(['init', 'app', '--language', 'typescript', '--project-name', 'my-app']); + + const result = convertYargsToUserInput(input); + + expect(result).toEqual({ + command: 'init', + init: expect.objectContaining({ + projectName: 'my-app', + TEMPLATE: 'app', + }), + globalOptions: expect.anything(), + }); + }); }); describe('config', () => { diff --git a/packages/aws-cdk/test/commands/init.test.ts b/packages/aws-cdk/test/commands/init.test.ts index 93b51ede4..37b9a08bf 100644 --- a/packages/aws-cdk/test/commands/init.test.ts +++ b/packages/aws-cdk/test/commands/init.test.ts @@ -65,7 +65,7 @@ describe('constructs version', () => { expect(Object.entries(pj.devDependencies)).toContainEqual(['aws-cdk-lib', '2.100']); }); - cliTest('can specify project name with --name option', async (workDir) => { + cliTest('can specify project name with --project-name option', async (workDir) => { await cliInit({ ioHelper, type: 'app', From 3dc752f4b2146f357c9d6102062bde6d00f8b203 Mon Sep 17 00:00:00 2001 From: Awesome YAMAUCHI Date: Fri, 19 Jun 2026 08:20:55 +0900 Subject: [PATCH 2/2] test(aws-cdk): add CLI command test for cdk init --project-name Adds a test that runs `cdk init` with `--project-name` and asserts that the generated package name and stack class name are correctly updated. This ensures the parsed project name actually reaches the init command handler. --- packages/aws-cdk/test/commands/init.test.ts | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/aws-cdk/test/commands/init.test.ts b/packages/aws-cdk/test/commands/init.test.ts index 37b9a08bf..982dc18fa 100644 --- a/packages/aws-cdk/test/commands/init.test.ts +++ b/packages/aws-cdk/test/commands/init.test.ts @@ -78,6 +78,28 @@ describe('constructs version', () => { expect(stackFile).toContain('export class MyProjectStack'); }); + cliTest('can specify project name with project-name option via CLI', async (workDir) => { + const { exec } = await import('child_process'); + const { promisify } = await import('util'); + const execAsync = promisify(exec); + const cdkBin = path.join(__dirname, '..', '..', 'bin', 'cdk'); + + const commonEnv = { ...process.env, CDK_DISABLE_VERSION_CHECK: '1', CI: 'true', TERM: 'dumb', NO_COLOR: '1' }; + const execOptions = { timeout: 30_000, killSignal: 9 }; + + await execAsync(`node ${cdkBin} init app --language typescript --project-name awesome-app --generate-only`, { + cwd: workDir, + env: commonEnv, + ...execOptions, + }); + + const stackFile = await fs.readFile(path.join(workDir, 'lib', 'awesome-app-stack.ts'), 'utf-8'); + expect(stackFile).toContain('export class AwesomeAppStack'); + + const packageJson = await fs.readJson(path.join(workDir, 'package.json')); + expect(packageJson.name).toEqual('awesome-app'); + }); + cliTest('asking for a nonexistent template fails', async (workDir) => { await expect(cliInit({ ioHelper,