Skip to content
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

feat: subprojects #332

Merged
merged 4 commits into from
Nov 24, 2020
Merged

feat: subprojects #332

merged 4 commits into from
Nov 24, 2020

Conversation

eladb
Copy link
Contributor

@eladb eladb commented Nov 23, 2020

Introduce an optional parent option to Project and outdir to allow implementing project trees.

The CompositeProject approach which was introduced in #289 has a limitation in which projects could not query who is their parent (because potentially a child can be added at any time). Also, it technically allowed the same child project to be added to multiple parents. Therefore, these classes are no longer available.

This change also moves outdir from the various synth() methods to ProjectOptions.

This early-binding approach is also more in-line with how CDK code is written, whereas during initialization it is possible to reason about the full synthesis context.

Additional APIs introduced in this change are project.files and project.findFile(path) which can be used to inspect the project's contents. findFile() can find files in projects and subprojects.

BREAKING CHANGE: The CompositeProject and ProjectComponent classes have been superseded by subprojects in order to allow safely accessing the parent project during subproject initialization phase. Use new Project({ parent, outdir }) to define this relationship.

  • The various synth() methods no longer accept an outdir. Instead, specify outdir in the project options.

Introduce an optional `parent` option to `Project` and `outdir` to allow implementing project trees.

The `CompositeProject` approach has a limitation in which projects could not query who is their parent (because potentially a child can be added at any time). Also, it technically allowed the same child project to be added to multiple parents.

This change also moves `outdir` from the various `synth()` methods to `ProjectOptions`.

This early-binding approach is also more in-line with how CDK code is written, whereas during initialization it is possible to reason about the full synthesis context.

BREAKING CHANGE: The `CompositeProject` and `ProjectComponent` classes have been superseded by subprojects in order to allow safely accessing the parent project during subproject initialization phase. Use `new Project({ parent, outdir })` to define this relationship.
* The various `synth()` methods no longer accept an `outdir`. Instead, specify `outdir` in the project options.
@eladb eladb requested a review from Chriscbr November 23, 2020 21:53
@eladb
Copy link
Contributor Author

eladb commented Nov 23, 2020

@misterjoshua would love to hear what you think about this. I've decided that CompositeProject has some issues and want to model subproject relationships in a more "CDK-idiomatic" way.

Copy link
Contributor

@misterjoshua misterjoshua left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eladb I love the structural approach you've taken here.

As-is, the code satisfies my original use case. I have left a few comments in the review - nothing too serious. :)

While reviewing, I was thinking that this approach opens up a future where a component in the root project could visit (like CDK aspects) all composed projects. Such a component might collect things like CI-agnostic build and test commands. At synth time, such a component could pop them in a github workflow, bitbucket pipeline, circle config, or whatever.

src/project.ts Show resolved Hide resolved
src/project.ts Show resolved Hide resolved
src/project.ts Show resolved Hide resolved
Copy link
Contributor

@Chriscbr Chriscbr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Echoing @misterjoshua 's comments, this looks good! 👍

Also if you could confirm that the projen CLI doesn't error when you run it in the root directory of a folder with nested projects (to avoid bringing back a bug like #323) that would be great. I believe the current behavior for node projects is that running yarn projen in a given directory will print out all of the commands for that project, as well as commands for any of its subprojects.

src/project.ts Outdated Show resolved Hide resolved
src/project.ts Show resolved Hide resolved
Also ensure that files do not override each other globally.
@eladb
Copy link
Contributor Author

eladb commented Nov 24, 2020

Also if you could confirm that the projen CLI doesn't error when you run it in the root directory of a folder with nested projects

Verified @Chriscbr

@eladb eladb merged commit 53244ae into master Nov 24, 2020
@eladb eladb deleted the benisrae/subprojects branch November 24, 2020 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants