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: introduce CompositeProject #289

Merged
merged 15 commits into from
Nov 11, 2020
Merged

Conversation

misterjoshua
Copy link
Contributor

@misterjoshua misterjoshua commented Nov 8, 2020

Introduces a CompositeProject type that allows multiple projects to be added with a relative directory and synthesized into a single tree.

const comp = new CompositeProject();
comp.addProject('packages/foo', new NodeProject(...));
comp.addProject('packages/bar', new NextjsProject(...));

comp.synth();

See also #284

@misterjoshua misterjoshua marked this pull request as draft November 8, 2020 22:42
@misterjoshua
Copy link
Contributor Author

@eladb @hoegertn Fresh PR for CompositeProject here.

src/composite-project.ts Outdated Show resolved Hide resolved
src/composite-project.ts Outdated Show resolved Hide resolved
src/composite-project.ts Outdated Show resolved Hide resolved
src/composite-project.ts Outdated Show resolved Hide resolved
src/composite-project.ts Outdated Show resolved Hide resolved
export class SubProjectComponent extends Component {
constructor(project: Project, private readonly options: SubProjectComponentOptions) {
super(project);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we could also offer access to the parent root then for .github stuff etc

@hoegertn I was thinking that there's a design decision to be made about how a project can know the parent root so that it knows the right place to put the .github stuff. Given that a sub-project is instantiated before it knows that it's a sub-project, it seems to me that there's a need to inform the sub-project of that. I could call back to the project to inform it here, for instance.

@misterjoshua misterjoshua marked this pull request as ready for review November 9, 2020 03:28
@misterjoshua
Copy link
Contributor Author

I'm starting to wonder if I like ProjectComponent more than everything else I've written here. 🤣 Well anyway, I'll leave this now for your guys' review.

Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

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

Looks promising!

src/composite-project.ts Outdated Show resolved Hide resolved
src/composite-project.ts Outdated Show resolved Hide resolved
@misterjoshua misterjoshua requested a review from eladb November 10, 2020 15:58
Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

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

Please add composite-project.ts to index.ts

src/composite-project.ts Show resolved Hide resolved
* ]
* ```
*/
projects?: CompositeProjectChild[];
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
projects?: CompositeProjectChild[];
readonly projects?: CompositeProjectChild[];

@misterjoshua misterjoshua requested a review from eladb November 10, 2020 22:16
src/composite-project.ts Outdated Show resolved Hide resolved
src/composite-project.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

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

A couple of minor tweaks and we are ready

misterjoshua and others added 2 commits November 11, 2020 11:28
@misterjoshua
Copy link
Contributor Author

A couple of minor tweaks and we are ready

@eladb Cool. The changes you requested are in now.

@mergify mergify bot merged commit d606b3d into projen:master Nov 11, 2020
@misterjoshua misterjoshua deleted the f-composite branch November 11, 2020 18:55
@misterjoshua
Copy link
Contributor Author

misterjoshua commented Nov 11, 2020

@eladb It looks like the build broke in master because after a version bump, NodeProject is looking for the not-yet-released projen version in npm during the tests. I'll see if I can figure out how to work around this.

mergify bot pushed a commit that referenced this pull request Nov 11, 2020
… bump (#300)

This should fix the build in master when bumping versions after #289. `NodeProject` in the tests wanted to pull the not-yet-released projen packages after the bump. This fix addresses the issue by changing the tests not to depend on any project type that needs to know Projen's version.
@eladb eladb mentioned this pull request Nov 23, 2020
eladb pushed a commit that referenced this pull request Nov 24, 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.
@resistdesign
Copy link

Am I allowed to cheer for a PR? 😛 🎉

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.

5 participants