chore(dev): app boilerplate

Electron, React, Vite app boilerplate

- license header
- pre-commit and commit-msg hooks
- storybook
- fix windows tests;
- fix linux build
- CI setup
- persistent store with electron-store and safeStorage
- localization with react-intl

Refs:
- https://github.com/haveno-dex/haveno-ui/projects/1#card-81001746
- https://github.com/haveno-dex/haveno-ui/projects/1#card-81001745

Authored-by: schowdhuri
Reviewed-by: localredhead
This commit is contained in:
Subir 2022-04-23 04:32:54 +05:30 committed by Subir
parent 3a379a7c55
commit a9893aa853
81 changed files with 16560 additions and 0 deletions

View file

@ -0,0 +1,90 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
import { app } from "electron";
import "./security-restrictions";
import { restoreOrCreateWindow } from "@src/mainWindow";
import { registerStoreHandlers } from "./services/store";
/**
* Prevent multiple instances
*/
const isSingleInstance = app.requestSingleInstanceLock();
if (!isSingleInstance) {
app.quit();
process.exit(0);
}
app.on("second-instance", restoreOrCreateWindow);
/**
* Disable Hardware Acceleration for more power-save
*/
app.disableHardwareAcceleration();
/**
* Shout down background process if all windows was closed
*/
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
/**
* @see https://www.electronjs.org/docs/v14-x-y/api/app#event-activate-macos Event: 'activate'
*/
app.on("activate", restoreOrCreateWindow);
/**
* Create app window when background process will be ready
*/
app
.whenReady()
.then(restoreOrCreateWindow)
.catch((e) => console.error("Failed create window:", e));
app
.whenReady()
.then(registerStoreHandlers)
.catch((e) => console.error("Failed to register store handlers:", e));
/**
* Install devtools in development mode only
*/
if (import.meta.env.DEV) {
app
.whenReady()
.then(() => import("electron-devtools-installer"))
.then(({ default: installExtension, REACT_DEVELOPER_TOOLS }) =>
installExtension(REACT_DEVELOPER_TOOLS, {
loadExtensionOptions: {
allowFileAccess: true,
},
})
)
.catch((e) => console.error("Failed install extension:", e));
}
/**
* Check new app version in production mode only
*/
if (import.meta.env.PROD) {
app
.whenReady()
.then(() => import("electron-updater"))
.then(({ autoUpdater }) => autoUpdater.checkForUpdatesAndNotify())
.catch((e) => console.error("Failed check updates:", e));
}

View file

@ -0,0 +1,78 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
import { BrowserWindow } from "electron";
import { join } from "path";
import { URL } from "url";
async function createWindow() {
const browserWindow = new BrowserWindow({
show: false, // Use 'ready-to-show' event to show window
webPreferences: {
nativeWindowOpen: true,
webviewTag: false, // The webview tag is not recommended. Consider alternatives like iframe or Electron's BrowserView. https://www.electronjs.org/docs/latest/api/webview-tag#warning
preload: join(__dirname, "../../preload/dist/index.cjs"),
},
});
/**
* If you install `show: true` then it can cause issues when trying to close the window.
* Use `show: false` and listener events `ready-to-show` to fix these issues.
*
* @see https://github.com/electron/electron/issues/25012
*/
browserWindow.on("ready-to-show", () => {
browserWindow?.show();
if (import.meta.env.DEV) {
browserWindow?.webContents.openDevTools();
}
});
/**
* URL for main window.
* Vite dev server for development.
* `file://../renderer/index.html` for production and test
*/
const pageUrl =
import.meta.env.DEV && import.meta.env.VITE_DEV_SERVER_URL !== undefined
? import.meta.env.VITE_DEV_SERVER_URL
: new URL(
"../renderer/dist/index.html",
"file://" + __dirname
).toString();
await browserWindow.loadURL(pageUrl);
return browserWindow;
}
/**
* Restore existing BrowserWindow or Create new BrowserWindow
*/
export async function restoreOrCreateWindow() {
let window = BrowserWindow.getAllWindows().find((w) => !w.isDestroyed());
if (window === undefined) {
window = await createWindow();
}
if (window.isMinimized()) {
window.restore();
}
window.focus();
}

