Skip to content

Commit

Permalink
refactor: removed ramda and updated deps
Browse files Browse the repository at this point in the history
- TS, prettier, and node
  • Loading branch information
t7yang committed Jul 29, 2024
1 parent bc5dbde commit 66e87b8
Show file tree
Hide file tree
Showing 22 changed files with 250 additions and 197 deletions.
156 changes: 98 additions & 58 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"format": "prettier . --write --ignore-unknown",
"lint": "eslint --fix --ext=ts,tsx src/",
"release": "standard-version -t '' --packageFiles package.json",
"update": "yarn upgrade-interactive",
"update": "ncu -i --format group",
"we:build": "web-ext build -s dist/firefox",
"we:sign": "web-ext sign --config=web-ext-config-firefox.js --no-config-discovery",
"prepare": "husky install"
Expand All @@ -32,7 +32,6 @@
},
"dependencies": {
"data-fixer": "^5.0.1",
"ramda": "^0.28.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"spectre.css": "^0.5.1",
Expand All @@ -41,8 +40,7 @@
"zod": "^3.20.2"
},
"devDependencies": {
"@types/node": "^16.0.0",
"@types/ramda": "^0.28.11",
"@types/node": "^22.0.0",
"@types/react": "^18.0.15",
"@types/react-dom": "^18.0.6",
"@types/webextension-polyfill": "^0.10.0",
Expand All @@ -53,16 +51,16 @@
"dotenv": "^16.0.0",
"eslint": "^8.13.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react": "^7.30.1",
"html-webpack-plugin": "^5.5.0",
"husky": "^8.0.1",
"nano-staged": "^0.8.0",
"prettier": "^2.7.1",
"prettier": "^3.3.3",
"standard-version": "^9.5.0",
"tongwen-dict": "^1.0.1",
"ts-loader": "^9.3.1",
"typescript": "~4.8.4",
"ts-loader": "^9.5.1",
"typescript": "~5.5.4",
"web-ext": "^7.1.1",
"webpack": "^5.73.0",
"webpack-cli": "^4.10.0",
Expand Down
9 changes: 3 additions & 6 deletions src/background/menu/browser-action.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assoc, pipe } from 'ramda';
import { LangType } from 'tongwen-core';
import { Menus } from 'webextension-polyfill';
import { isUrlPattern } from '../../preference/filter-rule';
import { FilterTarget } from '../../preference/types/v2';
import { i18n } from '../../service/i18n/i18n';
Expand Down Expand Up @@ -60,11 +60,8 @@ export async function createBrowserActionMenus(state: BgState): Promise<(string
const browserActionMenuItems: menus.CreateProperties[] = [
...createBrowserActionProperties(),
...createClipboardProperties(state),
].map(
pipe(
assoc<menus.ContextType[], 'contexts'>('contexts', ['browser_action']),
assoc<menus.ItemType, 'type'>('type', 'normal'),
),
].map(item =>
Object.assign(item, { type: 'normal', contexts: ['browser_action'] } satisfies Menus.CreateCreatePropertiesType),
);

return Promise.all(browserActionMenuItems.map(item => menus.create(item)));
Expand Down
4 changes: 2 additions & 2 deletions src/background/state/bg-state.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { evolve } from 'ramda';
import { Converter } from 'tongwen-core';
import { patchRulesRegExp } from '../../preference/filter-rule';
import { Pref } from '../../preference/types/lastest';
Expand All @@ -14,7 +13,8 @@ export interface BgState {
logger: Logger;
}

const patchRegExp: (pref: Pref) => Pref = evolve({ filter: { rules: patchRulesRegExp } });
const patchRegExp: (pref: Pref) => Pref = pref =>
Object.assign(pref, { filter: Object.assign(pref.filter, { rules: patchRulesRegExp(pref.filter.rules) }) });

export const updateLogger = (state: BgState) => {
state.logger = loggerWith(state.pref.general.debugMode);
Expand Down
4 changes: 2 additions & 2 deletions src/background/state/mount-pref-listener.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { evolve } from 'ramda';
import { BgState, updateLogger } from '.';
import { patchRulesRegExp } from '../../preference/filter-rule';
import { Pref } from '../../preference/types/lastest';
Expand Down Expand Up @@ -30,7 +29,8 @@ export function mountPrefListener(state: BgState) {
break;
case 'filter':
if (change?.newValue) {
state.pref.filter = evolve({ rules: patchRulesRegExp })(change!.newValue as PrefFilter);
const filter = change!.newValue as PrefFilter;
state.pref.filter = Object.assign(filter, { ...filter, rules: patchRulesRegExp(filter.rules) });
}
break;
case 'word':
Expand Down
3 changes: 1 addition & 2 deletions src/content/services/convert-nodes-text.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { pluck } from 'ramda';
import { LangType, ParsedResult } from 'tongwen-core';
import { BgActNodeText, BgActType } from '../../service/runtime/interface';
import { runtime } from '../../service/runtime/runtime';

export const convertNodesText = (target: LangType, pns: ParsedResult[]): Promise<string[]> => {
const req: BgActNodeText = {
type: BgActType.NodesText,
payload: { target, texts: pluck('text', pns) },
payload: { target, texts: pns.map(p => p.text) },
};
return runtime.sendMessage(req).then(({ payload: { texts } }: BgActNodeText) => texts);
};
Loading

0 comments on commit 66e87b8

Please sign in to comment.