[GH-ISSUE #7252] [Maintenance] Migrate "*.electron" and "*.api" file extensions to "resolve.conditions" #17259

Closed
opened 2026-04-14 20:09:51 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @MatissJanis on GitHub (Mar 21, 2026).
Original GitHub issue: https://github.com/actualbudget/actual/issues/7252

Originally assigned to: @MatissJanis on GitHub.

Notice: written by AI, but heavily moderated by me.

Summary

The codebase currently uses two different mechanisms for platform-specific module resolution:

  1. Extension priority — Vite configs prepend .electron.ts or .api.ts to resolve.extensions, so index.electron.ts is found before index.ts
  2. Conditional exportspackage.json "exports" field with resolve.conditions (partially adopted in desktop-client)

We should consolidate on approach 2: define conditions in loot-core/package.json exports and configure resolve.conditions in the consuming Vite configs. This makes the resolution explicit and declarative rather than relying on file extension ordering.

Current state

Files using platform extensions (all in packages/loot-core/src/)

.electron.ts files (8):

  • shared/platform.electron.ts
  • server/encryption/encryption-internals.electron.ts
  • platform/server/asyncStorage/index.electron.ts
  • platform/server/connection/index.electron.ts
  • platform/server/fetch/index.electron.ts
  • platform/server/fs/index.electron.ts
  • platform/server/fs/path-join.electron.ts
  • platform/server/sqlite/index.electron.ts

.api.ts files (8): Mirror the above. Most are single-line re-exports of the .electron file (e.g. export * from './index.electron').

Vite configs using extension-based resolution

Config Current approach
packages/loot-core/vite.desktop.config.ts Prepends .electron.js, .electron.ts, .electron.tsx to resolve.extensions
packages/api/vite.config.ts Prepends .api.ts to resolve.extensions
packages/desktop-client/vite.config.ts Already uses resolve.conditions: ['electron', ...] for non-generic-browser builds, but also prepends .browser.* extensions for generic browser builds

Desired state

  1. Add conditional exports to loot-core/package.json for each platform module, using "electron" and "api" conditions that point at the .electron.ts files (keeping filenames as-is). Where an .api.ts file has a different implementation (not just a re-export), the "api" condition should point at that file.

  2. Remove redundant .api.ts re-export files — where an .api.ts file only does export * from './index.electron', delete it and have the "api" condition point directly at the .electron.ts file.

  3. Update all three Vite configs to use resolve.conditions instead of extension-priority:

    • packages/loot-core/vite.desktop.config.ts — use conditions: ['electron', ...] instead of prepending .electron.* extensions
    • packages/api/vite.config.ts — use conditions: ['api', ...] instead of prepending .api.ts extensions
    • packages/desktop-client/vite.config.ts — already partially done; clean up any remaining extension-based resolution for electron/api
  4. Do NOT touch .browser.ts files or browser extension resolution — that is being handled separately.

Out of scope

  • .browser.ts / .browser.tsx extension resolution (separate effort)
  • Renaming any .electron.ts files
Originally created by @MatissJanis on GitHub (Mar 21, 2026). Original GitHub issue: https://github.com/actualbudget/actual/issues/7252 Originally assigned to: @MatissJanis on GitHub. **Notice:** written by AI, but heavily moderated by me. ## Summary The codebase currently uses two different mechanisms for platform-specific module resolution: 1. **Extension priority** — Vite configs prepend `.electron.ts` or `.api.ts` to `resolve.extensions`, so `index.electron.ts` is found before `index.ts` 2. **Conditional exports** — `package.json` `"exports"` field with `resolve.conditions` (partially adopted in `desktop-client`) We should consolidate on approach 2: define conditions in `loot-core/package.json` exports and configure `resolve.conditions` in the consuming Vite configs. This makes the resolution explicit and declarative rather than relying on file extension ordering. ## Current state ### Files using platform extensions (all in `packages/loot-core/src/`) **`.electron.ts` files (8):** - `shared/platform.electron.ts` - `server/encryption/encryption-internals.electron.ts` - `platform/server/asyncStorage/index.electron.ts` - `platform/server/connection/index.electron.ts` - `platform/server/fetch/index.electron.ts` - `platform/server/fs/index.electron.ts` - `platform/server/fs/path-join.electron.ts` - `platform/server/sqlite/index.electron.ts` **`.api.ts` files (8):** Mirror the above. Most are single-line re-exports of the `.electron` file (e.g. `export * from './index.electron'`). ### Vite configs using extension-based resolution | Config | Current approach | |---|---| | `packages/loot-core/vite.desktop.config.ts` | Prepends `.electron.js`, `.electron.ts`, `.electron.tsx` to `resolve.extensions` | | `packages/api/vite.config.ts` | Prepends `.api.ts` to `resolve.extensions` | | `packages/desktop-client/vite.config.ts` | Already uses `resolve.conditions: ['electron', ...]` for non-generic-browser builds, but also prepends `.browser.*` extensions for generic browser builds | ## Desired state 1. **Add conditional exports to `loot-core/package.json`** for each platform module, using `"electron"` and `"api"` conditions that point at the `.electron.ts` files (keeping filenames as-is). Where an `.api.ts` file has a different implementation (not just a re-export), the `"api"` condition should point at that file. 2. **Remove redundant `.api.ts` re-export files** — where an `.api.ts` file only does `export * from './index.electron'`, delete it and have the `"api"` condition point directly at the `.electron.ts` file. 3. **Update all three Vite configs** to use `resolve.conditions` instead of extension-priority: - `packages/loot-core/vite.desktop.config.ts` — use `conditions: ['electron', ...]` instead of prepending `.electron.*` extensions - `packages/api/vite.config.ts` — use `conditions: ['api', ...]` instead of prepending `.api.ts` extensions - `packages/desktop-client/vite.config.ts` — already partially done; clean up any remaining extension-based resolution for electron/api 4. **Do NOT touch `.browser.ts` files or browser extension resolution** — that is being handled separately. ## Out of scope - `.browser.ts` / `.browser.tsx` extension resolution (separate effort) - Renaming any `.electron.ts` files
GiteaMirror added the AI generatedtech debtmaintenanceAPI labels 2026-04-14 20:09:51 -05:00
Author
Owner

@MatissJanis commented on GitHub (Mar 21, 2026):

Doing this work will help us reduce the complexity of our build process quite significantly. Additionally: it might reduce bundle size all across the board.

Unless anyone beats me to it (please do!) I plan on doing this when I'm finished with the other work that has been started. Creating an issue so I would not forget.

<!-- gh-comment-id:4104310934 --> @MatissJanis commented on GitHub (Mar 21, 2026): Doing this work will help us reduce the complexity of our build process quite significantly. Additionally: it might reduce bundle size all across the board. Unless anyone beats me to it (please do!) I plan on doing this when I'm finished with the other work that has been started. Creating an issue so I would not forget.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/actual#17259