Skip to content

Commit 437c157

Browse files
committed
🐛 Use JSON5 to parse manifest.json (closes #216)
1 parent 9f01aa8 commit 437c157

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"clean-webpack-plugin": "^4.0.0",
5757
"colors": "^1.4.0",
5858
"cross-env": "^7.0.3",
59+
"json5": "^2.2.3",
5960
"lodash": "^4.17.21",
6061
"minimist": "^1.2.6",
6162
"useragent": "^2.3.0",

src/utils/manifest.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { readFileSync } from "fs";
22
import { flatMapDeep } from "lodash";
3+
import JSON5 from "json5";
34
import { Compiler, Entry } from "webpack";
45
import { bgScriptEntryErrorMsg, bgScriptManifestRequiredMsg } from "../messages/errors";
56

@@ -8,8 +9,8 @@ export function extractEntries(
89
manifestPath: string,
910
webpackOutput: Compiler["options"]["output"] = {},
1011
): IEntriesOption {
11-
const manifestJson = JSON.parse(readFileSync(manifestPath).toString()) as IExtensionManifest;
12-
const { background, content_scripts } = manifestJson;
12+
const manifestJson = JSON5.parse(readFileSync(manifestPath).toString()) as IExtensionManifest;
13+
const { background, content_scripts: contentScripts } = manifestJson;
1314
const { filename } = webpackOutput;
1415

1516
if (!filename) {
@@ -31,9 +32,9 @@ export function extractEntries(
3132
throw new TypeError(bgScriptEntryErrorMsg.get());
3233
}
3334

34-
const contentEntries: unknown = content_scripts
35+
const contentEntries: unknown = contentScripts
3536
? flatMapDeep(Object.keys(webpackEntry), (entryName) =>
36-
content_scripts.map(({ js }) =>
37+
contentScripts.map(({ js }) =>
3738
js.map((contentItem) => contentItem.replace(toRemove, "")).filter((contentItem) => contentItem === entryName),
3839
),
3940
)

0 commit comments

Comments
 (0)