Bump Electron to latest and use native ESM
This commit bumps Electron and related dependencies to their latest
versions to leverage native ESM support. It adjusts build configuration
to use native ESM support instead of relying on CommonJS bundling.
Key changes:
- Bump Electron to latest v29.
Electron v28 ships with native ESM/ECMAScript modules support.
Details on Electron ESM support:
- electron/electron#21457
- electron/electron#37535
- Bump `electron-builder` to latest v24.13.
`electron-builder` is used to package and publish the application.
It supports ESM since 24.10.
Details on `electron-builder` ESM support:
- electron-userland/electron-builder#7936
- electron-userland/electron-builder#7935
- Bump `electron-log` to latest v5.1.
`electron-log` supports ESM since version 5.0.4.
Details on `electron-log` ESM support:
- megahertz/electron-log#390.
- Change `electron-vite` configuration to bundle as ESM instead of
CommonJS to leverage Electron's native ESM support.
Other supporting changes:
- Add type hint for electron-builder configuration file.
- Update import statements for `electron-updater` as it still is a
CommonJS module and does not support ESM.
Details:
- electron-userland/electron-builder#7976
- Improve `electron-builder` configuration file to dynamically locate
main entry files, supporting various JavaScript file extensions
(`.js`, `.mjs` and `.cjs`) to facilitate easier future changes.
- Change comment about Electron process-specific module alias
registration. This issue has been fixed in `electron-vite`, but
subpath module imports for Electron still do not work when building
tests (`npm run test:unit`).
Details:
- alex8088/electron-vite#372
- Add `electron-log` in bundling process instead of externalizing to
workaround Electron ESM loader issues with subpath imports (inability
to do `electron-log/main`).
Details:
- alex8088/electron-vite#401
- electron/electron#41241
- Improve desktop runtime error checks' assertion message for better
clarity.
This commit is contained in:
@@ -13,4 +13,4 @@ export const RENDERER_URL = process.env.ELECTRON_RENDERER_URL;
|
||||
|
||||
export const RENDERER_HTML_PATH = join('file://', __dirname, '../renderer/index.html');
|
||||
|
||||
export const PRELOADER_SCRIPT_PATH = join(__dirname, '../preload/index.cjs');
|
||||
export const PRELOADER_SCRIPT_PATH = join(__dirname, '../preload/index.mjs');
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
import { app, dialog } from 'electron/main';
|
||||
import { autoUpdater, type UpdateInfo } from 'electron-updater';
|
||||
import { ElectronLogger } from '@/infrastructure/Log/ElectronLogger';
|
||||
import { UpdateProgressBar } from './UpdateProgressBar';
|
||||
import { getAutoUpdater } from './ElectronAutoUpdaterFactory';
|
||||
import type { AppUpdater, UpdateInfo } from 'electron-updater';
|
||||
import type { ProgressInfo } from 'electron-builder';
|
||||
|
||||
export async function handleAutoUpdate() {
|
||||
const autoUpdater = getAutoUpdater();
|
||||
if (await askDownloadAndInstall() === DownloadDialogResult.NotNow) {
|
||||
return;
|
||||
}
|
||||
startHandlingUpdateProgress();
|
||||
startHandlingUpdateProgress(autoUpdater);
|
||||
await autoUpdater.downloadUpdate();
|
||||
}
|
||||
|
||||
function startHandlingUpdateProgress() {
|
||||
function startHandlingUpdateProgress(autoUpdater: AppUpdater) {
|
||||
const progressBar = new UpdateProgressBar();
|
||||
progressBar.showIndeterminateState();
|
||||
autoUpdater.on('error', (e) => {
|
||||
@@ -29,11 +31,11 @@ function startHandlingUpdateProgress() {
|
||||
autoUpdater.on('update-downloaded', async (info: UpdateInfo) => {
|
||||
ElectronLogger.info('@update-downloaded@\n', info);
|
||||
progressBar.close();
|
||||
await handleUpdateDownloaded();
|
||||
await handleUpdateDownloaded(autoUpdater);
|
||||
});
|
||||
}
|
||||
|
||||
async function handleUpdateDownloaded() {
|
||||
async function handleUpdateDownloaded(autoUpdater: AppUpdater) {
|
||||
if (await askRestartAndInstall() === InstallDialogResult.NotNow) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import electronUpdater, { type AppUpdater } from 'electron-updater';
|
||||
|
||||
export function getAutoUpdater(): AppUpdater {
|
||||
// Using destructuring to access autoUpdater due to the CommonJS module of 'electron-updater'.
|
||||
// It is a workaround for ESM compatibility issues, see https://github.com/electron-userland/electron-builder/issues/7976.
|
||||
const { autoUpdater } = electronUpdater;
|
||||
return autoUpdater;
|
||||
}
|
||||
@@ -1,13 +1,16 @@
|
||||
import { autoUpdater, type UpdateInfo } from 'electron-updater';
|
||||
import { ElectronLogger } from '@/infrastructure/Log/ElectronLogger';
|
||||
import { requiresManualUpdate, startManualUpdateProcess } from './ManualUpdater/ManualUpdateCoordinator';
|
||||
import { handleAutoUpdate } from './AutomaticUpdateCoordinator';
|
||||
import { getAutoUpdater } from './ElectronAutoUpdaterFactory';
|
||||
import type { UpdateInfo } from 'electron-updater';
|
||||
|
||||
interface Updater {
|
||||
checkForUpdates(): Promise<void>;
|
||||
}
|
||||
|
||||
export function setupAutoUpdater(): Updater {
|
||||
const autoUpdater = getAutoUpdater();
|
||||
|
||||
autoUpdater.logger = ElectronLogger;
|
||||
|
||||
// Auto-downloads are disabled to allow separate handling of 'check' and 'download' actions,
|
||||
|
||||
Reference in New Issue
Block a user