Added typechecks

This commit is contained in:
Oliver Schwendener 2023-10-04 16:01:03 +02:00
parent 4558edc18e
commit e3e6ab323e
No known key found for this signature in database
GPG Key ID: 65FB86201210F104
13 changed files with 75 additions and 44 deletions

View File

@ -1,12 +1,12 @@
name: Build
on:
push:
branches:
- main
pull_request:
branches:
- main
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
@ -24,22 +24,26 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
cache: pnpm
- name: Install dependencies
run: pnpm install
env:
NODE_ENV: development
NODE_ENV: development
- name: Lint TypeScript files
- name: Run typecheck
run: |
pnpm typecheck:electron
pnpm typecheck:renderer
- name: Run linter
run: pnpm lint
- name: Prettier check src folder
run: pnpm exec prettier --check src/**/*
- name: Prettier check electron folder
run: pnpm exec prettier --check electron/**/*
- name: Run prettier
run: |
pnpm exec prettier --check src/**/*
pnpm exec prettier --check electron/**/*
- name: Run tests
run: pnpm test

View File

@ -24,7 +24,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
cache: pnpm
- name: Install dependencies
@ -32,6 +32,22 @@ jobs:
env:
NODE_ENV: development
- name: Run typecheck
run: |
pnpm typecheck:electron
pnpm typecheck:renderer
- name: Run linter
run: pnpm lint
- name: Run prettier
run: |
pnpm exec prettier --check src/**/*
pnpm exec prettier --check electron/**/*
- name: Run tests
run: pnpm test
- name: Bundle files
run: pnpm bundle
env:

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
dist-electron/
dist/
release/
tsconfig.node.tsbuildinfo
.DS_Store

View File