View file

@ -0,0 +1,159 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
import { app, shell } from "electron";
import { URL } from "url";
/**
* List of origins that you allow open INSIDE the application and permissions for each of them.
*
* In development mode you need allow open `VITE_DEV_SERVER_URL`
*/
const ALLOWED_ORIGINS_AND_PERMISSIONS = new Map<
string,
Set<
| "clipboard-read"
| "media"
| "display-capture"
| "mediaKeySystem"
| "geolocation"
| "notifications"
| "midi"
| "midiSysex"
| "pointerLock"
| "fullscreen"
| "openExternal"
| "unknown"
>
>(
import.meta.env.DEV && import.meta.env.VITE_DEV_SERVER_URL
? [[new URL(import.meta.env.VITE_DEV_SERVER_URL).origin, new Set()]]
: []
);
/**
* List of origins that you allow open IN BROWSER.
* Navigation to origins below is possible only if the link opens in a new window
*
* @example
* <a
* target="_blank"
* href="https://github.com/"
* >
*/
const ALLOWED_EXTERNAL_ORIGINS = new Set<`https://${string}`>([
"https://github.com",
]);
app.on("web-contents-created", (_, contents) => {
/**
* Block navigation to origins not on the allowlist.
*
* Navigation is a common attack vector. If an attacker can convince the app to navigate away
* from its current page, they can possibly force the app to open web sites on the Internet.
*
* @see https://www.electronjs.org/docs/latest/tutorial/security#13-disable-or-limit-navigation
*/
contents.on("will-navigate", (event, url) => {
const { origin } = new URL(url);
if (ALLOWED_ORIGINS_AND_PERMISSIONS.has(origin)) {
return;
}
// Prevent navigation
event.preventDefault();
if (import.meta.env.DEV) {
console.warn("Blocked navigating to an unallowed origin:", origin);
}
});
/**
* Block requested unallowed permissions.
* By default, Electron will automatically approve all permission requests.
*
* @see https://www.electronjs.org/docs/latest/tutorial/security#5-handle-session-permission-requests-from-remote-content
*/
contents.session.setPermissionRequestHandler(
(webContents, permission, callback) => {
const { origin } = new URL(webContents.getURL());
const permissionGranted =
!!ALLOWED_ORIGINS_AND_PERMISSIONS.get(origin)?.has(permission);
callback(permissionGranted);
if (!permissionGranted && import.meta.env.DEV) {
console.warn(
`${origin} requested permission for '${permission}', but was blocked.`
);
}
}
);
/**
* Hyperlinks to allowed sites open in the default browser.
*
* The creation of new `webContents` is a common attack vector. Attackers attempt to convince the app to create new windows,
* frames, or other renderer processes with more privileges than they had before; or with pages opened that they couldn't open before.
* You should deny any unexpected window creation.
*
* @see https://www.electronjs.org/docs/latest/tutorial/security#14-disable-or-limit-creation-of-new-windows
* @see https://www.electronjs.org/docs/latest/tutorial/security#15-do-not-use-openexternal-with-untrusted-content
*/
contents.setWindowOpenHandler(({ url }) => {
const { origin } = new URL(url);
// @ts-expect-error Type checking is performed in runtime
if (ALLOWED_EXTERNAL_ORIGINS.has(origin)) {
// Open default browser
shell.openExternal(url).catch(console.error);
} else if (import.meta.env.DEV) {
console.warn("Blocked the opening of an unallowed origin:", origin);
}
// Prevent creating new window in application
return { action: "deny" };
});
/**
* Verify webview options before creation
*
* Strip away preload scripts, disable Node.js integration, and ensure origins are on the allowlist.
*
* @see https://www.electronjs.org/docs/latest/tutorial/security#12-verify-webview-options-before-creation
*/
contents.on("will-attach-webview", (event, webPreferences, params) => {
const { origin } = new URL(params.src);
if (!ALLOWED_ORIGINS_AND_PERMISSIONS.has(origin)) {
if (import.meta.env.DEV) {
console.warn(
`A webview tried to attach ${params.src}, but was blocked.`
);
}
event.preventDefault();
return;
}
// Strip away preload scripts if unused or verify their location is legitimate
delete webPreferences.preload;
// @ts-expect-error `preloadURL` exists - see https://www.electronjs.org/docs/latest/api/web-contents#event-will-attach-webview
delete webPreferences.preloadURL;
// Disable Node.js integration
webPreferences.nodeIntegration = false;
});
});

