From c6d275674d819fac590a7d01704e35e0af3ea174 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 1 Aug 2021 15:42:46 -0400 Subject: [PATCH] Revert "Make the nodejs package load a serialized version of the PSL" This reverts commit 46c6ff8708419614201d3e477b20f74c2c275afd. --- platform/nodejs/main.js | 15 +++++++++++---- tools/make-nodejs.sh | 4 ++-- tools/make-psl.json.js | 40 ---------------------------------------- 3 files changed, 13 insertions(+), 46 deletions(-) delete mode 100755 tools/make-psl.json.js diff --git a/platform/nodejs/main.js b/platform/nodejs/main.js index 8c9bbe998..171ec8636 100644 --- a/platform/nodejs/main.js +++ b/platform/nodejs/main.js @@ -25,6 +25,7 @@ import { createRequire } from 'module'; +import './lib/punycode.js'; import './lib/publicsuffixlist/publicsuffixlist.js'; import globals from './js/globals.js'; @@ -97,10 +98,16 @@ async function enableWASM() { return false; } -function pslInit() { - const require = createRequire(import.meta.url); // jshint ignore:line - const json = require('./data/publicsuffixlist.json'); - globals.publicSuffixList.fromSelfie(json); +function pslInit(raw) { + if ( typeof raw !== 'string' || raw.trim() === '' ) { + const require = createRequire(import.meta.url); // jshint ignore:line + raw = require('./data/effective_tld_names.json'); + if ( typeof raw !== 'string' || raw.trim() === '' ) { + console.error('Unable to populate public suffix list'); + return; + } + } + globals.publicSuffixList.parse(raw, globals.punycode.toASCII); return globals.publicSuffixList; } diff --git a/tools/make-nodejs.sh b/tools/make-nodejs.sh index 6d5bfff2f..9404d2c2d 100755 --- a/tools/make-nodejs.sh +++ b/tools/make-nodejs.sh @@ -39,13 +39,13 @@ UASSETS=submodules/uAssets # https://github.com/uBlockOrigin/uBlock-issues/issues/1664#issuecomment-888332409 THIRDPARTY=$UASSETS/thirdparties/publicsuffix.org mkdir -p $DES/data +node -pe "JSON.stringify(fs.readFileSync('$THIRDPARTY/list/effective_tld_names.dat', 'utf8'))" \ + > $DES/data/effective_tld_names.json THIRDPARTY=$UASSETS/thirdparties/easylist-downloads.adblockplus.org node -pe "JSON.stringify(fs.readFileSync('$THIRDPARTY/easylist.txt', 'utf8'))" \ > $DES/data/easylist.json node -pe "JSON.stringify(fs.readFileSync('$THIRDPARTY/easyprivacy.txt', 'utf8'))" \ > $DES/data/easyprivacy.json -# https://github.com/cliqz-oss/adblocker/pull/2091#issuecomment-890545926 -node ./tools/make-psl.json.js cp platform/nodejs/*.js $DES/ cp platform/nodejs/*.json $DES/ diff --git a/tools/make-psl.json.js b/tools/make-psl.json.js deleted file mode 100755 index 0228492bc..000000000 --- a/tools/make-psl.json.js +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - - uBlock Origin - a browser extension to block requests. - Copyright (C) 2014-present Raymond Hill - - 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 {http://www.gnu.org/licenses/}. - - Home: https://github.com/gorhill/uBlock -*/ - -/* globals process, require */ - -'use strict'; - -const fs = require('fs'); -const raw = fs.readFileSync('./submodules/uAssets/thirdparties/publicsuffix.org/list/effective_tld_names.dat', 'utf8'); -const punycode = require('../src/lib/punycode.js'); -const psl = require('../src/lib/publicsuffixlist/publicsuffixlist.js'); - -if ( typeof raw !== 'string' || raw.trim() === '' ) { - return process.exit('Unable to populate public suffix list'); -} - -psl.parse(raw, punycode.toASCII); - -fs.writeFileSync( - './dist/build/uBlock0.nodejs/data/publicsuffixlist.json', - JSON.stringify(psl.toSelfie()) -);