v5 migration codemod
with-heart opened this issue · comments
This issue is for building a codemod that migrates a codebase from v4 to v5. The codemod would analyze the abstract syntax tree (AST) of the codebase in order to identify syntax changes that need to be made and apply those changes.
We'd also need to create a cli to apply the codemod. I can't remember if there's an xstate
cli out there already or not, but if so we can reuse it. I'm thinking xstate codemod v4-to-v5
or something like that.
You can find the current (as of 4/14) migration guide here: https://docs-git-davidkpiano-v5-outline-statelyai.vercel.app/xstate-v5/migration
Here's a table of changes to target:
v4 | v5 | Changes to make | Comments/Questions |
---|---|---|---|
Machine |
createMachine |
|
|
cond |
guard |
|
|
cond and actions objects can have any key |
objects can only have type and params |
|
|
(context, event) |
({context, event}) |
|
if the arguments aren't named context and event , we'll need to make sure that the object's keys use the correct names (example: (ctx) becomes ({context: ctx}) ) |
actor.onTransition |
actor.subscribe |
? | do they have the same interface? |
send |
raise /sendTo |
? | is there a way to tell from send usage which new fn should be used instead? |
internal: false |
reenter: true |
|
|
interpret(machine).start(state) |
interpret(machine, {state}).start() |
|
|
actor.send('event') |
actor.send({type: 'event'}) |
|
|
null event ('' ) |
always |
|
|
createMachine(config, options) |
createMachine(config).provide(options) |
|
|
machine.withConfig(options, context) |
machine.provide({…options, context}) |
|
need to handle cases where both .withConfig and .withContext were called |
machine.withContext(context) |
machine.provide({context}) |
|
need to handle cases where both .withConfig and .withContext were called |
predictableActionArguments: true |
- |
|
|
strict: true |
- |
|
|
state.history |
- |
|
is there anything else we could do here? maybe notify the user that state.history no longer exists and where it's being used so they can adjust their code? |
actor.batch([...]) |
removed |
|
is this an appropriate solution? |
config.schema |
config.types |
|
need to make sure this works together with config.tsTypes change |
config.tsTypes |
config.types.typegen |
|
need to make sure this works together with config.schema change |