Skip to content

Commit 566c454

Browse files
committed
fix: disable content scripts
1 parent ee7db13 commit 566c454

File tree

5 files changed

+35
-68
lines changed

5 files changed

+35
-68
lines changed

biome.json

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
{
2-
"$schema": "https://biomejs.dev/schemas/1.6.1/schema.json",
3-
"organizeImports": {
4-
"enabled": true
5-
},
6-
"formatter": {
7-
"indentStyle": "space",
8-
"indentWidth": 2
9-
},
10-
"javascript": {
11-
"formatter": {
12-
"trailingComma": "es5"
13-
}
14-
},
15-
"linter": {
16-
"enabled": true,
17-
"rules": {
18-
"recommended": true
19-
}
20-
}
2+
"$schema": "https://biomejs.dev/schemas/1.6.1/schema.json",
3+
"organizeImports": {
4+
"enabled": true
5+
},
6+
"formatter": {
7+
"indentStyle": "space",
8+
"indentWidth": 2
9+
},
10+
"javascript": {
11+
"formatter": {
12+
"trailingComma": "es5"
13+
}
14+
},
15+
"linter": {
16+
"enabled": true,
17+
"rules": {
18+
"recommended": true
19+
}
20+
},
21+
"files": {
22+
"ignore": ["dist"]
2123
}
22-
24+
}

packages/rsbuild-plugin-web-extension/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
".": {
1111
"types": "./dist/index.d.ts",
1212
"import": "./dist/index.js",
13-
"require": "./dist/index.cjs",
14-
"default": "./dist/index.js"
13+
"require": "./dist/index.cjs"
1514
}
1615
},
1716
"files": ["dist"],

packages/rsbuild-plugin-web-extension/src/index.ts

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type RsbuildPlugin } from "@rsbuild/core";
1+
import type { RsbuildPlugin } from "@rsbuild/core";
22
import { makeManifest } from "./manifest/make-manifest.js";
33

44
interface Options {
@@ -19,46 +19,10 @@ export const pluginWebExtension = ({ manifest }: Options): RsbuildPlugin => ({
1919
* @issue https://github.com/web-infra-dev/rspack/issues/5971
2020
* @ref https://github.com/webdiscus/html-bundler-webpack-plugin
2121
*/
22-
const entry = htmlEntryPoints.reduce(
23-
(acc, [name, entry]) => ({
24-
...acc,
25-
[name]: entry?.replace(/\.html$/, ".tsx"),
26-
}),
27-
{}
28-
);
29-
30-
const contentScripts = manifest.content_scripts?.map((script) => {
31-
if (!script.js) {
32-
return;
33-
}
34-
if (script.js.length > 1) {
35-
throw new Error(
36-
`Multiple scripts are not supported for content_scripts not yet: ${script.js}` // TODO: support multiple scripts
37-
);
38-
}
39-
if (!/index\.(js|ts|tsx)$/.test(script.js[0].split("/").pop()!)) {
40-
throw new Error(
41-
`Support only index.(js|ts|tsx) is supported for content_scripts yet: ${script.js}` // TODO: support file name to entry name
42-
);
43-
}
44-
45-
const entryName = script.js[0]
46-
.split("/")
47-
.pop()!
48-
.replace(/\.(js|ts|tsx)$/, "");
49-
50-
return {
51-
[entryName]: script.js[0],
52-
};
53-
});
54-
55-
const contentScriptsEntry = contentScripts?.reduce(
56-
(acc, scripts) => ({
57-
...acc,
58-
...scripts,
59-
}),
60-
{}
61-
);
22+
const entry = htmlEntryPoints.reduce((acc, [name, entry]) => {
23+
acc[name] = entry?.replace(/\.html$/, ".tsx");
24+
return acc;
25+
}, {} as Record<string, string | undefined>);
6226

6327
api.modifyRspackConfig((config, { mergeConfig, HtmlPlugin }) => {
6428
return mergeConfig(config, {
@@ -80,7 +44,6 @@ export const pluginWebExtension = ({ manifest }: Options): RsbuildPlugin => ({
8044
source: {
8145
entry: {
8246
...entry,
83-
...contentScriptsEntry,
8447
background: manifest.background?.service_worker || "",
8548
},
8649
},

packages/rsbuild-plugin-web-extension/src/manifest/make-manifest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ export const makeManifest = async (
1818
ManifestParser.convertManifestToString(manifest.default)
1919
);
2020

21-
logger.log(`Manifest file created`);
21+
logger.log("Manifest file created");
2222
};

packages/rsbuild-plugin-web-extension/src/manifest/parser.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ const getOutputFile = (file: string): string => {
99
class ManifestParser {
1010
private constructor() {}
1111

12-
static convertManifestToString(manifest: Manifest): string {
12+
static convertManifestToString(_manifest: Manifest): string {
13+
let manifest = { ..._manifest };
1314
if (process.env.__FIREFOX__) {
14-
manifest = this.convertToFirefoxCompatibleManifest(manifest);
15+
manifest = ManifestParser.convertToFirefoxCompatibleManifest(manifest);
1516
}
1617

1718
return getOutputFile(JSON.stringify(manifest, null, 2));
@@ -34,7 +35,9 @@ class ManifestParser {
3435
manifestCopy.content_security_policy = {
3536
extension_pages: "script-src 'self'; object-src 'self'",
3637
};
37-
delete manifestCopy.options_page;
38+
39+
manifestCopy.options_page = undefined;
40+
3841
return manifestCopy as Manifest;
3942
}
4043
}

0 commit comments

Comments
 (0)