Skip to content

Commit

Permalink
Clean up files, exports, dependencies (#4974)
Browse files Browse the repository at this point in the history
* install and configure knip

* remove unused exports

* remove export keyword from unused exports

* remove unused files

* clean up dependencies

* tag deprecated aliases

* organize core exports

* re-export actor-specific ActorRef types

* remove outdated changeset

* restore david's scripts

* remove knip entries for examples and templates

* remove tslib

* upgrade knip and simplify config

* move svelte-jester to root package.json

* upgrade knip to latest

* add xstate-svelte/test/tsconfig.json to knip workspaces config
  • Loading branch information
with-heart committed Jul 29, 2024
1 parent ccaeb44 commit 536cde6
Show file tree
Hide file tree
Showing 27 changed files with 326 additions and 1,208 deletions.
28 changes: 28 additions & 0 deletions .knip.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"$schema": "https://unpkg.com/knip@5/schema.json",
"workspaces": {
".": {
"entry": ["scripts/*.js"],
"project": ["scripts/*.js"]
},
"packages/xstate-svelte": {
"typescript": "test/tsconfig.json"
}
},
"ignore": [
// used for `#is-development` conditional import
"packages/**/{true,false}.ts",
// file acts as a type test
"packages/xstate-svelte/test/interpreterAsReadable.svelte"
],
"ignoreBinaries": ["svelte-check", "docs:build"],
"ignoreDependencies": [
"@xstate-repo/jest-utils",
"@xstate-repo/jest-utils/setup",
"synckit",
// package.json#exports aren't added as entry points, because `dist/` is .gitignored
"react",
"xstate",
"@types/ws"
]
}
20 changes: 6 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"typecheck": "tsc",
"test": "jest",
"test:core": "jest packages/core",
"dev": "node ./scripts/dev.js",
"changeset": "changeset",
"release": "changeset publish",
"version": "changeset version && node ./scripts/bump-peer-dep-ranges.js"
Expand All @@ -46,47 +45,40 @@
},
"homepage": "https://github.com/statelyai/xstate#readme",
"dependencies": {
"@actions/exec": "^1.0.2",
"@babel/core": "^7.23.3",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/preset-env": "^7.23.3",
"@babel/preset-react": "^7.23.3",
"@babel/preset-typescript": "^7.23.3",
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.2",
"@jest/types": "^29.6.3",
"@manypkg/cli": "^0.16.1",
"@manypkg/get-packages": "^1.1.3",
"@preconstruct/cli": "^2.8.1",
"@testing-library/jest-dom": "^6.1.4",
"@testing-library/vue": "^6.6.1",
"@types/jest": "^29.5.10",
"@types/node": "^12.11.1",
"@vue/compiler-sfc": "^3.0.11",
"@vue/vue3-jest": "^29.2.6",
"babel-jest": "^29.7.0",
"babel-preset-solid": "^1.8.4",
"gh-pages": "^2.0.1",
"husky": "^3.1.0",
"jest": "^29.7.0",
"jest-config": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-regex-util": "^29.6.3",
"jest-resolve": "^29.7.0",
"jest-snapshot": "^29.7.0",
"jest-watch-typeahead": "^2.2.2",
"knip": "^5.27.0",
"lint-staged": "^8.2.1",
"markdown-it-codesandbox-embed": "^0.1.0",
"patch-package": "^6.5.1",
"prettier": "^3.1.0",
"prettier-plugin-jsdoc": "^1.3.0",
"spawn-command": "0.0.2-1",
"svelte-jester": "^2.3.2",
"synckit": "^0.8.5",
"tslib": "^2.3.1",
"tslint": "^5.11.0",
"typescript": "^5.4.2",
"vue": "^3.0.11",
"webpack-dev-middleware": "^3.6.0"
},
"resolutions": {
"**/tslib": "^2.3.1"
"vue": "^3.0.11"
},
"husky": {
"hooks": {
Expand Down
2 changes: 0 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@
"@scion-scxml/test-framework": "^2.0.15",
"@xstate-repo/jest-utils": "*",
"ajv": "^8.12.0",
"jsdom": "^14.0.0",
"jsdom-global": "^3.0.2",
"pkg-up": "^3.1.0",
"rxjs": "^7.8.0",
"xml-js": "^1.6.11"
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/StateMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ import type {
} from './types.ts';
import { resolveReferencedActor, toStatePath } from './utils.ts';

export const STATE_IDENTIFIER = '#';
export const WILDCARD = '*';
const STATE_IDENTIFIER = '#';

export class StateMachine<
TContext extends MachineContext,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/actions/stopChild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,6 @@ export function stopChild<
* Stops a child actor.
*
* @deprecated Use `stopChild(...)` instead
* @alias
*/
export const stop = stopChild;
4 changes: 2 additions & 2 deletions packages/core/src/actors/callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ export type CallbackActorRef<
TInput = NonReducibleUnknown
> = ActorRefFrom<CallbackActorLogic<TEvent, TInput>>;

export type Receiver<TEvent extends EventObject> = (
type Receiver<TEvent extends EventObject> = (
listener: {
bivarianceHack(event: TEvent): void;
}['bivarianceHack']
) => void;

export type InvokeCallback<
type InvokeCallback<
TEvent extends EventObject = AnyEventObject,
TSentEvent extends EventObject = AnyEventObject,
TInput = NonReducibleUnknown,
Expand Down
17 changes: 5 additions & 12 deletions packages/core/src/createActor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,6 @@ import { toObserver } from './utils.ts';

export const $$ACTOR_TYPE = 1;

export type SnapshotListener<TLogic extends AnyActorLogic> = (
snapshot: SnapshotFrom<TLogic>
) => void;

export type EventListener<TEvent extends EventObject = EventObject> = (
event: TEvent
) => void;

export type Listener = () => void;
export type ErrorListener = (error: any) => void;

// those values are currently used by @xstate/react directly so it's important to keep the assigned values in sync
export enum ProcessingStatus {
NotStarted = 0,
Expand Down Expand Up @@ -817,8 +806,12 @@ export function createActor<TLogic extends AnyActorLogic>(
* options, if any.
*
* @deprecated Use `createActor` instead
* @alias
*/
export const interpret = createActor;

/** @deprecated Use `Actor` instead. */
/**
* @deprecated Use `Actor` instead.
* @alias
*/
export type Interpreter = typeof Actor;
37 changes: 0 additions & 37 deletions packages/core/src/dev/redux.ts

This file was deleted.

35 changes: 13 additions & 22 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,38 @@
export * from './actions.ts';
export * from './actors/index.ts';
export { SimulatedClock } from './SimulatedClock.ts';
export { type Spawner } from './spawn.ts';
export { isMachineSnapshot, type MachineSnapshot } from './State.ts';
export { StateMachine } from './StateMachine.ts';
export { getStateNodes } from './stateUtils.ts';
export * from './types.ts';
export { waitFor } from './waitFor.ts';
import { createMachine } from './createMachine.ts';
export { getInitialSnapshot, getNextSnapshot } from './getNextSnapshot.ts';
import {
export { StateNode } from './StateNode.ts';
export * from './actions.ts';
export * from './actors/index.ts';
export { assertEvent } from './assert.ts';
export {
Actor,
createActor,
interpret,
type Interpreter
} from './createActor.ts';
import { StateNode } from './StateNode.ts';
// TODO: decide from where those should be exported
export { createMachine } from './createMachine.ts';
export { getInitialSnapshot, getNextSnapshot } from './getNextSnapshot.ts';
export { and, not, or, stateIn } from './guards.ts';
export { setup } from './setup.ts';
export type { ActorSystem } from './system.ts';
export type {
InspectedActorEvent,
InspectedEventEvent,
InspectedSnapshotEvent,
InspectionEvent
} from './inspection.ts';
export { setup } from './setup.ts';
export { type Spawner } from './spawn.ts';
export { getStateNodes } from './stateUtils.ts';
export type { ActorSystem } from './system.ts';
export { toPromise } from './toPromise.ts';
export * from './types.ts';
export {
getAllOwnEventDescriptors as __unsafe_getAllOwnEventDescriptors,
matchesState,
pathToStateValue,
toObserver
} from './utils.ts';
export {
Actor,
createActor,
createMachine,
interpret,
StateNode,
type Interpreter
};
export { assertEvent } from './assert.ts';
export { waitFor } from './waitFor.ts';

declare global {
interface SymbolConstructor {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/inspection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type InspectionEvent =
| InspectedMicrostepEvent
| InspectedActionEvent;

export interface BaseInspectionEventProperties {
interface BaseInspectionEventProperties {
rootId: string; // the session ID of the root
/**
* The relevant actorRef for the inspection event.
Expand All @@ -30,7 +30,7 @@ export interface InspectedSnapshotEvent extends BaseInspectionEventProperties {
snapshot: Snapshot<unknown>;
}

export interface InspectedMicrostepEvent extends BaseInspectionEventProperties {
interface InspectedMicrostepEvent extends BaseInspectionEventProperties {
type: '@xstate.microstep';
event: AnyEventObject; // { type: string, ... }
snapshot: Snapshot<unknown>;
Expand Down
12 changes: 0 additions & 12 deletions packages/core/src/memo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,3 @@ export function memo<T>(object: any, key: string, fn: () => T): T {

return memoizedData[key];
}

export function evict(object: any, key?: string): void {
if (!key) {
return void cache.delete(object);
}

const memoizedData = cache.get(object);

if (memoizedData) {
delete memoizedData[key];
}
}
20 changes: 10 additions & 10 deletions packages/core/src/stateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type AnyStateNodeIterable = StateNodeIterable<any, any>;

type AdjList = Map<AnyStateNode, Array<AnyStateNode>>;

export const isAtomicStateNode = (stateNode: StateNode<any, any>) =>
const isAtomicStateNode = (stateNode: StateNode<any, any>) =>
stateNode.type === 'atomic' || stateNode.type === 'final';

function getChildren<TContext extends MachineContext, TE extends EventObject>(
Expand Down Expand Up @@ -158,7 +158,7 @@ function getValueFromAdj(baseNode: AnyStateNode, adjList: AdjList): StateValue {
return stateValue;
}

export function getAdjList<
function getAdjList<
TContext extends MachineContext,
TE extends EventObject
>(stateNodes: StateNodeIterable<TContext, TE>): AdjList {
Expand Down Expand Up @@ -462,7 +462,7 @@ export function formatInitialTransition<
return transition;
}

export function resolveTarget(
function resolveTarget(
stateNode: AnyStateNode,
targets: ReadonlyArray<string | AnyStateNode> | undefined
): ReadonlyArray<AnyStateNode> | undefined {
Expand Down Expand Up @@ -528,7 +528,7 @@ function isHistoryNode(
return stateNode.type === 'history';
}

export function getInitialStateNodesWithTheirAncestors(
function getInitialStateNodesWithTheirAncestors(
stateNode: AnyStateNode
) {
const states = getInitialStateNodes(stateNode);
Expand Down Expand Up @@ -562,7 +562,7 @@ export function getInitialStateNodes(stateNode: AnyStateNode) {
return set;
}
/** Returns the child state node from its relative `stateKey`, or throws. */
export function getStateNode(
function getStateNode(
stateNode: AnyStateNode,
stateKey: string
): AnyStateNode {
Expand Down Expand Up @@ -653,7 +653,7 @@ export function getStateNodes<
);
}

export function transitionAtomicNode<
function transitionAtomicNode<
TContext extends MachineContext,
TEvent extends EventObject
>(
Expand All @@ -680,7 +680,7 @@ export function transitionAtomicNode<
return next;
}

export function transitionCompoundNode<
function transitionCompoundNode<
TContext extends MachineContext,
TEvent extends EventObject
>(
Expand Down Expand Up @@ -714,7 +714,7 @@ export function transitionCompoundNode<
return next;
}

export function transitionParallelNode<
function transitionParallelNode<
TContext extends MachineContext,
TEvent extends EventObject
>(
Expand Down Expand Up @@ -828,7 +828,7 @@ function hasIntersection<T>(s1: Iterable<T>, s2: Iterable<T>): boolean {
return false;
}

export function removeConflictingTransitions(
function removeConflictingTransitions(
enabledTransitions: Array<AnyTransitionDefinition>,
stateNodeSet: Set<AnyStateNode>,
historyValue: AnyHistoryValue
Expand Down Expand Up @@ -1835,7 +1835,7 @@ export function resolveStateValue(
return getStateValue(rootNode, [...allStateNodes]);
}

export function stateValuesEqual(
function stateValuesEqual(
a: StateValue | undefined,
b: StateValue | undefined
): boolean {
Expand Down
Loading

0 comments on commit 536cde6

Please sign in to comment.