Skip to content
This repository was archived by the owner on Mar 5, 2023. It is now read-only.

Rewrite to ts morph #78

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bae5ac4
Rewrite for type-level extractor using ts-morph
Andarist Sep 14, 2020
1805f5b
Merge branch 'master' into rewrite-to-ts-morph
Andarist Sep 14, 2020
9b45dfc
Implement array extraction
Andarist Sep 14, 2020
560fe30
Fixed minor issues
Andarist Sep 15, 2020
748d65e
Implemented options extractor
Andarist Sep 15, 2020
2564bd3
Added support for extracting delayed transitions
Andarist Sep 15, 2020
88f143d
Merge branch 'master' into rewrite-to-ts-morph
Andarist Sep 15, 2020
cc61a46
Add support for extracting `always`
Andarist Sep 16, 2020
0cf8405
Use entry/exit properties over onEntry/onExit in the complex machine …
Andarist Sep 16, 2020
c534077
Added support for action objects and fixed issue with inline function…
Andarist Sep 16, 2020
4b4f3f4
Fixed the Action extractor when there is no type for it and add funct…
Andarist Sep 16, 2020
3d3696c
Allow for inline actions in the Actions extractor
Andarist Sep 16, 2020
218b5a4
Rewritten to extract based on the inline AST nodes and only fallback …
Andarist Sep 19, 2020
1fa58b1
Merge branch 'master' into rewrite-to-ts-morph
Andarist Sep 20, 2020
61783fa
Rewrite extraction to work purely~ on types
Andarist Feb 25, 2021
06d6dd6
Remove undefined initial from one of the parallel examples
Andarist Apr 9, 2021
df7f672
Fixed an issue in the Action extractor
Andarist Apr 9, 2021
683b6ec
Merge branch 'master' into rewrite-to-ts-morph
Andarist Apr 9, 2021
cbade56
Switch to using createMachine exclusively and fix some tests which we…
Andarist Apr 9, 2021
9a7c2d1
Add delays extractor to the options extractor
Andarist Apr 9, 2021
ea38207
Added fail cases
mattpocock Apr 13, 2021
d98aac0
Fixed extracting string actions from onDone
Andarist Apr 17, 2021
44aec32
Add snapshots releases workflow
Andarist Apr 29, 2021
0b74547
Add changeset
Andarist Apr 29, 2021
b4f1697
Update Changesets
Andarist Apr 29, 2021
0305fc1
Tweak snapshot release workflow
Andarist Apr 29, 2021
a140c23
Empty commit
Andarist Apr 29, 2021
d352d52
Remove publish-related scripts from the xstate-compiled directory
Andarist Apr 29, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"$schema": "https://unpkg.com/@changesets/config@1.3.0/schema.json",
"$schema": "https://unpkg.com/@changesets/config@1.6.0/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"linked": [],
"access": "public",
"baseBranch": "master",
"updateInternalDependencies": "patch",
"ignore": []
"ignore": [],
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
"useCalculatedVersionForSnapshots": true
}
}
5 changes: 5 additions & 0 deletions .changeset/sharp-yaks-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'xstate-codegen': minor
---

The implementation has been rewritten to be based on TypeScript compiler APIs which enhances the possibility of static analysis.
29 changes: 29 additions & 0 deletions .github/workflows/snapshot-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Snapshot Release

on: pull_request

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Setup node
uses: actions/setup-node@v2
with:
node-version: 12.x

- name: Install dependencies
run: yarn

- name: Prepare artifacts
run: yarn build

- name: Release a snapshot
run: |
yarn changeset version --snapshot pr${{ github.event.pull_request.number }}
yarn changeset publish --tag pr${{ github.event.pull_request.number }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
"packages/*"
],
"scripts": {
"x": "yarn workspace xstate-codegen"
"x": "yarn workspace xstate-codegen",
"build": "npm run build --prefix packages/xstate-compiled",
"changeset": "changeset"
},
"devDependencies": {
"ts-node":"9.0.0"
"@changesets/cli": "^2.16.0",
"ts-node": "9.0.0"
}
}
3 changes: 1 addition & 2 deletions packages/xstate-compiled/.npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
bin/__tests__
bin/fake_node_modules
examples
coverage
node_modules
node_modules
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Machine, send, assign } from '@xstate/compiled';
import { createMachine, send, assign } from '@xstate/compiled';

type Attendee = {
name: string;
Expand Down Expand Up @@ -46,7 +46,7 @@ const assignAttendee = assign<
};
});

export const addViewingAttendeesMachine = Machine<
export const addViewingAttendeesMachine = createMachine<
Context,
Event,
'addViewingAttendees'
Expand Down
41 changes: 0 additions & 41 deletions packages/xstate-compiled/examples/chooseAction.machine.ts

This file was deleted.

31 changes: 18 additions & 13 deletions packages/xstate-compiled/examples/complexMachine.machine.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { assign, Machine, send, StateWithMatches } from '@xstate/compiled';
import {
assign,
createMachine,
send,
StateWithMatches,
} from '@xstate/compiled';

type GetDemoMatterportViewingSubscription = {};

