Skip to content

Commit

Permalink
Migrate to WXT
Browse files Browse the repository at this point in the history
This reverts commit 006763e.
  • Loading branch information
aklinker1 committed Feb 12, 2025
1 parent 006763e commit 39d766d
Show file tree
Hide file tree
Showing 32 changed files with 329 additions and 443 deletions.
91 changes: 91 additions & 0 deletions .github/workflows/submit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Submit for Review

This comment has been minimized.

Copy link
@aklinker1

aklinker1 Feb 12, 2025

Author Owner

This is just an example workflow for doing a release with conventional commits. Use it as inspiration for updating your own release process.

on:
workflow_dispatch:
inputs:
dryRun:
default: false
type: boolean
description: Skip submission and perform a dry run

jobs:
validate:
name: Validate
uses: ./.github/workflows/validate.yml
secrets: inherit

submit:
name: Submit
runs-on: ubuntu-22.04
needs: [validate]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: oven-sh/setup-bun@v2

- name: Configure Git
run: |
git config user.email "github-actions@users.noreply.github.com"
git config user.name "GitHub Actions"
- name: Install dependencies
run: bun install --frozen-lockfile

- name: Bump Version
id: version
run: |
bunx changelogen@latest --bump
NEW_VERSION=$(bun --print 'require("./package.json").version')
echo "newVersion=$NEW_VERSION" >> "$GITHUB_OUTPUT"
- name: Build and Zip
run: |
bun run zip
bun run zip:firefox
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
path: .output/*.zip
if-no-files-found: error
include-hidden-files: true

- name: Submit
run: |
bun wxt submit \
--chrome-zip .output/*-chrome.zip \
--firefox-zip .output/*-firefox.zip --firefox-sources-zip .output/*-sources.zip
env:
DRY_RUN: ${{ inputs.dryRun }}
CHROME_EXTENSION_ID: ${{ secrets.CHROME_EXTENSION_ID }}
CHROME_CLIENT_ID: ${{ secrets.CHROME_CLIENT_ID }}
CHROME_CLIENT_SECRET: ${{ secrets.CHROME_CLIENT_SECRET }}
CHROME_REFRESH_TOKEN: ${{ secrets.CHROME_REFRESH_TOKEN }}
FIREFOX_EXTENSION_ID: ${{ secrets.FIREFOX_EXTENSION_ID }}
FIREFOX_JWT_ISSUER: ${{ secrets.FIREFOX_JWT_ISSUER }}
FIREFOX_JWT_SECRET: ${{ secrets.FIREFOX_JWT_SECRET }}
EDGE_PRODUCT_ID: ${{ secrets.EDGE_PRODUCT_ID }}
EDGE_CLIENT_ID: ${{ secrets.EDGE_CLIENT_ID }}
EDGE_CLIENT_SECRET: ${{ secrets.EDGE_CLIENT_SECRET }}
EDGE_ACCESS_TOKEN_URL: ${{ secrets.EDGE_ACCESS_TOKEN_URL }}

- name: Commit and Push
if: ${{ !inputs.dryRun }}
run: |
git add package.json CHANGELOG.md
git commit -am "chore(release): v$NEW_VERSION"
git tag v$NEW_VERSION
git push
git push --tags
env:
NEW_VERSION: ${{ steps.version.outputs.newVersion }}

- name: Release
if: ${{ !inputs.dryRun }}
run: pnpx changelogen@latest gh release ${{ steps.version.outputs.newVersion }} --token ${{ github.token }}

# Don't upload sources zip - it can contain .env files, which may include secrets
- name: Upload ZIPs
if: ${{ !inputs.dryRun }}
run: gh release upload ${{ steps.version.outputs.newVersion }} .output/*-chrome.zip .output/*-firefox.zip
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pnpm-debug.log*
lerna-debug.log*

node_modules
dist
.output

This comment has been minimized.

Copy link
@aklinker1

aklinker1 Feb 12, 2025

Author Owner

The default output folder is .output in WXT, not dist.

artifacts
*.local
coverage
Expand Down
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ dist-*
artifacts
coverage
.wxt
dist
.output
coverage
*.lock
413 changes: 127 additions & 286 deletions bun.lock

Large diffs are not rendered by default.

22 changes: 0 additions & 22 deletions manifest.json

This file was deleted.

22 changes: 13 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,38 @@
"type": "module",
"scripts": {
"check": "check",
"dev": "vite",
"build": "vite build",
"dev": "wxt",
"dev:firefox": "wxt --browser firefox",

This comment has been minimized.

Copy link
@aklinker1

aklinker1 Feb 12, 2025

Author Owner

This commit also adds firefox support, which CRXJS doesn't support.

"build": "wxt build",
"build:firefox": "wxt build --browser firefox",
"test": "vitest",
"test:coverage": "vitest run --coverage",
"prepare": "simple-git-hooks"
"zip": "wxt zip",
"zip:firefox": "wxt zip -b firefox",
"prepare": "simple-git-hooks",
"postinstall": "wxt prepare"
},
"dependencies": {
"@aklinker1/check": "^1.4.5",
"@tanstack/vue-query": "^5.59.13",
"@webext-core/messaging": "^2.0.2",
"@webext-core/proxy-service": "^1.2.0",
"@wxt-dev/storage": "^1.1.0",

This comment has been minimized.

Copy link
@aklinker1

aklinker1 Feb 12, 2025

Author Owner

This dependency is shipped apart of WXT, and doesn't need to be installed manually after the migration.

"async-mutex": "^0.5.0",
"fast-deep-equal": "^3.1.3",
"minimatch": "^10.0.1",
"ofetch": "^1.4.1"
},
"devDependencies": {
"@aklinker1/generate-changelog": "^1.1.2",
"@crxjs/vite-plugin": "^2.0.0-beta.31",
"@iconify/json": "^2.2.261",
"@tailwindcss/vite": "^4.0.6",
"@types/bun": "^1.1.11",
"@types/chrome": "^0.0.304",
"@types/chrome": "^0.0.278",
"@types/jsdom": "^21.1.7",
"@vitejs/plugin-vue": "^5.2.1",
"@vitest/coverage-v8": "^2.1.3",
"@wxt-dev/auto-icons": "^1.0.2",
"@wxt-dev/i18n": "^0.2.1",
"@wxt-dev/module-vue": "^1.0.1",
"daisyui": "^5.0.0-beta.7",
"env-cmd": "^10.1.0",
"fast-glob": "^3.3.2",
Expand All @@ -45,10 +49,10 @@
"tailwindcss": "^4.0.6",
"typescript": "^5.6.3",
"unplugin-icons": "^0.19.3",
"vite": "6.0.8",
"vitest": "^2.1.3",
"vue": "^3.5.12",
"vue-tsc": "^2.1.6"
"vue-tsc": "^2.1.6",
"wxt": "^0.19.11"
},
"simple-git-hooks": {
"pre-commit": "bun lint-staged"
Expand Down
10 changes: 0 additions & 10 deletions src/background.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/components/CommitDiff.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { i18n } from "@/utils/i18n";

This comment has been minimized.

Copy link
@aklinker1

aklinker1 Feb 12, 2025

Author Owner

WXT uses auto-imports by default, so you'll see lots of imports removed during this migration. You can disable auto-imports instead if you don't want to update every file's imports.

import { createDiffComponent } from "./createDiffComponent";

export const CommitDiff = createDiffComponent({
getAdditionsElement: () =>
document.querySelector<HTMLElement>("#toc>*>strong:nth-child(2)"),
Expand Down
3 changes: 0 additions & 3 deletions src/components/CompareDiff.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { i18n } from "@/utils/i18n";
import { createDiffComponent } from "./createDiffComponent";

export const CompareDiff = createDiffComponent({
getAdditionsElement: () =>
document.querySelectorAll<HTMLElement>(".toc-diff-stats>strong")[0],
Expand Down
2 changes: 0 additions & 2 deletions src/components/CustomListItem.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<script lang="ts" setup>
import { i18n } from "@/utils/i18n";
defineProps<{
value: string;
}>();
Expand Down
1 change: 0 additions & 1 deletion src/components/CustomListsPref.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import { computed } from "vue";
import type { CustomLists } from "@/utils/storage";
import CustomListItem from "./CustomListItem.vue";
import { i18n } from "@/utils/i18n";
const customLists = defineModel<CustomLists>("customLists", { required: true });
Expand Down
3 changes: 0 additions & 3 deletions src/components/OptionsForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import {
githubPatStorage,
customListsStorage,
} from "@/utils/storage";
import { useForm } from "@/composables/useForm";
import { commitHashDiffsCache } from "@/utils/global-cache";
import { i18n } from "@/utils/i18n";
const { state, hasChanges, reset, saveChanges } = useForm<{
hideGeneratedLineCount: boolean;
Expand Down
3 changes: 0 additions & 3 deletions src/components/PrDiff.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { i18n } from "@/utils/i18n";
import { createDiffComponent } from "./createDiffComponent";

export const PrDiff = createDiffComponent({
getAdditionsElement: () =>
document.querySelector<HTMLElement>("#diffstat .color-fg-success"),
Expand Down
2 changes: 0 additions & 2 deletions src/components/ShowGeneratedCountPref.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<script lang="ts" setup>
import { i18n } from "@/utils/i18n";
const hideLineCount = defineModel<boolean>("hideGeneratedLineCount", {
required: true,
});
Expand Down
3 changes: 0 additions & 3 deletions src/components/TokenPref.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<script lang="ts" setup>
import IMdiEye from "~icons/mdi/eye";
import IMdiEyeOffOutline from "~icons/mdi/eye-off-outline";
import { ref } from "vue";
import { i18n } from "@/utils/i18n";
import useGithubUserQuery from "@/composables/useGithubUserQuery";
const token = defineModel<string>("githubPat", {
required: true,
Expand Down
5 changes: 0 additions & 5 deletions src/components/createDiffComponent.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import { DIFF_COMPONENT_ID, GREY_COLOR } from "@/utils/constants";
import type { RecalculateResult } from "@/utils/github";
import { hideGeneratedLineCountStorage } from "@/utils/storage";
import { Spinner } from "./Spinner";
import { i18n } from "@/utils/i18n";
import { logger } from "@/utils/logger";

export function createDiffComponent(options: {
getAdditionsElement: () => HTMLElement | null | undefined;
Expand Down
1 change: 0 additions & 1 deletion src/composables/useForm.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import isDeepEqual from "fast-deep-equal";
import { computed, reactive } from "vue";

export function useForm<T extends Record<string, any>>(
initialState: T,
Expand Down
2 changes: 0 additions & 2 deletions src/composables/useGithubUserQuery.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { getGithubService, Github } from "@/utils/github";
import { QueryKeys } from "@/utils/QueryKeys";
import { useQuery } from "@tanstack/vue-query";

export default function (token: { value: string | undefined }) {
const github = getGithubService();
Expand Down
38 changes: 0 additions & 38 deletions src/content.ts

This file was deleted.

12 changes: 12 additions & 0 deletions src/entrypoints/background.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { registerGithubService, createGithubApi } from "@/utils/github";

export default defineBackground(() => {

This comment has been minimized.

Copy link
@aklinker1

aklinker1 Feb 12, 2025

Author Owner

Only difference with the background is we now wrap all the code in a call to defineBackground(() => { ... })

This comment has been minimized.

Copy link
@aklinker1

aklinker1 Feb 12, 2025

Author Owner

You may want to consider opting into the ESM background script: https://wxt.dev/guide/essentials/es-modules.html#background

CRXJS uses ESM background scripts by default, whereas WXT does not.

const api = createGithubApi();
registerGithubService(api);

browser.runtime.onInstalled.addListener(async ({ reason }) => {
if (reason === "install") {
void browser.runtime.openOptionsPage();
}
});
});
34 changes: 34 additions & 0 deletions src/entrypoints/content.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
export default defineContentScript({

This comment has been minimized.

Copy link
@aklinker1

aklinker1 Feb 12, 2025

Author Owner

Similar to the background, our content script code is now inside defineContentScript. Additionally, you'll notice this is where we configure the matches and run_at that appear in the manifest for this content script.

matches: ["*://*.github.com/*"],
runAt: "document_end",

main() {
main();
// TODO: schedule next interval for 1 second AFTER the main function finishes. If the main
// function takes more than 1 second, it might cause problems.
setInterval(main, SECOND);
},
});

function main() {
const repo = getCurrentRepo();
const owner = getCurrentOwner();
if (!repo || !owner) return;

const pr = getCurrentPr();
if (pr) return replaceCount({ type: "pr", repo, owner, pr }, PrDiff);

const commitHash = getCurrentRef();
if (commitHash)
return replaceCount(
{ type: "commit", repo, owner, ref: commitHash },
CommitDiff,
);

const commitRefs = getCurrentCompare();
if (commitRefs)
return replaceCount(
{ type: "compare", repo, owner, commitRefs },
CompareDiff,
);
}
3 changes: 2 additions & 1 deletion src/options.html → src/entrypoints/options/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="./options.ts" type="module"></script>

This comment has been minimized.

Copy link
@aklinker1

aklinker1 Feb 12, 2025

Author Owner

This file moved, and we renamed the main script to just main.ts inside the src/entrypoints/options/ directory.

<script src="./main.ts" type="module"></script>
<link rel="stylesheet" href="~/assets/tailwind.css" />
<meta name="manifest.open_in_tab" content="false" />

This comment has been minimized.

Copy link
@aklinker1

aklinker1 Feb 12, 2025

Author Owner

Additionally, notice that this is where we configure the open_in_tab option that would normally go in the manifest.

</head>
<body class="p-4 gap-4 flex flex-col"></body>
</html>
2 changes: 0 additions & 2 deletions src/options.ts → src/entrypoints/options/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import Options from "@/pages/Options.vue";
import { VueQueryPlugin } from "@tanstack/vue-query";
import { i18n } from "./utils/i18n";
import { createApp } from "vue";

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

Expand Down
1 change: 0 additions & 1 deletion src/utils/cache/createKeyValueCache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { storage } from "@wxt-dev/storage";
import { Mutex } from "async-mutex";

interface CachedValue<TValue> {
Expand Down
Loading

1 comment on commit 39d766d

@aklinker1
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main thing to recognize is that CRXJS found entrypoints by looking at a manifest.json file, whereas WXT finds entrypoints by looking for files in the entrypoints directory.

Please sign in to comment.