Skip to content

Commit

Permalink
switch to esm
Browse files Browse the repository at this point in the history
  • Loading branch information
nottobe committed Aug 20, 2024
1 parent 7f4113e commit 6cc5d00
Show file tree
Hide file tree
Showing 11 changed files with 482 additions and 434 deletions.
File renamed without changes.
8 changes: 4 additions & 4 deletions forge.config.js → forge.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { FuseV1Options, FuseVersion } = require('@electron/fuses');
module.exports = {
packagerConfig: {
asar: false,
ignore: ['tests/','tmp/']
ignore: ['tests/', 'tmp/']
},
rebuildConfig: {},
makers: [
Expand Down Expand Up @@ -35,17 +35,17 @@ module.exports = {
{
// `entry` is just an alias for `build.lib.entry` in the corresponding file of `config`.
entry: 'src/electron/main.js',
config: 'vite.main.config.mjs',
config: 'vite.main.config.js',
},
{
entry: 'src/electron/preload.js',
config: 'vite.preload.config.mjs',
config: 'vite.preload.config.js',
},
],
renderer: [
{
name: 'main_window',
config: 'vite.renderer.config.mjs',
config: 'vite.renderer.config.js',
},
],
},
Expand Down
29 changes: 15 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.5.7-unstabl-unstablee",
"description": "Wahoo Missing Configuration GUI App",
"main": ".vite/build/main.js",
"type": "module",
"author": "Viacheslav Tykhanovskyi",
"license": "GPL-3.0-or-later",
"scripts": {
Expand All @@ -16,33 +17,33 @@
"devDependencies": {
"@babel/core": "^7.24.3",
"@babel/preset-env": "^7.24.3",
"@electron-forge/cli": "^7.3.1",
"@electron-forge/maker-deb": "^7.3.1",
"@electron-forge/maker-rpm": "^7.3.1",
"@electron-forge/maker-squirrel": "^7.3.1",
"@electron-forge/maker-zip": "^7.3.1",
"@electron-forge/plugin-auto-unpack-natives": "^7.3.1",
"@electron-forge/plugin-fuses": "^7.2.0",
"@electron-forge/plugin-vite": "^7.3.1",
"@electron/fuses": "^1.7.0",
"@electron-forge/cli": "^7.4.0",
"@electron-forge/maker-deb": "^7.4.0",
"@electron-forge/maker-rpm": "^7.4.0",
"@electron-forge/maker-squirrel": "^7.4.0",
"@electron-forge/maker-zip": "^7.4.0",
"@electron-forge/plugin-auto-unpack-natives": "^7.4.0",
"@electron-forge/plugin-fuses": "^7.4.0",
"@electron-forge/plugin-vite": "^7.4.0",
"@electron/fuses": "^1.8.0",
"@vitejs/plugin-vue": "^5.0.4",
"autoprefixer": "^10.4.14",
"babel-jest": "^29.7.0",
"compare-json": "^0.4.0",
"electron": "29.1.6",
"electron": "^32.0.0",
"html-to-image": "^1.11.11",
"jest": "^29.7.0",
"mitt": "^3.0.0",
"postcss": "^8.4.21",
"prettier": "^2.8.7",
"tailwindcss": "^3.3.1",
"vite": "^5.0.12"
"vite": "^5.4.1"
},
"dependencies": {
"cross-env": "^7.0.3",
"electron-context-menu": "^3.6.1",
"electron-squirrel-startup": "^1.0.0",
"electron-unhandled": "^4.0.1",
"electron-squirrel-startup": "^1.0.1",
"electron-unhandled": "^5.0.0",
"extract-zip": "^2.0.1",
"log4js": "^6.9.1",
"vue": "^3.2.47",
Expand All @@ -55,4 +56,4 @@
"not dead",
"not ie 11"
]
}
}
File renamed without changes.
44 changes: 24 additions & 20 deletions src/electron/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import path from "path";
import log4js from "log4js";
import { createRequire } from 'node:module';
import { fileURLToPath } from 'node:url';
import unhandled from "electron-unhandled";

