Skip to content

Commit 6b3f799

Browse files
committed
refactor: Vitest migration
1 parent 9f1a337 commit 6b3f799

37 files changed

Lines changed: 1252 additions & 1882 deletions

‎.github/workflows/tests.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
uses: actions/checkout@v4
2020

2121
- name: Use Node.js 24
22-
uses: actions/setup-node@v3
22+
uses: actions/setup-node@v4
2323
with:
2424
node-version: 24
2525
cache: 'yarn'

‎.idea/runConfigurations/Tests.xml‎

Lines changed: 8 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.vscode/extensions.json‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
{
2-
"recommendations": [
3-
"hbenl.vscode-mocha-test-adapter",
4-
"esbenp.prettier-vscode"
5-
]
6-
}
2+
"recommendations": ["vitest.explorer", "esbenp.prettier-vscode"]
3+
}

‎.vscode/settings.json‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,5 @@
33
"editor.defaultFormatter": "esbenp.prettier-vscode",
44
"[typescript]": {
55
"editor.defaultFormatter": "esbenp.prettier-vscode"
6-
},
7-
"mochaExplorer.files": ["tests/**/*.{js,ts,cjs,mjs}"],
8-
"mochaExplorer.require": [
9-
"esbuild-register"
10-
]
11-
}
6+
}
7+
}

‎CHANGELOG.md‎

Lines changed: 75 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,171 +1,178 @@
11
# Changelog
22

3+
## v7.0.0
4+
5+
- **Breaking:** the package is now published as native ESM only. The CommonJS build (`build/index-cjs.js`) has been removed. Use `import`, or `require()` on Node.js 20.19+ / 22.12+ where loading ESM from CommonJS is supported.
6+
- **Breaking:** the minimum supported Node.js version is now 20.19 (or 22.12+).
7+
- The test suite now runs on vitest instead of mocha.
8+
- Updated all dependencies.
9+
310
## v6.2.0
411

5-
- Fixed an issue where if the first value of a `$eq` operation was null or undefined it did not always return false.
12+
- Fixed an issue where if the first value of a `$eq` operation was null or undefined it did not always return false.
613

714
## v6.1.0
815

9-
- Added support for arrays of objects in array operations.
16+
- Added support for arrays of objects in array operations.
1017

1118
## v6.0.0
1219

13-
- Fixed an issue where trying to run actions in an invalid way would cause errors. They now no-op.
20+
- Fixed an issue where trying to run actions in an invalid way would cause errors. They now no-op.
1421

1522
## v5.9.3
1623

17-
- Fixed an issue where when a timer performs a state transition, events were still ran with the old state.
24+
- Fixed an issue where when a timer performs a state transition, events were still ran with the old state.
1825

1926
## v5.9.2
2027

21-
- Timers are now properly returned and saved when `doEventHandlers` is called.
28+
- Timers are now properly returned and saved when `doEventHandlers` is called.
2229

2330
## v5.9.1
2431

25-
- Timers are now cleared using pop to ensure they're garbage collected.
32+
- Timers are now cleared using pop to ensure they're garbage collected.
2633

2734
## v5.9.0
2835

29-
- Timers are now properly cleared on state transition.
30-
- Timers are now handled first before anything else.
36+
- Timers are now properly cleared on state transition.
37+
- Timers are now handled first before anything else.
3138

3239
## v5.8.0
3340

34-
- Context is only read from if a reference is prepended with a `$`.
35-
- Switch statements are now used when handling ops, this means ordering is now respected.
41+
- Context is only read from if a reference is prepended with a `$`.
42+
- Switch statements are now used when handling ops, this means ordering is now respected.
3643

3744
## v5.7.0
3845

39-
- Added support for 2 operand `$mul` actions.
46+
- Added support for 2 operand `$mul` actions.
4047

4148
## v5.6.2
4249

43-
- Fixed values not being properly deleted if they were truthy.
50+
- Fixed values not being properly deleted if they were truthy.
4451

4552
## v5.6.1
4653

47-
- Fixed actions not getting constants from the definition.
54+
- Fixed actions not getting constants from the definition.
4855

4956
## v5.6.0
5057

51-
- Added support for the `$reset` operator using the original context from the definition.
52-
- Added `originalContext` option to `HandleActionsOptions`.
58+
- Added support for the `$reset` operator using the original context from the definition.
59+
- Added `originalContext` option to `HandleActionsOptions`.
5360

5461
## v5.5.2
5562

56-
- Fixed irregular events not being handled correctly.
63+
- Fixed irregular events not being handled correctly.
5764

5865
## v5.5.1
5966

