diff --git a/packages/desktop-electron/index.ts b/packages/desktop-electron/index.ts index 3b4206d9f45..c71a021267c 100644 --- a/packages/desktop-electron/index.ts +++ b/packages/desktop-electron/index.ts @@ -1,5 +1,5 @@ import fs from 'fs'; -import NodeModule from 'module'; +import Module from 'module'; import path from 'path'; import { @@ -14,6 +14,8 @@ import { UtilityProcess, } from 'electron'; import isDev from 'electron-is-dev'; +// @ts-strict-ignore +import fetch from 'node-fetch'; import promiseRetry from 'promise-retry'; import { getMenu } from './menu'; @@ -26,10 +28,6 @@ import './setRequireHook'; import './security'; -const Module: typeof NodeModule & { globalPaths: string[] } = - // eslint-disable-next-line @typescript-eslint/no-explicit-any - NodeModule as unknown as any; - Module.globalPaths.push(__dirname + '/..'); // This allows relative URLs to be resolved to app:// which makes @@ -38,7 +36,7 @@ protocol.registerSchemesAsPrivileged([ { scheme: 'app', privileges: { standard: true } }, ]); -global.fetch = require('node-fetch'); +global.fetch = fetch; if (!isDev || !process.env.ACTUAL_DOCUMENT_DIR) { process.env.ACTUAL_DOCUMENT_DIR = app.getPath('documents'); diff --git a/packages/desktop-electron/modules.d.ts b/packages/desktop-electron/modules.d.ts new file mode 100644 index 00000000000..509b52346bd --- /dev/null +++ b/packages/desktop-electron/modules.d.ts @@ -0,0 +1,8 @@ +declare module 'module' { + const globalPaths: string[]; +} + +// bundles not available until we build them +declare module 'loot-core/lib-dist/bundle.desktop.js' { + const initApp: (isDev: boolean) => void; +} diff --git a/packages/desktop-electron/server.html b/packages/desktop-electron/server.html deleted file mode 100644 index 3aa919d2a45..00000000000 --- a/packages/desktop-electron/server.html +++ /dev/null @@ -1,8 +0,0 @@ - - -
- - - - - diff --git a/packages/desktop-electron/server.js b/packages/desktop-electron/server.js deleted file mode 100644 index 82cbacf80a6..00000000000 --- a/packages/desktop-electron/server.js +++ /dev/null @@ -1,15 +0,0 @@ -require('./setRequireHook'); -require('module').globalPaths.push(__dirname + '/..'); - -global.fetch = require('node-fetch'); - -// Lazy load backend code -function getBackend() { - // eslint-disable-next-line import/extensions - return require('loot-core/lib-dist/bundle.desktop.js'); -} - -const isDev = false; - -// Start the app -getBackend().initApp(isDev); diff --git a/packages/desktop-electron/server.ts b/packages/desktop-electron/server.ts new file mode 100644 index 00000000000..4ca016ca99a --- /dev/null +++ b/packages/desktop-electron/server.ts @@ -0,0 +1,20 @@ +import Module from 'module'; + +// @ts-strict-ignore +import fetch from 'node-fetch'; + +import './setRequireHook'; + +Module.globalPaths.push(__dirname + '/..'); +global.fetch = fetch; + +const lazyLoadBackend = async (isDev: boolean) => { + // eslint-disable-next-line import/extensions + const bundle = await import('loot-core/lib-dist/bundle.desktop.js'); + bundle.initApp(isDev); +}; + +const isDev = false; + +// Start the app +lazyLoadBackend(isDev); diff --git a/upcoming-release-notes/2995.md b/upcoming-release-notes/2995.md new file mode 100644 index 00000000000..02772299665 --- /dev/null +++ b/upcoming-release-notes/2995.md @@ -0,0 +1,6 @@ +--- +category: Maintenance +authors: [MikesGlitch] +--- + +Update Electron server file to use typescript