-
Notifications
You must be signed in to change notification settings - Fork 4.3k
feat(cli): added build field to cdk.json
#17176
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
Conversation
build field to cdk.jsonbuild field to cdk.json
skinny85
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.
Looks good! Some minor details.
Can you also add a PR description stating what is this change accomplishing, and why is it being added?
|
@eladb can you also take a look? Thanks! |
|
|
||
| const build = config.settings.get(['build']); | ||
| if (build) { | ||
| await exec([build]); |
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.
What happens if "build" is set to something like "mvn package"? How does this split into program and args?
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.
exec() now splits its argument into command and args before spawning the process.
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.
Seems like exec() treats the first item in the array as the command but this is not true in the case I described above.
Can you add a test to verify ?
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.
You're right, the split doesn't happen in the case of the build key. It winds up working because the whole command just get put into command and spawn() happily accepts it.
| // user gets to see it sooner. Plus, capturing doesn't interact nicely with some | ||
| // processes like Maven. | ||
| const proc = childProcess.spawn(commandLine[0], commandLine.slice(1), { | ||
| const command = commandAndArgs[0]; |
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.
What happens if commandAndArgs[0] is mvn package
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 think we just need to accept a single string and pass it down to spawn(). Since you use shell:true this should just work without splitting to arguments imho
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 need to split the arguments because of the other usage of exec(), namely this line:
await exec(commandLine);
commandLine is defined by
const commandLine = await guessExecutable(appToArray(app));
guessExecutable() needs a string[], not a string. Do you want me to rework this so that we don't need to have any string[]s passed to exec(), and instead make exec() take just a string? exec() previously operated on a string[].
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.
@eladb if commandAndArgs[0] is mvn package then spawn() will still correctly start the process.
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.
Seems a bit messy but if this works as is i am okay with that
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.
@eladb just made this cleaner, now mvn package will be split into ["mvn", "package"] instead of the previous ["mvn package"]. Would appreciate another pass on the PR!
| } | ||
|
|
||
| const commandLine = await guessExecutable(appToArray(app)); | ||
| const commandLine = await guessExecutable(commandToArray(app)); |
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.
Not sure this is better TBH...
What happens if the command has quotes in it?
For example "mvn package"?
Bottom line, I think we should simply spawn this command without splitting it into arguments and with shell:true. There's a variant of spawn I believe that just accepts a single string and passes it to the shell.
There are also intricacies related to Windows/POSIX here that can blow up in 5,000 ways, so I rather we avoid any parsing of the command line if possible.
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.
@eladb just to be clear - you also want to change how we handle the "app" key, right? And no longer do any splitting there?
skinny85
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.
One small comment.
eladb
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.
Looks good
|
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
|
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Adds a `build` field to `cdk.json`. The command specified in the `build` will be executed before synthesis. This can be used to build any code that needs to be built before synthesis (for example, CDK App code or Lambda Function code). This is part of the changes needed for the `cdk watch` command (aws/aws-cdk-rfcs#383). ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Adds a
buildfield tocdk.json. The command specified in thebuildwill be executed before synthesis. This can be used to build any code that needs to be built before synthesis (for example, CDK App code or Lambda Function code).This is part of the changes needed for the
cdk watchcommand(aws/aws-cdk-rfcs#383).
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license