Skip to content

Commit 7da090d

Browse files
committed
update node to 18 and most npm dependencies
1 parent d5cd82f commit 7da090d

File tree

14 files changed

+94
-54
lines changed

14 files changed

+94
-54
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ jobs:
136136
submodules: recursive
137137
- uses: actions/setup-node@v3
138138
with:
139-
node-version: '16'
139+
node-version: '18'
140140
- run: extension/.ci/build --lint # debug version
141141
- run: extension/.ci/build --lint --release
142142

extension/package.json

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,30 @@
3535
"webext-options-sync": "^1.0.0"
3636
},
3737
"devDependencies": {
38-
"@babel/core": "^7.16.0",
39-
"@babel/eslint-parser": "^7.16.3",
40-
"@babel/preset-env": "^7.16.4",
41-
"@babel/preset-flow": "^7.16.0",
42-
"babel-loader": "^8.2.3",
38+
"@babel/core": "^7.20.12",
39+
"@babel/eslint-parser": "^7.19.1",
40+
"@babel/preset-env": "^7.20.2",
41+
"@babel/preset-flow": "^7.18.6",
42+
"babel-loader": "^9.1.2",
4343
"chrome-webstore-upload-cli": "^2.1.0",
4444
"clean-webpack-plugin": "^4.0.0",
45-
"copy-webpack-plugin": "^10.0.0",
46-
"css-loader": "^6.5.1",
47-
"eslint": "^8.15.0",
45+
"copy-webpack-plugin": "^11.0.0",
46+
"css-loader": "^6.7.3",
47+
"eslint": "^8.31.0",
4848
"eslint-plugin-flowtype": "^8.0.3",
49-
"flow-bin": "^0.133.0",
50-
"flow-interfaces-chrome": "^0.6.0",
51-
"jest": "^28.1.0",
52-
"jest-environment-jsdom": "^28.1.0",
49+
"flow-bin": "^0.196.3",
50+
"flow-interfaces-chrome": "^0.7.0",
51+
"jest": "^29.3.1",
52+
"jest-environment-jsdom": "^29.3.1",
5353
"jest-fetch-mock": "^3.0.3",
54-
"node-fetch": "^2.6.1",
54+
"loader-utils": "^3.2.1",
55+
"node-fetch": "^3.3.0",
5556
"style-loader": "^3.3.1",
56-
"web-ext": "^6.8.0",
57-
"web-ext-submit": "^6.8.0",
58-
"webpack": "^5.64.4",
59-
"webpack-cli": "^4.9.1",
60-
"webpack-dev-server": "^4.6.0",
57+
"web-ext": "^7.4.0",
58+
"web-ext-submit": "^7.4.0",
59+
"webpack": "^5.75.0",
60+
"webpack-cli": "^5.0.1",
61+
"webpack-dev-server": "^4.11.1",
6162
"webpack-extension-manifest-plugin": "^0.8.0"
6263
},
6364
"private": "true"

extension/patcher.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const loaderUtils = require('loader-utils')
33

44
module.exports.default = function (source) {
5-
const options = loaderUtils.getOptions(this)
5+
const options = this.getOptions()
66
const patches = options.patches;
77
for (const patch of patches) {
88
let res = source.replace(patch.code, patch.newCode)

extension/src/async_chrome.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Awrap0 {
1414
cb: (R => void)) => void))
1515
: (() => Promise<R>)
1616
{
17+
// $FlowFixMe
1718
return helper(fn)
1819
}
1920
}
@@ -24,6 +25,7 @@ class Awrap1<A> {
2425
cb: (R => void)) => void))
2526
: ((arg1: A) => Promise<R>)
2627
{
28+
// $FlowFixMe
2729
return helper(fn)
2830
}
2931
}
@@ -35,11 +37,13 @@ class Awrap2<A1, A2> {
3537
cb: (R => void)) => void))
3638
: ((arg1: A1, arg2: A2) => Promise<R>)
3739
{
40+
// $FlowFixMe
3841
return helper(fn)
3942
}
4043
}
4144

4245

