-
Notifications
You must be signed in to change notification settings - Fork 62
feat(cli): add package manager option to cdk init #961
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(cli): add package manager option to cdk init #961
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #961 +/- ##
==========================================
+ Coverage 87.38% 87.40% +0.02%
==========================================
Files 71 72 +1
Lines 10010 10036 +26
Branches 1311 1314 +3
==========================================
+ Hits 8747 8772 +25
Misses 1240 1240
- Partials 23 24 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…nto feat(init)/support-package-manager-option
mrgrain
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, few notes.
| /** | ||
| * The package manager to use to install dependencies. Only applicable for TypeScript and JavaScript projects. | ||
| * | ||
| * @default - undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of undefined describe what it does
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This JSDoc is auto generated during the build process, and as mentioned in #961 (comment) comments, I think difficult to change this @default comment because package-manager option can't set default value.
…nto feat(init)/support-package-manager-option
ren-yamanashi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks review! I fixed.
| /** | ||
| * The package manager to use to install dependencies. Only applicable for TypeScript and JavaScript projects. | ||
| * | ||
| * @default - undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mrgrain
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
almost there!
| 'from-path': { type: 'string', desc: 'Path to a local custom template directory or multi-template repository', requiresArg: true, conflicts: ['lib-version'] }, | ||
| 'template-path': { type: 'string', desc: 'Path to a specific template within a multi-template repository', requiresArg: true }, | ||
| 'package-manager': { type: 'string', desc: 'The package manager to use to install dependencies. Only applicable for TypeScript and JavaScript projects.', choices: JS_PACKAGE_MANAGERS }, | ||
| 'package-manager': { type: 'string', desc: 'The package manager to use to install dependencies. Only applicable for TypeScript and JavaScript projects.', default: JS_PACKAGE_MANAGER.NPM, choices: Object.values(JS_PACKAGE_MANAGER) }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can't add a default here, this will now always cause a warning for other languages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| await withTempDir(async (workDir) => { | ||
| const warnSpy = jest.spyOn(ioHelper.defaults, 'warn'); | ||
|
|
||
| await cliInit({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm aware there's no infrastructure yet for this in this test file, but can we make this an end-to-end test of the CLI please, instead of testing just cliInit. Same for the other one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed some test cases. deedd00
I'm aware there's no infrastructure yet for this in this test file
I referred to test that was already implemented as an E2E test.
aws-cdk-cli/packages/aws-cdk/test/commands/init.test.ts
Lines 732 to 746 in deedd00
| cliTest('conflict between lib-version and from-path is enforced', async (workDir) => { | |
| const { exec } = await import('child_process'); | |
| const { promisify } = await import('util'); | |
| const execAsync = promisify(exec); | |
| const templateDir = await createSingleLanguageTemplate(workDir, 'conflict-test', 'typescript'); | |
| const cdkBin = path.join(__dirname, '..', '..', 'bin', 'cdk'); | |
| // Test that using both flags together causes an error | |
| await expect(execAsync(`node ${cdkBin} init app --language typescript --lib-version 2.0.0 --from-path ${templateDir} --generate-only`, { | |
| cwd: workDir, | |
| env: { ...process.env, CDK_DISABLE_VERSION_CHECK: '1' }, | |
| })).rejects.toThrow(); | |
| }); |
Same for the other one.
Would you suggesting that test cases within describe('package-manager option' should also be made into e2e tests? Or suggesting that all test cases within describe('validate CLI init options' should be made into e2e tests?
I suspect it's latter, so I've implemented it that way (please comment if I'm mistaken).
ren-yamanashi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed! Please confirm.
| 'from-path': { type: 'string', desc: 'Path to a local custom template directory or multi-template repository', requiresArg: true, conflicts: ['lib-version'] }, | ||
| 'template-path': { type: 'string', desc: 'Path to a specific template within a multi-template repository', requiresArg: true }, | ||
| 'package-manager': { type: 'string', desc: 'The package manager to use to install dependencies. Only applicable for TypeScript and JavaScript projects.', choices: JS_PACKAGE_MANAGERS }, | ||
| 'package-manager': { type: 'string', desc: 'The package manager to use to install dependencies. Only applicable for TypeScript and JavaScript projects.', default: JS_PACKAGE_MANAGER.NPM, choices: Object.values(JS_PACKAGE_MANAGER) }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /** | ||
| * The package manager to use to install dependencies. Only applicable for TypeScript and JavaScript projects. | ||
| * | ||
| * @default - undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This JSDoc is auto generated during the build process, and as mentioned in #961 (comment) comments, I think difficult to change this @default comment because package-manager option can't set default value.
| await withTempDir(async (workDir) => { | ||
| const warnSpy = jest.spyOn(ioHelper.defaults, 'warn'); | ||
|
|
||
| await cliInit({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed some test cases. deedd00
I'm aware there's no infrastructure yet for this in this test file
I referred to test that was already implemented as an E2E test.
aws-cdk-cli/packages/aws-cdk/test/commands/init.test.ts
Lines 732 to 746 in deedd00
| cliTest('conflict between lib-version and from-path is enforced', async (workDir) => { | |
| const { exec } = await import('child_process'); | |
| const { promisify } = await import('util'); | |
| const execAsync = promisify(exec); | |
| const templateDir = await createSingleLanguageTemplate(workDir, 'conflict-test', 'typescript'); | |
| const cdkBin = path.join(__dirname, '..', '..', 'bin', 'cdk'); | |
| // Test that using both flags together causes an error | |
| await expect(execAsync(`node ${cdkBin} init app --language typescript --lib-version 2.0.0 --from-path ${templateDir} --generate-only`, { | |
| cwd: workDir, | |
| env: { ...process.env, CDK_DISABLE_VERSION_CHECK: '1' }, | |
| })).rejects.toThrow(); | |
| }); |
Same for the other one.
Would you suggesting that test cases within describe('package-manager option' should also be made into e2e tests? Or suggesting that all test cases within describe('validate CLI init options' should be made into e2e tests?
I suspect it's latter, so I've implemented it that way (please comment if I'm mistaken).
Fixes #940
Adds
--package-manageroption tocdk initfor choosing npm, yarn, or pnpm when initializing TypeScript/JavaScript projects.Usage
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license