Skip to content

Commit 71d6065

Browse files
committed
fix: update dependencies accross the board
1 parent a23702a commit 71d6065

13 files changed

+1974
-2345
lines changed

.bin/createLangIds.ts

+20-21
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,13 @@ export const getLangsFromYaml = (): Map<string, StringSet> => {
7575
)
7676
);
7777

78-
const langsOrderedByNumSpeakers: Map<
79-
string,
80-
StringSet
81-
> = allLangsByNumSpeakers.reduce((newLs, l) => {
82-
if (langs.has(l)) {
83-
newLs.set(l, langs.get(l) as StringSet);
84-
}
85-
return newLs;
86-
}, new Map<string, StringSet>());
78+
const langsOrderedByNumSpeakers: Map<string, StringSet> =
79+
allLangsByNumSpeakers.reduce((newLs, l) => {
80+
if (langs.has(l)) {
81+
newLs.set(l, langs.get(l) as StringSet);
82+
}
83+
return newLs;
84+
}, new Map<string, StringSet>());
8785
const langsWithUnknownSpeakers = [...langs].filter(
8886
([l]) => !langsOrderedByNumSpeakers.has(l)
8987
);
@@ -165,18 +163,19 @@ export const getLangIdSubstrings = (
165163
};
166164

167165
const mostPromisingSubstrings = new Map<string, Map<string, StringSet>>(
168-
[...substringsMap].sort((
169-
[ss1, lTm1],
170-
[ss2, lTm2] // ss == substring, lTm == languageTranslationMap
171-
) =>
172-
ss1.length !== ss2.length || lTm1.size !== lTm2.size
173-
? // sort short substrings and substrings with few language matches before others
174-
ss1.length +
175-
[...lTm1].reduce(ignoreDuplicateTranslations, []).length -
176-
(ss2.length +
177-
[...lTm2].reduce(ignoreDuplicateTranslations, []).length)
178-
: // if we can’t distinguish that way, sort substrings that match many translations first
179-
[...lTm2][0][1].size - [...lTm1][0][1].size
166+
[...substringsMap].sort(
167+
(
168+
[ss1, lTm1],
169+
[ss2, lTm2] // ss == substring, lTm == languageTranslationMap
170+
) =>
171+
ss1.length !== ss2.length || lTm1.size !== lTm2.size
172+
? // sort short substrings and substrings with few language matches before others
173+
ss1.length +
174+
[...lTm1].reduce(ignoreDuplicateTranslations, []).length -
175+
(ss2.length +
176+
[...lTm2].reduce(ignoreDuplicateTranslations, []).length)
177+
: // if we can’t distinguish that way, sort substrings that match many translations first
178+
[...lTm2][0][1].size - [...lTm1][0][1].size
180179
)
181180
);
182181

.bin/test/createLangIds.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ describe("createLangIds", () => {
3232

3333
const result = getLangIdSubstrings(langs);
3434

35-
expect(result.size).toEqual(2);
36-
expect(result.get("gl")?.has("d")).toEqual(true);
37-
expect(result.get("fr")?.has("u")).toEqual(true);
35+
expect(result.size).toBe(2);
36+
expect(result.get("gl")?.has("d")).toBe(true);
37+
expect(result.get("fr")?.has("u")).toBe(true);
3838
});
3939
});
4040

.eslintrc.js

-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@ module.exports = {
1616
"plugin:jest/recommended",
1717
"plugin:jest/style",
1818
"prettier",
19-
"prettier/@typescript-eslint",
2019
],
2120
};

.github/workflows/codeql.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: "CodeQL"
22

33
on:
44
push:
5-
branches: [ "master" ]
5+
branches: ["master"]
66
pull_request:
7-
branches: [ "master" ]
7+
branches: ["master"]
88
schedule:
99
- cron: "56 0 * * 5"
1010

@@ -20,7 +20,7 @@ jobs:
2020
strategy:
2121
fail-fast: false
2222
matrix:
23-
language: [ javascript ]
23+
language: [javascript]
2424

