refactor(app): migrate to ESM; preload emitted as CJS for sandbox (Phase 5d-3b)

App source (main/preload/worker/renderer) -> ESM; app is now type: module;
__dirname via import.meta.url; worker spawned with type module. Preload is built
as CJS (electron-vite output format) because the sandboxed renderer does not
support ESM preload; main loads ../preload/index.js. Removed dead imports
(nativeImage, readline) and the obsolete scripts/dev.js.

Tests: 4 app tests require->import; app-main-settings rewritten with node:test
mock.module + dynamic import (replacing CJS Module._load mocking); test script
adds --experimental-test-module-mocks. electron-vite build clean, 119/119, and
npm run dev verified: app launches, preload bridges IPC, data loads.
This commit is contained in:
tommy0103
2026-07-09 11:05:00 +08:00
parent 80c125a572
commit 905c10789a
16 changed files with 313 additions and 555 deletions
+3 -5
View File
@@ -46,16 +46,13 @@
"out/**"
],
"asarUnpack": [
"**/node_modules/better-sqlite3/**"
"node_modules/better-sqlite3/**/*"
],
"extraResources": [
{
"from": "../scripts/schema.sql",
"to": "scripts/schema.sql"
}
],
"asarUnpack": [
"node_modules/better-sqlite3/**/*"
]
},
"dependencies": {
@@ -70,5 +67,6 @@
"vite": "^6.0.0",
"vue": "^3.4.0",
"vue-router": "^4.3.0"
}
},
"type": "module"
}