fix(aws-cdk): correct project-name argument mapping in cdk init#1644
Conversation
sai-ray
left a comment
There was a problem hiding this comment.
Hey @TORIFUKUKaiou, nice catch and thanks for fixing this! It's been silently doing nothing since it was added, the handler was reading the wrong property, so it always fell back to the folder name.
One thing: we'll need a test that actually runs the command with option and confirms the name comes through, so this can't quietly break again.
Head branch was pushed to by a user without write access
|
Could you also update your branch with the latest main before we run CI? It's a bit behind, and I'd like CI to run against the current base. Thanks! |
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`.
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.
bf6c35f to
3dc752f
Compare
|
Done! I've rebased my branch with the latest main and pushed the updates. The branch is now up to date with the current base. Thanks! |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1644 +/- ##
==========================================
+ Coverage 88.78% 88.80% +0.01%
==========================================
Files 77 77
Lines 11354 11354
Branches 1584 1584
==========================================
+ Hits 10081 10083 +2
+ Misses 1243 1241 -2
Partials 30 30
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The
--project-name(-n) option forcdk initwas silently ignored because the legacy code path incli.tsreferencedargs.name(a non-existent property) instead ofargs.projectName.Yargs automatically converts the kebab-case option
--project-nametoargs.projectNamevia camelCase conversion, but the mapping incorrectly usedargs.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
--nameinstead of--project-name.Fixes aws/aws-cdk#31992
Validation
I verified the fix locally in the devcontainer environment by running the modified CLI and comparing the outputs.
Verify
yargsargument parsing:Added a new unit test in
packages/aws-cdk/test/cli/cli-arguments.test.tsto verify that the--project-nameoption correctly maps to theprojectNameproperty in the config.Verify generated project structure and files:
I generated two projects with the same target project name (
awesome-app)—one by relying on the default fallback (directory name) and the other by explicitly specifying--project-name:Result:
The
diffcommand yielded no differences, confirming that--project-name awesome-appwas correctly respected and generated identical files (includingpackage.json, stack file names, and class names insidelib/andbin/) regardless of the directory name.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license