From 15947b34f5c3066d21480b85953779e0b2df1237 Mon Sep 17 00:00:00 2001 From: Anderson Entwistle <46688047+aentwist@users.noreply.github.com> Date: Thu, 8 Aug 2024 11:37:57 -0600 Subject: [PATCH] chore(ui): fix tsconfig See also - https://github.com/P4sca1/cron-schedule/issues/289#issuecomment-1570015802 - https://github.com/microsoft/TypeScript/issues/50794 --- ui/src/api.ts | 4 ++-- ui/src/main.ts | 6 ++--- ui/src/preload.ts | 6 ++--- ui/tsconfig.app.json | 46 ++++++++++++++------------------------ ui/tsconfig.base.json | 18 +++++++++++++++ ui/tsconfig.node.json | 25 +++++++++++++++------ ui/vite.main.config.ts | 2 +- ui/vite.preload.config.ts | 6 ++++- ui/vite.renderer.config.ts | 2 +- 9 files changed, 68 insertions(+), 47 deletions(-) create mode 100644 ui/tsconfig.base.json diff --git a/ui/src/api.ts b/ui/src/api.ts index 702c9b5..b180e4d 100644 --- a/ui/src/api.ts +++ b/ui/src/api.ts @@ -2,8 +2,8 @@ import { spawn } from "child_process"; import type { BrowserWindow } from "electron"; import { app, ipcMain } from "electron"; import path from "path"; -import type { CommandData, Message, RunData, SettingsData } from "./types"; -import { CommandType } from "./types"; +import type { CommandData, Message, RunData, SettingsData } from "./types.ts"; +import { CommandType } from "./types.ts"; export class Api { private static instance = new Api(); diff --git a/ui/src/main.ts b/ui/src/main.ts index 9ebe7d7..88de99e 100644 --- a/ui/src/main.ts +++ b/ui/src/main.ts @@ -1,9 +1,9 @@ import { BrowserWindow, app, ipcMain, shell } from "electron"; import fs from "fs/promises"; import path from "path"; -import { Api } from "./api"; -import type { RootState } from "./stores"; -import { registerUpdateHandlers, startUpdatePolling } from "./update"; +import { Api } from "./api.ts"; +import type { RootState } from "./stores/index.ts"; +import { registerUpdateHandlers, startUpdatePolling } from "./update.ts"; // Handle creating/removing shortcuts on Windows when installing/uninstalling. if (require("electron-squirrel-startup")) { diff --git a/ui/src/preload.ts b/ui/src/preload.ts index 7a9d432..604ccd1 100644 --- a/ui/src/preload.ts +++ b/ui/src/preload.ts @@ -2,9 +2,9 @@ // https://www.electronjs.org/docs/latest/tutorial/process-model#preload-scripts import { contextBridge, ipcRenderer } from "electron"; -import type { RootState } from "./stores"; -import type { Message, RunData, SettingsData } from "./types"; -import { CommandType } from "./types"; +import type { RootState } from "./stores/index.ts"; +import type { Message, RunData, SettingsData } from "./types.ts"; +import { CommandType } from "./types.ts"; const electronApi = { saveState: (state: Partial): Promise => diff --git a/ui/tsconfig.app.json b/ui/tsconfig.app.json index ac6c495..5bd9648 100644 --- a/ui/tsconfig.app.json +++ b/ui/tsconfig.app.json @@ -1,32 +1,20 @@ { - "compilerOptions": { - "target": "ES2021", - "useDefineForClassFields": true, - "lib": ["ES2021", "DOM", "DOM.Iterable"], - "module": "commonjs", - "skipLibCheck": true, - "esModuleInterop": true, - "noImplicitAny": true, - "sourceMap": true, - "baseUrl": ".", - "outDir": "dist", - - /* Bundler mode */ - "moduleResolution": "node", - // "allowImportingTsExtensions": true, - "resolveJsonModule": true, - // "isolatedModules": true, - "noEmit": true, - "jsx": "react-jsx", - // https://github.com/emotion-js/emotion/issues/1249#issuecomment-828088254 - "jsxImportSource": "@emotion/react", - "types": ["vitest/globals"], + "extends": "./tsconfig.base.json", + "include": ["src/**/*"], + "exclude": [ + "src/main.ts", + "src/preload.ts", + "src/update.ts", + "src/api.ts", - /* Linting */ - "strict": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true - }, - "include": ["src/**/*"] + "src/**/*.test.*", + "src/App.tesst.tsx" + ], + "compilerOptions": { + "module": "esnext", + "moduleResolution": "bundler", + "isolatedModules": true, + "noEmit": true, // might not be needed + "lib": ["esnext"] + } } diff --git a/ui/tsconfig.base.json b/ui/tsconfig.base.json new file mode 100644 index 0000000..26dbcfd --- /dev/null +++ b/ui/tsconfig.base.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + // recommended + "target": "es2016", + "module": "esnext", + "esModuleInterop": true, + "strict": true, + "skipLibCheck": true, + + // other common options + "resolveJsonModule": true, + + // both app and node (test) need jsx + "jsx": "react-jsx", + // https://github.com/emotion-js/emotion/issues/1249#issuecomment-828088254 + "jsxImportSource": "@emotion/react" + } +} diff --git a/ui/tsconfig.node.json b/ui/tsconfig.node.json index 3a35aec..b6e2449 100644 --- a/ui/tsconfig.node.json +++ b/ui/tsconfig.node.json @@ -1,10 +1,21 @@ { + "extends": "./tsconfig.base.json", + "include": [ + "src/main.ts", + "src/preload.ts", + "src/update.ts", + "src/api.ts", + + "src/**/*.test.*", + + "*.config.*", + "forge.env.d.ts" + ], "compilerOptions": { - "skipLibCheck": true, - "module": "ESNext", - "moduleResolution": "bundler", - "allowSyntheticDefaultImports": true, - "strict": true - }, - "include": ["vite.*.ts", "forge.*.ts"] + "module": "nodenext", + "moduleResolution": "nodenext", + "noEmit": true, + "allowImportingTsExtensions": true, + "types": ["vitest/globals"] + } } diff --git a/ui/vite.main.config.ts b/ui/vite.main.config.ts index 6d4dd4a..32774b9 100644 --- a/ui/vite.main.config.ts +++ b/ui/vite.main.config.ts @@ -5,7 +5,7 @@ import { getBuildConfig, getBuildDefine, pluginHotRestart, -} from "./vite.base.config"; +} from "./vite.base.config.ts"; // https://vitejs.dev/config export default defineConfig((env) => { diff --git a/ui/vite.preload.config.ts b/ui/vite.preload.config.ts index 65d8334..889d363 100644 --- a/ui/vite.preload.config.ts +++ b/ui/vite.preload.config.ts @@ -1,6 +1,10 @@ import type { ConfigEnv, UserConfig } from "vite"; import { defineConfig, mergeConfig } from "vite"; -import { external, getBuildConfig, pluginHotRestart } from "./vite.base.config"; +import { + external, + getBuildConfig, + pluginHotRestart, +} from "./vite.base.config.ts"; // https://vitejs.dev/config export default defineConfig((env) => { diff --git a/ui/vite.renderer.config.ts b/ui/vite.renderer.config.ts index bc2c0b1..f2c28df 100644 --- a/ui/vite.renderer.config.ts +++ b/ui/vite.renderer.config.ts @@ -1,6 +1,6 @@ import type { ConfigEnv, UserConfig } from "vite"; import { defineConfig } from "vite"; -import { pluginExposeRenderer } from "./vite.base.config"; +import { pluginExposeRenderer } from "./vite.base.config.ts"; // https://vitejs.dev/config export default defineConfig((env) => {