2525
steps:
2626
- name: Checkout

package.json

+23-21
Original file line numberDiff line numberDiff line change
@@ -91,36 +91,38 @@
9191
"type": "git",
9292
"url": "git@github.com:ClaudiuCeia/detect-translation.git"
9393
},
94-
"dependencies": {},
94+
"dependencies": {
95+
"text-encoding": "^0.7.0"
96+
},
9597
"devDependencies": {
9698
"@pika/pack": "^0.5.0",
9799
"@pika/plugin-build-web": "^0.9.2",
98100
"@pika/plugin-bundle-web": "^0.9.2",
99101
"@pika/plugin-ts-standard-pkg": "^0.9.2",
100102
"@skypack/package-check": "^0.2.2",
101-
"@types/jest": "^26.0.20",
102-
"@typescript-eslint/eslint-plugin": "^4.15.1",
103-
"@typescript-eslint/parser": "^4.15.1",
104-
"cldr": "^6.0.0",
105-
"eslint": "^7.20.0",
106-
"eslint-config-prettier": "^7.2.0",
107-
"eslint-plugin-jest": "^24.1.5",
108-
"husky": "^5.0.9",
109-
"jest": "^26.6.3",
110-
"jest-environment-jsdom": "^26.6.2",
111-
"jest-environment-jsdom-global": "^2.0.4",
112-
"js-yaml": "^4.0.0",
113-
"lint-staged": "^10.5.4",
103+
"@types/jest": "^29.2.2",
104+
"@typescript-eslint/eslint-plugin": "^5.42.1",
105+
"@typescript-eslint/parser": "^5.42.1",
106+
"cldr": "^7.2.0",
107+
"eslint": "^8.27.0",
108+
"eslint-config-prettier": "^8.5.0",
109+
"eslint-plugin-jest": "^27.1.5",
110+
"husky": "^8.0.2",
111+
"jest": "^29.3.1",
112+
"jest-environment-jsdom": "^29.3.1",
113+
"jest-environment-jsdom-global": "^4.0.0",
114+
"js-yaml": "^4.1.0",
115+
"lint-staged": "^13.0.3",
114116
"mutationobserver-shim": "^0.3.7",
115117
"pika-plugin-legacy-browser": "^2.0.0",
116118
"pika-plugin-package.json": "^1.0.2",
117-
"pinst": "^2.1.4",
118-
"prettier": "^2.2.1",
119+
"pinst": "^3.0.0",
120+
"prettier": "^2.7.1",
119121
"rimraf": "^3.0.2",
120-
"sanitize-html": "^2.3.2",
121-
"source-map-explorer": "^2.5.2",
122-
"ts-jest": "^26.5.1",
123-
"ts-node": "^9.1.1",
124-
"typescript": "^4.1.5"
122+
"sanitize-html": "^2.7.3",
123+
"source-map-explorer": "^2.5.3",
124+
"ts-jest": "^29.0.3",
125+
"ts-node": "^10.9.1",
126+
"typescript": "^4.8.4"
125127
}
126128
}

setup-jest.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// setup-jest.js
22
import sanitizeHtml from "sanitize-html";
33
import "mutationobserver-shim";
4+
import { TextDecoder, TextEncoder } from "text-encoding";
45

56
// Monkey-patch jsdom to make it support innerText
67
// see https://github.com/jsdom/jsdom/issues/1245#issuecomment-470192636
@@ -16,3 +17,7 @@ Object.defineProperty(global.Element.prototype, "innerText", {
1617
},
1718
configurable: true, // make it so that it doesn't blow chunks on re-running tests with things like --watch
1819
});
20+
21+
// Monkey-patch jsdom to support TextEncoder/TextDecoder
22+
global.TextEncoder = TextEncoder;
23+
global.TextDecoder = TextDecoder;

src/test/client.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import JSDOMEnvironment from "jest-environment-jsdom";
44
declare const jsdom: JSDOMEnvironment["dom"];
55

