ionide / Fornax

Scriptable static site generator using type safe F# DSL to define page templates.
MIT License
244 stars 44 forks source link

SiteContents not being persisted to the generator? #76

Closed absolutejam closed 3 years ago

absolutejam commented 3 years ago

Describe the bug

First off, sorry if this isn't the correct place for this. I have a strong feeling it's more PICNIC than an actual bug, but perhaps shedding a bit of light on this might be valuable for anyone in the same position. I also tried casting my hook into the Slack, but didn't get any bites.

I've restructured the basic example a little and was just toying with Fornax generally, but I'm finding that whatever I put in to my SiteContents within my loaders is not then available in my generators. I'm not sure if I'm missing something super basic, but I was hoping I could get a little bit of guidance. If it's something that perhaps needs clearing up in the docs for clueless people like me, I'm happy to help with that.

I've tried a number of dfferent types, and I've also been able to confirm that the record goes in to the DI container (as I can get it back out within the loader), but once I come to the generator stage, I can't seem to retrieve them. I know it's something obvious I'm missing...

I've created a dump of the repo I was working on here here.

To Reproduce Steps to reproduce the behaviour:

  1. Clone the example
  2. fornax watch
  3. Observe the exception that the Site record couldn't be pulled from the DI container, despite being added in the globalloader.fsx

Environment (please complete the following information):

drewknab commented 3 years ago

----------EDIT---------- I see, looks like I was wrong.

FTR the error I was getting on fornax watch is:

`An unexpected error happend: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.

---> System.Exception: Could not get FSI_0016.Types+Site at FSI_0016.Helpers.SiteContents.GetValue[t](SiteContents X1) at FSI_0016.Post.generate(SiteContents ctx, String projectRoot, String page) --- End of inner exception stack trace ---.`

absolutejam commented 3 years ago

Sorry, I'm not sure why I didn't include the stack trace originally 🤦

Is it possible to add break points to Fornax, or would I have to clone, build and run it like that?

Krzysztof-Cieslak commented 3 years ago

Ok, this is tricky. Basically, as far as I understand, the issue is a result of including types.fsx file multiple times - it's included in every loader and every generator (through includes.fsx file). Every time you include types.fsx file new Site record type is defined and as a result, those are actually different types (if you'd inspect all that through reflection you'd notice the fully qualified names of types are different).

The solution to that is to include types.fsx file normally only once (just in globalloader.fsx for example), and for all other files it needs to be added in #if !FORNAX section - this will "power" editor tooling but won't be actually evaluated in underlying F# Interactive session that Fornax creates.

absolutejam commented 3 years ago

Thanks for looking at this @Krzysztof-Cieslak!

I'll have a look at doing that and see where I get with it. Now I understand the use of the #if !FORNAX directive too, awesome.