diff --git a/platform/mv3/salvage-ruleids.mjs b/platform/mv3/salvage-ruleids.mjs index 02b290801..f11d986e7 100644 --- a/platform/mv3/salvage-ruleids.mjs +++ b/platform/mv3/salvage-ruleids.mjs @@ -79,21 +79,21 @@ async function main() { a.id = 0; return [ JSON.stringify(a), id ]; })); - const usedIds = new Set(); + const reusedIds = new Set(); for ( const afterRule of afterRules ) { afterRule.id = 0; const key = JSON.stringify(afterRule); const beforeId = beforeMap.get(key); if ( beforeId === undefined ) { continue; } - if ( usedIds.has(beforeId) ) { continue; } + if ( reusedIds.has(beforeId) ) { continue; } afterRule.id = beforeId; - usedIds.add(beforeId); + reusedIds.add(beforeId); } // Assign new ids to unmatched rules let ruleIdGenerator = 1; for ( const afterRule of afterRules ) { if ( afterRule.id !== 0 ) { continue; } - while ( usedIds.has(ruleIdGenerator) ) { ruleIdGenerator += 1; } + while ( reusedIds.has(ruleIdGenerator) ) { ruleIdGenerator += 1; } afterRule.id = ruleIdGenerator++; } afterRules.sort((a, b) => a.id - b.id); @@ -102,11 +102,10 @@ async function main() { for ( const afterRule of afterRules ) { lines.push(JSON.stringify(afterRule, null, indent)); } + const path = `${afterDir}/rulesets/${folder}/${file}`; + console.log(` Salvaged ${reusedIds.size} ids in ${folder}/${file}`); writePromises.push( - fs.writeFile( - `${afterDir}/rulesets/${folder}/${file}`, - `[\n${lines.join(',\n')}\n]\n` - ) + fs.writeFile(path, `[\n${lines.join(',\n')}\n]\n`) ); } } diff --git a/tools/make-mv3.sh b/tools/make-mv3.sh index a29e24add..af8637423 100755 --- a/tools/make-mv3.sh +++ b/tools/make-mv3.sh @@ -13,32 +13,30 @@ for i in "$@"; do case $i in quick) QUICK="yes" - shift # past argument=value ;; full) FULL="yes" - shift # past argument=value ;; firefox) PLATFORM="firefox" - shift # past argument=value ;; chromium) PLATFORM="chromium" - shift # past argument=value ;; uBOLite_+([0-9]).+([0-9]).+([0-9]).+([0-9])) TAGNAME="$i" FULL="yes" - shift # past argument=value ;; - before=+([print])) + before=+([[:print:]])) BEFORE="${i:7}" - shift # past argument=value ;; esac done +echo "PLATFORM=$PLATFORM" +echo "TAGNAME=$TAGNAME" +echo "BEFORE=$BEFORE" + DES="dist/build/uBOLite.$PLATFORM" if [ "$QUICK" != "yes" ]; then @@ -117,6 +115,12 @@ if [ "$QUICK" != "yes" ]; then cp "$UBO_DIR"/src/web_accessible_resources/* "$TMPDIR"/web_accessible_resources/ cd "$TMPDIR" node --no-warnings make-rulesets.js output="$DES" platform="$PLATFORM" + if [ -n "$BEFORE" ]; then + echo "*** uBOLite.mv3: salvaging rule ids to minimize diff size" + echo " before=$BEFORE/$PLATFORM" + echo " after=$DES" + node salvage-ruleids.mjs before="$BEFORE"/"$PLATFORM" after="$DES" + fi cd - > /dev/null rm -rf "$TMPDIR" fi @@ -132,10 +136,6 @@ if [ -z "$TAGNAME" ] && [ "$PLATFORM" = "firefox" ]; then fi if [ "$FULL" = "yes" ]; then - if [ -n "$BEFORE" ]; then - echo "*** uBOLite.mv3: salvaging rule ids to minimize diff size" - node salvage-ruleids.mjs before="$BEFORE"/"$PLATFORM" after="$DES" - fi EXTENSION="zip" if [ "$PLATFORM" = "firefox" ]; then EXTENSION="xpi"