mattpocock / xstate-codegen

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

Typescript path aliases cannot be used #23

Open danielkcz opened 4 years ago

danielkcz commented 4 years ago

I am using path aliases quite heavily. An example of my tsconfig.json.

{
  "compilerOptions": {
    "baseUrl": "src",
    "paths": {
      "~machinery/graphql": ["generated/machinerygraphql"],
      "~machinery/*": ["*"],
      "~tools/*": ["../../tools/src/*"]
    },
  },
}

Then in the code I can do eg. import { getNow } from '~tools/timing'. Works like a charm with other tooling (after some hassle).

However, running xstate-codegen I am getting Error: Cannot find module '~tools/timing'.

I suppose based on the https://github.com/mattpocock/xstate-codegen/issues/21#issuecomment-691312065 it should be solved when transition is done?

mattpocock commented 4 years ago

This makes sense why this wouldn't work, rollup doesn't know about your aliases. Another reason why the transition mentioned in #21 makes sense.

As with that comment, a workaround is to extract the machines into their own file which doesn't use aliases. Is that workable for you?

danielkcz commented 4 years ago

workaround is to extract the machines into their own file which doesn't use aliases. Is that workable for you?

Not really, because those imported functions are an inherent part of the machine. I am even used to splitting everything like this and the main bootMachine.ts does not have any aliased imports.

image

It's alright, I will wait for the transition. You are doing a great thing here. Looking forward to a moment when all these nasty edge cases are figured out.