60-
- Fixed contract IDs not being passed to conditions and transitions.
67+
- Fixed contract IDs not being passed to conditions and transitions.
6168

6269
## v5.5.0
6370

64-
- Added support for long arrays to the `$eq` operator.
71+
- Added support for long arrays to the `$eq` operator.
6572

6673
## v5.4.0
6774

68-
- Added support for contract IDs in `$pushunique`.
75+
- Added support for contract IDs in `$pushunique`.
6976

7077
## v5.3.0
7178

72-
- Fixed a bug which would cause timers to be persisted, preventing them from starting again.
79+
- Fixed a bug which would cause timers to be persisted, preventing them from starting again.
7380

7481
## v5.2.0
7582

7683
NOTE: This release contains 2 potentially breaking changes.
7784
They are in a semver-minor release because both align the parser more with the IOI behavior.
7885

79-
- Added prepack script so building from source works properly.
80-
- _Breaking_: Fixed handleEvent resetting the context when an event is disregarded.
81-
- _Breaking_: Removed support for `$div`, as it never actually existed in the game.
82-
- Updated build dependencies.
86+
- Added prepack script so building from source works properly.
87+
- _Breaking_: Fixed handleEvent resetting the context when an event is disregarded.
88+
- _Breaking_: Removed support for `$div`, as it never actually existed in the game.
89+
- Updated build dependencies.
8390

8491
## v5.1.0
8592

86-
- Require a timestamp on all events (for timers). This is breaking, but needed to be done.
93+
- Require a timestamp on all events (for timers). This is breaking, but needed to be done.
8794

8895
## v5.0.0
8996

90-
- Removed debug in favor of a user-provided logging function.
91-
- Reworked timers to use a better system that is controlled by the library consumer.
92-
- Fixed the `$le` implementation.
93-
- Refactored type definitions a bit.
97+
- Removed debug in favor of a user-provided logging function.
98+
- Reworked timers to use a better system that is controlled by the library consumer.
99+
- Fixed the `$le` implementation.
100+
- Refactored type definitions a bit.
94101

95102
## v4.3.0
96103

97-
- Fixed inconsistent getting and setting behavior as a result of the last patch.
98-
- Added new documentation, and improved existing documentation.
99-
- Renamed `$gte` and `$lte` to `$ge` and `$le` to be consistent with the usage of the game.
104+
- Fixed inconsistent getting and setting behavior as a result of the last patch.
105+
- Added new documentation, and improved existing documentation.
106+
- Renamed `$gte` and `$lte` to `$ge` and `$le` to be consistent with the usage of the game.
100107

101108
## v4.2.0
102109

103-
- `$pushunique` can now be used as a condition.
104-
- `(`, `)`, and leading `$` (and `$.`) are now automatically removed from strings if resolved.
110+
- `$pushunique` can now be used as a condition.
111+
- `(`, `)`, and leading `$` (and `$.`) are now automatically removed from strings if resolved.
105112

106113
## v4.1.0
107114

108-
- Added `Count` property to arrays.
109-
- Removed support for comparing arrays with `$eq`.
115+
- Added `Count` property to arrays.
116+
- Removed support for comparing arrays with `$eq`.
110117

111118
## v4.0.0
112119

113-
- Added tracing functionality to assist with finding bugs.
114-
- Support `$remove` action.
115-
- Synchronized copyright headers.
116-
- `handleEvent` now automatically handles the immediately invoked event upon transitions.
120+
- Added tracing functionality to assist with finding bugs.
121+
- Support `$remove` action.
122+
- Synchronized copyright headers.
123+
- `handleEvent` now automatically handles the immediately invoked event upon transitions.
117124

118125
## v3.3.0
119126

120-
- Moved the build setup to esbuild.
121-
- Proper ES modules are now published that can be loaded by Node.js and the browser.
122-
- Added code coverage.
123-
- Handle nested array nodes.
124-
- Fixed a crash that could be caused by handling actions in `handleEvent`.
125-
- Added some new tests.
127+
- Moved the build setup to esbuild.
128+
- Proper ES modules are now published that can be loaded by Node.js and the browser.
129+
- Added code coverage.
130+
- Handle nested array nodes.
131+
- Fixed a crash that could be caused by handling actions in `handleEvent`.
132+
- Added some new tests.
126133

127134
## v3.2.1
128135

129-
- Fixed the actions not being executed correctly in `handleEvent`.
130-
- Fixed some outstanding issues with timers.
136+
- Fixed the actions not being executed correctly in `handleEvent`.
137+
- Fixed some outstanding issues with timers.
131138

132139
## v3.2.0
133140