export const complexMachineMachine = Machine<
export const complexMachineMachine = createMachine<
ComplexMachineContext,
ComplexMachineEvent,
'complexMachine'
Expand Down Expand Up @@ -38,7 +43,7 @@ export const complexMachineMachine = Machine<
],
},
errored: {
onEntry: send('REPORT_NO_PERMISSION_TO_VIEW'),
entry: send('REPORT_NO_PERMISSION_TO_VIEW'),
},
isLoggedInAsAUser: {
entry: 'startDataStream',
Expand Down Expand Up @@ -94,7 +99,7 @@ export const complexMachineMachine = Machine<
},
},
errored: {
onEntry: send('REPORT_NO_PERMISSION_TO_VIEW'),
entry: send('REPORT_NO_PERMISSION_TO_VIEW'),
},
checksComplete: {
type: 'final',
Expand All @@ -103,7 +108,7 @@ export const complexMachineMachine = Machine<
onDone: 'awaitingFirstPacketOfData',
},
awaitingFirstPacketOfData: {
onEntry: 'startDataStream',
entry: 'startDataStream',
on: {
RECEIVE_DATA: [
{
Expand Down Expand Up @@ -421,7 +426,7 @@ export const complexMachineMachine = Machine<
on: {
JOIN_CALL: 'requestingTwilioAudioOptions',
},
onEntry: 'reportHasNotJoinedCall',
entry: 'reportHasNotJoinedCall',
},
requestingTwilioAudioOptions: {
invoke: {
Expand Down Expand Up @@ -470,7 +475,7 @@ export const complexMachineMachine = Machine<
},
inCall: {
type: 'parallel',
onEntry: 'reportHasJoinedCall',
entry: 'reportHasJoinedCall',
states: {
callOptionsModal: {
initial: 'closed',
Expand Down Expand Up @@ -512,7 +517,7 @@ export const complexMachineMachine = Machine<
],
},
noVideo: {
onEntry: ['reportHostIsNotSharingVideo'],
entry: ['reportHostIsNotSharingVideo'],
on: {
TURN_ON_VIDEO: {
cond: 'isHost',
Expand All @@ -534,8 +539,8 @@ export const complexMachineMachine = Machine<
},
},
video: {
onEntry: ['reportHostIsSharingVideo'],
onExit: ['reportHostIsNotSharingVideo'],
entry: ['reportHostIsSharingVideo'],
exit: ['reportHostIsNotSharingVideo'],
on: {
HIDE_VIDEO: {
target: 'noVideo',
Expand All @@ -560,14 +565,14 @@ export const complexMachineMachine = Machine<
],
},
muted: {
onEntry: 'ensureMicrophoneMuted',
entry: 'ensureMicrophoneMuted',
on: {
TOGGLE_MUTE: 'unmuted',
UNMUTE: 'unmuted',
},
},
unmuted: {
onEntry: 'ensureMicrophoneUnmuted',
entry: 'ensureMicrophoneUnmuted',
on: {
TOGGLE_MUTE: 'muted',
MUTE: 'muted',
Expand All @@ -578,7 +583,7 @@ export const complexMachineMachine = Machine<
},
},
callErrored: {
onEntry: 'reportHasNotJoinedCall',
entry: 'reportHasNotJoinedCall',
type: 'final',
},
},
Expand Down
68 changes: 0 additions & 68 deletions packages/xstate-compiled/examples/createMachineOptions.machine.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Machine, interpret } from '@xstate/compiled';
import { createMachine, interpret } from '@xstate/compiled';

type Data = {
yeah: boolean;
Expand All @@ -13,7 +13,7 @@ type Event =
| { type: 'CANCEL' }
| { type: 'done.invoke.makeFetch'; data: Data };

const machine = Machine<Context, Event, 'fetchMachineNullishCoalesce'>({
const machine = createMachine<Context, Event, 'fetchMachineNullishCoalesce'>({
initial: 'idle',
states: {
idle: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Machine, interpret } from '@xstate/compiled';
import { createMachine } from '@xstate/compiled';
import { useMachine } from '@xstate/compiled/react';

type Data = {
Expand All @@ -14,7 +14,7 @@ type Event =
| { type: 'CANCEL' }
| { type: 'done.invoke.makeFetch'; data: Data };

const machine = Machine<Context, Event, 'fetchMachineOptionalActions'>(
const machine = createMachine<Context, Event, 'fetchMachineOptionalActions'>(
{
initial: 'idle',
states: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Machine, interpret } from '@xstate/compiled';
import { createMachine } from '@xstate/compiled';
import { useMachine } from '@xstate/compiled/react';

type Data = {
Expand All @@ -14,7 +14,7 @@ type Event =
| { type: 'CANCEL' }
| { type: 'done.invoke.makeFetch'; data: Data };

const machine = Machine<Context, Event, 'fetchMachineOptionalServices'>(
const machine = createMachine<Context, Event, 'fetchMachineOptionalServices'>(
{
initial: 'idle',
states: {
Expand Down
4 changes: 2 additions & 2 deletions packages/xstate-compiled/examples/fetchMachine.machine.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Machine, interpret } from '@xstate/compiled';
import { createMachine, interpret } from '@xstate/compiled';

type Data = {
yeah: boolean;
Expand All @@ -13,7 +13,7 @@ type Event =
| { type: 'CANCEL' }
| { type: 'done.invoke.makeFetch'; data: Data };

const machine = Machine<Context, Event, 'fetchMachine'>({
const machine = createMachine<Context, Event, 'fetchMachine'>({
initial: 'idle',
states: {
idle: {
Expand Down
Loading