View file

@ -0,0 +1,60 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
import { ipcMain, safeStorage } from "electron";
import Store from "electron-store";
import type {
IStoreSchema,
IUserInfo,
UserInfoInputType,
IUserPermission,
} from "@src/types";
import { StoreKeys, StoreSchema } from "@src/types";
const store = new Store<IStoreSchema>({ schema: StoreSchema });
export function registerStoreHandlers() {
ipcMain.handle("store:userinfo", async (_, payload?: UserInfoInputType) => {
const prevData = store.get(StoreKeys.UserInfo);
// retrieve encrypted data like so:
// safeStorage.decryptString(Buffer.from(prevData.password));
if (!payload) {
return prevData;
}
const userInfo: IUserInfo = {
...payload,
// encrypt sensitive data before storage
password: safeStorage.encryptString(payload.password),
};
store.set(StoreKeys.UserInfo, {
...(prevData ?? {}),
...userInfo,
});
return store.get(StoreKeys.UserInfo);
});
ipcMain.handle(
"store:permissions",
async (_, permissions?: Array<IUserPermission>) => {
const prevData = store.get(StoreKeys.Permissions);
if (!permissions) {
return prevData;
}
store.set(StoreKeys.Permissions, [...(prevData || []), ...permissions]);
return store.get(StoreKeys.Permissions);
}
);
}

View file

@ -0,0 +1,17 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
export * from "./store";

View file

@ -0,0 +1,64 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
import type { Schema } from "electron-store";
export enum StoreKeys {
UserInfo = "UserInfo",
Permissions = "Permissions",
}
// TS types for StoreSchema
export interface IStoreSchema {
[StoreKeys.UserInfo]: IUserInfo;
[StoreKeys.Permissions]: Array<IUserPermission>;
}
export interface IUserInfo {
username: string;
password: Buffer;
}
export type UserInfoInputType = Omit<IUserInfo, "password"> & {
password: string;
};
export interface IUserPermission {
name: string;
}
// this schema is used by electron-store
// must mirror IStoreSchema
export const StoreSchema: Schema<IStoreSchema> = {
[StoreKeys.UserInfo]: {
type: "object",
required: [],
properties: {
username: { type: "string" },
},
},
[StoreKeys.Permissions]: {
type: "array",
default: [],
items: {
type: "object",
required: [],
properties: {
name: { type: "string" },
},
},
},
};

View file

@ -0,0 +1,82 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
import type { MaybeMocked } from "vitest";
import { beforeEach, expect, test, vi } from "vitest";
import { restoreOrCreateWindow } from "../src/mainWindow";
import { BrowserWindow } from "electron";
/**
* Mock real electron BrowserWindow API
*/
vi.mock("electron", () => {
const bw = vi.fn() as MaybeMocked<typeof BrowserWindow>;
// @ts-expect-error It's work in runtime, but I Haven't idea how to fix this type error
bw.getAllWindows = vi.fn(() => bw.mock.instances);
bw.prototype.loadURL = vi.fn();
bw.prototype.on = vi.fn();
bw.prototype.destroy = vi.fn();
bw.prototype.isDestroyed = vi.fn();
bw.prototype.isMinimized = vi.fn();
bw.prototype.focus = vi.fn();
bw.prototype.restore = vi.fn();
return { BrowserWindow: bw };
});
beforeEach(() => {
vi.clearAllMocks();
});
test("Should create new window", async () => {
const { mock } = vi.mocked(BrowserWindow);
expect(mock.instances).toHaveLength(0);
await restoreOrCreateWindow();
expect(mock.instances).toHaveLength(1);
expect(mock.instances[0].loadURL).toHaveBeenCalledOnce();
expect(mock.instances[0].loadURL).toHaveBeenCalledWith(
expect.stringMatching(/index\.html$/)
);
});
test("Should restore existing window", async () => {
const { mock } = vi.mocked(BrowserWindow);
// Create Window and minimize it
await restoreOrCreateWindow();
expect(mock.instances).toHaveLength(1);
const appWindow = vi.mocked(mock.instances[0]);
appWindow.isMinimized.mockReturnValueOnce(true);
await restoreOrCreateWindow();
expect(mock.instances).toHaveLength(1);
expect(appWindow.restore).toHaveBeenCalledOnce();
});
test("Should create new window if previous was destroyed", async () => {
const { mock } = vi.mocked(BrowserWindow);
// Create Window and destroy it
await restoreOrCreateWindow();
expect(mock.instances).toHaveLength(1);
const appWindow = vi.mocked(mock.instances[0]);
appWindow.isDestroyed.mockReturnValueOnce(true);
await restoreOrCreateWindow();
expect(mock.instances).toHaveLength(2);
});

