mattpocock / xstate-codegen

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

Consuming @xstate/compiled/react in monorepo #47

Open danielkcz opened 4 years ago

danielkcz commented 4 years ago

image

Here is the minimal repo that shows this problem: https://github.com/FredyC/xstate-codegen-monorepo

yarn install
yarn machinery codegen
yarn web validate

I have no idea why it should be a problem considering @xstate/compiled exists in root node_modules.

danielkcz commented 4 years ago

In the branch use-paths I tried a slightly different approach with path aliases, but the outcome is the same.

Specifically, it means I import from ~machinery/xstate/react and that alias is defined in tsconfig. It also utilizes outDir.

danielkcz commented 4 years ago

Oh wait, I just noticed that @xstate/compiled has been written to modules/machinery/node_modules instead of a root one. Well, that explains it...

danielkcz commented 4 years ago

I have figured an ugly workaround. In the modules/web/package.json I've added this and it works.

"@xstate/compiled": "file:../machinery/node_modules/@xstate/compiled",

I am not sure how a proper solution should look like.

danielkcz commented 4 years ago

Well, that wasn't the right workaround either. When I modified that machine it went haywire.

So I ended up moving codegen execution to root. It will correctly output to root node_modules and behaves correctly.

I suppose ultimately it's the right solution and documenting it should be good enough.

mattpocock commented 4 years ago

OK, to fix this we should probably add a --cwd flag that allows you to pick the current working directory. This wouldn't be too hard to implement/document. What do you think?

danielkcz commented 4 years ago

Yea, that could certainly help as well.

mattpocock commented 4 years ago

@FredyC Here's a PR which might help with the above:

https://github.com/mattpocock/xstate-codegen/pull/50/files