Closed danielkcz closed 3 years ago
Ah yes, this is annoying. My fix for this is to add xstate-codegen "src/**/**.whatever.ts" --once
in a postinstall script, so that you're covered after these reinstalls. We should add this to documentation as the 'official' way.
I guess for now it would do, but duplicating that pattern in package.json
could be a nightmare if something more elaborate is needed.
What do you mean by more elaborate?
Well, you need to duplicate that command with --once
including the pattern to run it as postinstall
script. I am not sure what is there to say to it. Perhaps it's my concern only :)
OK - I think there are two options here:
Document this approach carefully to make sure people adopt it as part of installation. I use it for my work repo and it does address 100% of the issues above.
Add an extra watch to the CLI to check the node_modules directory to check for deletions. This is the more complex approach, and doesn't cover all bases. For instance, what if someone runs yarn install
but the CLI watch isn't running?
There are surely more pressing matters than this, so don't worry too much about it right now. Maybe next year when everything is running smoothly :)
About the duplication, I actually realized it's possible to do this, so that's totally fine. Strangely enough, it doesn't run always for some reason. I am not really sure why yet. Might be related to monorepo situation and having this in root means it will run only when root packages changes 🤷
"codegen": "xstate-codegen \"modules/machinery/src/**/*Machine.ts\"",
"postinstall": "yarn codegen --once"
There is one gotcha when running in CI. Since my machines depend on other generated stuff (GraphQL), the build was failing because it attempted to run codegen too soon. My solution is to use --ignore-scripts
for the CI run. It's a bit fragile, but it will do for now.
@FredyC Sometimes it won't run when you add or remove a package in a workspace, but it should always run when you run yarn install in root.
I mean it's kinda expected, but annoying what it happens. I wanted to install a new dependency and suddenly app started complaining it cannot find that module.
I guess codegen should also watch on its own output and when it disappears, rerun the generator.