Skip to content

Commit 14eb68f

Browse files
authored
Abstract out Chrome extension manifest writing into a webpack plugin (#472)
The code is somewhat repetitive, so it's nice to share it across extension packages. Making it a `webpack` plugin also allows us to tap into `webpack`'s watch mode!
1 parent 5ee4e32 commit 14eb68f

File tree

28 files changed

+221
-180
lines changed

28 files changed

+221
-180
lines changed

workspaces/leetcode-prettier-extension/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
"url": "https://github.com/miorel"
1515
},
1616
"type": "module",
17-
"exports": "./src/extension/main.ts",
17+
"exports": "./src/main.ts",
1818
"scripts": {
19-
"build": "tsx src/scripts/writeManifest.ts && cross-env NODE_OPTIONS=\"--import tsx\" webpack",
19+
"build": "cross-env NODE_OPTIONS=\"--import tsx\" webpack",
2020
"format": "prettier --color --write .",
2121
"lint": "eslint --color --max-warnings=0 .",
2222
"typecheck": "tsc --pretty --project ."
@@ -26,7 +26,7 @@
2626
},
2727
"devDependencies": {
2828
"@code-chronicles/eslint-config": "workspace:*",
29-
"@code-chronicles/util": "workspace:*",
29+
"@code-chronicles/webpack-chrome-extension-manifest-plugin": "workspace:*",
3030
"@types/node": "22.7.6",
3131
"cross-env": "7.0.3",
3232
"eslint": "9.12.0",
File renamed without changes.

workspaces/leetcode-prettier-extension/src/scripts/constants.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

workspaces/leetcode-prettier-extension/src/scripts/getManifest.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

workspaces/leetcode-prettier-extension/src/scripts/writeManifest.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

workspaces/leetcode-prettier-extension/webpack.config.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import path from "node:path";
22

3-
import type { Configuration } from "webpack";
43
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
4+
import type { Configuration } from "webpack";
5+
import { WebpackChromeExtensionManifestPlugin } from "@code-chronicles/webpack-chrome-extension-manifest-plugin";
56

67
import packageJson from "./package.json" with { type: "json" };
78

9+
const SCRIPT_FILENAME = "main.js";
10+
811
const config: Configuration = {
912
target: "web",
1013
entry: path.resolve(__dirname, packageJson.exports),
1114
output: {
12-
filename: "main.js",
15+
filename: SCRIPT_FILENAME,
1316
path: path.resolve(__dirname, "dist"),
1417
},
1518

@@ -34,7 +37,28 @@ const config: Configuration = {
3437
conditionNames: ["import"],
3538
},
3639

37-
plugins: [new ForkTsCheckerWebpackPlugin()],
40+
plugins: [
41+
new ForkTsCheckerWebpackPlugin(),
42+
43+
new WebpackChromeExtensionManifestPlugin({
44+
name: "LeetCode Prettier Formatting",
45+
description: packageJson.description,
46+
version: packageJson.version,
47+
48+
// eslint-disable-next-line camelcase
49+
manifest_version: 3,
50+
// eslint-disable-next-line camelcase
51+
content_scripts: [
52+
{
53+
matches: ["https://*.leetcode.com/*"],
54+
js: [SCRIPT_FILENAME],
55+
// eslint-disable-next-line camelcase
56+
run_at: "document_start",
57+
world: "MAIN",
58+
},
59+
],
60+
}),
61+
],
3862
};
3963

4064
export default config;

workspaces/leetcode-zen-mode/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
"url": "https://github.com/miorel"
1515
},
1616
"type": "module",
17-
"exports": "./src/extension/main.ts",
17+
"exports": "./src/main.ts",
1818
"scripts": {
19-
"build": "tsx src/scripts/writeManifest.ts && cross-env NODE_OPTIONS=\"--import tsx\" webpack",
19+
"build": "cross-env NODE_OPTIONS=\"--import tsx\" webpack",
2020
"format": "prettier --color --write .",
2121
"lint": "eslint --color --max-warnings=0 .",
2222
"typecheck": "tsc --pretty --project ."
@@ -27,6 +27,7 @@
2727
},
2828
"devDependencies": {
2929
"@code-chronicles/eslint-config": "workspace:*",
30+
"@code-chronicles/webpack-chrome-extension-manifest-plugin": "workspace:*",
3031
"@types/node": "22.7.6",
3132
"cross-env": "7.0.3",
3233
"eslint": "9.12.0",

workspaces/leetcode-zen-mode/src/extension/patchJsxFactory.ts

Lines changed: 0 additions & 52 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)