View file

@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "esnext",
"target": "esnext",
"sourceMap": false,
"moduleResolution": "Node",
"skipLibCheck": true,
"strict": true,
"isolatedModules": true,
"allowSyntheticDefaultImports": true,
"types": ["node", "vite-plugin-svgr/client"],
"baseUrl": ".",
"paths": {
"@src/*": ["./src/*"],
"@services/*": ["./src/services/*"],
"@types/*": ["./src/types/*"]
}
},
"include": ["src/**/*.ts", "../../types/**/*.d.ts"],
"exclude": ["**/*.spec.ts", "**/*.test.ts"]
}

View file

@ -0,0 +1,63 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
import { node } from "../../.electron-vendors.cache.json";
import { join } from "path";
import { builtinModules } from "module";
const PACKAGE_ROOT = __dirname;
/**
* @type {import('vite').UserConfig}
* @see https://vitejs.dev/config/
*/
const config = {
mode: process.env.MODE,
root: PACKAGE_ROOT,
envDir: process.cwd(),
resolve: {
alias: {
"@src/": join(PACKAGE_ROOT, "src") + "/",
"@services/": join(PACKAGE_ROOT, "src", "services") + "/",
"@types/": join(PACKAGE_ROOT, "src", "types") + "/",
},
},
build: {
sourcemap: "inline",
target: `node${node}`,
outDir: "dist",
assetsDir: ".",
minify: process.env.MODE !== "development",
lib: {
entry: "src/index.ts",
formats: ["cjs"],
},
rollupOptions: {
external: [
"electron",
"electron-devtools-installer",
...builtinModules.flatMap((p) => [p, `node:${p}`]),
],
output: {
entryFileNames: "[name].cjs",
},
},
emptyOutDir: true,
brotliSize: false,
},
};
export default config;

26
packages/preload/contracts.d.ts vendored Normal file
View file

@ -0,0 +1,26 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
/* eslint-disable @typescript-eslint/consistent-type-imports */
interface Exposed {
readonly nodeCrypto: Readonly<typeof import("./src/nodeCrypto").nodeCrypto>;
readonly versions: Readonly<typeof import("./src/versions").versions>;
readonly electronStore: Readonly<typeof import("./src/store").store>;
}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface Window extends Exposed {}

View file

@ -0,0 +1,32 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
import { contextBridge } from "electron";
/**
* Typesafe wrapper for `electron.contextBridge.exposeInMainWorld`.
* Guarantees that all exposed APIs will comply with contracts.
* @param key The key to inject the API onto window with. The API will be accessible on window[apiKey].
* @param api Your API
*
* @see https://www.electronjs.org/docs/latest/api/context-bridge#contextbridgeexposeinmainworldapikey-api
*/
export function exposeInMainWorld<T extends keyof Exposed & string>(
key: T,
api: Exposed[T]
) {
return contextBridge.exposeInMainWorld(key, api);
}

View file

@ -0,0 +1,23 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
/**
* @module preload
*/
import "./nodeCrypto";
import "./versions";
import "./store";

View file