66
describe("Test client translations", () => {
7-
let el: HTMLElement = (null as unknown) as HTMLElement;
7+
let el: HTMLElement = null as unknown as HTMLElement;
88
let observer: MutationObserver | undefined;
99

1010
beforeEach(() => {
@@ -25,14 +25,14 @@ describe("Test client translations", () => {
2525
try {
2626
expect(service).toEqual(Services.GOOGLE);
2727
expect(lang).toEqual(targetLang);
28-
expect(type).toEqual("client");
28+
expect(type).toBe("client");
2929
resolve();
3030
} catch (err) {
3131
reject(err);
3232
}
3333
});
3434

35-
jsdom.reconfigure({ url: "https://www.example.com/" }); // eslint-disable-line
35+
jsdom!.reconfigure({ url: "https://www.example.com/" }); // eslint-disable-line
3636

3737
document.documentElement.setAttribute("class", "");
3838
document.documentElement.lang = sourceLang;

src/test/getDocumentLang.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import getDocumentLang from "../getDocumentLang";
22
import skipToMainContentLangIds from "../translations/Skip-to-main-content";
33

44
describe("getDocumentLang", () => {
5-
let el: HTMLElement = (null as unknown) as HTMLElement;
5+
let el: HTMLElement = null as unknown as HTMLElement;
66

77
beforeEach(() => {
88
document.documentElement.lang = "en";
@@ -20,7 +20,7 @@ describe("getDocumentLang", () => {
2020

2121
const { lang: result } = getDocumentLang({ lang: "en" });
2222

23-
expect(result).toEqual("pl");
23+
expect(result).toBe("pl");
2424
});
2525

2626
it("should identify the language from the text element", () => {
@@ -33,7 +33,7 @@ describe("getDocumentLang", () => {
3333
},
3434
});
3535

36-
expect(result).toEqual("ru");
36+
expect(result).toBe("ru");
3737
});
3838

3939
it("should identify the language from the text content", () => {
@@ -48,14 +48,14 @@ describe("getDocumentLang", () => {
4848
},
4949
});
5050

51-
expect(result).toEqual("fr");
51+
expect(result).toBe("fr");
5252
});
5353

5454
it("should normalise the language tag", () => {
5555
document.documentElement.lang = "iw";
5656

5757
const { lang: result } = getDocumentLang({ lang: "en" });
5858

59-
expect(result).toEqual("he");
59+
expect(result).toBe("he");
6060
});
6161
});

src/test/proxy.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe("Test proxy translations", () => {
2626
try {
2727
expect(service).toEqual(Services.GOOGLE);
2828
expect(lang).toEqual(targetLang);
29-
expect(type).toEqual("proxy");
29+
expect(type).toBe("proxy");
3030
resolve();
3131
} catch (err) {
3232
reject(err);
@@ -52,7 +52,7 @@ describe("Test proxy translations", () => {
5252
try {
5353
expect(service).toEqual(Services.BAIDU);
5454
expect(lang).toEqual(targetLang);
55-
expect(type).toEqual("proxy");
55+
expect(type).toBe("proxy");
5656
resolve();
5757
} catch (err) {
5858
reject(err);

src/test/services.test.ts

-46
This file was deleted.

src/whichClientTranslation.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const whichClientTranslation = (
2222
): LangTranslatorInfo => {
2323
const [service] =
2424
(Object.entries(SERVICES_SELECTORS).find(([, selector]) =>
25-
document.querySelector(selector as string)
25+
document.querySelector(selector)
2626
) as [Services, string] | undefined) || [];
2727

2828
return {

src/whichProxyTranslation.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const whichProxyTranslation = (
3131
const { hostname } = location;
3232

3333
const [service] = (Object.entries(PROXIES_HOSTNAMES).find(([, hostnames]) =>
34-
(hostnames as Array<HostnamePattern>).find((match) =>
34+
hostnames.find((match) =>
3535
match instanceof RegExp ? match.test(hostname) : match === hostname
3636
)
3737
) || []) as [Services, Array<HostnamePattern>];

0 commit comments

Comments
 (0)