From 370527353aab54d2ce53ab59ff658ce24455d6fe Mon Sep 17 00:00:00 2001 From: Rustem Mussabekov Date: Mon, 10 Jun 2024 14:53:49 +0300 Subject: [PATCH] Fix path resolve --- build/version.mjs | 9 +++++---- src/webview/index.mjs | 3 ++- src/window.mjs | 3 ++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/build/version.mjs b/build/version.mjs index ce630d7..b3315ec 100644 --- a/build/version.mjs +++ b/build/version.mjs @@ -1,5 +1,6 @@ -import fs from 'fs'; +import fs from 'fs' +import { resolve } from 'path' -const version = JSON.parse(fs.readFileSync(new URL('../webapp/package.json', import.meta.url).pathname, 'utf-8')).version; -const packageContent = fs.readFileSync(new URL('../package.json', import.meta.url).pathname, 'utf-8'); -fs.writeFileSync(new URL('../package.json', import.meta.url).pathname, packageContent.replace(/version": "(.*)"/i, `version": "${version}"`), 'utf-8'); \ No newline at end of file +const version = JSON.parse(fs.readFileSync(resolve(import.meta.dirname, '../webapp/package.json'), 'utf-8')).version; +const packageContent = fs.readFileSync(resolve(import.meta.dirname, '../package.json'), 'utf-8'); +fs.writeFileSync(resolve(import.meta.dirname, '../package.json'), packageContent.replace(/version": "(.*)"/i, `version": "${version}"`), 'utf-8'); \ No newline at end of file diff --git a/src/webview/index.mjs b/src/webview/index.mjs index be3238f..f8f46ab 100644 --- a/src/webview/index.mjs +++ b/src/webview/index.mjs @@ -1,8 +1,9 @@ import { app } from 'electron' +import { resolve } from 'path' const onWillAttachWebview = (_, webPreferences) => { //preload highligh script for all webview's - webPreferences.preload = new URL('./highlight.js', import.meta.url).pathname + webPreferences.preload = resolve(import.meta.dirname, './highlight.js') } export default function() { diff --git a/src/window.mjs b/src/window.mjs index 9464ea3..576ebff 100644 --- a/src/window.mjs +++ b/src/window.mjs @@ -1,6 +1,7 @@ import { BrowserWindow, nativeTheme } from 'electron' import isDev from 'electron-is-dev' import windowState from 'electron-window-state' +import { resolve } from 'path' class Window { window = null @@ -62,7 +63,7 @@ class Window { if (isDev) this.window.loadURL('http://localhost:2000') else - this.window.loadFile(new URL('../webapp/dist/electron/prod/index.html', import.meta.url).pathname) + this.window.loadFile(resolve(import.meta.dirname, '../webapp/dist/electron/prod/index.html')) //events this.window.once('ready-to-show', this.window.show)