Skip to content

A local-first personal finance app

[AI] Enable TypeScript composite project references across monorepo (#7062)

Matiss Janis Aboltins387c8fce169a
diff --git a/.gitignore b/.gitignore
index 114a949446..3734a994ae 100644
--- a/.gitignore
+++ b/.gitignore
@@ -33,7 +33,9 @@ packages/desktop-electron/dist
packages/desktop-electron/loot-core
packages/desktop-client/service-worker
packages/plugins-service/dist
+packages/component-library/dist
packages/loot-core/lib-dist
+**/.tsbuildinfo
packages/sync-server/coverage
bundle.desktop.js
bundle.desktop.js.map
diff --git a/bin/package-electron b/bin/package-electron
index 8dfaeac4c1..a10e09bc68 100755
--- a/bin/package-electron
+++ b/bin/package-electron
@@ -59,6 +59,9 @@ yarn workspace loot-core build:browser
yarn workspace @actual-app/web build:browser
yarn workspace @actual-app/sync-server build
+# Emit loot-core declarations so desktop-electron (which includes typings/window.ts) can build
+yarn workspace loot-core exec tsc -p tsconfig.json
+
yarn workspace desktop-electron update-client
(
diff --git a/package.json b/package.json
index 08ba079882..0d53db6560 100644
--- a/package.json
+++ b/package.json
@@ -54,10 +54,10 @@
"vrt:docker": "./bin/run-vrt",
"rebuild-electron": "./node_modules/.bin/electron-rebuild -m ./packages/loot-core",
"rebuild-node": "yarn workspace loot-core rebuild",
- "lint": "oxfmt --check . && oxlint --type-aware",
- "lint:fix": "oxfmt . && oxlint --fix --type-aware",
+ "lint": "yarn workspace @actual-app/api clean && oxfmt --check . && oxlint --type-aware",
+ "lint:fix": "yarn workspace @actual-app/api clean && oxfmt . && oxlint --fix --type-aware",
"install:server": "yarn workspaces focus @actual-app/sync-server --production",
- "typecheck": "tsc -p tsconfig.root.json --noEmit && lage typecheck",
+ "typecheck": "yarn workspace @actual-app/api clean && tsc -b && tsc -p tsconfig.root.json --noEmit && lage typecheck",
"jq": "./node_modules/node-jq/bin/jq",
"prepare": "husky"
},
diff --git a/packages/api/tsconfig.json b/packages/api/tsconfig.json
index 8cd4a1dd6e..69ea5e9204 100644
--- a/packages/api/tsconfig.json
+++ b/packages/api/tsconfig.json
@@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
+ "composite": true,
// Using ES2021 because that's the newest version where
// the latest Node 16.x release supports all of the features
"target": "ES2021",
@@ -8,14 +9,18 @@
"moduleResolution": "node10",
"noEmit": false,
"declaration": true,
+ "declarationMap": true,
"outDir": "dist",
"rootDir": ".",
"declarationDir": "@types",
+ "tsBuildInfoFile": "dist/.tsbuildinfo",
"paths": {
- "loot-core/*": ["./@types/loot-core/src/*"]
+ // TEMPORARY
+ "loot-core/*": ["../loot-core/src/*"]
},
"plugins": [{ "name": "typescript-strict-plugin", "paths": ["."] }]
},
+ "references": [{ "path": "../crdt" }, { "path": "../loot-core" }],
"include": ["."],
"exclude": ["**/node_modules/*", "dist", "@types", "*.test.ts"]
}
diff --git a/packages/component-library/.storybook/preview.tsx b/packages/component-library/.storybook/preview.tsx
index b6679dce98..f2195d9650 100644
--- a/packages/component-library/.storybook/preview.tsx
+++ b/packages/component-library/.storybook/preview.tsx
@@ -3,6 +3,7 @@ import { type ReactNode } from 'react';
import type { Preview } from '@storybook/react-vite';
// Not ideal to import from desktop-client, but we need a source of truth for theme variables
+// TODO: this needs refactoring
import * as darkTheme from '../../desktop-client/src/style/themes/dark';
import * as developmentTheme from '../../desktop-client/src/style/themes/development';
import * as lightTheme from '../../desktop-client/src/style/themes/light';
diff --git a/packages/component-library/package.json b/packages/component-library/package.json
index 9f81665c61..e9ec817c06 100644
--- a/packages/component-library/package.json
+++ b/packages/component-library/package.json
@@ -58,6 +58,7 @@
"react": "19.2.4",
"react-dom": "19.2.4",
"storybook": "^10.2.7",
+ "vite-tsconfig-paths": "^5.1.4",
"vitest": "^4.0.18"
},
"peerDependencies": {
diff --git a/packages/component-library/tsconfig.json b/packages/component-library/tsconfig.json
index b21368159b..9b087aceb2 100644
--- a/packages/component-library/tsconfig.json
+++ b/packages/component-library/tsconfig.json
@@ -1,9 +1,14 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
- "noEmit": true,
+ "composite": true,
+ "noEmit": false,
+ "declaration": true,
+ "declarationMap": true,
"rootDir": "src",
- "strict": true
+ "strict": true,
+ "outDir": "dist",
+ "tsBuildInfoFile": "dist/.tsbuildinfo"
},
"include": ["src/**/*.ts", "src/**/*.tsx"],
"exclude": ["node_modules"]
diff --git a/packages/crdt/tsconfig.json b/packages/crdt/tsconfig.json
index e5101b723f..e8b5acde17 100644
--- a/packages/crdt/tsconfig.json
+++ b/packages/crdt/tsconfig.json
@@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
+ "composite": true,
// Using ES2021 because that's the newest version where
// the latest Node 16.x release supports all of the features
"target": "ES2021",
@@ -8,8 +9,10 @@
"moduleResolution": "node10",
"noEmit": false,
"declaration": true,
+ "declarationMap": true,
"strict": true,
- "outDir": "dist"
+ "outDir": "dist",
+ "tsBuildInfoFile": "dist/.tsbuildinfo"
},
"include": ["."],
"exclude": ["dist", "**/*.test.ts", "**/*.spec.ts"]
diff --git a/packages/desktop-client/package.json b/packages/desktop-client/package.json
index f232771b62..039f4fe66f 100644
--- a/packages/desktop-client/package.json
+++ b/packages/desktop-client/package.json
@@ -97,7 +97,6 @@
"uuid": "^13.0.0",
"vite": "^7.3.1",
"vite-plugin-pwa": "^1.2.0",
- "vite-tsconfig-paths": "^5.1.4",
"vitest": "^4.0.18",
"xml2js": "^0.6.2"
}
diff --git a/packages/desktop-client/tsconfig.json b/packages/desktop-client/tsconfig.json
index ad637cec77..7927b0ea57 100644
--- a/packages/desktop-client/tsconfig.json
+++ b/packages/desktop-client/tsconfig.json
@@ -1,13 +1,29 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
- "noEmit": true,
+ "composite": true,
+ "noEmit": false,
+ "declaration": true,
+ "declarationMap": true,
+ "emitDeclarationOnly": true,
+ "outDir": "build/ts",
+ "rootDir": "src",
+ "tsBuildInfoFile": "build/ts/.tsbuildinfo",
+ "paths": {
+ // TODO: move to subpath imports
+ "@desktop-client/*": ["./src/*"]
+ },
"plugins": [{ "name": "typescript-strict-plugin", "paths": ["."] }]
},
+ "references": [
+ { "path": "../loot-core" },
+ { "path": "../component-library" }
+ ],
"include": [
"src/**/*.ts",
"src/**/*.tsx",
- "../../packages/loot-core/typings/pegjs.ts",
+ "src/**/*.js",
+ // TODO: remove loot-core dependency
"../../packages/loot-core/typings/window.ts"
],
"exclude": [
diff --git a/packages/desktop-client/tsconfig.service-worker.json b/packages/desktop-client/tsconfig.service-worker.json
index 56ebc5b10a..12e39ee2c8 100644
--- a/packages/desktop-client/tsconfig.service-worker.json
+++ b/packages/desktop-client/tsconfig.service-worker.json
@@ -1,7 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
+ "composite": true,
"noEmit": false,
+ "declaration": true,
"outDir": "./service-worker",
"target": "ES2022",
"lib": ["ES2022", "WebWorker", "DOM", "DOM.Iterable"],
@@ -11,7 +13,8 @@
"esModuleInterop": true,
"skipLibCheck": true,
"strict": false,
- "types": ["vite/client"]
+ "types": ["vite/client"],
+ "tsBuildInfoFile": "./service-worker/.tsbuildinfo"
},
"include": ["src/plugin-service-worker.ts"],
"exclude": ["**/*.test.ts", "**/*.spec.ts"]
diff --git a/packages/desktop-client/vite.config.mts b/packages/desktop-client/vite.config.mts
index add2ccb40f..e4e8f5249f 100644
--- a/packages/desktop-client/vite.config.mts
+++ b/packages/desktop-client/vite.config.mts
@@ -1,4 +1,5 @@
import * as path from 'path';
+import { fileURLToPath } from 'url';
import inject from '@rollup/plugin-inject';
import basicSsl from '@vitejs/plugin-basic-ssl';
@@ -9,7 +10,8 @@ import { visualizer } from 'rollup-plugin-visualizer';
import { defineConfig, loadEnv } from 'vite';
import type { Plugin } from 'vite';
import { VitePWA } from 'vite-plugin-pwa';
-import viteTsconfigPaths from 'vite-tsconfig-paths';
+
+const __dirname = path.dirname(fileURLToPath(import.meta.url));
const addWatchers = (): Plugin => ({
name: 'add-watchers',
@@ -150,6 +152,12 @@ export default defineConfig(async ({ mode }) => {
},
resolve: {
extensions: resolveExtensions,
+ alias: {
+ '@desktop-client': path.join(__dirname, 'src'),
+ },
+ ...(!env.IS_GENERIC_BROWSER && {
+ conditions: ['electron', 'module', 'browser', 'default'],
+ }),
},
plugins: [
// electron (desktop) builds do not support PWA
@@ -204,7 +212,6 @@ export default defineConfig(async ({ mode }) => {
plugins: ['babel-plugin-react-compiler'],
},
}),
- viteTsconfigPaths({ root: '../..' }),
visualizer({ template: 'raw-data' }),
!!env.HTTPS && basicSsl(),
],
diff --git a/packages/desktop-electron/preload.ts b/packages/desktop-electron/preload.ts
index 90341a8e6a..456c1dbe30 100644
--- a/packages/desktop-electron/preload.ts
+++ b/packages/desktop-electron/preload.ts
@@ -1,3 +1,4 @@
+// @ts-strict-ignore
import { contextBridge, ipcRenderer } from 'electron';
import type { IpcRenderer } from 'electron';
diff --git a/packages/desktop-electron/tsconfig.json b/packages/desktop-electron/tsconfig.json
index 4af99749cd..871a950cbf 100644
--- a/packages/desktop-electron/tsconfig.json
+++ b/packages/desktop-electron/tsconfig.json
@@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
+ "composite": true,
// Using ES2021 because that's the newest version where
// the latest Node 16.x release supports all of the features
"target": "ES2021",
@@ -8,11 +9,14 @@
"moduleResolution": "node10",
"noEmit": false,
"declaration": true,
+ "declarationMap": true,
"outDir": "build",
"rootDir": "..",
+ "tsBuildInfoFile": "build/.tsbuildinfo",
"plugins": [{ "name": "typescript-strict-plugin", "paths": ["."] }]
},
- "include": [".", "../../packages/loot-core/typings/window.ts"],
+ "references": [{ "path": "../loot-core" }, { "path": "../sync-server" }],
+ "include": ["."],
"exclude": [
"**/node_modules/*",
"build/**/*",
diff --git a/packages/loot-core/bin/build-api b/packages/loot-core/bin/build-api
index 6af657cb6d..d6667fb415 100755
--- a/packages/loot-core/bin/build-api
+++ b/packages/loot-core/bin/build-api
@@ -5,17 +5,7 @@ set -euo pipefail
cd "$(dirname "$0")/.." || exit 1
ROOT="$(pwd -P)"
-yarn tsc -p tsconfig.api.json --outDir ../api/@types/loot-core/
-# Copy existing handwritten .d.ts files, as tsc doesn't move them for us
-dest="../../api/@types/loot-core"
-cd src
-find . -type f -name "*.d.ts" | while read -r f
-do
- d=$(dirname "${f}")
- d="${dest}/${d}"
- mkdir -p "${d}"
- cp "${f}" "${d}"
-done
-cd "$ROOT"
-yarn vite build --config ./vite.api.config.ts;
+# Emit declarations to lib-dist/decl so api package (and tsc -b) can consume them
+yarn tsc -p tsconfig.json
+yarn vite build --config ./vite.api.config.ts
./bin/copy-migrations ../api
diff --git a/packages/loot-core/package.json b/packages/loot-core/package.json
index ca05c48b90..c09d26b840 100644
--- a/packages/loot-core/package.json
+++ b/packages/loot-core/package.json
@@ -33,7 +33,7 @@
"./client/undo": "./src/client/undo.ts",
"./mocks": "./src/mocks/index.ts",
"./platform/client/connection": {
- "node": "./src/platform/client/connection/index.ts",
+ "electron": "./src/platform/client/connection/index.ts",
"default": "./src/platform/client/connection/index.browser.ts"
},
"./platform/client/undo": "./src/platform/client/undo/index.ts",
@@ -47,8 +47,8 @@
"./server/budget/types/*": "./src/server/budget/types/*.d.ts",
"./server/*": "./src/server/*.ts",
"./shared/*": "./src/shared/*.ts",
- "./types/models": "./src/types/models/index.d.ts",
- "./types/*": "./src/types/*.d.ts",
+ "./types/models": "./src/types/models/index.ts",
+ "./types/*": "./src/types/*.ts",
"./lib-dist/electron/bundle.desktop.js": "./lib-dist/electron/bundle.desktop.js"
},
"scripts": {
@@ -90,7 +90,6 @@
"devDependencies": {
"@actual-app/api": "workspace:^",
"@actual-app/crdt": "workspace:^",
- "@actual-app/web": "workspace:^",
"@swc/core": "^1.15.11",
"@types/adm-zip": "^0.5.7",
"@types/better-sqlite3": "^7.6.13",
diff --git a/packages/loot-core/src/platform/client/undo/index.ts b/packages/loot-core/src/platform/client/undo/index.ts
index 4ec4e6b4d4..b1ea0d8f10 100644
--- a/packages/loot-core/src/platform/client/undo/index.ts
+++ b/packages/loot-core/src/platform/client/undo/index.ts
@@ -1,10 +1,10 @@
-// This is temporary until we move all loot-core/client over to desktop-client.
-// oxlint-disable-next-line eslint/no-restricted-imports
-import type { Modal } from '@actual-app/web/src/modals/modalsSlice';
import { v4 as uuidv4 } from 'uuid';
import type { UndoState as ServerUndoState } from '../../../server/undo';
+// oxlint-disable-next-line @typescript-eslint/no-explicit-any
+type Modal = any; // TODO: fix me
+
type UndoState = {
url: string | null;
openModal: Modal | null;
diff --git a/packages/loot-core/tsconfig.api.json b/packages/loot-core/tsconfig.api.json
deleted file mode 100644
index 349518c690..0000000000
--- a/packages/loot-core/tsconfig.api.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- "extends": "./tsconfig.json",
- "compilerOptions": {
- "rootDir": ".",
- "declaration": true,
- "emitDeclarationOnly": true,
- "allowJs": false,
- "noEmit": false
- },
- "include": ["./typings", "./src/server/*"],
- "exclude": [
- "**/node_modules/*",
- "**/build/*",
- "**/lib-dist/*",
- "./src/server/bench.ts"
- ]
-}
diff --git a/packages/loot-core/tsconfig.json b/packages/loot-core/tsconfig.json
index c5d0d20cf5..65c9f5e10b 100644
--- a/packages/loot-core/tsconfig.json
+++ b/packages/loot-core/tsconfig.json
@@ -1,15 +1,28 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
- "noEmit": true,
+ "composite": true,
+ "noEmit": false,
+ "declaration": true,
+ "declarationMap": true,
+ "emitDeclarationOnly": true,
+ "outDir": "lib-dist/decl",
+ "rootDir": ".",
+ "tsBuildInfoFile": "lib-dist/decl/.tsbuildinfo",
"types": ["vite/client", "vitest/globals", "node"],
+ "paths": {
+ // Allow importing from hyperformula's internal typings for custom function plugins
+ "hyperformula/typings/*": ["../../node_modules/hyperformula/typings/*"]
+ },
"plugins": [{ "name": "typescript-strict-plugin", "paths": ["."] }]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"typings/**/*.ts",
- "typings/**/*.d.ts"
+ "typings/**/*.d.ts",
+ "migrations/**/*.js",
+ "src/server/tests/mockData.json"
],
"exclude": [
"node_modules",
diff --git a/packages/plugins-service/tsconfig.json b/packages/plugins-service/tsconfig.json
index 3cf12372d6..0c7f5dad2c 100644
--- a/packages/plugins-service/tsconfig.json
+++ b/packages/plugins-service/tsconfig.json
@@ -1,5 +1,6 @@
{
"compilerOptions": {
+ "composite": true,
"target": "ES2022",
"lib": ["ES2022", "WebWorker", "DOM", "DOM.Iterable"],
"module": "ES2022",
@@ -9,8 +10,11 @@
"skipLibCheck": true,
"strict": false,
"types": ["vite/client"],
+ "declaration": true,
+ "declarationMap": true,
"outDir": "dist",
"rootDir": "src",
+ "tsBuildInfoFile": "dist/.tsbuildinfo",
"plugins": [{ "name": "typescript-strict-plugin", "paths": ["."] }]
},
"include": ["src/**/*"],
diff --git a/packages/sync-server/tsconfig.json b/packages/sync-server/tsconfig.json
index 4ff66d7075..7fbd3a1e15 100644
--- a/packages/sync-server/tsconfig.json
+++ b/packages/sync-server/tsconfig.json
@@ -1,11 +1,16 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
+ "composite": true,
"lib": ["ES2021"],
"noEmit": false,
+ "declaration": true,
+ "declarationMap": true,
"outDir": "build",
+ "tsBuildInfoFile": "build/.tsbuildinfo",
"plugins": [{ "name": "typescript-strict-plugin", "paths": ["."] }]
},
+ "references": [{ "path": "../crdt" }],
"include": [
"src/**/*",
"migrations/**/*",
diff --git a/tsconfig.json b/tsconfig.json
index a2465d8379..99c1793e6a 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,11 +1,15 @@
{
"references": [
- // TODO: enable once every project is ts
- // { "path": "./packages/api" },
- // { "path": "./packages/desktop-client" }
+ { "path": "./packages/crdt" },
+ { "path": "./packages/component-library" },
+ { "path": "./packages/plugins-service" },
+ { "path": "./packages/loot-core" },
+ { "path": "./packages/api" },
+ { "path": "./packages/desktop-client" },
+ { "path": "./packages/sync-server" },
+ { "path": "./packages/desktop-electron" }
],
"compilerOptions": {
- // "composite": true,
"target": "ES2022",
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"allowSyntheticDefaultImports": true,
@@ -28,17 +32,9 @@
"moduleResolution": "bundler",
"module": "es2022",
// Until/if we build using tsc
- "noEmit": true,
- "paths": {
- // TEMPORARY: Until we can fix the "exports" in the loot-core package.json
- "loot-core/*": ["./packages/loot-core/src/*"],
- "@desktop-client/*": ["./packages/desktop-client/src/*"],
- "@desktop-client/e2e/*": ["./packages/desktop-client/e2e/*"],
- // Allow importing from hyperformula's internal typings for custom function plugins
- "hyperformula/typings/*": ["./node_modules/hyperformula/typings/*"]
- }
+ "noEmit": true
},
- "include": ["packages/**/*", "bin/*.ts"],
+ "include": ["bin/*.ts"],
"exclude": [
"**/.*/",
"node_modules",
diff --git a/upcoming-release-notes/7062.md b/upcoming-release-notes/7062.md
new file mode 100644
index 0000000000..5e6b7ccb12
--- /dev/null
+++ b/upcoming-release-notes/7062.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [MatissJanis]
+---
+
+TypeScript: start using composite references
diff --git a/yarn.lock b/yarn.lock
index 8f5a080c4d..7d789e2c1e 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -60,6 +60,7 @@ __metadata:
react-dom: "npm:19.2.4"
storybook: "npm:^10.2.7"
usehooks-ts: "npm:^3.1.1"
+ vite-tsconfig-paths: "npm:^5.1.4"
vitest: "npm:^4.0.18"
peerDependencies:
react: ">=19.2"
@@ -138,7 +139,7 @@ __metadata:
languageName: unknown
linkType: soft
-"@actual-app/web@workspace:*, @actual-app/web@workspace:^, @actual-app/web@workspace:packages/desktop-client":
+"@actual-app/web@workspace:*, @actual-app/web@workspace:packages/desktop-client":
version: 0.0.0-use.local
resolution: "@actual-app/web@workspace:packages/desktop-client"
dependencies:
@@ -220,7 +221,6 @@ __metadata:
uuid: "npm:^13.0.0"
vite: "npm:^7.3.1"
vite-plugin-pwa: "npm:^1.2.0"
- vite-tsconfig-paths: "npm:^5.1.4"
vitest: "npm:^4.0.18"
xml2js: "npm:^0.6.2"
languageName: unknown
@@ -19649,7 +19649,6 @@ __metadata:
dependencies:
"@actual-app/api": "workspace:^"
"@actual-app/crdt": "workspace:^"
- "@actual-app/web": "workspace:^"
"@jlongster/sql.js": "npm:^1.6.7"
"@reduxjs/toolkit": "npm:^2.11.2"
"@rschedule/core": "npm:^1.5.0"