mattpocock / xstate-codegen

A codegen tool for 100% TS type-safety in XState
MIT License
245 stars 12 forks source link

Publishing package with generated types #62

Open Silverwolf90 opened 3 years ago

Silverwolf90 commented 3 years ago

How would one go about publishing a compiled machine w/ generated types to npm (ie: can be consumed by js or ts)?

I see that there's an --outDir parameter but not obvious how to me how to use this as part of a publish script. The consumer of the package might also have machines (w/ generated types) as well. Basically, curious what the workflow is if you've got your machines distributed across multiple packages.

danielkcz commented 3 years ago

I think this use case was never thought of. In theory, it could work if you set up postinstall script for your package and let it generate types there.

But it will be a problem in case of multiple packages generating this since all will be writing to @xstate/compiled. You would need to utilize --outDir to have a different output directory per package and import from that within the package instead of @xstate/compiled.

Silverwolf90 commented 3 years ago

Good to know, makes sense why I got nowhere with this 😅

Feels like this is a use-case that should be pretty streamlined-- I'd definitely be willing to help get it there!