Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to vite #805

Merged
merged 28 commits into from
Dec 9, 2024
Merged
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
3f9cb6e
Add .tsbuildinfo files to .gitignore
Dec 6, 2024
f27c3d7
Vite: 1. Replace react-scripts & craco scripts and dependencies
Dec 6, 2024
341e756
Vite: 2. Add vite.config.ts
Dec 6, 2024
9f42139
Vite: 3. Update tsconfig.json
Dec 6, 2024
6e149b1
Other tsconfig.json changes copied from spenno!?
Dec 6, 2024
772084e
Vite: 4. Update lock file
Dec 6, 2024
2ba4eb3
Vite: 5. Move index.html to root
Dec 6, 2024
f19536e
Vite: 6. Update index.html
Dec 6, 2024
40cbab3
Vite: 7. Replace env var usage
Dec 6, 2024
21fd677
Vite: remove src/react-app-env.d.ts
Dec 6, 2024
7fc4646
Setup vitest to replace react-script tests and jest
Dec 6, 2024
1f2009e
Uninstall @types/jest
Dec 7, 2024
2c50fe0
Vite: tentatively ugprade to all latest
Dec 7, 2024
d57d42b
Vitest: use explicit imports
Dec 7, 2024
ccf1656
Remove now-unnecessary override for typescript and react-refresh
Dec 7, 2024
97c09a8
Setup eslint using eslint-config-react-app
Dec 7, 2024
ebf1c3c
Add lint to CI tasks
Dec 7, 2024
6299ea7
Basic eslint config for tichu-client-ts-lib and tichu-term-client --…
Dec 7, 2024
de514bf
Fix TichuWebSocketHandler#debug -- maybe this only fails since eslint?
Dec 7, 2024
e20402b
tichu-web:lint: address react/display-name and react/no-unescaped-ent…
Dec 8, 2024
7b19a45
Moving towards a self-sufficient eslint config (#808)
Dec 8, 2024
fece983
Address some linting errors/warns or bypass them
Dec 8, 2024
76b0693
Vite#preserveSymlinks to work with workspaces
Dec 9, 2024
d455aa1
Update package-lock.json
Dec 7, 2024
993e8bb
Replace @storybook/react-webpack5 and @storybook/preset-create-react-…
Dec 9, 2024
8efbd1f
Update package-lock
Dec 9, 2024
6dfad61
Update storybook config to use vite instead of webpack
Dec 9, 2024
2969539
Change storybook config to typescript, simplify
Dec 9, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jobs:
fail-fast: false # continue other jobs if one in matrix fails
matrix:
npm-command: [
"lint",
"build",
"test", # while tichu-client-ts-lib and tichu-term-client use ava and run tests after compiling main code, that's not the case for tichu-web, so running test additionally here
"prettier-check-all",
Expand Down
1 change: 1 addition & 0 deletions tichu-clients/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ build/
storybook-static/
*.local
*.log
*.tsbuildinfo
26,966 changes: 8,199 additions & 18,767 deletions tichu-clients/package-lock.json

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions tichu-clients/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"prepare": "cd .. && husky tichu-clients/.husky",
"build": "npm run build -ws",
"test": "npm run test -ws # ⚠️ tichu-web will run tests in watch mode when not on CI",
"lint": "npm run lint -w tichu-web # ⚠️ eslint not currently setup for other packages",
"term-client": "npm run start -w tichu-term-client",
"web": "npm run start -w tichu-web",
"web-storybook": "npm run storybook -w tichu-web",
Expand All @@ -26,8 +27,5 @@
"packages/tichu-client-ts-lib",
"packages/tichu-term-client",
"packages/tichu-web"
],
"overrides": {
"react-refresh": "0.14.2"
}
]
}
8 changes: 7 additions & 1 deletion tichu-clients/packages/tichu-client-ts-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"tscov:d": "tscov --details",
"publish-package": "npm run build && npm publish",
"docs": "typedoc --out docs ./src",
"test": "npm run build"
"test": "npm run build",
"lint": "eslint src/"
},
"keywords": [],
"author": "",
Expand Down Expand Up @@ -51,5 +52,10 @@
},
"compile": false
}
},
"eslintConfig": {
"extends": [
"eslint:recommended"
]
}
}
8 changes: 7 additions & 1 deletion tichu-clients/packages/tichu-term-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"tscov:d": "tscov --details",
"publish-package": "npm run build && npm publish",
"docs": "typedoc --out docs ./src",
"test": "npm run build"
"test": "npm run build",
"lint": "eslint src/"
},
"keywords": [],
"author": "",
Expand Down Expand Up @@ -55,5 +56,10 @@
},
"compile": false
}
},
"eslintConfig": {
"extends": [
"eslint:recommended"
]
}
}
38 changes: 0 additions & 38 deletions tichu-clients/packages/tichu-web/.storybook/main.js

