Minor Changes
-
1148d89:
xstate-codemod migrateaccepts--json, which prints one JSON report to stdout. The command exits with code2when manual migration is needed, and the report lists each site undermanualSiteswith its file, line, column, API, and hint.A new report transform,
report-suffixed-lifecycle-events, flagsonkeys written asxstate.done.state.<id>,xstate.done.actor.<id>,xstate.error.actor.<id>, orxstate.after.<delay>.<id>. v6 raises the plain event type with the id in a field, so those transitions never fire after migration. Another report transform,report-action-shapes, flags non-functionentryandexitvalues, transition arrays, and transitionactions,guard, andcondkeys, which v6 rejects.A new report transform,
report-implementations, flags a secondcreateMachineargument, which v6 ignores.A new transform,
lower-actions, rewrites v5 transitions withactionsorguard, transition arrays, andentry/exitlists as v6 functions, convertingassign,enqueueActions,raise,sendTo,sendParent,forwardTo,emit,log,cancel,stopChild,spawnChild,and,or,not, andstateIn, including named implementations and module-level constants defined in the same file. Named actions and guards keep their v5 signatures, and a namedassignaction becomes a function that returns a context patch. It also moves an object-literal secondcreateMachineargument into the config and rewritesfromPromise(fn)ascreateAsyncLogic({ run: fn }). Code it cannot rewrite is left unchanged and reported.// before on: { INC: { target: 'active', guard: 'canInc', actions: assign({ count: ({ context }) => context.count + 1 }) } } // after on: { INC: (args) => { if (!args.guards.canInc(args)) return; return { target: 'active', context: { count: args.context.count + 1 } }; } }
types-to-schemasconverts the per-key formtypes: { context: {} as C, events: {} as E }, builds an events map from same-file type aliases, and writesevents: types<E>()for other event types instead of leavingtypesin place.New
baselineandverifycommands check that a migrated machine behaves like the v5 original.baselinerecords a trace of generated event sequences under XState v5, andverifyreplays them against the v6 module and reports the diffs.baselineandverifyaccept--input <file>, a JSON value passed as the machine'sinput. While a machine runs,Date.now(),performance.now(), andMath.random()return simulated, seeded values, so machines that store them incontextcompare equal, and a v5 root actor'ssendParenterror is classified as the intentionalroot-send-parentdelta.--no-simple-pathsskips the graph's simple paths whenbaselinetimes out.npx @xstate/codemod baseline src/checkout.ts --out .xstate-migrate/checkout.json npx @xstate/codemod migrate src/checkout.ts --json # fix the reported manualSites npx @xstate/codemod verify --baseline .xstate-migrate/checkout.json src/checkout.tsmigratereports string literals that name v5 inspection event types (@xstate.snapshot,@xstate.event,@xstate.action,@xstate.microstep,@xstate.deadletter), which v6 never emits.
Patch Changes
- Updated dependencies [599ec3c]
- xstate@6.0.0-beta.1