chore(deps): upgrade electron-dl from v3 to v4 (pure ESM)

electron-dl v4 is a pure ESM package. Since the Electron main process
is compiled with TypeScript "module": "commonjs", static import() gets
transformed to require() which cannot load ESM. Use Function() to
preserve a real dynamic import() at runtime.
This commit is contained in:
Johannes Millan 2026-03-31 15:06:19 +02:00
parent 8e71b5a6e9
commit 92e342af68
3 changed files with 69 additions and 40 deletions

View file

@ -12,7 +12,6 @@ import {
} from 'electron';
import { join } from 'path';
import { initDebug } from './debug';
import electronDl from 'electron-dl';
import { IPC } from './shared-with-frontend/ipc-events.const';
import { initBackupAdapter } from './backup';
import { initLocalFileSyncAdapter } from './local-file-sync';
@ -124,13 +123,21 @@ export const startApp = (): void => {
// NOTE: opening the folder crashes the mas build
if (!IS_MAC) {
electronDl({
openFolderWhenDone: true,
onCompleted: (file) => {
if (mainWin) {
mainWin.webContents.send(IPC.ANY_FILE_DOWNLOADED, file);
}
},
// electron-dl v4 is pure ESM — TypeScript's "module": "commonjs" compiles
// import() to require(), which cannot load ESM. Use Function to preserve
// a real dynamic import() at runtime.
const importEsm = Function('modulePath', 'return import(modulePath)') as (
m: string,
) => Promise<{ default: (options: Record<string, unknown>) => void }>;
importEsm('electron-dl').then(({ default: electronDl }) => {
electronDl({
openFolderWhenDone: true,
onCompleted: (file: Record<string, unknown>) => {
if (mainWin) {
mainWin.webContents.send(IPC.ANY_FILE_DOWNLOADED, file);
}
},
});
});
}

84
package-lock.json generated
View file

@ -19,7 +19,7 @@
"@material-symbols/font-400": "^0.40.2",
"@noble/ciphers": "^2.1.1",
"capacitor-plugin-safe-area": "^4.0.3",
"electron-dl": "^3.5.2",
"electron-dl": "^4.0.0",
"electron-localshortcut": "^3.2.1",
"electron-log": "^5.4.3",
"electron-window-state": "^5.0.3",
@ -15081,17 +15081,17 @@
}
},
"node_modules/electron-dl": {
"version": "3.5.2",
"resolved": "https://registry.npmjs.org/electron-dl/-/electron-dl-3.5.2.tgz",
"integrity": "sha512-i104cl+u8yJ0lhpRAtUWfeGuWuL1PL6TBiw2gLf0MMIBjfgE485Ags2mcySx4uWU9P9uj/vsD3jd7X+w1lzZxw==",
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/electron-dl/-/electron-dl-4.0.0.tgz",
"integrity": "sha512-USiB9816d2JzKv0LiSbreRfTg5lDk3lWh0vlx/gugCO92ZIJkHVH0UM18EHvKeadErP6Xn4yiTphWzYfbA2Ong==",
"license": "MIT",
"dependencies": {
"ext-name": "^5.0.0",
"pupa": "^2.0.1",
"unused-filename": "^2.1.0"
"pupa": "^3.1.0",
"unused-filename": "^4.0.1"
},
"engines": {
"node": ">=12"
"node": ">=18"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
@ -15775,12 +15775,15 @@
}
},
"node_modules/escape-goat": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/escape-goat/-/escape-goat-2.1.1.tgz",
"integrity": "sha512-8/uIhbG12Csjy2JEW7D9pHbreaVaS/OpN3ycnyvElTdwM5n6GY6W6e2IPemfvGZeUMqZ9A/3GqIZMgKnBhAw/Q==",
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/escape-goat/-/escape-goat-4.0.0.tgz",
"integrity": "sha512-2Sd4ShcWxbx6OY1IHyla/CVNwvg7XwZVoXZHcSu9w9SReNP1EzzD5T8NWKIR38fIqEns9kDWKUQTXXAmlDrdPg==",
"license": "MIT",
"engines": {
"node": ">=8"
"node": ">=12"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/escape-html": {
@ -21803,15 +21806,6 @@
"ufo": "^1.6.3"
}
},
"node_modules/modify-filename": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/modify-filename/-/modify-filename-1.1.0.tgz",
"integrity": "sha512-EickqnKq3kVVaZisYuCxhtKbZjInCuwgwZWyAmRIp1NTMhri7r3380/uqwrUHfaDiPzLVTuoNy4whX66bxPVog==",
"license": "MIT",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/mri": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz",
@ -23348,6 +23342,7 @@
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz",
"integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=8"
@ -24329,15 +24324,18 @@
"license": "MIT"
},
"node_modules/pupa": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/pupa/-/pupa-2.1.1.tgz",
"integrity": "sha512-l1jNAspIBSFqbT+y+5FosojNpVpF94nlI+wDUpqP9enwOTfHx9f0gh5nB96vl+6yTpsJsypeNrwfzPrKuHB41A==",
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/pupa/-/pupa-3.3.0.tgz",
"integrity": "sha512-LjgDO2zPtoXP2wJpDjZrGdojii1uqO0cnwKoIoUzkfS98HDmbeiGmYiXo3lXeFlq2xvne1QFQhwYXSUCLKtEuA==",
"license": "MIT",
"dependencies": {
"escape-goat": "^2.0.0"
"escape-goat": "^4.0.0"
},
"engines": {
"node": ">=8"
"node": ">=12.20"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/pvtsutils": {
@ -28404,16 +28402,40 @@
}
},
"node_modules/unused-filename": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/unused-filename/-/unused-filename-2.1.0.tgz",
"integrity": "sha512-BMiNwJbuWmqCpAM1FqxCTD7lXF97AvfQC8Kr/DIeA6VtvhJaMDupZ82+inbjl5yVP44PcxOuCSxye1QMS0wZyg==",
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/unused-filename/-/unused-filename-4.0.1.tgz",
"integrity": "sha512-ZX6U1J04K1FoSUeoX1OicAhw4d0aro2qo+L8RhJkiGTNtBNkd/Fi1Wxoc9HzcVu6HfOzm0si/N15JjxFmD1z6A==",
"license": "MIT",
"dependencies": {
"modify-filename": "^1.1.0",
"path-exists": "^4.0.0"
"escape-string-regexp": "^5.0.0",
"path-exists": "^5.0.0"
},
"engines": {
"node": ">=8"
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/unused-filename/node_modules/escape-string-regexp": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-5.0.0.tgz",
"integrity": "sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw==",
"license": "MIT",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/unused-filename/node_modules/path-exists": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/path-exists/-/path-exists-5.0.0.tgz",
"integrity": "sha512-RjhtfwJOxzcFmNOi6ltcbcu4Iu+FL3zEj83dk4kAS+fVpTxXLO1b38RvJgT/0QwvV/L3aY9TAnyv0EOqW4GoMQ==",
"license": "MIT",
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
}
},
"node_modules/update-browserslist-db": {

View file

@ -151,7 +151,7 @@
"@material-symbols/font-400": "^0.40.2",
"@noble/ciphers": "^2.1.1",
"capacitor-plugin-safe-area": "^4.0.3",
"electron-dl": "^3.5.2",
"electron-dl": "^4.0.0",
"electron-localshortcut": "^3.2.1",
"electron-log": "^5.4.3",
"electron-window-state": "^5.0.3",