@xstate/codemod 0.1.0-alpha.4 → 0.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xstate/codemod",
3
- "version": "0.1.0-alpha.4",
3
+ "version": "0.1.0-beta.1",
4
4
  "description": "Codemods for migrating XState source between versions (v5 → v6)",
5
5
  "keywords": [
6
6
  "xstate",
@@ -17,11 +17,13 @@
17
17
  },
18
18
  "exports": {
19
19
  ".": "./dist/xstate-codemod.js",
20
- "./package.json": "./package.json"
20
+ "./package.json": "./package.json",
21
+ "./skills/*": "./skills/*"
21
22
  },
22
23
  "files": [
23
24
  "dist",
24
- "bin"
25
+ "bin",
26
+ "skills"
25
27
  ],
26
28
  "repository": {
27
29
  "type": "git",
@@ -31,7 +33,10 @@
31
33
  "url": "https://github.com/statelyai/xstate/issues"
32
34
  },
33
35
  "dependencies": {
34
- "ts-morph": "^24.0.0"
36
+ "ts-morph": "^24.0.0",
37
+ "tsx": "^4.23.13",
38
+ "xstate5": "npm:xstate@^5.33.0",
39
+ "xstate": "^6.0.0-beta.1"
35
40
  },
36
41
  "devDependencies": {
37
42
  "vitest": "^3.2.2"
@@ -40,6 +45,11 @@
40
45
  "umdName": "XStateCodemod",
41
46
  "entrypoints": [
42
47
  "./index.ts"
43
- ]
48
+ ],
49
+ "exports": {
50
+ "extra": {
51
+ "./skills/*": "./skills/*"
52
+ }
53
+ }
44
54
  }
45
55
  }
@@ -0,0 +1,52 @@
1
+ ---
2
+ name: migrate-v5-to-v6
3
+ description: Use when converting an XState v5 machine file to v6 and checking that the converted machine behaves like the original.
4
+ ---
5
+
6
+ Run these steps for one machine file at a time. `<name>` is a short name for the file.
7
+
8
+ 1. Record the v5 behavior before editing the file:
9
+
10
+ ```bash
11
+ npx @xstate/codemod baseline <file> --out .xstate-migrate/<name>.json
12
+ ```
13
+
14
+ Add `--events events.json` when events carry payloads. The file maps each event type to a list of payloads:
15
+ `{ "ADD_ITEM": [{ "type": "ADD_ITEM", "sku": "A1" }] }`.
16
+ Event types without an entry are sent as `{ type }`.
17
+
18
+ Add `--stubs stubs.json` when the machine invokes or spawns actors by name. Each actor is `"pending"` (the default), `{ "done": output }`, or `{ "error": value }`:
19
+ `{ "actors": { "fetchUser": { "done": { "id": 1 } } }, "delays": { "RETRY": 100 } }`.
20
+ `delays` sets named delays in milliseconds. `{}` resolves with `undefined` and `{ "done": null }` resolves with `null`. One baseline holds one outcome per actor, so cover `onError` paths with a second baseline that uses a different `--stubs` file.
21
+
22
+ Add `--input input.json` when the machine reads `input`.
23
+
24
+ If baseline times out, pass `--no-simple-paths`.
25
+
26
+ 2. Convert the file:
27
+
28
+ ```bash
29
+ npx @xstate/codemod migrate <file> --json
30
+ ```
31
+
32
+ Exit 0: continue. Exit 2: fix every `manualSites` entry by hand, using its `api` and `hint` and `docs/xstate-v5-to-v6.md`. Change nothing else.
33
+
34
+ 3. Check the behavior:
35
+
36
+ ```bash
37
+ npx @xstate/codemod verify --baseline .xstate-migrate/<name>.json <file> --json
38
+ ```
39
+
40
+ - If the report has `startError`, exit 0 proves nothing: fix the input/stubs until it clears, then rerun.
41
+ - Exit 0: done.
42
+ - Exit 4: fix the load or run error described in `error.message`, then rerun.
43
+ - Exit 3: for each `diffs[]` entry with `classification: "unclassified"`, reproduce it with `witness` (the events and clock advances up to `step`), compare `expected` (v5) with `actual` (v6) for `field`, fix the v6 code, then rerun step 3.
44
+
45
+ Repeat step 3 until it exits 0.
46
+
47
+ Rules:
48
+
49
+ - Never edit the baseline file.
50
+ - Never widen `--compare` to make a diff disappear.
51
+ - Report every `unstubbed` entry to the user. Inline actor logic runs for real and is not stubbed.
52
+ - Stop and ask the user after 5 repair rounds without exit 0.