Skip to content

Commit

Permalink
Merge pull request #677 from alexzurbonsen/allow-manifests-with-jsonc
Browse files Browse the repository at this point in the history
  • Loading branch information
tm1000 authored Jul 22, 2024
2 parents ff770e7 + 9914953 commit e127b4f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@types/chrome": "^0.0.268",
"@types/firefox-webext-browser": "^120.0.3",
"ajv": "^6.12.6",
"jsonc-parser": "^3.3.1",
"mustache": "^4.2.0",
"webpack-sources": "^3.2.3",
"ws": "^8.16.0"
Expand Down
9 changes: 6 additions & 3 deletions src/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import webpack, { Compiler, Compilation, Stats } from "webpack";
import Mustache from "mustache";
import { constants, readFileSync } from "fs";
import { access } from "fs/promises";
import { stripComments } from "jsonc-parser";
import vendors from "./vendors.json";
import {
Manifest,
Expand Down Expand Up @@ -164,7 +165,7 @@ class WebextensionPlugin {
const manifestBuffer = readFileSync(manifestPath, {
encoding: "utf8",
});
const manifest = JSON.parse(manifestBuffer);
const manifest = JSON.parse(stripComments(manifestBuffer));
const serviceWorker = manifest?.background?.service_worker ?? null;

if (
Expand Down Expand Up @@ -374,11 +375,13 @@ class WebextensionPlugin {
compilation.options.context,
this.manifestNameDefault
);
const manifestBuffer = await this.readFile(manifestPath);
const manifestBuffer = readFileSync(manifestPath, {
encoding: "utf8",
});
let manifest: Manifest;
// Convert to JSON
try {
manifest = JSON.parse(manifestBuffer);
manifest = JSON.parse(stripComments(manifestBuffer));
} catch (error) {
throw new Error(`Could not parse ${this.manifestNameDefault}`);
}
Expand Down

0 comments on commit e127b4f

Please sign in to comment.