Skip to content

Commit 256f9d1

Browse files
committed
chore: Upgrade to @webext-core/proxy-service v2
1 parent 9ceb0dc commit 256f9d1

File tree

7 files changed

+26
-23
lines changed

7 files changed

+26
-23
lines changed

bun.lock

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"@aklinker1/check": "^2.1.2",
2222
"@tanstack/vue-query": "^5.59.13",
2323
"@webext-core/messaging": "^2.0.2",
24-
"@webext-core/proxy-service": "^1.2.0",
24+
"@webext-core/proxy-service": "^2.0.0-rc.1",
2525
"async-mutex": "^0.5.0",
2626
"fast-deep-equal": "^3.1.3",
2727
"minimatch": "^10.0.1",

src/composables/useGithubUserQuery.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { getGithubService, Github } from "@/utils/github";
1+
import { Github } from "@/utils/github";
2+
import { createProxyService } from "@webext-core/proxy-service";
23

34
export default function (token: { value: string | undefined }) {
4-
const github = getGithubService();
5+
const github = createProxyService(GITHUB_SERVICE_KEY);
56

67
return useQuery<Github.User | undefined>({
78
queryKey: [QueryKeys.GithubUser, token],

src/entrypoints/background.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { registerGithubService, createGithubApi } from "@/utils/github";
1+
import { createGithubApi, createGithubService } from "@/utils/github";
2+
import { registerService } from "@webext-core/proxy-service";
23

34
export default defineBackground(() => {
4-
const api = createGithubApi();
5-
registerGithubService(api);
5+
const githubApi = createGithubApi();
6+
const githubService = createGithubService(githubApi);
7+
registerService(GITHUB_SERVICE_KEY, githubService);
68

79
browser.runtime.onInstalled.addListener(async ({ reason }) => {
810
if (reason === "install") {

src/utils/ProxyServiceKeys.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { ProxyServiceKey } from "@webext-core/proxy-service";
2+
import type { GithubService } from "./github";
3+
4+
export const GITHUB_SERVICE_KEY =
5+
"github-service" as ProxyServiceKey<GithubService>;

src/utils/github/service.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import { defineProxyService } from "@webext-core/proxy-service";
2-
import type { GithubApi } from "./api";
3-
import type { DiffEntry } from "./types";
41
import { minimatch } from "minimatch";
52
import { GitAttributes } from "../gitattributes";
3+
import type { GithubApi } from "./api";
4+
import type { DiffEntry, User } from "./types";
65

7-
export const [registerGithubService, getGithubService] = defineProxyService(
8-
"GithubService",
9-
createGithubService,
10-
);
6+
export interface GithubService {
7+
recalculateDiff(options: RecalculateOptions): Promise<RecalculateResult>;
8+
getUser(token: string): Promise<User>;
9+
}
1110

12-
function createGithubService(api: GithubApi) {
11+
export function createGithubService(api: GithubApi): GithubService {
1312
const mountCache: { [mountId: number]: RecalculateResult } = {};
1413

1514
/**
@@ -121,9 +120,7 @@ function createGithubService(api: GithubApi) {
121120
}
122121

123122
return {
124-
async recalculateDiff(
125-
options: RecalculateOptions,
126-
): Promise<RecalculateResult> {
123+
async recalculateDiff(options) {
127124
// Cache the result if the same content script tries to get the result multiple times.
128125
if (mountCache[options.mountId]) {
129126
logger.debug("[recalculateDiff] Using mount cache");

src/utils/replaceCount.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getGithubService } from "./github";
1+
import { createProxyService } from "@webext-core/proxy-service";
22
import type { RecalculateOptions, RecalculateResult } from "./github";
33

44
/**
@@ -12,7 +12,7 @@ export function replaceCount(
1212
if (existing) return;
1313

1414
const start = Date.now();
15-
const github = getGithubService();
15+
const github = createProxyService(GITHUB_SERVICE_KEY);
1616
const stats = github.recalculateDiff(options).then((diff) => {
1717
logger.debug("Diff:", diff);
1818
logger.debug(`Diff calculated in ${Date.now() - start}ms`);

0 commit comments

Comments
 (0)