Skip to content

Commit

Permalink
apply a tweak to the manifest for firefox extensions
Browse files Browse the repository at this point in the history
thanks mozilla mozilla/web-ext#2532
  • Loading branch information
MoralCode committed Jun 23, 2023
1 parent 479dbc0 commit 07c8387
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
},
"scripts": {
"clean": "rm -rf build/*; rm -rf dist/*",
"build": "NODE_ENV=production webpack --config webpack.config.mjs",
"build-dev": "NODE_ENV=development webpack --config webpack.config.mjs"
"build:chrome": "NODE_ENV=production webpack --env browser=chrome --config webpack.config.mjs",
"build:firefox": "NODE_ENV=production webpack --env browser=firefox --config webpack.config.mjs",
"build-dev:chrome": "NODE_ENV=development webpack --env browser=chrome--config webpack.config.mjs",
"build-dev:firefox": "NODE_ENV=development webpack --env browser=chrome --config webpack.config.mjs"
},
"repository": {
"type": "git",
Expand Down
15 changes: 12 additions & 3 deletions webpack.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function transformName(input) {
return names.join(' ');
}

function modify(buffer) {
function modify(buffer, isFirefox) {
// copy-webpack-plugin passes a buffer
const manifest = JSON.parse(buffer.toString());

Expand All @@ -44,11 +44,18 @@ function modify(buffer) {
manifest.author = pkgjson.author;
manifest.name = transformName(pkgjson.name);

if (!isFirefox) {
manifest.background.service_worker = manifest.background.scripts[0];
delete manifest.background.scripts;
}

// pretty print to JSON with two spaces
return JSON.stringify(manifest, null, 2);
}

export default function (env) {
if (!env.browser) env.browser = "chrome";

return {
// For some reason, webpack insists on having an entrypoint and making some JS
// here we give it an entrypoint it cant make anything useful from and then later we use
Expand All @@ -70,7 +77,7 @@ export default function (env) {
from: manifestPath,
to: BUILD_DIR,
transform(content) {
return modify(content);
return modify(content, env.browser === "firefox");
},
},
{
Expand All @@ -95,7 +102,9 @@ export default function (env) {
sourceDir: BUILD_DIR,
artifactsDir: DIST_DIR,
buildPackage: true,
overwriteDest: true
overwriteDest: true,
runLint: env.browser === 'firefox',
outputFilename: `${pkgjson.name}_${pkgjson.version}_${env.browser === 'firefox' ? "firefox" : "chrome"}.zip`
})
],

Expand Down

0 comments on commit 07c8387

Please sign in to comment.