Skip to content

Commit

Permalink
Configure TypeScript project references
Browse files Browse the repository at this point in the history
Improvements:
- The common/ project is automatically built by dependent projects
- Building common/ in in the "prepare" script is thus no longer necessary
- Vite and server hot-reloading now work if files in common/ change
- Recompiling common after every change is done automatically
- Using "go to definition" now jumps to the .ts file rather than the .d.ts

Changes:
- Use TypeScript project references to refer to common/ from client/ and server/
- Set "composite" and "declarationMap" options in common/tsconfig.json
    - See https://www.typescriptlang.org/docs/handbook/project-references.html
- Use tsc --build in order to build references automatically
- Replace nodemon and ts-node with ts-watch in server in order to use the new tsc --build mode
    - See TypeStrong/ts-node#897 (comment)
    - Remove now unneeded SIGUSR2 signal handler which was for nodemon
- Use tsc-watch before Vite in client in order for hot-reloading to work if common/ changes
- Update TypeScript version
- Add vite.config.node.json to be consistent with expected Vite project defaults

GitLab: #151
Change-Id: Id2f84fe45e44c4d8b4e6d3b324e1aee322c52df6
  • Loading branch information
KRMisha committed Nov 23, 2022
1 parent 3470d07 commit 86917ea
Show file tree
Hide file tree
Showing 11 changed files with 921 additions and 882 deletions.
13 changes: 7 additions & 6 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"private": true,
"type": "module",
"scripts": {
"start": "vite",
"start": "tsc-watch --build ../common --onSuccess \"vite\"",
"start:prod": "vite preview",
"build": "tsc && vite build",
"clean": "rm -rf dist",
"build": "tsc --build && vite build",
"clean": "rm -rf dist *.tsbuildinfo",
"test": "jest src",
"test:cypress": "cypress open",
"lint": "eslint .",
Expand Down Expand Up @@ -48,7 +48,6 @@
"filesize": "^10.0.5",
"framer-motion": "^7.3.5",
"i18next": "^21.9.2",
"jami-web-common": "file:../common",
"mime": "^3.0.0",
"qrcode.react": "^3.1.0",
"react": "^18.2.0",
Expand All @@ -64,6 +63,7 @@
},
"devDependencies": {
"@types/jest": "^28.1.8",
"@types/node": "^18.11.9",
"@types/react": "^18.0.17",
"@types/react-dom": "^18.0.6",
"@types/react-modal": "^3.13.1",
Expand All @@ -73,8 +73,9 @@
"eslint-plugin-react-hooks": "^4.6.0",
"i18next-parser": "^6.5.0",
"sass": "^1.54.5",
"typescript": "^4.7.4",
"vite": "^3.1.8",
"tsc-watch": "^5.0.3",
"typescript": "~4.8.4",
"vite": "^3.2.3",
"vite-plugin-svgr": "^2.2.2"
}
}
3 changes: 2 additions & 1 deletion client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
"strict": true,
"skipLibCheck": true
},
"include": ["src"]
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }, { "path": "../common" }]
}
10 changes: 10 additions & 0 deletions client/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"composite": true,
"module": "esnext",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"skipLibCheck": true
},
"include": ["vite.config.ts"]
}
4 changes: 2 additions & 2 deletions client/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
*/
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';
import svgrPlugin from 'vite-plugin-svgr';
import svgr from 'vite-plugin-svgr';

export default defineConfig({
plugins: [react(), svgr()],
server: {
host: '0.0.0.0',
port: 3000,
Expand All @@ -30,5 +31,4 @@ export default defineConfig({
define: {
global: {},
},
plugins: [react(), svgrPlugin()],
});
9 changes: 3 additions & 6 deletions common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@
"main": "dist/index.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist/index.js"
],
"scripts": {
"build": "tsc --build",
"clean": "rm -rf dist tsconfig.tsbuildinfo",
"clean": "rm -rf dist *.tsbuildinfo",
"lint": "eslint src",
"lint:fix": "npm run lint -- --fix",
"format": "prettier --write src",
"format:check": "prettier --check src"
},
"dependencies": {
"typescript": "^4.8.4"
"devDependencies": {
"typescript": "~4.8.4"
}
}
2 changes: 2 additions & 0 deletions common/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"compilerOptions": {
"composite": true,
"target": "esnext",
"module": "esnext",
"rootDir": "src",
"moduleResolution": "node",
"declaration": true,
"declarationMap": true,
"outDir": "dist",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
Expand Down
Loading

0 comments on commit 86917ea

Please sign in to comment.