Skip to content

Commit 5e3ed98

Browse files
homerchen19claude
andauthored
chore: migrate toolchain to pnpm/vite/vitest (#50)
* docs: add toolchain migration design spec Spec for migrating yarn→pnpm, microbundle→vite, jest→vitest. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * docs: update spec with review feedback Address spec reviewer issues: consolidated vite.config.ts, added outDir/husky v9/testing-library risk notes, added pnpm pack step. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * docs: add toolchain migration implementation plan Step-by-step plan for yarn→pnpm, microbundle→vite, jest→vitest migration. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * chore: migrate from yarn to pnpm Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * chore: replace microbundle with vite for library builds Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * chore: replace jest with vitest Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * chore: update devDependencies to latest versions * chore: remove design docs from codebase Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: use discriminated union for Action type Replace `as T` assertions with proper type narrowing by making Action<T> a discriminated union. TypeScript now knows newPresent is non-optional in Set and Reset action types. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * docs: update install command to npm in README Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 814675d commit 5e3ed98

11 files changed

Lines changed: 2248 additions & 5507 deletions

File tree

.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4-
npm run pretty-quick
4+
pnpm run pretty-quick

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ undo/redo functionality with React [Hooks](https://reactjs.org/docs/hooks-intro.
1414
## Installation
1515

1616
```sh
17-
yarn add use-undo
17+
npm install use-undo
1818
```
1919

2020
## Usage

__test__/checkpoint.spec.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { render, cleanup, fireEvent } from '@testing-library/react';
32

43
import useUndo from '../index';

__test__/index.spec.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { render, cleanup, fireEvent } from '@testing-library/react';
32

43
import useUndo from '../index';

index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ export interface Actions<T> {
1616
canRedo: boolean;
1717
}
1818

19-
interface Action<T> {
20-
type: ActionType;
21-
historyCheckpoint?: boolean;
22-
newPresent?: T;
23-
}
19+
type Action<T> =
20+
| { type: ActionType.Undo }
21+
| { type: ActionType.Redo }
22+
| { type: ActionType.Set; newPresent: T; historyCheckpoint?: boolean }
23+
| { type: ActionType.Reset; newPresent: T };
2424

2525
export interface State<T> {
2626
past: T[];

jest.config.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

package.json

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,50 @@
1212
"bugs": {
1313
"url": "https://github.com/homerchen19/use-undo/issues"
1414
},
15-
"source": "index.ts",
16-
"main": "lib/use-undo.js",
17-
"umd:main": "lib/use-undo.umd.js",
18-
"module": "lib/use-undo.m.js",
15+
"main": "lib/use-undo.cjs",
16+
"module": "lib/use-undo.mjs",
1917
"types": "lib/index.d.ts",
18+
"exports": {
19+
".": {
20+
"import": {
21+
"types": "./lib/index.d.ts",
22+
"default": "./lib/use-undo.mjs"
23+
},
24+
"require": {
25+
"types": "./lib/index.d.ts",
26+
"default": "./lib/use-undo.cjs"
27+
}
28+
}
29+
},
2030
"scripts": {
21-
"build": "rimraf lib && microbundle -o lib/ --name use-undo --sourcemap false --no-compress",
22-
"prepublishOnly": "yarn build",
23-
"preversion": "yarn test:cov",
24-
"test": "jest",
25-
"test:cov": "jest --coverage --runInBand --forceExit",
26-
"test:watch": "jest --watch",
27-
"pre-commit": "pretty-quick --staged",
31+
"build": "vite build",
32+
"prepublishOnly": "pnpm build",
33+
"preversion": "pnpm test:cov",
34+
"test": "vitest run",
35+
"test:cov": "vitest run --coverage",
36+
"test:watch": "vitest",
2837
"pretty-quick": "pretty-quick",
29-
"prepare": "husky install"
38+
"prepare": "husky"
3039
},
3140
"files": [
3241
"lib"
3342
],
3443
"devDependencies": {
35-
"@testing-library/react": "^11.2.7",
36-
"@types/jest": "^27",
37-
"@types/node": "^15.6.1",
38-
"@types/react": "^17.0.8",
39-
"@types/react-dom": "^17.0.5",
40-
"husky": "^6.0.0",
41-
"jest": "^27.0.3",
42-
"microbundle": "^0.13.1",
43-
"prettier": "^2.3.0",
44-
"pretty-quick": "^3.1.0",
45-
"react": "^17.0.2",
46-
"react-dom": "^17.0.2",
47-
"rimraf": "^3.0.2",
48-
"ts-jest": "^27.0.1",
49-
"typescript": "^4.3.2"
44+
"@testing-library/dom": "^10.4.1",
45+
"@testing-library/react": "^16.3.2",
46+
"@types/react": "^18.3.28",
47+
"@types/react-dom": "^18.3.7",
48+
"@vitest/coverage-v8": "^4.1.1",
49+
"husky": "^9.1.7",
50+
"jsdom": "^29.0.1",
51+
"prettier": "^3.8.1",
52+
"pretty-quick": "^4.2.2",
53+
"react": "^18.3.1",
54+
"react-dom": "^18.3.1",
55+
"typescript": "^6.0.2",
56+
"vite": "^8.0.2",
57+
"vite-plugin-dts": "^4.5.4",
58+
"vitest": "^4.1.1"
5059
},
5160
"peerDependencies": {
5261
"react": ">=16.8.6",

0 commit comments

Comments
 (0)