mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
server-esm: Fix use of __dirname
This commit is contained in:
parent
27c296fa6c
commit
b6c5880484
1
package-lock.json
generated
1
package-lock.json
generated
@ -105,7 +105,6 @@
|
||||
"@types/jsdom": "^21.1.6",
|
||||
"@types/mime-types": "^2.1.4",
|
||||
"@types/multer": "^1.4.11",
|
||||
"@types/node": "^20.11.19",
|
||||
"@types/safe-compare": "^1.1.2",
|
||||
"@types/sanitize-html": "^2.11.0",
|
||||
"@types/sax": "^1.2.7",
|
||||
|
@ -128,7 +128,6 @@
|
||||
"@types/jsdom": "^21.1.6",
|
||||
"@types/mime-types": "^2.1.4",
|
||||
"@types/multer": "^1.4.11",
|
||||
"@types/node": "^20.11.19",
|
||||
"@types/safe-compare": "^1.1.2",
|
||||
"@types/sanitize-html": "^2.11.0",
|
||||
"@types/sax": "^1.2.7",
|
||||
|
@ -1,12 +1,15 @@
|
||||
import etapi from "../support/etapi.js";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
etapi.describeEtapi("import", () => {
|
||||
// temporarily skip this test since test-export.zip is missing
|
||||
xit("import", async () => {
|
||||
const scriptDir = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
const zipFileBuffer = fs.readFileSync(
|
||||
path.resolve(__dirname, "test-export.zip")
|
||||
path.resolve(scriptDir, "test-export.zip")
|
||||
);
|
||||
|
||||
const response = await etapi.postEtapiContent(
|
||||
|
14
src/app.ts
14
src/app.ts
@ -4,6 +4,8 @@ import favicon from "serve-favicon";
|
||||
import cookieParser from "cookie-parser";
|
||||
import helmet from "helmet";
|
||||
import compression from "compression";
|
||||
import { fileURLToPath } from "url";
|
||||
import { dirname } from "path";
|
||||
import sessionParser from "./routes/session_parser.js";
|
||||
import utils from "./services/utils.js";
|
||||
import assets from "./routes/assets.js";
|
||||
@ -16,8 +18,10 @@ await import('./becca/becca_loader');
|
||||
|
||||
const app = express();
|
||||
|
||||
const scriptDir = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
// view engine setup
|
||||
app.set('views', path.join(__dirname, 'views'));
|
||||
app.set('views', path.join(scriptDir, 'views'));
|
||||
app.set('view engine', 'ejs');
|
||||
|
||||
if (!utils.isElectron()) {
|
||||
@ -35,11 +39,11 @@ app.use(express.json({ limit: '500mb' }));
|
||||
app.use(express.raw({ limit: '500mb' }));
|
||||
app.use(express.urlencoded({ extended: false }));
|
||||
app.use(cookieParser());
|
||||
app.use(express.static(path.join(__dirname, 'public/root')));
|
||||
app.use(`/manifest.webmanifest`, express.static(path.join(__dirname, 'public/manifest.webmanifest')));
|
||||
app.use(`/robots.txt`, express.static(path.join(__dirname, 'public/robots.txt')));
|
||||
app.use(express.static(path.join(scriptDir, 'public/root')));
|
||||
app.use(`/manifest.webmanifest`, express.static(path.join(scriptDir, 'public/manifest.webmanifest')));
|
||||
app.use(`/robots.txt`, express.static(path.join(scriptDir, 'public/robots.txt')));
|
||||
app.use(sessionParser);
|
||||
app.use(favicon(`${__dirname}/../images/app-icons/win/icon.ico`));
|
||||
app.use(favicon(`${scriptDir}/../images/app-icons/win/icon.ico`));
|
||||
|
||||
assets.register(app);
|
||||
routes.register(app);
|
||||
|
@ -3,7 +3,8 @@ import { Router } from "express";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
const specPath = path.join(__dirname, 'etapi.openapi.yaml');
|
||||
import { fileURLToPath } from "url";
|
||||
const specPath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'etapi.openapi.yaml');
|
||||
let spec: string | null = null;
|
||||
|
||||
function register(router: Router) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
import assetPath from "../services/asset_path.js";
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import express from "express";
|
||||
import env from "../services/env.js";
|
||||
import serveStatic from "serve-static";
|
||||
@ -15,7 +16,7 @@ const persistentCacheStatic = (root: string, options?: serveStatic.ServeStaticOp
|
||||
};
|
||||
|
||||
function register(app: express.Application) {
|
||||
const srcRoot = path.join(__dirname, '..');
|
||||
const srcRoot = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||
app.use(`/${assetPath}/app`, persistentCacheStatic(path.join(srcRoot, 'public/app')));
|
||||
app.use(`/${assetPath}/app-dist`, persistentCacheStatic(path.join(srcRoot, 'public/app-dist')));
|
||||
app.use(`/${assetPath}/fonts`, persistentCacheStatic(path.join(srcRoot, 'public/fonts')));
|
||||
|
@ -2,7 +2,8 @@ import log from "./log.js";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
const RESOURCE_DIR = path.resolve(__dirname, "../..");
|
||||
import { fileURLToPath } from "url";
|
||||
const RESOURCE_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
|
||||
|
||||
// where the "trilium" executable is
|
||||
const ELECTRON_APP_ROOT_DIR = path.resolve(RESOURCE_DIR, "../..");
|
||||
|
@ -2,12 +2,14 @@ import { Menu, Tray } from 'electron';
|
||||
import path from "path";
|
||||
import windowService from "./window.js";
|
||||
import optionService from "./options.js";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
let tray: Tray;
|
||||
// `mainWindow.isVisible` doesn't work with `mainWindow.show` and `mainWindow.hide` - it returns `false` when the window
|
||||
// is minimized
|
||||
let isVisible = true;
|
||||
|
||||
|
||||
// Inspired by https://github.com/signalapp/Signal-Desktop/blob/dcb5bb672635c4b29a51adec8a5658e3834ec8fc/app/tray_icon.ts#L20
|
||||
const getIconSize = () => {
|
||||
switch (process.platform) {
|
||||
@ -23,7 +25,7 @@ const getIconPath = () => {
|
||||
const iconSize = getIconSize();
|
||||
|
||||
return path.join(
|
||||
__dirname,
|
||||
path.dirname(fileURLToPath(import.meta.url)),
|
||||
"../..",
|
||||
"images",
|
||||
"app-icons",
|
||||
|
@ -10,6 +10,9 @@ import keyboardActionsService from "./keyboard_actions.js";
|
||||
import remoteMain from "@electron/remote/main"
|
||||
import { App, BrowserWindow, WebContents, ipcMain } from 'electron';
|
||||
|
||||
import { fileURLToPath } from "url";
|
||||
import { dirname } from "path";
|
||||
|
||||
// Prevent the window being garbage collected
|
||||
let mainWindow: BrowserWindow | null;
|
||||
let setupWindow: BrowserWindow | null;
|
||||
@ -128,7 +131,7 @@ function configureWebContents(webContents: WebContents, spellcheckEnabled: boole
|
||||
}
|
||||
|
||||
function getIcon() {
|
||||
return path.join(__dirname, '../../images/app-icons/png/256x256' + (env.isDev() ? '-dev' : '') + '.png');
|
||||
return path.join(dirname(fileURLToPath(import.meta.url)), '../../images/app-icons/png/256x256' + (env.isDev() ? '-dev' : '') + '.png');
|
||||
}
|
||||
|
||||
async function createSetupWindow() {
|
||||
|
@ -12,7 +12,37 @@
|
||||
"lib": ["ES2022"],
|
||||
"downlevelIteration": true,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true
|
||||
"esModuleInterop": true,
|
||||
"types": [
|
||||
"@types/archiver",
|
||||
"@types/better-sqlite3",
|
||||
"@types/cls-hooked",
|
||||
"@types/compression",
|
||||
"@types/cookie-parser",
|
||||
"@types/csurf",
|
||||
"@types/debounce",
|
||||
"@types/ejs",
|
||||
"@types/escape-html",
|
||||
"@types/express",
|
||||
"@types/express-session",
|
||||
"@types/html",
|
||||
"@types/ini",
|
||||
"@types/jasmine",
|
||||
"@types/jsdom",
|
||||
"@types/mime-types",
|
||||
"@types/multer",
|
||||
"@types/safe-compare",
|
||||
"@types/sanitize-html",
|
||||
"@types/sax",
|
||||
"@types/semver",
|
||||
"@types/serve-favicon",
|
||||
"@types/session-file-store",
|
||||
"@types/stream-throttle",
|
||||
"@types/tmp",
|
||||
"@types/turndown",
|
||||
"@types/ws",
|
||||
"@types/xml2js"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"./src/**/*.js",
|
||||
|
Loading…
x
Reference in New Issue
Block a user