mirror of
https://github.com/actualbudget/actual.git
synced 2026-03-22 00:13:45 -05:00
* [AI] Desktop client, E2E, loot-core, sync-server and tooling updates Co-authored-by: Cursor <cursoragent@cursor.com> * Refactor database handling in various modules to use async/await for improved readability and error handling. This includes updates to database opening and closing methods across multiple files, ensuring consistent asynchronous behavior. Additionally, minor adjustments were made to encryption functions to support async operations. * Refactor sync migration tests to utilize async/await for improved readability. Updated transaction handling to streamline event expectations and cleanup process. * Refactor various functions to utilize async/await for improved readability and error handling. Updated service stopping, encryption, and file upload/download methods to ensure consistent asynchronous behavior across the application. * Refactor BudgetFileSelection component to use async/await for onSelect method, enhancing error handling and readability. Update merge tests to utilize async/await for improved clarity in transaction merging expectations. * Refactor filesystem module to use async/await for init function and related database operations, enhancing error handling and consistency across file interactions. Updated tests to reflect asynchronous behavior in database operations and file writing. * Fix typo in init function declaration to ensure it returns a Promise<void> instead of Proise<void>. * Update VRT screenshots Auto-generated by VRT workflow PR: #6987 * Update tests to use async/await for init function in web filesystem, ensuring consistent asynchronous behavior in database operations. * Update VRT screenshot for payees filter test to reflect recent changes * Update filesystem module to remove web-specific implementations and streamline path handling. Refactor file operations to enhance type safety and consistency across different environments. Add tests for SQLite interactions and ensure proper handling of database transactions. * Add release notes for maintenance: Remove usage of 'web' file types * Refactor filesystem module to use type annotations for exports and improve consistency across methods. Remove deprecated web file handling and enhance encryption functions for better browser compatibility. * Trigger CI * Add asyncStorage API file to export Electron index module * Trigger CI * Feedback: typo --------- Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
225 lines
6.5 KiB
TypeScript
225 lines
6.5 KiB
TypeScript
import * as path from 'path';
|
|
|
|
import inject from '@rollup/plugin-inject';
|
|
import basicSsl from '@vitejs/plugin-basic-ssl';
|
|
import react from '@vitejs/plugin-react';
|
|
import type { PreRenderedAsset } from 'rollup';
|
|
import { visualizer } from 'rollup-plugin-visualizer';
|
|
/// <reference types="vitest" />
|
|
import { defineConfig, loadEnv } from 'vite';
|
|
import type { Plugin } from 'vite';
|
|
import { VitePWA } from 'vite-plugin-pwa';
|
|
import viteTsconfigPaths from 'vite-tsconfig-paths';
|
|
|
|
const addWatchers = (): Plugin => ({
|
|
name: 'add-watchers',
|
|
configureServer(server) {
|
|
server.watcher
|
|
.add([
|
|
path.resolve('../loot-core/lib-dist/electron/*.js'),
|
|
path.resolve('../loot-core/lib-dist/browser/*.js'),
|
|
])
|
|
.on('all', function () {
|
|
for (const wsc of server.ws.clients) {
|
|
wsc.send(JSON.stringify({ type: 'static-changed' }));
|
|
}
|
|
});
|
|
},
|
|
});
|
|
|
|
// Inject build shims using the inject plugin
|
|
const injectShims = (): Plugin[] => {
|
|
const buildShims = path.resolve('./src/build-shims.js');
|
|
const commonInject = {
|
|
exclude: ['src/setupTests.ts'],
|
|
global: [buildShims, 'global'],
|
|
};
|
|
|
|
return [
|
|
{
|
|
name: 'inject-build-process',
|
|
config: () => ({
|
|
// rename process.env in build mode so it doesn't get set to an empty object up by the vite:define plugin
|
|
// this isn't needed in serve mode, because vite:define doesn't empty it in serve mode. And defines also happen last anyways in serve mode.
|
|
define: {
|
|
'process.env': `_process.env`,
|
|
},
|
|
}),
|
|
apply: 'build',
|
|
},
|
|
{
|
|
...inject({
|
|
...commonInject,
|
|
process: [buildShims, 'process'],
|
|
}),
|
|
enforce: 'post',
|
|
apply: 'serve',
|
|
},
|
|
{
|
|
...inject({
|
|
...commonInject,
|
|
_process: [buildShims, 'process'],
|
|
}),
|
|
enforce: 'post',
|
|
apply: 'build',
|
|
},
|
|
];
|
|
};
|
|
|
|
// https://vitejs.dev/config/
|
|
|
|
export default defineConfig(async ({ mode }) => {
|
|
const env = loadEnv(mode, process.cwd(), '');
|
|
const devHeaders = {
|
|
'Cross-Origin-Opener-Policy': 'same-origin',
|
|
'Cross-Origin-Embedder-Policy': 'require-corp',
|
|
};
|
|
|
|
// Forward Netlify env variables
|
|
if (process.env.REVIEW_ID) {
|
|
process.env.REACT_APP_REVIEW_ID = process.env.REVIEW_ID;
|
|
process.env.REACT_APP_BRANCH = process.env.BRANCH;
|
|
}
|
|
|
|
let resolveExtensions = [
|
|
'.mjs',
|
|
'.js',
|
|
'.mts',
|
|
'.ts',
|
|
'.jsx',
|
|
'.tsx',
|
|
'.json',
|
|
];
|
|
|
|
if (env.IS_GENERIC_BROWSER) {
|
|
resolveExtensions = [
|
|
'.browser.js',
|
|
'.browser.jsx',
|
|
'.browser.ts',
|
|
'.browser.tsx',
|
|
...resolveExtensions,
|
|
];
|
|
}
|
|
|
|
const browserOpen = env.BROWSER_OPEN ? `//${env.BROWSER_OPEN}` : true;
|
|
|
|
return {
|
|
base: '/',
|
|
envPrefix: 'REACT_APP_',
|
|
build: {
|
|
terserOptions: {
|
|
compress: false,
|
|
mangle: false,
|
|
},
|
|
target: 'es2022',
|
|
sourcemap: true,
|
|
outDir: mode === 'desktop' ? 'build-electron' : 'build',
|
|
assetsDir: 'static',
|
|
manifest: true,
|
|
assetsInlineLimit: 0,
|
|
chunkSizeWarningLimit: 1500,
|
|
rollupOptions: {
|
|
output: {
|
|
assetFileNames: (assetInfo: PreRenderedAsset) => {
|
|
const info = assetInfo.name?.split('.') ?? [];
|
|
let extType = info[info.length - 1];
|
|
if (/png|jpe?g|svg|gif|tiff|bmp|ico/i.test(extType)) {
|
|
extType = 'img';
|
|
} else if (/woff|woff2/.test(extType)) {
|
|
extType = 'media';
|
|
}
|
|
return `static/${extType}/[name].[hash][extname]`;
|
|
},
|
|
chunkFileNames: 'static/js/[name].[hash].chunk.js',
|
|
entryFileNames: 'static/js/[name].[hash].js',
|
|
},
|
|
},
|
|
},
|
|
server: {
|
|
host: true,
|
|
headers: mode === 'development' ? devHeaders : undefined,
|
|
port: +env.PORT || 5173,
|
|
open: env.BROWSER
|
|
? ['chrome', 'firefox', 'edge', 'browser', 'browserPrivate'].includes(
|
|
env.BROWSER,
|
|
)
|
|
: browserOpen,
|
|
watch: {
|
|
disableGlobbing: false,
|
|
},
|
|
},
|
|
resolve: {
|
|
extensions: resolveExtensions,
|
|
},
|
|
plugins: [
|
|
// electron (desktop) builds do not support PWA
|
|
mode === 'desktop'
|
|
? undefined
|
|
: VitePWA({
|
|
registerType: 'prompt',
|
|
// TODO: The plugin worker build is currently disabled due to issues with offline support. Fix this
|
|
// strategies: 'injectManifest',
|
|
// srcDir: 'service-worker',
|
|
// filename: 'plugin-sw.js',
|
|
// manifest: {
|
|
// name: 'Actual',
|
|
// short_name: 'Actual',
|
|
// description: 'A local-first personal finance tool',
|
|
// theme_color: '#5c3dbb',
|
|
// background_color: '#5c3dbb',
|
|
// display: 'standalone',
|
|
// start_url: './',
|
|
// },
|
|
// injectManifest: {
|
|
// maximumFileSizeToCacheInBytes: 10 * 1024 * 1024, // 10MB
|
|
// swSrc: `service-worker/plugin-sw.js`,
|
|
// },
|
|
devOptions: {
|
|
enabled: true, // We need service worker in dev mode to work with plugins
|
|
type: 'module',
|
|
},
|
|
workbox: {
|
|
globPatterns: [
|
|
'**/*.{js,css,html,txt,wasm,sql,sqlite,ico,png,woff2,webmanifest}',
|
|
],
|
|
ignoreURLParametersMatching: [/^v$/],
|
|
navigateFallback: '/index.html',
|
|
maximumFileSizeToCacheInBytes: 10 * 1024 * 1024, // 10MB
|
|
navigateFallbackDenylist: [
|
|
/^\/account\/.*$/,
|
|
/^\/admin\/.*$/,
|
|
/^\/secret\/.*$/,
|
|
/^\/openid\/.*$/,
|
|
/^\/plugins\/.*$/,
|
|
/^\/kcab\/.*$/,
|
|
/^\/plugin-data\/.*$/,
|
|
],
|
|
},
|
|
}),
|
|
injectShims(),
|
|
addWatchers(),
|
|
react({
|
|
babel: {
|
|
// n.b. Must be a string to ensure plugin resolution order. See https://github.com/actualbudget/actual/pull/5853
|
|
plugins: ['babel-plugin-react-compiler'],
|
|
},
|
|
}),
|
|
viteTsconfigPaths({ root: '../..' }),
|
|
visualizer({ template: 'raw-data' }),
|
|
!!env.HTTPS && basicSsl(),
|
|
],
|
|
test: {
|
|
include: ['src/**/*.{test,spec}.?(c|m)[jt]s?(x)'],
|
|
environment: 'jsdom',
|
|
globals: true,
|
|
setupFiles: './src/setupTests.ts',
|
|
testTimeout: 10000,
|
|
onConsoleLog(log: string, type: 'stdout' | 'stderr'): boolean | void {
|
|
// print only console.error
|
|
return type === 'stderr';
|
|
},
|
|
maxWorkers: 2,
|
|
},
|
|
};
|
|
});
|