import {
Expand All @@ -10,6 +12,9 @@ import {
dialog,
} from "electron";

const require = createRequire(import.meta.url);
const __dirname = path.dirname(fileURLToPath(import.meta.url));

if (app.getGPUFeatureStatus().gpu_compositing.includes("disabled")) {
app.disableHardwareAcceleration();
}
Expand All @@ -18,8 +23,8 @@ import contextMenu from "electron-context-menu";

import AdbWrapper from "src/domain/adb-wrapper.js";
import DeviceService from "src/domain/device-service.js";
import {resolveResources} from "./resources.js";
import {translate} from "./i18n.js";
import { resolveResources } from "./resources.js";
import { translate } from "./i18n.js";

// Stop the app launching multiple times during install on Windows
if (require("electron-squirrel-startup")) app.quit();
Expand Down Expand Up @@ -57,8 +62,7 @@ const setupLogger = () => {
log.level = "debug";

log.info(
`Starting ${app.getName()}-${app.getVersion()} ${process.platform}-${
process.arch
`Starting ${app.getName()}-${app.getVersion()} ${process.platform}-${process.arch
}-${process.version} (${process.env.NODE_ENV})...`
);

Expand Down Expand Up @@ -160,21 +164,21 @@ const buildMenuTemplate = (messages, locale) => {
// { role: 'appMenu' }
...(isMac
? [
{
label: app.name,
submenu: [
{ role: "about" },
{ type: "separator" },
{ role: "services" },
{ type: "separator" },
{ role: "hide" },
{ role: "hideOthers" },
{ role: "unhide" },
{ type: "separator" },
{ role: "quit" },
],
},
]
{
label: app.name,
submenu: [
{ role: "about" },
{ type: "separator" },
{ role: "services" },
{ type: "separator" },
{ role: "hide" },
{ role: "hideOthers" },
{ role: "unhide" },
{ type: "separator" },
{ role: "quit" },
],
},
]
: []),
// { role: 'fileMenu' }
{
Expand Down Expand Up @@ -315,7 +319,7 @@ app.whenReady().then(() => {
fs.writeFile(
"screenshots/screenshot.png",
Buffer.from(image, "base64"),
(e) => {}
(e) => { }
);
});

Expand Down
File renamed without changes.
23 changes: 8 additions & 15 deletions vite.base.config.mjs → vite.base.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { builtinModules } from 'node:module';
import pkg from './package.json';

export const builtins = [
'electron',
...builtinModules.map((m) => [m, `node:${m}`]).flat(),
];
export const builtins = ['electron', ...builtinModules.map((m) => [m, `node:${m}`]).flat()];

export const external = [...builtins, ...Object.keys(pkg.dependencies || {})];

export const esmodule = pkg.type === 'module';

/** @type {(env: import('vite').ConfigEnv<'build'>) => import('vite').UserConfig} */
export const getBuildConfig = (env) => {
const { root, mode, command } = env;
Expand All @@ -22,6 +21,7 @@ export const getBuildConfig = (env) => {
outDir: '.vite/build',
watch: command === 'serve' ? {} : null,
minify: command === 'build',
sourcemap: command === 'serve',
},
clearScreen: false,
};
Expand All @@ -47,17 +47,12 @@ export const getDefineKeys = (names) => {
/** @type {(env: import('vite').ConfigEnv<'build'>) => Record<string, any>} */
export const getBuildDefine = (env) => {
const { command, forgeConfig } = env;
const names = forgeConfig.renderer
.filter(({ name }) => name != null)
.map(({ name }) => name);
const names = forgeConfig.renderer.filter(({ name }) => name != null).map(({ name }) => name);
const defineKeys = getDefineKeys(names);
const define = Object.entries(defineKeys).reduce((acc, [name, keys]) => {
const { VITE_DEV_SERVER_URL, VITE_NAME } = keys;
const def = {
[VITE_DEV_SERVER_URL]:
command === 'serve'
? JSON.stringify(process.env[VITE_DEV_SERVER_URL])
: undefined,
[VITE_DEV_SERVER_URL]: command === 'serve' ? JSON.stringify(process.env[VITE_DEV_SERVER_URL]) : undefined,
[VITE_NAME]: JSON.stringify(name),
};
return { ...acc, ...def };
Expand All @@ -81,9 +76,7 @@ export const pluginExposeRenderer = (name) => {
/** @type {import('node:net').AddressInfo} */
const addressInfo = server.httpServer?.address();
// Expose env constant for main process use.
process.env[
VITE_DEV_SERVER_URL
] = `http://localhost:${addressInfo?.port}`;
process.env[VITE_DEV_SERVER_URL] = `http://localhost:${addressInfo?.port}`;
});
},
};
Expand All @@ -106,4 +99,4 @@ export const pluginHotRestart = (command) => {
}
},
};
};
};
5 changes: 3 additions & 2 deletions vite.main.config.mjs → vite.main.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import {
getBuildConfig,
getBuildDefine,
external,
esmodule,
pluginHotRestart,
} from './vite.base.config.mjs';
} from './vite.base.config';

// https://vitejs.dev/config
export default defineConfig((env) => {
Expand All @@ -17,7 +18,7 @@ export default defineConfig((env) => {
lib: {
entry: forgeConfigSelf.entry,
fileName: () => '[name].js',
formats: ['cjs'],
formats: [esmodule ? 'es' : 'cjs'],
},
rollupOptions: {
external,
Expand Down
2 changes: 1 addition & 1 deletion vite.preload.config.mjs → vite.preload.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
getBuildConfig,
external,
pluginHotRestart,
} from './vite.base.config.mjs';
} from './vite.base.config';

// https://vitejs.dev/config
export default defineConfig((env) => {
Expand Down
4 changes: 2 additions & 2 deletions vite.renderer.config.mjs → vite.renderer.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from 'vite';
import { pluginExposeRenderer } from './vite.base.config.mjs';
import { pluginExposeRenderer } from './vite.base.config';
import { fileURLToPath, URL } from 'node:url'
import vue from '@vitejs/plugin-vue';

Expand All @@ -9,7 +9,7 @@ export default defineConfig((env) => {
const forgeEnv = env;
const { root, mode, forgeConfigSelf } = forgeEnv;
const name = forgeConfigSelf.name ?? '';

/** @type {import('vite').UserConfig} */
return {
root,
Expand Down
Loading

0 comments on commit 6cc5d00

Please sign in to comment.