Skip to content

Commit 006763e

Browse files
committed
chore: Migrate to CRXJS completed
1 parent ca79703 commit 006763e

32 files changed

+443
-329
lines changed

.github/workflows/submit.yml

-91
This file was deleted.

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pnpm-debug.log*
88
lerna-debug.log*
99

1010
node_modules
11-
.output
11+
dist
1212
artifacts
1313
*.local
1414
coverage

.prettierignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ dist-*
33
artifacts
44
coverage
55
.wxt
6-
.output
6+
dist
77
coverage
88
*.lock

bun.lock

+286-127
Large diffs are not rendered by default.

manifest.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "__MSG_name__",
3+
"description": "__MSG_description__",
4+
"version": "1.7.1",
5+
"manifest_version": 3,
6+
"default_locale": "en",
7+
"permissions": ["storage"],
8+
"options_ui": {
9+
"page": "src/options.html",
10+
"open_in_tab": false
11+
},
12+
"background": {
13+
"service_worker": "src/background.ts",
14+
"type": "module"
15+
},
16+
"content_scripts": [
17+
{
18+
"matches": ["*://*.github.com/*"],
19+
"js": ["src/content.ts"]
20+
}
21+
]
22+
}

package.json

+9-13
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,34 @@
66
"type": "module",
77
"scripts": {
88
"check": "check",
9-
"dev": "wxt",
10-
"dev:firefox": "wxt --browser firefox",
11-
"build": "wxt build",
12-
"build:firefox": "wxt build --browser firefox",
9+
"dev": "vite",
10+
"build": "vite build",
1311
"test": "vitest",
1412
"test:coverage": "vitest run --coverage",
15-
"zip": "wxt zip",
16-
"zip:firefox": "wxt zip -b firefox",
17-
"prepare": "simple-git-hooks",
18-
"postinstall": "wxt prepare"
13+
"prepare": "simple-git-hooks"
1914
},
2015
"dependencies": {
2116
"@aklinker1/check": "^1.4.5",
2217
"@tanstack/vue-query": "^5.59.13",
2318
"@webext-core/messaging": "^2.0.2",
2419
"@webext-core/proxy-service": "^1.2.0",
20+
"@wxt-dev/storage": "^1.1.0",
2521
"async-mutex": "^0.5.0",
2622
"fast-deep-equal": "^3.1.3",
2723
"minimatch": "^10.0.1",
2824
"ofetch": "^1.4.1"
2925
},
3026
"devDependencies": {
3127
"@aklinker1/generate-changelog": "^1.1.2",
28+
"@crxjs/vite-plugin": "^2.0.0-beta.31",
3229
"@iconify/json": "^2.2.261",
3330
"@tailwindcss/vite": "^4.0.6",
3431
"@types/bun": "^1.1.11",
35-
"@types/chrome": "^0.0.278",
32+
"@types/chrome": "^0.0.304",
3633
"@types/jsdom": "^21.1.7",
34+
"@vitejs/plugin-vue": "^5.2.1",
3735
"@vitest/coverage-v8": "^2.1.3",
38-
"@wxt-dev/auto-icons": "^1.0.2",
3936
"@wxt-dev/i18n": "^0.2.1",
40-
"@wxt-dev/module-vue": "^1.0.1",
4137
"daisyui": "^5.0.0-beta.7",
4238
"env-cmd": "^10.1.0",
4339
"fast-glob": "^3.3.2",
@@ -49,10 +45,10 @@
4945
"tailwindcss": "^4.0.6",
5046
"typescript": "^5.6.3",
5147
"unplugin-icons": "^0.19.3",
48+
"vite": "6.0.8",
5249
"vitest": "^2.1.3",
5350
"vue": "^3.5.12",
54-
"vue-tsc": "^2.1.6",
55-
"wxt": "^0.19.11"
51+
"vue-tsc": "^2.1.6"
5652
},
5753
"simple-git-hooks": {
5854
"pre-commit": "bun lint-staged"

src/background.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { registerGithubService, createGithubApi } from "@/utils/github";
2+
3+
const api = createGithubApi();
4+
registerGithubService(api);
5+
6+
chrome.runtime.onInstalled.addListener(async ({ reason }) => {
7+
if (reason === "install") {
8+
void chrome.runtime.openOptionsPage();
9+
}
10+
});

src/components/CommitDiff.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { i18n } from "@/utils/i18n";
2+
import { createDiffComponent } from "./createDiffComponent";
3+
14
export const CommitDiff = createDiffComponent({
25
getAdditionsElement: () =>
36
document.querySelector<HTMLElement>("#toc>*>strong:nth-child(2)"),

src/components/CompareDiff.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { i18n } from "@/utils/i18n";
2+
import { createDiffComponent } from "./createDiffComponent";
3+
14
export const CompareDiff = createDiffComponent({
25
getAdditionsElement: () =>
36
document.querySelectorAll<HTMLElement>(".toc-diff-stats>strong")[0],

src/components/CustomListItem.vue

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script lang="ts" setup>
2+
import { i18n } from "@/utils/i18n";
3+
24
defineProps<{
35
value: string;
46
}>();

src/components/CustomListsPref.vue

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { computed } from "vue";
33
import type { CustomLists } from "@/utils/storage";
44
import CustomListItem from "./CustomListItem.vue";
5+
import { i18n } from "@/utils/i18n";
56
67
const customLists = defineModel<CustomLists>("customLists", { required: true });
78

src/components/OptionsForm.vue

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import {
88
githubPatStorage,
99
customListsStorage,
1010
} from "@/utils/storage";
11+
import { useForm } from "@/composables/useForm";
12+
import { commitHashDiffsCache } from "@/utils/global-cache";
13+
import { i18n } from "@/utils/i18n";
1114
1215
const { state, hasChanges, reset, saveChanges } = useForm<{
1316
hideGeneratedLineCount: boolean;

src/components/PrDiff.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { i18n } from "@/utils/i18n";
2+
import { createDiffComponent } from "./createDiffComponent";
3+
14
export const PrDiff = createDiffComponent({
25
getAdditionsElement: () =>
36
document.querySelector<HTMLElement>("#diffstat .color-fg-success"),

src/components/ShowGeneratedCountPref.vue

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script lang="ts" setup>
2+
import { i18n } from "@/utils/i18n";
3+
24
const hideLineCount = defineModel<boolean>("hideGeneratedLineCount", {
35
required: true,
46
});

src/components/TokenPref.vue

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<script lang="ts" setup>
22
import IMdiEye from "~icons/mdi/eye";
33
import IMdiEyeOffOutline from "~icons/mdi/eye-off-outline";
4+
import { ref } from "vue";
5+
import { i18n } from "@/utils/i18n";
6+
import useGithubUserQuery from "@/composables/useGithubUserQuery";
47
58
const token = defineModel<string>("githubPat", {
69
required: true,

src/components/createDiffComponent.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
import { DIFF_COMPONENT_ID, GREY_COLOR } from "@/utils/constants";
12
import type { RecalculateResult } from "@/utils/github";
3+
import { hideGeneratedLineCountStorage } from "@/utils/storage";
4+
import { Spinner } from "./Spinner";
5+
import { i18n } from "@/utils/i18n";
6+
import { logger } from "@/utils/logger";
27

38
export function createDiffComponent(options: {
49
getAdditionsElement: () => HTMLElement | null | undefined;

src/composables/useForm.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import isDeepEqual from "fast-deep-equal";
2+
import { computed, reactive } from "vue";
23

34
export function useForm<T extends Record<string, any>>(
45
initialState: T,

src/composables/useGithubUserQuery.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { getGithubService, Github } from "@/utils/github";
2+
import { QueryKeys } from "@/utils/QueryKeys";
3+
import { useQuery } from "@tanstack/vue-query";
24

35
export default function (token: { value: string | undefined }) {
46
const github = getGithubService();

src/content.ts

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { CommitDiff } from "./components/CommitDiff";
2+
import { CompareDiff } from "./components/CompareDiff";
3+
import { PrDiff } from "./components/PrDiff";
4+
import { getCurrentCompare } from "./utils/getCurrentCompare";
5+
import { getCurrentOwner } from "./utils/getCurrentOwner";
6+
import { getCurrentPr } from "./utils/getCurrentPr";
7+
import { getCurrentRef } from "./utils/getCurrentRef";
8+
import { getCurrentRepo } from "./utils/getCurrentRepo";
9+
import { replaceCount } from "./utils/replaceCount";
10+
import { SECOND } from "./utils/time";
11+
12+
main();
13+
// TODO: schedule next interval for 1 second AFTER the main function finishes. If the main
14+
// function takes more than 1 second, it might cause problems.
15+
setInterval(main, SECOND);
16+
17+
function main() {
18+
const repo = getCurrentRepo();
19+
const owner = getCurrentOwner();
20+
if (!repo || !owner) return;
21+
22+
const pr = getCurrentPr();
23+
if (pr) return replaceCount({ type: "pr", repo, owner, pr }, PrDiff);
24+
25+
const commitHash = getCurrentRef();
26+
if (commitHash)
27+
return replaceCount(
28+
{ type: "commit", repo, owner, ref: commitHash },
29+
CommitDiff,
30+
);
31+
32+
const commitRefs = getCurrentCompare();
33+
if (commitRefs)
34+
return replaceCount(
35+
{ type: "compare", repo, owner, commitRefs },
36+
CompareDiff,
37+
);
38+
}

src/entrypoints/background.ts

-12
This file was deleted.

src/entrypoints/content.ts

-34
This file was deleted.

src/entrypoints/options/index.html src/options.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
<meta charset="UTF-8" />
55
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<script src="./main.ts" type="module"></script>
7+
<script src="./options.ts" type="module"></script>
88
<link rel="stylesheet" href="~/assets/tailwind.css" />
9-
<meta name="manifest.open_in_tab" content="false" />
109
</head>
1110
<body class="p-4 gap-4 flex flex-col"></body>
1211
</html>

src/entrypoints/options/main.ts src/options.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import Options from "@/pages/Options.vue";
22
import { VueQueryPlugin } from "@tanstack/vue-query";
3+
import { i18n } from "./utils/i18n";
4+
import { createApp } from "vue";
35

46
document.title = i18n.t("options.title");
57

src/utils/cache/createKeyValueCache.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { storage } from "@wxt-dev/storage";
12
import { Mutex } from "async-mutex";
23

34
interface CachedValue<TValue> {

0 commit comments

Comments
 (0)