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

Docs: how to mixin from local file? #174

Closed
bestickley opened this issue Dec 11, 2023 · 12 comments
Closed

Docs: how to mixin from local file? #174

bestickley opened this issue Dec 11, 2023 · 12 comments

Comments

@bestickley
Copy link

Hi, thanks so much for this library! Has really helped cdk-nextjs offer a flexible/customizable L3 construct to deploy Next.js on AWS.

Given the example from the docs:

new ProjenStruct(project, { name: 'MyProjectOptions' })
  .mixin(Struct.fromFqn('projen.typescript.TypeScriptProjectOptions'))
  .omit('sampleCode', 'projenrcTs', 'projenrcTsOptions');

How could I adjust this example to create a new interface from a local file like:

new ProjenStruct(project, { name: 'MyProjectOptions' })
  .mixin(Struct.fromLocal('./my/file/path/TypeScriptProjectOptions.ts'))
  .omit('sampleCode', 'projenrcTs', 'projenrcTsOptions');
@mrgrain
Copy link
Owner

mrgrain commented Dec 11, 2023

Thanks for the kind words @bestickley I'm glad it is helping!

Regarding your suggestion, I'm not sure that's possible. jsii-struct-builder is using a jsii assembly for reflection on existing interfaces. What you are suggesting is pointing to a raw TS file that could contain anything! Even if we assume that it's just an interface, we would now need to reflect on it and that's kind-of difficult. At least not something I would want to implement in this package. Maybe there are existing tools that can provide this?

Taking one step back, may I ask what you are trying to achieve with it?

@bestickley
Copy link
Author

@mrgrain, ah I see. I didn't know this package relied on jsii assembly for reflection of existing interfaces. In cdk-nextjs project linked above, I'm exposing an overrides property on the props of the main construct: Nextjs. I'm using this package to create optional interfaces for CDK Prop types used like FunctionProps, DistributionProps etc so we don't have to use any. I'd also like to offer overrides for constructs created locally in this package like NextjsBucketDeployment which is is used in NextjsServer and NextjsStaticAssets. I didn't think I could use Struct.fromFqn to reference that construct so that's why I created this issue.

@mrgrain
Copy link
Owner

mrgrain commented Dec 11, 2023

Hm, I see. So something you actually can do, is reference a FQN from the local assembly. E.g.: Struct.fromFqn('cdk-nextjs.NextjsBucketDeployment'). Only thing to consider is that there's a bootstrapping issue because you need the local .jsii to be already available. 🤔

@bestickley
Copy link
Author

Oh I see. I thought Struct.fromFqn looked in node_modules so that wouldn't work. Yes, I would have a circular dependency issue :/

@bestickley
Copy link
Author

Whoops, didn't mean to close.

@mrgrain
Copy link
Owner

mrgrain commented Dec 11, 2023

I thought Struct.fromFqn looked in node_modules so that wouldn't work

Haha yeah. I only implemented that recently: #159

@bestickley
Copy link
Author

Haha, well I appreciate you implementing that! Any ideas on how to get around bootstrap issue?

@mrgrain
Copy link
Owner

mrgrain commented Dec 11, 2023

Any ideas on how to get around bootstrap issue?

You will have to run projen compile first, which unlike projen build doesn't do a projen default at the start.

@mrgrain
Copy link
Owner

mrgrain commented Dec 11, 2023

Otherwise you could define all your interfaces (even the completely new ones) with jsii-struct-builder. That is possibly a bit annoying & manual, but would give you a single source of truth.

@bestickley
Copy link
Author

@mrgrain, I think I'll try to modify the GitHub action to run projen compile first instead of just running projen build. Is there a simple or documented way to do that?

Here is an example of our GitHub Action (failing because I need to run projen compile first): https://github.com/jetbridge/cdk-nextjs/actions/runs/7171276028/job/19525876169?pr=181

@mrgrain
Copy link
Owner

mrgrain commented Dec 11, 2023

Not this specifically, but I reckon you could patch the workflow files directly using the low level API:

https://projen.io/escape-hatches.html#object-file-patches

@bestickley
Copy link
Author

Worked perfectly. Thanks so much, @mrgrain!

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

No branches or pull requests

2 participants