46+
// $FlowFixMe
4347
function helper<R, TArgs: *>(fn): ((...args: TArgs) => Promise<R>) {
4448
return (...args: Array<any>) => {
4549
return new Promise((resolve, reject) => {
@@ -60,26 +64,40 @@ function helper<R, TArgs: *>(fn): ((...args: TArgs) => Promise<R>) {
6064
// fucking hell.. also had to make them properties because apis might not exist in certain contexts
6165
// e.g. access to chrome.tabs.get might crash
6266
export const achrome = {
67+
// $FlowFixMe
6368
bookmarks: {
69+
// $FlowFixMe
6470
get search () { return new Awrap1<{url: string} >().wrap(chrome.bookmarks.search ) },
71+
// $FlowFixMe
6572
get getTree () { return new Awrap0 ().wrap(chrome.bookmarks.getTree ) },
6673
},
74+
// $FlowFixMe
6775
tabs: {
76+
// $FlowFixMe
6877
get get () { return new Awrap1<number >().wrap(chrome.tabs.get ) },
78+
// $FlowFixMe
6979
get query () { return new Awrap1<{currentWindow?: boolean, active?: boolean}>().wrap(chrome.tabs.query ) },
80+
// $FlowFixMe
7081
get executeScript() { return new Awrap2<number, {file?: string, code?: string} >().wrap(chrome.tabs.executeScript) },
82+
// $FlowFixMe
7183
get insertCSS () { return new Awrap2<number, {file?: string, code?: string} >().wrap(chrome.tabs.insertCSS ) },
7284
},
85+
// $FlowFixMe
7386
runtime: {
87+
// $FlowFixMe
7488
get getPlatformInfo() { return new Awrap0 ().wrap(chrome.runtime.getPlatformInfo) },
89+
// $FlowFixMe
7590
get sendMessage () { return new Awrap1<{}>().wrap(chrome.runtime.sendMessage ) },
7691
},
92+
// $FlowFixMe
7793
history: {
7894
// crap, missing in flow-interfaces-chrome
95+
// $FlowFixMe
7996
get getVisits () { return new Awrap1<{url: string }>().wrap<Array<VisitItem>>(
8097
// $FlowFixMe
8198
chrome.history.getVisits
8299
) },
100+
// $FlowFixMe
83101
get search () { return new Awrap1<{text: string, startTime?: number, endTime?: number}>().wrap<Array<HistoryItem>>(
84102
// $FlowFixMe
85103
chrome.history.search

extension/src/background.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ async function handleOpenSearch(p: SearchPageParams = {}) {
583583
}
584584

585585

586-
const onMessageCallback = async (msg) => { // TODO not sure if should defensify here?
586+
const onMessageCallback = async (msg: any) => { // TODO not sure if should defensify here?
587587
const method = msg.method
588588
if (method == Methods.GET_SIDEBAR_VISITS) {
589589
// TODO not sure if it might do unnecessary notifications here?
@@ -795,7 +795,7 @@ window.addEventListener('keydown', cancel)
795795
796796
}`})
797797
},
798-
handleZapperResult: async function(msg) {
798+
handleZapperResult: async function(msg: any) {
799799
const urls: Array<Url> = msg.data
800800
await AddToMarkVisitedExcludelist.add(urls)
801801
},

extension/src/common.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export class Visit {
6868
// ugh..
6969
toJObject(): any {
7070
const o = {}
71+
// $FlowFixMe[prop-missing]
7172
Object.assign(o, this)
7273
// $FlowFixMe
7374
o.time = o.time .getTime()
@@ -81,6 +82,7 @@ export class Visit {
8182
o.dt_local = new Date(o.dt_local)
8283
// $FlowFixMe
8384
const v = new Visit()
85+
// $FlowFixMe[prop-missing]
8486
Object.assign(v, o)
8587
return v
8688
}
@@ -142,7 +144,10 @@ export class Visits {
142144
// NOTE: JSON.stringify will use this method
143145
toJObject(): any {
144146
const o = {}
147+
// $FlowFixMe[prop-missing]
145148
Object.assign(o, this)
149+
// $FlowFixMe[prop-missing]
150+
// $FlowFixMe[incompatible-use]
146151
o.visits = o.visits.map(v => {
147152
return (v instanceof Visit)
148153
? v.toJObject()
@@ -153,6 +158,7 @@ export class Visits {
153158
}
154159

155160
static fromJObject(o: any): Visits {
161+
// $FlowFixMe[prop-missing]
156162
o.visits = o.visits.map(x => {
157163
const err = x.error
158164
if (err != null) {
@@ -164,8 +170,10 @@ export class Visits {
164170
return Visit.fromJObject(x)
165171
}
166172
})
173+
// $FlowFixMe[prop-missing]
167174
// $FlowFixMe
168175
const r = new Visits()
176+
// $FlowFixMe[prop-missing]
169177
Object.assign(r, o)
170178
return r
171179
}
@@ -205,7 +213,7 @@ export type SearchPageParams = {
205213
}
206214

207215
// $FlowFixMe
208-
export function log() {
216+
export function log(): void {
209217
const args = [];
210218
for (var i = 1; i < arguments.length; i++) {
211219
const arg = arguments[i];
@@ -219,13 +227,13 @@ export function asList(bl: string): Array<string> {
219227
return bl.split(/\n/).filter(s => s.length > 0);
220228
}
221229

222-
export function addStyle(doc: Document, css: string) {
230+
export function addStyle(doc: Document, css: string): void {
223231
const st = doc.createElement('style');
224232
st.appendChild(doc.createTextNode(css));
225233
unwrap(doc.head).appendChild(st);
226234
}
227235

228-
export function safeSetInnerHTML(element: HTMLElement, html: string) {
236+
export function safeSetInnerHTML(element: HTMLElement, html: string): void {
229237
const tags = new DOMParser()
230238
.parseFromString(html, 'text/html')
231239
.getElementsByTagName('body')[0]
@@ -289,6 +297,7 @@ export function rejectIfHttpError(response: HttpResponse): HttpResponse {
289297
}
290298

291299
// todo ugh, need to use some proper type annotations?
300+
// $FlowFixMe[missing-local-annot]
292301
function fetch_typed(...args): Promise<HttpResponse> {
293302
// $FlowFixMe
294303
return fetch(...args)

extension/src/display.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class Binder {
5252
this.options = options
5353
}
5454

55-
makeChild(parent: HTMLElement, name: string, classes: ?Array<CssClass> = null) {
55+
makeChild(parent: HTMLElement, name: string, classes: ?Array<CssClass> = null): HTMLElement {
5656
const res = this.doc.createElement(name);
5757
if (classes != null) {
5858
for (const cls of classes) {
@@ -63,7 +63,7 @@ export class Binder {
6363
return res;
6464
}
6565

66-
makeTchild(parent: HTMLElement, text: string) {
66+
makeTchild(parent: HTMLElement, text: string): Text {
6767
const res = this.doc.createTextNode(text);
6868
parent.appendChild(res);
6969
return res;
@@ -72,8 +72,10 @@ export class Binder {
7272
async renderError(
7373
parent: HTMLElement,
7474
error: Error,
75-
) {
75+
): Promise<void> {
76+
// $FlowFixMe[method-unbinding]
7677
const child = this.makeChild .bind(this)
78+
// $FlowFixMe[method-unbinding]
7779
const tchild = this.makeTchild.bind(this)
7880

7981
const item = child(parent, 'li', ['error'])
@@ -96,9 +98,11 @@ export class Binder {
9698
locator,
9799
relative,
98100
}: Params,
99-
) {
101+
): Promise<HTMLElement> {
100102
// todo ugh. looks like Flow can't guess the type of closure that we get by .bind...
103+
// $FlowFixMe[method-unbinding]
101104
const child = this.makeChild.bind(this);
105+
// $FlowFixMe[method-unbinding]
102106
const tchild = this.makeTchild.bind(this); // TODO still necessary??
103107

104108
const item = child(parent, 'li', relative ? ['relative'] : []);

extension/src/normalise.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import type {Url} from './common';
77
//
88
var R = RegExp;
99

10-
export const
10+
const
1111
STRIP_RULES = [
1212
[[R('.*') , R('^\\w+://' )]],
1313
[[R('.*') , R('(www|ww|amp)\\.' )]],
1414
[[R('.*') , R('[&#].*$' )]],
1515
[[R('.*') , R('/$' )]],
1616
]
17-
; // TODO perhaps that should be semi-configurable
17+
// TODO perhaps that should be semi-configurable
1818

1919
// TODO maybe use that normalisation library and then adjust query params etc
2020

extension/src/notifications.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Toastify({
9090
}
9191

9292
// TODO maybe if tabId = -1, show normal notification?
93-
async function showTabNotification(tabId: ?number, message: string, opts: ToastOptions) {
93+
async function showTabNotification(tabId: ?number, message: string, opts: ToastOptions): Promise<void> {
9494
if (tabId == null) {
9595
// not much else we can do..
9696
desktopNotify(message)
@@ -117,16 +117,16 @@ async function showTabNotification(tabId: ?number, message: string, opts: ToastO
117117
}
118118

119119
export const notifications = {
120-
notify: async function(tabId: ?number, message: string, opts: ToastOptions) {
120+
notify: async function(tabId: ?number, message: string, opts: ToastOptions): Promise<void> {
121121
return showTabNotification(tabId, message, opts)
122122
},
123-
error: async function(tabId: number, e: Error | string) {
123+
error: async function(tabId: number, e: Error | string): Promise<void> {
124124
return notifications.notify(tabId, String(e), {color: 'red'})
125125
},
126-
page_ignored: async function(tabId: ?number, url: ?Url, reason: string) {
126+
page_ignored: async function(tabId: ?number, url: ?Url, reason: string): Promise<void> {
127127
return notifications.notify(tabId, `${url || ''} is ignored: ${reason}`, {color: 'red'})
128128
},
129-
excluded: async function(tabId: number, b: Blacklisted) {
129+
excluded: async function(tabId: number, b: Blacklisted): Promise<void> {
130130
return notifications.notify(tabId, `${b.url} is excluded: ${b.reason}`, {color: 'red'})
131131
},
132132
desktop: desktopNotify,

extension/src/options.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const USE_ORIGINAL_TZ = true;
9090
export const GROUP_CONSECUTIVE_SECONDS = 20 * 60;
9191

9292
// TODO: make it configurable in options?
93-
export const THIS_BROWSER_TAG = getBrowser()
93+
export const THIS_BROWSER_TAG: string = getBrowser()
9494

9595
// TODO allow to export settings
9696
// https://github.com/fregante/webext-options-sync/issues/23
@@ -296,17 +296,18 @@ export async function setOptions(opts: StoredOptions) {
296296
await os.set(opts)
297297
}
298298

299-
export async function setOption(opt: Opt1 | Opt2) {
299+
export async function setOption(opt: Opt1 | Opt2): Promise<void> {
300300
const os = optSync()
301301
await os.set(opt)
302302
}
303303

304-
export async function resetOptions() {
304+
export async function resetOptions(): Promise<void> {
305305
const os = optSync()
306306
await os.setAll({})
307307
}
308308

309-
function toggleOption(toggle: (StoredOptions) => void): () => Promise<void> {
309+
type ToggleOptionRes = () => Promise<void>
310+
function toggleOption(toggle: (StoredOptions) => void): ToggleOptionRes {
310311
return async () => {
311312
const opts = await getStoredOptions()
312313
toggle(opts)
@@ -315,9 +316,9 @@ function toggleOption(toggle: (StoredOptions) => void): () => Promise<void> {
315316
}
316317

317318
export const Toggles = {
318-
showSidebar : toggleOption((opts) => { opts.sidebar_always_show = !opts.sidebar_always_show; }),
319-
markVisited : toggleOption((opts) => { opts.mark_visited_always = !opts.mark_visited_always; }),
320-
showHighlights: toggleOption((opts) => { opts.highlight_on = !opts.highlight_on ; }),
319+
showSidebar : (toggleOption((opts) => { opts.sidebar_always_show = !opts.sidebar_always_show; }): ToggleOptionRes),
320+
markVisited : (toggleOption((opts) => { opts.mark_visited_always = !opts.mark_visited_always; }): ToggleOptionRes),
321+
showHighlights: (toggleOption((opts) => { opts.highlight_on = !opts.highlight_on ; }): ToggleOptionRes),
321322
}
322323

323324
// TODO try optionsStorage.syncForm?

0 commit comments

Comments
 (0)