Adapt build scripts to mixed MV3/MV2 12.x development cycles.

This commit is contained in:
hackademix 2024-11-18 10:07:29 +01:00
parent f3c92588f2
commit af88ebc38b
No known key found for this signature in database
GPG Key ID: 231A83AFDA9C2434
3 changed files with 63 additions and 24 deletions

View File

@ -172,34 +172,15 @@ strip_rc_ver "$MANIFEST_OUT"
# manifest.json patching for Chromium:
EXTRA_PERMS=""
if grep 'patchWorkers.js' "$MANIFEST_OUT" >/dev/null 2>&1; then
EXTRA_PERMS='"debugger",'
fi
GECKO_PERMS="dns|<all_urls>|webRequestBlocking"
# skip "application" manifest key
(grep -B1000 '"name": "NoScript"' "$MANIFEST_OUT"; \
grep -A2000 '"version":' "$MANIFEST_OUT") | \
# auto-update URL for the Edge version on the Microsoft Store
sed -e '/"name":/a\' -e ' "update_url": "'$EDGE_UPDATE_URL'",' | \
# skip embeddingDocument.js and dns permission
grep -Pv 'content/embeddingDocument.js|"dns",' | \
# add "debugger" permission for patchWorkers.js
sed -re 's/( *)"webRequestBlocking",/&\n\1'"$EXTRA_PERMS"'/' | \
# add origin fallback for content scripts
sed -re 's/( *)"match_about_blank": *true/\1"match_origin_as_fallback": true,\n&/' > \
"$MANIFEST_OUT".tmp && \
mv "$MANIFEST_OUT.tmp" "$MANIFEST_OUT"
node manifest.js $MANIFEST_OUT
CHROME_ZIP=$(build | grep 'ready: .*\.zip' | sed -re 's/.* ready: //')
if [ -f "$CHROME_ZIP" ]; then
mv "$CHROME_ZIP" "$XPI$DBG-edge.zip"
# remove Edge-specific manifest lines and package for generic Chromium
grep -v '"update_url":' "$MANIFEST_OUT" > "$MANIFEST_OUT.tmp" && \
mv "$MANIFEST_OUT.tmp" "$MANIFEST_OUT" && \
build
mv "$CHROME_ZIP" "$XPI$DBG-chrome.zip"
node manifest.js mv3 $MANIFEST_OUT && build
mv "$CHROME_ZIP" "$XPI$DBG-chrome.zip"
fi
mv "$BUILD" "$CHROMIUM_UNPACKED"

58
manifest.js Normal file
View File

@ -0,0 +1,58 @@
/*
* NoScript Commons Library
* Reusable building blocks for cross-browser security/privacy WebExtensions.
* Copyright (C) 2020-2024 Giorgio Maone <https://maone.net>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
"use strict";
const fs = require('fs');
const path = require('path');
const args = process.argv.slice(2);
const MANIFEST_VER = /^m?v?[2-3]$/i.test(args[0]) ? args.shift() : "mv3edge";
const MANIFEST_SRC = args[0] || "src/manifest.json";
const MANIFEST_DEST = args[1] || args[0] || "build/manifest.json";
const EDGE_UPDATE_URL = "https://edge.microsoft.com/extensionwebstorebase/v1/crx";
console.log(`${MANIFEST_SRC} --[${MANIFEST_VER}]--> ${MANIFEST_DEST}`);
const srcContent = fs.readFileSync(MANIFEST_SRC, 'utf8');
const json = JSON.parse(srcContent);
if (MANIFEST_VER.includes(3)) {
delete json.browser_specific_settings;
if (MANIFEST_VER.includes("edge")) {
json.update_url = EDGE_UPDATE_URL;
} else if (json.update_url === EDGE_UPDATE_URL) {
delete json.update_url;
}
json.permissions = json.permissions
.filter(p => !
/^(?:<all_urls>|webRequestBlocking)$/
.test(p)
);
for (const cs of json.content_scripts) {
cs.js = cs.js.filter(js => !js.includes("content/embeddingDocument.js"))
}
delete json.browser_action;
delete json.commands._execute_browser_action
}
const destContent = JSON.stringify(json, null, 2);
fs.writeFileSync(MANIFEST_DEST, destContent);
console.log(`Written ${MANIFEST_DEST}`);

@ -1 +1 @@
Subproject commit ec68d37aaf9279a81aa5970942e166777a1ab9f4
Subproject commit b9610d41876354963584737b3ce668e6583e0546