@ -0,0 +1,27 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
import { type BinaryLike, createHash } from "crypto";
import { exposeInMainWorld } from "./exposeInMainWorld";
function sha256sum(data: BinaryLike) {
return createHash("sha256").update(data).digest("hex");
}
// Export for types in contracts.d.ts
export const nodeCrypto = { sha256sum } as const;
exposeInMainWorld("nodeCrypto", nodeCrypto);

View file

@ -0,0 +1,27 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
import { ipcRenderer } from "electron";
import { exposeInMainWorld } from "./exposeInMainWorld";
import type { UserInfoInputType } from "./types";
// Export for types in contracts.d.ts
export const store = {
storeUserinfo: async (data?: UserInfoInputType) =>
ipcRenderer.invoke("store:userinfo", data),
};
exposeInMainWorld("electronStore", store);

View file

@ -0,0 +1,17 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
export * from "./store";

View file

@ -0,0 +1,64 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
import type { Schema } from "electron-store";
export enum StoreKeys {
UserInfo = "UserInfo",
Permissions = "Permissions",
}
// TS types for StoreSchema
export interface IStoreSchema {
[StoreKeys.UserInfo]: IUserInfo;
[StoreKeys.Permissions]: Array<IUserPermission>;
}
export interface IUserInfo {
username: string;
password: Buffer;
}
export type UserInfoInputType = Omit<IUserInfo, "password"> & {
password: string;
};
export interface IUserPermission {
name: string;
}
// this schema is used by electron-store
// must mirror IStoreSchema
export const StoreSchema: Schema<IStoreSchema> = {
[StoreKeys.UserInfo]: {
type: "object",
required: [],
properties: {
username: { type: "string" },
},
},
[StoreKeys.Permissions]: {
type: "array",
default: [],
items: {
type: "object",
required: [],
properties: {
name: { type: "string" },
},
},
},
};

View file

@ -0,0 +1,22 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
import { exposeInMainWorld } from "./exposeInMainWorld";
// Export for types in contracts.d.ts
export const versions = process.versions;
exposeInMainWorld("versions", versions);

View file

@ -0,0 +1,47 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
import { createHash } from "crypto";
import { afterEach, expect, test, vi } from "vitest";
const exposeInMainWorldMock = vi.fn();
vi.mock("electron", () => ({
contextBridge: { exposeInMainWorld: exposeInMainWorldMock },
}));
afterEach(() => {
vi.clearAllMocks();
});
test("versions", async () => {
await import("../src/versions");
expect(exposeInMainWorldMock).toBeCalledTimes(1);
expect(exposeInMainWorldMock).lastCalledWith("versions", process.versions);
});
test("nodeCrypto", async () => {
await import("../src/nodeCrypto");
expect(exposeInMainWorldMock).toBeCalledTimes(1);
expect(exposeInMainWorldMock.mock.calls[0][0]).toBe("nodeCrypto");
expect(exposeInMainWorldMock.mock.calls[0][1]).toHaveProperty("sha256sum");
const data = "rawData";
const expectedHash = createHash("sha256").update(data).digest("hex");
expect(exposeInMainWorldMock.mock.calls[0][1].sha256sum(data)).toBe(
expectedHash
);
});

View file

@ -0,0 +1,17 @@
{
"compilerOptions": {
"module": "esnext",
"target": "esnext",
"sourceMap": false,
"moduleResolution": "Node",
"skipLibCheck": true,
"strict": true,
"isolatedModules": true,
"types": ["node"],
"baseUrl": "."
},
"include": ["src/**/*.ts", "contracts.d.ts", "../../types/**/*.d.ts"],
"exclude": ["**/*.spec.ts", "**/*.test.ts"]
}

View file

@ -0,0 +1,54 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
import { chrome } from "../../.electron-vendors.cache.json";
import { builtinModules } from "module";
const PACKAGE_ROOT = __dirname;
/**
* @type {import('vite').UserConfig}
* @see https://vitejs.dev/config/
*/
const config = {
mode: process.env.MODE,
root: PACKAGE_ROOT,
envDir: process.cwd(),
build: {
sourcemap: "inline",
target: `chrome${chrome}`,
outDir: "dist",
assetsDir: ".",
minify: process.env.MODE !== "development",
lib: {
entry: "src/index.ts",
formats: ["cjs"],
},
rollupOptions: {
external: [
"electron",
...builtinModules.flatMap((p) => [p, `node:${p}`]),
],
output: {
entryFileNames: "[name].cjs",
},
},
emptyOutDir: true,
brotliSize: false,
},
};
export default config;

