Add browser build configuration for API package#7247
Add browser build configuration for API package#7247MatissJanis wants to merge 13 commits intomasterfrom
Conversation
The API package was previously Node.js-only due to its dependency on better-sqlite3 and Node.js fs/path modules. This adds a browser build that uses loot-core's existing browser platform implementations (sql.js/WASM, IndexedDB, absurd-sql) instead. Changes: - Add index.web.ts: browser entry point (no Node.js version check or node-fetch polyfill) - Add vite.browser.config.ts: browser-targeted Vite build that resolves to browser platform files (index.ts) instead of Node.js ones (index.api.ts -> index.electron.ts) - Update package.json: conditional exports (browser vs default/node), module field, build:browser script - Update tsconfig.json: exclude new config file from type checking The browser build outputs dist/browser.js (ESM) alongside the existing dist/index.js (CJS/Node). Bundlers that support the "browser" condition in package.json exports will automatically use the browser build. https://claude.ai/code/session_01MnxRXLNjqXrVb5CdsC85Fb
- Remove `internal` export from index.web.ts (keep as local variable) - Use `yarn build:node && yarn build:browser` in build script - Remove unnecessary `node:` external from vite.browser.config.ts (Vite handles browser externalization automatically) https://claude.ai/code/session_01MnxRXLNjqXrVb5CdsC85Fb
✅ Deploy Preview for actualbudget ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for actualbudget-storybook ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for actualbudget-website ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
The API package was previously Node.js-only due to its dependency on better-sqlite3 and Node.js fs/path modules. This adds a browser build that uses loot-core's existing browser platform implementations (sql.js/WASM, IndexedDB, absurd-sql) instead. Changes: - Add index.web.ts: browser entry point (no Node.js version check or node-fetch polyfill) - Add vite.browser.config.ts: browser-targeted Vite build that resolves to browser platform files (index.ts) instead of Node.js ones (index.api.ts -> index.electron.ts) - Update package.json: conditional exports (browser vs default/node), module field, build:browser script - Update tsconfig.json: exclude new config file from type checking The browser build outputs dist/browser.js (ESM) alongside the existing dist/index.js (CJS/Node). Bundlers that support the "browser" condition in package.json exports will automatically use the browser build. https://claude.ai/code/session_01MnxRXLNjqXrVb5CdsC85Fb
- Remove `internal` export from index.web.ts (keep as local variable) - Use `yarn build:node && yarn build:browser` in build script - Remove unnecessary `node:` external from vite.browser.config.ts (Vite handles browser externalization automatically) https://claude.ai/code/session_01MnxRXLNjqXrVb5CdsC85Fb
6d6e032 to
3e2303e
Compare
Add type assertion for aqlQuery result to fix 'result is of type unknown' error introduced in #7240. https://claude.ai/code/session_01MnxRXLNjqXrVb5CdsC85Fb
There was a problem hiding this comment.
Maybe we should do index.browser.ts? Because that's the naming we use in loot-core
There was a problem hiding this comment.
That makes sense.
Also added some unit tests.
Still have not done a manual test though, so am not 100% confident in this PR. But I have to leave it here. Will circle back in ~1 week. Or you can take over it if you like
There was a problem hiding this comment.
Also to note: if we start using api directly in desktop-client - the bundle size will go up by approx 4mb as we would be double-bundling loot-core. To solve this we need to also address #7252 and then slightly change the build process for the api package. All doable.. but I haven't gotten to this yet.
…albudget/actual into claude/browser-compatible-api-QbhHh
… API package. This change is part of the ongoing refactor to streamline the API for browser compatibility.
- Introduced `npm-run-all` for improved script management in package.json. - Updated Vite configuration to include test settings for both browser and Node environments. - Added integration tests for API CRUD operations, including budget and category management. - Created setup files for browser and Node testing environments. - Updated yarn.lock to include new dependencies. This commit enhances the testing framework and ensures better compatibility across environments.
Description
API package: browser support 🎉
Related issue(s)
n/a
Testing
The build scripts can be verified by running:
yarn build:node- builds the Node.js versionyarn build:browser- builds the browser versionyarn build- builds both versionsExisting tests should continue to pass with no regressions. We now also have browser-specific tests.
Checklist
https://claude.ai/code/session_01MnxRXLNjqXrVb5CdsC85Fb
Bundle Stats
View detailed bundle stats
desktop-client
Total
View detailed bundle breakdown
Added
No assets were added
Removed
No assets were removed
Bigger
No assets were bigger
Smaller
No assets were smaller
Unchanged
loot-core
Total
View detailed bundle breakdown
Added
No assets were added
Removed
No assets were removed
Bigger
No assets were bigger
Smaller
No assets were smaller
Unchanged
api
Total
View detailed bundle breakdown
Added
No assets were added
Removed
No assets were removed
Bigger
No assets were bigger
Smaller
No assets were smaller
Unchanged
cli
Total
View detailed bundle breakdown
Added
No assets were added
Removed
No assets were removed
Bigger
No assets were bigger
Smaller
No assets were smaller
Unchanged