1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-05 11:37:01 +02:00

Fix the salvaging of rule ids

This commit is contained in:
Raymond Hill 2024-03-11 22:22:57 -04:00
parent 7c14b3963e
commit 2c9ab8ee04
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 18 additions and 19 deletions

View File

@ -79,21 +79,21 @@ async function main() {
a.id = 0; a.id = 0;
return [ JSON.stringify(a), id ]; return [ JSON.stringify(a), id ];
})); }));
const usedIds = new Set(); const reusedIds = new Set();
for ( const afterRule of afterRules ) { for ( const afterRule of afterRules ) {
afterRule.id = 0; afterRule.id = 0;
const key = JSON.stringify(afterRule); const key = JSON.stringify(afterRule);
const beforeId = beforeMap.get(key); const beforeId = beforeMap.get(key);
if ( beforeId === undefined ) { continue; } if ( beforeId === undefined ) { continue; }
if ( usedIds.has(beforeId) ) { continue; } if ( reusedIds.has(beforeId) ) { continue; }
afterRule.id = beforeId; afterRule.id = beforeId;
usedIds.add(beforeId); reusedIds.add(beforeId);
} }
// Assign new ids to unmatched rules // Assign new ids to unmatched rules
let ruleIdGenerator = 1; let ruleIdGenerator = 1;
for ( const afterRule of afterRules ) { for ( const afterRule of afterRules ) {
if ( afterRule.id !== 0 ) { continue; } if ( afterRule.id !== 0 ) { continue; }
while ( usedIds.has(ruleIdGenerator) ) { ruleIdGenerator += 1; } while ( reusedIds.has(ruleIdGenerator) ) { ruleIdGenerator += 1; }
afterRule.id = ruleIdGenerator++; afterRule.id = ruleIdGenerator++;
} }
afterRules.sort((a, b) => a.id - b.id); afterRules.sort((a, b) => a.id - b.id);
@ -102,11 +102,10 @@ async function main() {
for ( const afterRule of afterRules ) { for ( const afterRule of afterRules ) {
lines.push(JSON.stringify(afterRule, null, indent)); lines.push(JSON.stringify(afterRule, null, indent));
} }
const path = `${afterDir}/rulesets/${folder}/${file}`;
console.log(` Salvaged ${reusedIds.size} ids in ${folder}/${file}`);
writePromises.push( writePromises.push(
fs.writeFile( fs.writeFile(path, `[\n${lines.join(',\n')}\n]\n`)
`${afterDir}/rulesets/${folder}/${file}`,
`[\n${lines.join(',\n')}\n]\n`
)
); );
} }
} }

View File

@ -13,32 +13,30 @@ for i in "$@"; do
case $i in case $i in
quick) quick)
QUICK="yes" QUICK="yes"
shift # past argument=value
;; ;;
full) full)
FULL="yes" FULL="yes"
shift # past argument=value
;; ;;
firefox) firefox)
PLATFORM="firefox" PLATFORM="firefox"
shift # past argument=value
;; ;;
chromium) chromium)
PLATFORM="chromium" PLATFORM="chromium"
shift # past argument=value
;; ;;
uBOLite_+([0-9]).+([0-9]).+([0-9]).+([0-9])) uBOLite_+([0-9]).+([0-9]).+([0-9]).+([0-9]))
TAGNAME="$i" TAGNAME="$i"
FULL="yes" FULL="yes"
shift # past argument=value
;; ;;
before=+([print])) before=+([[:print:]]))
BEFORE="${i:7}" BEFORE="${i:7}"
shift # past argument=value
;; ;;
esac esac
done done
echo "PLATFORM=$PLATFORM"
echo "TAGNAME=$TAGNAME"
echo "BEFORE=$BEFORE"
DES="dist/build/uBOLite.$PLATFORM" DES="dist/build/uBOLite.$PLATFORM"
if [ "$QUICK" != "yes" ]; then if [ "$QUICK" != "yes" ]; then
@ -117,6 +115,12 @@ if [ "$QUICK" != "yes" ]; then
cp "$UBO_DIR"/src/web_accessible_resources/* "$TMPDIR"/web_accessible_resources/ cp "$UBO_DIR"/src/web_accessible_resources/* "$TMPDIR"/web_accessible_resources/
cd "$TMPDIR" cd "$TMPDIR"
node --no-warnings make-rulesets.js output="$DES" platform="$PLATFORM" 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 cd - > /dev/null
rm -rf "$TMPDIR" rm -rf "$TMPDIR"
fi fi
@ -132,10 +136,6 @@ if [ -z "$TAGNAME" ] && [ "$PLATFORM" = "firefox" ]; then
fi fi
if [ "$FULL" = "yes" ]; then 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" EXTENSION="zip"
if [ "$PLATFORM" = "firefox" ]; then if [ "$PLATFORM" = "firefox" ]; then
EXTENSION="xpi" EXTENSION="xpi"