View file

@ -0,0 +1,29 @@
{
"env": {
"browser": true,
"node": false
},
"extends": [
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended",
"plugin:react/jsx-runtime",
"plugin:prettier/recommended"
],
"parserOptions": {
"parser": "@typescript-eslint/parser",
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": ["@typescript-eslint", "react"],
"rules": {
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/consistent-type-imports": "error",
"prettier/prettier": "error"
},
"settings": {
"react": {
"version": "detect"
}
}
}

View file

@ -0,0 +1,15 @@
<svg width="410" height="404" viewBox="0 0 410 404" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M399.641 59.5246L215.643 388.545C211.844 395.338 202.084 395.378 198.228 388.618L10.5817 59.5563C6.38087 52.1896 12.6802 43.2665 21.0281 44.7586L205.223 77.6824C206.398 77.8924 207.601 77.8904 208.776 77.6763L389.119 44.8058C397.439 43.2894 403.768 52.1434 399.641 59.5246Z" fill="url(#paint0_linear)"/>
<path d="M292.965 1.5744L156.801 28.2552C154.563 28.6937 152.906 30.5903 152.771 32.8664L144.395 174.33C144.198 177.662 147.258 180.248 150.51 179.498L188.42 170.749C191.967 169.931 195.172 173.055 194.443 176.622L183.18 231.775C182.422 235.487 185.907 238.661 189.532 237.56L212.947 230.446C216.577 229.344 220.065 232.527 219.297 236.242L201.398 322.875C200.278 328.294 207.486 331.249 210.492 326.603L212.5 323.5L323.454 102.072C325.312 98.3645 322.108 94.137 318.036 94.9228L279.014 102.454C275.347 103.161 272.227 99.746 273.262 96.1583L298.731 7.86689C299.767 4.27314 296.636 0.855181 292.965 1.5744Z" fill="url(#paint1_linear)"/>
<defs>
<linearGradient id="paint0_linear" x1="6.00017" y1="32.9999" x2="235" y2="344" gradientUnits="userSpaceOnUse">
<stop stop-color="#41D1FF"/>
<stop offset="1" stop-color="#BD34FE"/>
</linearGradient>
<linearGradient id="paint1_linear" x1="194.651" y1="8.81818" x2="236.076" y2="292.989" gradientUnits="userSpaceOnUse">
<stop stop-color="#FFEA83"/>
<stop offset="0.0833333" stop-color="#FFDD35"/>
<stop offset="1" stop-color="#FFA800"/>
</linearGradient>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
http-equiv="Content-Security-Policy"
content="script-src 'self' blob:"
/>
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script src="./src/index.tsx" type="module"></script>
</body>
</html>

View file

@ -0,0 +1,33 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
import { Routes, Route } from "react-router-dom";
import { Home } from "@pages/Home";
import { Page2 } from "@pages/Page2";
export const ROUTES = {
Home: "/",
Page2: "page2",
};
export function AppRoutes() {
return (
<Routes>
<Route path={ROUTES.Home} element={<Home />} />
<Route path={ROUTES.Page2} element={<Page2 />} />
</Routes>
);
}

View file

@ -0,0 +1,27 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
import { Box } from "@mantine/core";
import { FormattedMessage } from "react-intl";
import { LangKeys } from "@constants/lang/LangKeys";
export function Header() {
return (
<Box component="header">
<FormattedMessage id={LangKeys.AppTitle} defaultMessage="Header" />
</Box>
);
}

View file

@ -0,0 +1,53 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
import type { FC } from "react";
import { useEffect, useMemo, useState } from "react";
import { IntlProvider as ReacIntlProvider } from "react-intl";
import type { LangKeys } from "@src/constants/lang/LangKeys";
const SupportedLocales = {
EN: "en",
ES: "es",
};
const DEFAULT_LOCALE = SupportedLocales.EN;
export const IntlProvider: FC = ({ children }) => {
const [messages, setMessages] = useState<{ [key in LangKeys]: string }>();
const locale = useMemo(
() =>
navigator.language in SupportedLocales
? navigator.language
: DEFAULT_LOCALE,
[navigator.language]
);
useEffect(() => {
console.log(navigator.language);
import(/* @vite-ignore */ `../../../constants/lang/${locale}.ts`).then(
(val) => {
setMessages(val.default);
}
);
}, [locale]);
return (
<ReacIntlProvider locale={locale} messages={messages}>
{children}
</ReacIntlProvider>
);
};

View file

@ -0,0 +1,30 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
import type { ComponentStory, ComponentMeta } from "@storybook/react";
import { Header } from "../Header";
export default {
title: "atoms/Header",
component: Header,
} as ComponentMeta<typeof Header>;
const Template: ComponentStory<typeof Header> = () => {
return <Header />;
};
export const Default = Template.bind({});
Default.args = {};

View file

@ -0,0 +1,20 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
export enum LangKeys {
AppTitle = "app.title",
Header = "app.header",
}

View file

@ -0,0 +1,24 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
import { LangKeys } from "./LangKeys";
const LangPackEN: { [key in LangKeys]: string } = {
[LangKeys.AppTitle]: "Welcome",
[LangKeys.Header]: "Electron Starter",
};
export default LangPackEN;

View file

@ -0,0 +1,24 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
import { LangKeys } from "./LangKeys";
const LangPackES: { [key in LangKeys]: string } = {
[LangKeys.AppTitle]: "Bienvenido",
[LangKeys.Header]: "Electron Starter",
};
export default LangPackES;

View file

View file

@ -0,0 +1,47 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
import { StrictMode } from "react";
import ReactDOM from "react-dom";
import { QueryClient, QueryClientProvider } from "react-query";
import { HashRouter } from "react-router-dom";
import { RecoilRoot } from "recoil";
import { IntlProvider } from "@atoms/IntlProvider";
import { AppRoutes } from "./Routes";
const queryClient = new QueryClient({
defaultOptions: {
queries: {
refetchOnWindowFocus: false,
staleTime: 60 * 1000, // 60 sec
},
},
});
ReactDOM.render(
<HashRouter>
<StrictMode>
<RecoilRoot>
<IntlProvider>
<QueryClientProvider client={queryClient}>
<AppRoutes />
</QueryClientProvider>
</IntlProvider>
</RecoilRoot>
</StrictMode>
</HashRouter>,
document.getElementById("app")
);

View file

@ -0,0 +1,32 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
import { Link } from "react-router-dom";
import { ROUTES } from "@src/Routes";
import { FormattedMessage } from "react-intl";
import { LangKeys } from "@constants/lang/LangKeys";
export function Home() {
return (
<div>
<h1>Home</h1>
<h2>
<FormattedMessage id={LangKeys.AppTitle} defaultMessage="welcome" />
</h2>
<Link to={ROUTES.Page2}>Page 2</Link>
</div>
);
}

View file

@ -0,0 +1,64 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
import type { FormEvent } from "react";
import { useEffect, useRef } from "react";
import { Link } from "react-router-dom";
import { ROUTES } from "@src/Routes";
export function Page2() {
const txtUserRef = useRef<HTMLInputElement>(null);
const txtPasswdRef = useRef<HTMLInputElement>(null);
const handleSubmit = (ev: FormEvent<HTMLFormElement>) => {
ev.preventDefault();
if (!txtUserRef.current || !txtPasswdRef.current) {
return;
}
window.electronStore
.storeUserinfo({
username: txtUserRef.current.value,
password: txtPasswdRef.current.value,
})
.then((value) => {
console.log({ value });
});
};
useEffect(() => {
if (txtUserRef.current) {
window.electronStore.storeUserinfo().then((value) => {
if (txtUserRef.current) {
txtUserRef.current.value = value.username;
}
});
}
}, [txtUserRef.current]);
return (
<div>
<h1>Page 2</h1>
<form onSubmit={handleSubmit}>
<input ref={txtUserRef} type="text" placeholder="username" />
<br />
<input ref={txtPasswdRef} type="password" placeholder="password" />
<button type="submit">Let me in</button>
</form>
<Link to={ROUTES.Home}>Go Home</Link>
</div>
);
}

View file

View file

@ -0,0 +1,17 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
export * from "./store";

View file

@ -0,0 +1,64 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
import type { Schema } from "electron-store";
export enum StoreKeys {
UserInfo = "UserInfo",
Permissions = "Permissions",
}
// TS types for StoreSchema
export interface IStoreSchema {
[StoreKeys.UserInfo]: IUserInfo;
[StoreKeys.Permissions]: Array<IUserPermission>;
}
export interface IUserInfo {
username: string;
password: Buffer;
}
export type UserInfoInputType = Omit<IUserInfo, "password"> & {
password: string;
};
export interface IUserPermission {
name: string;
}
// this schema is used by electron-store
// must mirror IStoreSchema
export const StoreSchema: Schema<IStoreSchema> = {
[StoreKeys.UserInfo]: {
type: "object",
required: [],
properties: {
username: { type: "string" },
},
},
[StoreKeys.Permissions]: {
type: "array",
default: [],
items: {
type: "object",
required: [],
properties: {
name: { type: "string" },
},
},
},
};

View file

View file

View file

@ -0,0 +1,36 @@
{
"compilerOptions": {
"module": "esnext",
"target": "esnext",
"sourceMap": false,
"moduleResolution": "Node",
"skipLibCheck": true,
"strict": true,
"isolatedModules": true,
"types": ["node", "vite-plugin-svgr/client"],
"jsx": "react-jsx",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"baseUrl": "./src",
"paths": {
"@atoms/*": ["components/atoms/*"],
"@constants/*": ["constants/*"],
"@molecules/*": ["components/molecules/*"],
"@organisms/*": ["components/organisms/*"],
"@pages/*": ["pages/*"],
"@src/*": ["./*"],
"@templates/*": ["components/templates/*"],
"@utils/*": ["utils/*"]
},
"lib": ["ESNext", "dom", "dom.iterable"]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"types/**/*.d.ts",
"../../types/**/*.d.ts",
"../preload/contracts.d.ts"
],
"exclude": ["**/*.spec.ts", "**/*.test.ts"]
}

View file

View file

@ -0,0 +1,77 @@
// =============================================================================
// Copyright 2022 Haveno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
/* eslint-env node */
const { chrome } = require("../../.electron-vendors.cache.json");
const { join } = require("path");
const { builtinModules } = require("module");
const react = require("@vitejs/plugin-react");
const svgrPlugin = require("vite-plugin-svgr");
const PACKAGE_ROOT = __dirname;
/**
* @type {import('vite').UserConfig}
* @see https://vitejs.dev/config/
*/
const config = {
mode: process.env.MODE,
root: PACKAGE_ROOT,
resolve: {
alias: {
"@atoms/": join(PACKAGE_ROOT, "src", "components", "atoms") + "/",
"@constants/": join(PACKAGE_ROOT, "src", "constants") + "/",
"@molecules/": join(PACKAGE_ROOT, "src", "components", "molecules") + "/",
"@organisms/": join(PACKAGE_ROOT, "src", "components", "organisms") + "/",
"@pages/": join(PACKAGE_ROOT, "src", "pages") + "/",
"@src/": join(PACKAGE_ROOT, "src") + "/",
"@templates/": join(PACKAGE_ROOT, "src", "components", "templates") + "/",
"@utils/": join(PACKAGE_ROOT, "src", "utils") + "/",
},
},
plugins: [
react(),
svgrPlugin({
svgrOptions: {
icon: true,
},
}),
],
base: "",
server: {
fs: {
strict: true,
},
},
build: {
sourcemap: true,
target: `chrome${chrome}`,
outDir: "dist",
assetsDir: ".",
rollupOptions: {
input: join(PACKAGE_ROOT, "index.html"),
external: [...builtinModules.flatMap((p) => [p, `node:${p}`])],
},
emptyOutDir: true,
brotliSize: false,
},
test: {
environment: "happy-dom",
},
};
module.exports = config;