diff --git a/electron-builder.json b/electron-builder.json index afdc1234..3e10e14d 100644 --- a/electron-builder.json +++ b/electron-builder.json @@ -10,7 +10,7 @@ "output": "dist", "app": "build" }, - "afterSign": "scripts/notarize.js", + "afterSign": "scripts/notarize.mjs", "mac": { "artifactName": "Bitwarden-Connector-${version}-mac.${ext}", "category": "public.app-category.productivity", diff --git a/jslib/electron/src/services/electronStorage.service.ts b/jslib/electron/src/services/electronStorage.service.ts index 0c0596da..4c9f6563 100644 --- a/jslib/electron/src/services/electronStorage.service.ts +++ b/jslib/electron/src/services/electronStorage.service.ts @@ -1,13 +1,11 @@ import * as fs from "fs"; import { ipcMain } from "electron"; +import Store from "electron-store"; import { StorageService } from "@/jslib/common/src/abstractions/storage.service"; import { NodeUtils } from "@/jslib/common/src/misc/nodeUtils"; -// eslint-disable-next-line -const Store = require("electron-store"); - export class ElectronStorageService implements StorageService { private store: any; diff --git a/package.json b/package.json index 1b951406..9715b151 100644 --- a/package.json +++ b/package.json @@ -32,8 +32,8 @@ "lint:fix": "eslint . --fix", "build": "concurrently -n Main,Rend -c yellow,cyan \"npm run build:main\" \"npm run build:renderer\"", "build:main": "webpack --config webpack.main.mjs", - "build:renderer": "webpack --config webpack.renderer.cjs", - "build:renderer:watch": "webpack --config webpack.renderer.cjs --watch", + "build:renderer": "webpack --config webpack.renderer.mjs", + "build:renderer:watch": "webpack --config webpack.renderer.mjs --watch", "build:dist": "npm run reset && npm run rebuild && npm run build", "build:cli": "webpack --config webpack.cli.mjs", "build:cli:watch": "webpack --config webpack.cli.mjs --watch", diff --git a/scripts/notarize.js b/scripts/notarize.mjs similarity index 85% rename from scripts/notarize.js rename to scripts/notarize.mjs index 3085278d..fa18b0cd 100644 --- a/scripts/notarize.js +++ b/scripts/notarize.mjs @@ -1,8 +1,9 @@ -/* eslint-disable @typescript-eslint/no-var-requires */ -require("dotenv").config(); -const { notarize } = require("@electron/notarize"); +import "dotenv/config"; +import notarizeModule from "@electron/notarize"; -exports.default = async function notarizing(context) { +const { notarize } = notarizeModule; + +export default async function notarizing(context) { const { electronPlatformName, appOutDir } = context; if (electronPlatformName !== "darwin") { return; @@ -33,4 +34,4 @@ exports.default = async function notarizing(context) { appleIdPassword: appleIdPassword, }); } -}; +} diff --git a/src/bwdc.ts b/src/bwdc.ts index afa06430..030910d0 100644 --- a/src/bwdc.ts +++ b/src/bwdc.ts @@ -1,4 +1,6 @@ import * as fs from "fs"; +import { dirname } from "node:path"; +import { fileURLToPath } from "node:url"; import * as path from "path"; import { StorageService as StorageServiceAbstraction } from "@/jslib/common/src/abstractions/storage.service"; @@ -17,6 +19,8 @@ import { ConsoleLogService } from "@/jslib/node/src/cli/services/consoleLog.serv import { NodeApiService } from "@/jslib/node/src/services/nodeApi.service"; import { NodeCryptoFunctionService } from "@/jslib/node/src/services/nodeCryptoFunction.service"; +import packageJson from "../package.json"; + import { DirectoryFactoryService } from "./abstractions/directory-factory.service"; import { Account } from "./models/account"; import { Program } from "./program"; @@ -31,8 +35,10 @@ import { StateService } from "./services/state.service"; import { StateMigrationService } from "./services/stateMigration.service"; import { SyncService } from "./services/sync.service"; -// eslint-disable-next-line -const packageJson = require("../package.json"); +// ESM __dirname polyfill for Node 20 + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); export class Main { dataFilePath: string; diff --git a/src/main.ts b/src/main.ts index 51c7f048..64906647 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,9 @@ +import { dirname } from "node:path"; +import { fileURLToPath } from "node:url"; import * as path from "path"; import { app } from "electron"; +import electronReload from "electron-reload"; import { StateFactory } from "@/jslib/common/src/factories/stateFactory"; import { GlobalState } from "@/jslib/common/src/models/domain/globalState"; @@ -18,6 +21,13 @@ import { Account } from "./models/account"; import { I18nService } from "./services/i18n.service"; import { StateService } from "./services/state.service"; +// ESM __dirname polyfill for Node 20 + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +// Import electron-reload for dev mode hot reload + export class Main { logService: ElectronLogService; i18nService: I18nService; @@ -50,8 +60,7 @@ export class Main { const watch = args.some((val) => val === "--watch"); if (watch) { - // eslint-disable-next-line - require("electron-reload")(__dirname, {}); + electronReload(__dirname, {}); } this.logService = new ElectronLogService(null, app.getPath("userData")); diff --git a/webpack.renderer.cjs b/webpack.renderer.mjs similarity index 82% rename from webpack.renderer.cjs rename to webpack.renderer.mjs index 96f2d47b..bbc5d085 100644 --- a/webpack.renderer.cjs +++ b/webpack.renderer.mjs @@ -1,10 +1,17 @@ -const path = require("path"); -const webpack = require("webpack"); -const { merge } = require("webpack-merge"); -const HtmlWebpackPlugin = require("html-webpack-plugin"); -const MiniCssExtractPlugin = require("mini-css-extract-plugin"); -const { AngularWebpackPlugin } = require("@ngtools/webpack"); -const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin"); +import path from "node:path"; +import { fileURLToPath } from "node:url"; +import { dirname } from "node:path"; +import webpack from "webpack"; +import { merge } from "webpack-merge"; +import HtmlWebpackPlugin from "html-webpack-plugin"; +import MiniCssExtractPlugin from "mini-css-extract-plugin"; +import { AngularWebpackPlugin } from "@ngtools/webpack"; +import TsconfigPathsPlugin from "tsconfig-paths-webpack-plugin"; +import sass from "sass"; + +// ESM __dirname polyfill for Node 20 +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); const common = { module: { @@ -99,7 +106,7 @@ const renderer = { { loader: "sass-loader", options: { - implementation: require("sass"), + implementation: sass, }, }, ], @@ -138,4 +145,4 @@ const renderer = { ], }; -module.exports = merge(common, renderer); +export default merge(common, renderer);