fix(nx/desktop): get dist to start by simplifying module import

This commit is contained in:
Elian Doran 2025-04-24 21:30:31 +03:00
parent aab545b82e
commit ec8740b179
No known key found for this signature in database
5 changed files with 85 additions and 77 deletions

8
apps/desktop/.swcrc Normal file
View File

@ -0,0 +1,8 @@
{
"jsc": {
"parser": {
"syntax": "typescript"
},
"target": "es2016"
}
}

View File

@ -1,8 +1,71 @@
import { initializeTranslations } from "@triliumnext/server/src/services/i18n.js"; import { initializeTranslations } from "@triliumnext/server/src/services/i18n.js";
import electron from "electron";
import sqlInit from "@triliumnext/server/src/services/sql_init.js";
import windowService from "@triliumnext/server/src/services/window.js";
import tray from "@triliumnext/server/src/services/tray.js";
import options from "@triliumnext/server/src/services/options.js";
import electronDebug from "electron-debug";
import electronDl from "electron-dl";
async function main() { async function main() {
// Prevent Trilium starting twice on first install and on uninstall for the Windows installer.
if ((require("electron-squirrel-startup")).default) {
process.exit(0);
}
// Adds debug features like hotkeys for triggering dev tools and reload
electronDebug();
electronDl({ saveAs: true });
// needed for excalidraw export https://github.com/zadam/trilium/issues/4271
electron.app.commandLine.appendSwitch("enable-experimental-web-platform-features");
electron.app.commandLine.appendSwitch("lang", options.getOptionOrNull("formattingLocale") ?? "en");
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
electron.app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
electron.app.quit();
}
});
electron.app.on("ready", async () => {
// electron.app.setAppUserModelId('com.github.zadam.trilium');
// if db is not initialized -> setup process
// if db is initialized, then we need to wait until the migration process is finished
if (sqlInit.isDbInitialized()) {
await sqlInit.dbReady;
await windowService.createMainWindow(electron.app);
if (process.platform === "darwin") {
electron.app.on("activate", async () => {
if (electron.BrowserWindow.getAllWindows().length === 0) {
await windowService.createMainWindow(electron.app);
}
});
}
tray.createTray();
} else {
await windowService.createSetupWindow();
}
await windowService.registerGlobalShortcuts();
});
electron.app.on("will-quit", () => {
electron.globalShortcut.unregisterAll();
});
// this is to disable electron warning spam in the dev console (local development only)
process.env["ELECTRON_DISABLE_SECURITY_WARNINGS"] = "true";
await initializeTranslations(); await initializeTranslations();
(await import("./electron.js")).default(); await import("@triliumnext/server/src/main.js");
} }
main(); main();

View File

@ -1,66 +0,0 @@
"use strict";
import electron from "electron";
import sqlInit from "@triliumnext/server/src/services/sql_init.js";
import windowService from "@triliumnext/server/src/services/window.js";
import tray from "@triliumnext/server/src/services/tray.js";
import options from "@triliumnext/server/src/services/options.js";
export default async function start() {
// Prevent Trilium starting twice on first install and on uninstall for the Windows installer.
if ((await import("electron-squirrel-startup")).default) {
process.exit(0);
}
// Adds debug features like hotkeys for triggering dev tools and reload
(await import("electron-debug")).default();
(await import("electron-dl")).default({ saveAs: true });
// needed for excalidraw export https://github.com/zadam/trilium/issues/4271
electron.app.commandLine.appendSwitch("enable-experimental-web-platform-features");
electron.app.commandLine.appendSwitch("lang", options.getOptionOrNull("formattingLocale") ?? "en");
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
electron.app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
electron.app.quit();
}
});
electron.app.on("ready", async () => {
// electron.app.setAppUserModelId('com.github.zadam.trilium');
// if db is not initialized -> setup process
// if db is initialized, then we need to wait until the migration process is finished
if (sqlInit.isDbInitialized()) {
await sqlInit.dbReady;
await windowService.createMainWindow(electron.app);
if (process.platform === "darwin") {
electron.app.on("activate", async () => {
if (electron.BrowserWindow.getAllWindows().length === 0) {
await windowService.createMainWindow(electron.app);
}
});
}
tray.createTray();
} else {
await windowService.createSetupWindow();
}
await windowService.registerGlobalShortcuts();
});
electron.app.on("will-quit", () => {
electron.globalShortcut.unregisterAll();
});
// this is to disable electron warning spam in the dev console (local development only)
process.env["ELECTRON_DISABLE_SECURITY_WARNINGS"] = "true";
await import("@triliumnext/server/src/main.js");
}

View File

@ -6,8 +6,9 @@ const outputDir = join(__dirname, 'dist');
module.exports = { module.exports = {
output: { output: {
path: outputDir, path: outputDir
}, },
target: [ "node" ],
plugins: [ plugins: [
new NxAppWebpackPlugin({ new NxAppWebpackPlugin({
target: 'node', target: 'node',
@ -21,18 +22,15 @@ module.exports = {
externalDependencies: [ externalDependencies: [
"electron/main", "electron/main",
"electron", "electron",
"@electron/remote" "@electron/remote",
"better-sqlite3"
], ],
assets: [ assets: [
] ]
}), }),
new CopyPlugin({ new CopyPlugin({
patterns: [ patterns: [
{
from: "node_modules/better-sqlite3/build/Release",
to: join(outputDir, "Release")
},
{ {
from: "../client/dist", from: "../client/dist",
to: join(outputDir, "public") to: join(outputDir, "public")
@ -44,8 +42,12 @@ module.exports = {
{ {
from: "../server/dist/assets", from: "../server/dist/assets",
to: join(outputDir, "assets") to: join(outputDir, "assets")
} },
{
from: "node_modules/better-sqlite3",
to: join(outputDir, "node_modules/better-sqlite3")
},
] ]
}) })
], ]
}; };

View File

@ -1,8 +1,9 @@
{ {
"extends": "../../tsconfig.base.json", "extends": "../../tsconfig.base.json",
"compilerOptions": { "compilerOptions": {
"module": "NodeNext", "module": "ESNext",
"moduleResolution": "nodenext", "moduleResolution": "nodenext",
"target": "ES2020",
"outDir": "dist", "outDir": "dist",
"types": [ "types": [
"node", "node",