134-
- Remove `lodash`'s `set` implementation in favor of a smaller one.
135-
- Better handling in `handleEvent` for falsy values.
141+
- Remove `lodash`'s `set` implementation in favor of a smaller one.
142+
- Better handling in `handleEvent` for falsy values.
136143

137144
## v3.1.0
138145

139-
- Handle immediately executing event handlers.
140-
- Enable enhanced tree shaking.
146+
- Handle immediately executing event handlers.
147+
- Enable enhanced tree shaking.
141148

142149
## v3.0.0
143150

144-
- Basically rewrote the whole thing to be faster and smaller, and have fewer issues.
145-
- Handling side effect state machines and conditional state machines are now separate functions.
146-
- Many other improvements, such as properly shipped ES modules, less file duplication, and more.
151+
- Basically rewrote the whole thing to be faster and smaller, and have fewer issues.
152+
- Handling side effect state machines and conditional state machines are now separate functions.
153+
- Many other improvements, such as properly shipped ES modules, less file duplication, and more.
147154

148155
## v2.1.0
149156

150-
- `$pushunique` and `$push` nodes now use the same implementation.
151-
- Added tests for `$inc` and `$dec` (+ fixed associated bugs).
152-
- Excluded TypeScript build info files from release files.
153-
- Replaced our implementation of `setObjectChild` with Lodash's version.
154-
- Updated dependencies.
157+
- `$pushunique` and `$push` nodes now use the same implementation.
158+
- Added tests for `$inc` and `$dec` (+ fixed associated bugs).
159+
- Excluded TypeScript build info files from release files.
160+
- Replaced our implementation of `setObjectChild` with Lodash's version.
161+
- Updated dependencies.
155162

156163
## v2.0.0
157164

158-
- The statemachine conditions can no longer be null or undefined.
159-
- The globals can no longer be null or undefined.
160-
- Support side effect nodes (`$set`, `$mul`, `$inc`, `$dec`, `$div` all work properly now).
161-
- The `check` method now returns an object in the format of `{ bool: boolean, globals: any }`, because side effect nodes can modify the globals object.
162-
- `findObjectChild` (formerly `$referenceToData`) and `setObjectChild` are now exported.
163-
- Added inline JSDoc.
165+
- The statemachine conditions can no longer be null or undefined.
166+
- The globals can no longer be null or undefined.
167+
- Support side effect nodes (`$set`, `$mul`, `$inc`, `$dec`, `$div` all work properly now).
168+
- The `check` method now returns an object in the format of `{ bool: boolean, globals: any }`, because side effect nodes can modify the globals object.
169+
- `findObjectChild` (formerly `$referenceToData`) and `setObjectChild` are now exported.
170+
- Added inline JSDoc.
164171

165172
## v1.0.1
166173

167-
- Same as v1.0.0 but re-published due to a bug.
174+
- Same as v1.0.0 but re-published due to a bug.
168175

169176
## v1.0.0
170177

171-
- First release.
178+
- First release.

‎README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Or, if you use npm:
3434
npm i @peacockproject/statemachine-parser
3535
```
3636

37+
This package is published as native ESM. It can also be loaded with `require()` on Node.js 20.19+ / 22.12+.
38+
3739
### Build from Source
3840

3941
```shell
@@ -46,7 +48,7 @@ yarn && yarn build
4648
## Usage
4749

4850
```js
49-
const { test } = require("@peacockproject/statemachine-parser")
51+
import { test } from "@peacockproject/statemachine-parser"
5052

5153
const condition = {
5254
$eq: ["$Value.Greeting", "Hi!"],

‎build.mjs‎

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022-2024 The Peacock Project
2+
* Copyright (c) 2022-2026 The Peacock Project
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,26 +16,16 @@
1616

1717
import esbuild, { analyzeMetafile } from "esbuild"
1818

19-
const sharedSettings = {
19+
const esm = await esbuild.build({
2020
entryPoints: ["src/index.ts"],
2121
bundle: true,
2222
write: true,
2323
outdir: "build",
2424
metafile: true,
2525
sourcemap: true,
26-
}
27-
28-
const esm = await esbuild.build({
29-
...sharedSettings,
3026
format: "esm",
27+
platform: "neutral",
28+
target: "es2022",
3129
})
3230

3331
console.log(await analyzeMetafile(esm.metafile))
34-
35-
const cjs = await esbuild.build({
36-
...sharedSettings,
37-
format: "cjs",
38-
entryNames: "index-cjs"
39-
})
40-
41-
console.log(await analyzeMetafile(cjs.metafile))

0 commit comments

Comments
 (0)