diff --git a/Makefile b/Makefile index 57be09a96..2ce9beb54 100644 --- a/Makefile +++ b/Makefile @@ -6,11 +6,13 @@ run_options := $(filter-out $@,$(MAKECMDGOALS)) compare maxcost medcost mincost modifiers record wasm sources := ./dist/version $(shell find ./assets -type f) $(shell find ./src -type f) -platform := $(wildcard platform/**/*) +platform := $(wildcard platform/*/*) assets := dist/build/uAssets -mv3-sources := $(shell find ./src -type f) $(shell find ./platform/mv3 -type f) +mv3-sources := $(shell find ./src -type f) $(wildcard platform/mv3/*) $(shell find ./platform/mv3/extension -type f) mv3-data := $(shell find ./dist/build/mv3-data -type f) -mv3-safari-deps := $(shell find ./platform/mv3/extension -type f) $(wildcard platform/mv3/safari/*) + +mv3-edge-deps := $(wildcard platform/mv3/edge/*) +mv3-safari-deps := $(wildcard platform/mv3/safari/*) all: chromium firefox npm @@ -77,7 +79,7 @@ dist/build/uBOLite.firefox: tools/make-mv3.sh $(mv3-sources) $(platform) $(mv3-d mv3-firefox: dist/build/uBOLite.firefox -dist/build/uBOLite.edge: tools/make-mv3.sh tools/make-edge.mjs $(mv3-sources) $(platform) $(mv3-data) dist/build/mv3-data +dist/build/uBOLite.edge: tools/make-mv3.sh $(mv3-sources) $(mv3-edge-deps) $(mv3-data) dist/build/mv3-data tools/make-mv3.sh edge mv3-edge: dist/build/uBOLite.edge diff --git a/tools/make-edge.mjs b/platform/mv3/edge/patch-extension.js similarity index 75% rename from tools/make-edge.mjs rename to platform/mv3/edge/patch-extension.js index 45bf7d7d7..78e482f5c 100644 --- a/tools/make-edge.mjs +++ b/platform/mv3/edge/patch-extension.js @@ -19,16 +19,33 @@ Home: https://github.com/gorhill/uBlock */ -'use strict'; +import fs from 'fs/promises'; +import process from 'process'; /******************************************************************************/ -import fs from 'fs/promises'; +const commandLineArgs = (( ) => { + const args = Object.create(null); + let name, value; + for ( const arg of process.argv.slice(2) ) { + const pos = arg.indexOf('='); + if ( pos === -1 ) { + name = arg; + value = ''; + } else { + name = arg.slice(0, pos); + value = arg.slice(pos+1); + } + args[name] = value; + } + return args; +})(); /******************************************************************************/ async function main() { - const manifestPath = 'dist/build/uBOLite.edge/manifest.json'; + const packageDir = commandLineArgs.packageDir; + const manifestPath = `${packageDir}/manifest.json`; // Get manifest content const manifest = await fs.readFile(manifestPath, { encoding: 'utf8' @@ -45,7 +62,7 @@ async function main() { } // Commit changes await fs.writeFile(manifestPath, - JSON.stringify(manifest, null, 2) + '\n' + JSON.stringify(manifest, null, 2) ); } diff --git a/platform/mv3/make-rulesets.js b/platform/mv3/make-rulesets.js index fc93c2ec3..8f6bc71e0 100644 --- a/platform/mv3/make-rulesets.js +++ b/platform/mv3/make-rulesets.js @@ -1413,7 +1413,7 @@ async function main() { const dayPart = now.getUTCDate(); const hourPart = Math.floor(now.getUTCHours()); const minutePart = Math.floor(now.getUTCMinutes()); - version = `${yearPart}.${monthPart}.${dayPart}.${hourPart * 60 + minutePart}`; + version = `${yearPart}.${monthPart*100+dayPart}.${hourPart*100+minutePart}`; } log(`Version: ${version}`, false); diff --git a/platform/mv3/safari/manifest.json b/platform/mv3/safari/manifest.json index c724367cb..d18525c1a 100644 --- a/platform/mv3/safari/manifest.json +++ b/platform/mv3/safari/manifest.json @@ -9,6 +9,11 @@ "type": "module", "persistent": false }, + "browser_specific_settings": { + "safari": { + "strict_min_version": "18.4" + } + }, "commands": { "enter-zapper-mode": { "description": "__MSG_zapperTipEnter__" diff --git a/platform/mv3/safari/patch-extension.js b/platform/mv3/safari/patch-extension.js index 6a285535c..142d48033 100644 --- a/platform/mv3/safari/patch-extension.js +++ b/platform/mv3/safari/patch-extension.js @@ -25,7 +25,7 @@ import process from 'process'; /******************************************************************************/ const commandLineArgs = (( ) => { - const args = new Map(); + const args = Object.create(null); let name, value; for ( const arg of process.argv.slice(2) ) { const pos = arg.indexOf('='); @@ -36,7 +36,7 @@ const commandLineArgs = (( ) => { name = arg.slice(0, pos); value = arg.slice(pos+1); } - args.set(name, value); + args[name] = value; } return args; })(); @@ -65,7 +65,7 @@ async function fixLongDescription(path) { async function fixLongDescriptions() { const promises = []; - const packageDir = commandLineArgs.get('packageDir'); + const packageDir = commandLineArgs.packageDir; const entries = await fs.readdir(`${packageDir}/_locales/`, { withFileTypes: true }); for ( const entry of entries ) { if ( entry.isDirectory() === false ) { continue; } @@ -79,11 +79,12 @@ async function fixLongDescriptions() { // Apple store rejects when version has four components. async function fixManifest() { - const packageDir = commandLineArgs.get('packageDir'); + const packageDir = commandLineArgs.packageDir; const path = `${packageDir}/manifest.json`; let text = await fs.readFile(path, { encoding: 'utf8' }); const manifest = JSON.parse(text); const match = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/.exec(manifest.version); + if ( match === null ) { return; } const month = parseInt(match[2], 10); const dayofmonth = parseInt(match[3], 10); const monthday /* sort of */ = month * 100 + dayofmonth; @@ -99,7 +100,6 @@ async function main() { fixLongDescriptions(), fixManifest(), ]); - } main(); diff --git a/tools/make-mv3.sh b/tools/make-mv3.sh index 7e1a89fb5..78413ed52 100755 --- a/tools/make-mv3.sh +++ b/tools/make-mv3.sh @@ -26,7 +26,7 @@ for i in "$@"; do safari) PLATFORM="safari" ;; - uBOLite_+([0-9]).+([0-9]).+([0-9]).+([0-9])) + uBOLite_+([0-9]).+([0-9]).+([0-9])) TAGNAME="$i" FULL="yes" ;; @@ -124,24 +124,12 @@ fi cd - > /dev/null rm -rf "$UBOL_BUILD_DIR" -# For Edge, declared rulesets must be at package root -if [ "$PLATFORM" = "edge" ]; then - echo "*** uBOLite.edge: Modify reference implementation for Edge compatibility" - mv "$UBOL_DIR"/rulesets/main/* "$UBOL_DIR/" - rmdir "$UBOL_DIR/rulesets/main" - node tools/make-edge.mjs -fi - -# For Safari, we must fix the package for compliance -if [ "$PLATFORM" = "safari" ]; then - node platform/mv3/safari/patch-extension.js packageDir="$UBOL_DIR" -fi - echo "*** uBOLite.$PLATFORM: extension ready" echo "Extension location: $UBOL_DIR/" # Local build if [ -z "$TAGNAME" ]; then + TAGNAME="uBOLite_$(jq -r .version "$UBOL_DIR"/manifest.json)" # Enable DNR rule debugging tmp=$(mktemp) jq '.permissions += ["declarativeNetRequestFeedback"]' \ @@ -153,6 +141,22 @@ if [ -z "$TAGNAME" ]; then jq '.browser_specific_settings.gecko.id = "uBOLite.dev@raymondhill.net"' "$UBOL_DIR/manifest.json" > "$tmp" \ && mv "$tmp" "$UBOL_DIR/manifest.json" fi +else + tmp=$(mktemp) + jq --arg version "${TAGNAME:8}" '.version = $version' "$UBOL_DIR/manifest.json" > "$tmp" \ + && mv "$tmp" "$UBOL_DIR/manifest.json" +fi + +# Platform-specific steps +if [ "$PLATFORM" = "edge" ]; then + # For Edge, declared rulesets must be at package root + echo "*** uBOLite.edge: Modify reference implementation for Edge compatibility" + mv "$UBOL_DIR"/rulesets/main/* "$UBOL_DIR/" + rmdir "$UBOL_DIR/rulesets/main" + node platform/mv3/edge/patch-extension.js packageDir="$UBOL_DIR" +elif [ "$PLATFORM" = "safari" ]; then + # For Safari, we must fix the package for compliance + node platform/mv3/safari/patch-extension.js packageDir="$UBOL_DIR" fi if [ "$FULL" = "yes" ]; then @@ -161,13 +165,6 @@ if [ "$FULL" = "yes" ]; then EXTENSION="xpi" fi echo "*** uBOLite.mv3: Creating publishable package..." - if [ -z "$TAGNAME" ]; then - TAGNAME="uBOLite_$(jq -r .version "$UBOL_DIR"/manifest.json)" - else - tmp=$(mktemp) - jq --arg version "${TAGNAME:8}" '.version = $version' "$UBOL_DIR/manifest.json" > "$tmp" \ - && mv "$tmp" "$UBOL_DIR/manifest.json" - fi UBOL_PACKAGE_NAME="$TAGNAME.$PLATFORM.mv3.$EXTENSION" UBOL_PACKAGE_DIR=$(mktemp -d) mkdir -p "$UBOL_PACKAGE_DIR"