This file was deleted.

31 changes: 31 additions & 0 deletions tichu-clients/packages/tichu-web/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { StorybookConfig } from "@storybook/react-vite";

const config: StorybookConfig = {
framework: {
name: "@storybook/react-vite",
options: {},
},
stories: ["../src/**/*.@(mdx|stories.@(ts|tsx|js|jsx))"],

addons: [
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/addon-storysource",
"@chromatic-com/storybook",
],
staticDirs: ["../public"],
typescript: {
// type-check stories during Storybook build
check: true,
reactDocgen: "react-docgen-typescript",
},

docs: {},

async viteFinal(config, options) {
// we'll likely need a way to exclude websocket ("ws") like we did with webpack/craco!?
return config;
},
};

export default config;
9 changes: 0 additions & 9 deletions tichu-clients/packages/tichu-web/craco.config.js

This file was deleted.

21 changes: 21 additions & 0 deletions tichu-clients/packages/tichu-web/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app but then migrated to Vite. I should really rewrite this file."
/>
<link rel="apple-touch-icon" href="/logo192.png" />
<link rel="manifest" href="/manifest.json" />
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script type="module" src="/src/index.tsx"></script>
</body>
</html>
56 changes: 45 additions & 11 deletions tichu-clients/packages/tichu-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@
"@testing-library/jest-dom": "6.6.3",
"@testing-library/react": "16.0.1",
"@testing-library/user-event": "14.5.2",
"@types/jest": "29.5.14",
"@types/node": "22.10.1",
"@types/react": "18.3.12",
"@types/react-dom": "18.3.1",
"notistack": "3.0.1",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-scripts": "5.0.1",
"tichu-client-ts-lib": "1.0.0",
"ts-enum-util": "4.1.0",
"typescript": "5.7.2"
Expand All @@ -27,19 +25,45 @@
"@emotion/styled": "11.13.5"
},
"scripts": {
"start": "craco start",
"build": "craco build",
"test": "craco test",
"eject": "react-scripts eject",
"start": "vite",
"build": "tsc && vite build",
"serve": "vite preview",
"test": "vitest",
"lint": "eslint src/",
"storybook": "storybook dev -p 9009",
"build-storybook": "storybook build"
},
"eslintConfig": {
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": true
},
"plugins": [
"@typescript-eslint"
],
"extends": [
"eslint:recommended",
"react-app",
"react-app/jest"
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"prettier"
],
"ignorePatterns": [
"build",
"lib",
"node_modules"
],
"overrides": [
{
"files": [
"**/*"
],
"rules": {
"@typescript-eslint/no-empty-function": "warn",
"@typescript-eslint/no-inferrable-types": "off"
}
},
{
"files": [
"**/*.stories.tsx"
Expand Down Expand Up @@ -71,17 +95,27 @@
},
"devDependencies": {
"@chromatic-com/storybook": "3.2.2",
"@craco/craco": "7.1.0",
"@storybook/addon-actions": "8.4.5",
"@storybook/addon-docs": "8.4.5",
"@storybook/addon-essentials": "8.4.5",
"@storybook/addon-links": "8.4.5",
"@storybook/addon-storysource": "8.4.5",
"@storybook/preset-create-react-app": "8.4.5",
"@storybook/react": "8.4.5",
"@storybook/react-webpack5": "8.4.5"
"@storybook/react-vite": "8.4.7",
"@vitejs/plugin-react": "4.3.4",
"eslint": "8.57.1",
"eslint-config-prettier": "9.1.0",
"eslint-config-react-app": "7.0.1",
"eslint-plugin-react-compiler": "19.0.0-beta-df7b47d-20241124",
"jsdom": "25.0.1",
"vite": "6.0.1",
"vite-plugin-eslint": "1.8.1",
"vite-plugin-svgr": "4.3.0",
"vitest": "2.1.8"
},
"/*": "these overrides only exist because we still unfortunately indirectly depend on CRA for eslint-config-react-app",
"overrides": {
"react-refresh": "0.14.2"
"eslint-plugin-react": "7.37.2",
"eslint-plugin-react-hooks": "5.0.0"
}
}
43 changes: 0 additions & 43 deletions tichu-clients/packages/tichu-web/public/index.html

This file was deleted.

4 changes: 3 additions & 1 deletion tichu-clients/packages/tichu-web/src/components/CardSet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ const withPosition =
<P extends object>(
Component: React.ComponentType<P>,
): React.FC<P & WithPositionProps> =>
// eslint-disable-next-line react/display-name
({ idx, totalCount, size, layout, ...props }: WithPositionProps) => {
const { tx, ty, rot } = calcTransform(layout, size, idx, totalCount);
type Position = "absolute"; // typescript bug ? https://github.com/microsoft/TypeScript/issues/11465 -- this type should be Property.Position but it's not available here, so just faking it
const styles = {
position: "absolute" as "absolute", // typescript bug ? https://github.com/microsoft/TypeScript/issues/11465
position: "absolute" as Position,
transformOrigin: "center",
transform: `translate(${tx}em, ${ty}em) rotate(${rot}deg)`,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
import { render } from "@testing-library/react";
import { CardView } from "./CardView";
import { cardFromName } from "tichu-client-ts-lib";
import { test, expect } from "vitest";
import "@testing-library/jest-dom/vitest";

test("renders the card name", () => {
const { getByText } = render(
<CardView card={cardFromName("*P")} onClick={() => {}} selected={false} />,

Check warning on line 10 in tichu-clients/packages/tichu-web/src/components/CardView.test.tsx

View workflow job for this annotation

GitHub Actions / Frontend lint 📍

Unexpected empty arrow function
);
expect(getByText(/Phoenix/)).toBeInTheDocument();
});
2 changes: 1 addition & 1 deletion tichu-clients/packages/tichu-web/src/components/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const Game: FC<{ sendMessage: SendFunction; gameState: GameState }> = ({
/>
))}
</div>
<p>It's {gameState.currentPlayer}'s turn</p>
<p>It&apos;s {gameState.currentPlayer}&apos;s turn</p>
<Player>
{gameState.hand ? (
<Hand sendCards={sendCards} cardsInHand={gameState.hand} />
Expand Down
15 changes: 9 additions & 6 deletions tichu-clients/packages/tichu-web/src/components/Room.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const Room: FC<{ user: User; websocketUrl: string }> = (props) => {
setChatMessages((currentMessages) => [...currentMessages, newMessage]);
};
const sentChatMessage = (text: string, onResponse: OnResponse) => {
wsClient!.send(new OutgoingChatMessage(text), onResponse);
wsClient?.send(new OutgoingChatMessage(text), onResponse);
};

const [activityLog, setActivityLog] = useState(
Expand Down Expand Up @@ -68,17 +68,20 @@ export const Room: FC<{ user: User; websocketUrl: string }> = (props) => {

useEffect(() => {
connect();
// Return a cleanup function
return () => {};
return () => {
/* nothing to do on cleanup */
};
}, [connect]);

const justWatch = () => {};
const justWatch = () => {
/* do nothing */
};
// TODO also better deal with absent wsClient
const join = (teamId: number) => () => {
wsClient!.send(new OutgoingGameMessage(new JoinParam(teamId)));
wsClient?.send(new OutgoingGameMessage(new JoinParam(teamId)));
};
const ready = () => {
wsClient!.send(new OutgoingGameMessage(new PlayerIsReadyParam()));
wsClient?.send(new OutgoingGameMessage(new PlayerIsReadyParam()));
};
const game = visitEnumValue(roomState.status).with<JSX.Element>({
[RoomStatus.OPEN]: () => <p>Trying to connect</p>,
Expand Down
Loading
Loading