@ -1,5 +1,5 @@
import type { UeliPlugin } from "@common/UeliPlugin";
import type { PluginDependencies } from "./PluginDependencies";
import type { PluginDependencies } from "../PluginDependencies";
export const setPluginDependencies = (plugins: UeliPlugin[], pluginDependencies: PluginDependencies) => {
for (const plugin of plugins) {

View File

@ -3,9 +3,15 @@ import type { IpcMain } from "electron";
import { serializePluginToIpcEventReturnValue } from "./serializePluginToIpcEventReturnValue";
export const subscribeToIpcMainEvents = (ipcMain: IpcMain, plugins: UeliPlugin[]) => {
ipcMain.on("pluginEnabled", (_, { pluginId }: { pluginId: string }) =>
plugins.find(({ id }) => id === pluginId).addSearchResultItemsToSearchIndex(),
);
ipcMain.on("pluginEnabled", (_, { pluginId }: { pluginId: string }) => {
const plugin = plugins.find(({ id }) => id === pluginId);
if (!plugin) {
throw new Error(`Unable to find plugin with id ${pluginId}`);
}
plugin.addSearchResultItemsToSearchIndex();
});
ipcMain.on("getSupportedPlugins", (event) => {
event.returnValue = plugins.map((plugin) => serializePluginToIpcEventReturnValue(plugin));

View File

@ -1,5 +1,5 @@
import { join } from "path";
import type { PluginDependencies } from "../PluginDependencies";
import type { PluginDependencies } from "../../PluginDependencies";
export class MacOsApplicationIconGenerator {
public constructor(private readonly pluginDependencies: PluginDependencies) {}

View File

@ -1,5 +1,5 @@
import { join, normalize, parse } from "path";
import type { PluginDependencies } from "../PluginDependencies";
import type { PluginDependencies } from "../../PluginDependencies";
import { Application } from "./Application";
import type { ApplicationRepository } from "./ApplicationRepository";
import type { MacOsApplicationIconGenerator } from "./MacOsApplicationIconGenerator";

View File

@ -1,5 +1,5 @@
import { join } from "path";
import type { PluginDependencies } from "../PluginDependencies";
import type { PluginDependencies } from "../../PluginDependencies";
import { Application } from "./Application";
import type { ApplicationRepository } from "./ApplicationRepository";
import type { WindowsApplicationRetrieverResult } from "./WindowsApplicationRetrieverResult";

View File

@ -16,12 +16,12 @@ export class SettingsManager {
return this.settings;
}
public getPluginSettingByKey<T>(pluginId: string, key: string, defaultValue?: T): T {
public getPluginSettingByKey<T>(pluginId: string, key: string, defaultValue: T): T {
return this.getSettingByKey<T>(`plugin[${pluginId}].${key}`, defaultValue);
}
public getSettingByKey<T>(key: string, defaultValue?: T): T {
return (this.settings[key] as T) ?? defaultValue;
public getSettingByKey<T>(key: string, defaultValue: T): T {
return (this.settings[key] as T | undefined) ?? defaultValue;
}
public async saveSetting<T>(key: string, value: T): Promise<void> {

View File

@ -18,7 +18,8 @@
"test:coverage": "vitest run --coverage",
"test:watch": "vitest",
"test": "vitest run",
"typecheck": "tsc --noEmit"
"typecheck:electron": "tsc -p tsconfig.node.json --noEmit",
"typecheck:renderer": "tsc -p tsconfig.json --noEmit"
},
"devDependencies": {
"@types/react": "^18.2.6",

View File

@ -1,4 +1,4 @@
import { SearchResultItem } from "@common/SearchResultItem";
import type { SearchResultItem } from "@common/SearchResultItem";
import { describe, expect, it } from "vitest";
import { filterSearchResultItemsBySearchTerm } from "./filterSearchResultItemsBySearchTerm";
@ -25,7 +25,7 @@ describe(filterSearchResultItemsBySearchTerm, () => {
it("should return an empty list if search term does not match any of the search result items", () =>
testFilterSearchResultItemsBySearchTerm({
searchResultItems: [{ id: "item1", name: "Item 1", description: "Item 1" }],
searchResultItems: [<SearchResultItem>{ id: "item1", name: "Item 1", description: "Item 1" }],
searchTerm: "search term",
fuzzyness: 0.6,
expected: [],
@ -34,33 +34,33 @@ describe(filterSearchResultItemsBySearchTerm, () => {
it("should return list of one item if search term matches one search result item", () =>
testFilterSearchResultItemsBySearchTerm({
searchResultItems: [
{ id: "item1", name: "Old Man's War", description: "An old book" },
{ id: "item2", name: "The Lock Artist", description: "A very old book" },
<SearchResultItem>{ id: "item1", name: "Old Man's War", description: "An old book" },
<SearchResultItem>{ id: "item2", name: "The Lock Artist", description: "A very old book" },
],
searchTerm: "Old",
fuzzyness: 0.6,
expected: [{ id: "item1", name: "Old Man's War", description: "An old book" }],
expected: [<SearchResultItem>{ id: "item1", name: "Old Man's War", description: "An old book" }],
}));
it("should be case insensitive", () =>
testFilterSearchResultItemsBySearchTerm({
searchResultItems: [{ id: "item1", name: "Item 1", description: "Item 1" }],
searchResultItems: [<SearchResultItem>{ id: "item1", name: "Item 1", description: "Item 1" }],
searchTerm: "item",
fuzzyness: 0.6,
expected: [{ id: "item1", name: "Item 1", description: "Item 1" }],
expected: [<SearchResultItem>{ id: "item1", name: "Item 1", description: "Item 1" }],
}));
it("should include items that partially match the search term if fuzzyness is high", () =>
testFilterSearchResultItemsBySearchTerm({
searchResultItems: [{ id: "item1", name: "Item 1", description: "Item 1" }],
searchResultItems: [<SearchResultItem>{ id: "item1", name: "Item 1", description: "Item 1" }],
searchTerm: "itm",
fuzzyness: 0.6,
expected: [{ id: "item1", name: "Item 1", description: "Item 1" }],
expected: [<SearchResultItem>{ id: "item1", name: "Item 1", description: "Item 1" }],
}));
it("should exclude items that partially match the search term if fuzzyness is low", () =>
testFilterSearchResultItemsBySearchTerm({
searchResultItems: [{ id: "item1", name: "Item 1", description: "Item 1" }],
searchResultItems: [<SearchResultItem>{ id: "item1", name: "Item 1", description: "Item 1" }],
searchTerm: "itm",
fuzzyness: 0.2,
expected: [],

View File

@ -20,6 +20,5 @@
"@common/*": ["./common/*"]
}
},
"include": ["src", "common"],
"references": [{ "path": "./tsconfig.node.json" }]
"include": ["src", "common"]
}

View File

@ -1,7 +1,7 @@
import react from "@vitejs/plugin-react";
import { rmSync } from "fs";
import { join } from "path";
import { defineConfig, type ConfigEnv, type ServerOptions, type UserConfig } from "vite";
import { AliasOptions, defineConfig, type ConfigEnv, type ServerOptions, type UserConfig } from "vite";
import electron from "vite-plugin-electron";
import renderer from "vite-plugin-electron-renderer";
import pkg from "./package.json";
@ -13,12 +13,14 @@ export default defineConfig(({ command }: ConfigEnv): UserConfig => {
const isBuild = command === "build";
const sourcemap = isServe;
return {
resolve: {
alias: {
"@": join(__dirname, "src"),
},
const resolve: { alias: AliasOptions } = {
alias: {
"@common": join(__dirname, "common"),
},
};
return {
resolve,
build: {
chunkSizeWarningLimit: 1000,
},
@ -31,6 +33,7 @@ export default defineConfig(({ command }: ConfigEnv): UserConfig => {
options.startup();
},
vite: {
resolve,
build: {
sourcemap,
minify: isBuild,
@ -49,6 +52,7 @@ export default defineConfig(({ command }: ConfigEnv): UserConfig => {
options.reload();
},
vite: {
resolve,
build: {
sourcemap: sourcemap ? "inline" : undefined,
minify: isBuild,