mirror of https://github.com/gorhill/uBlock.git
Make the nodejs package load a serialized version of the PSL
Related discussion: - https://github.com/cliqz-oss/adblocker/pull/2091#issuecomment-890545926
This commit is contained in:
parent
8a33bda653
commit
46c6ff8708
|
@ -25,7 +25,6 @@
|
||||||
|
|
||||||
import { createRequire } from 'module';
|
import { createRequire } from 'module';
|
||||||
|
|
||||||
import './lib/punycode.js';
|
|
||||||
import './lib/publicsuffixlist/publicsuffixlist.js';
|
import './lib/publicsuffixlist/publicsuffixlist.js';
|
||||||
|
|
||||||
import globals from './js/globals.js';
|
import globals from './js/globals.js';
|
||||||
|
@ -98,16 +97,10 @@ async function enableWASM() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function pslInit(raw) {
|
function pslInit() {
|
||||||
if ( typeof raw !== 'string' || raw.trim() === '' ) {
|
const require = createRequire(import.meta.url); // jshint ignore:line
|
||||||
const require = createRequire(import.meta.url); // jshint ignore:line
|
const json = require('./data/publicsuffixlist.json');
|
||||||
raw = require('./data/effective_tld_names.json');
|
globals.publicSuffixList.fromSelfie(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;
|
return globals.publicSuffixList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,13 +39,13 @@ UASSETS=submodules/uAssets
|
||||||
# https://github.com/uBlockOrigin/uBlock-issues/issues/1664#issuecomment-888332409
|
# https://github.com/uBlockOrigin/uBlock-issues/issues/1664#issuecomment-888332409
|
||||||
THIRDPARTY=$UASSETS/thirdparties/publicsuffix.org
|
THIRDPARTY=$UASSETS/thirdparties/publicsuffix.org
|
||||||
mkdir -p $DES/data
|
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
|
THIRDPARTY=$UASSETS/thirdparties/easylist-downloads.adblockplus.org
|
||||||
node -pe "JSON.stringify(fs.readFileSync('$THIRDPARTY/easylist.txt', 'utf8'))" \
|
node -pe "JSON.stringify(fs.readFileSync('$THIRDPARTY/easylist.txt', 'utf8'))" \
|
||||||
> $DES/data/easylist.json
|
> $DES/data/easylist.json
|
||||||
node -pe "JSON.stringify(fs.readFileSync('$THIRDPARTY/easyprivacy.txt', 'utf8'))" \
|
node -pe "JSON.stringify(fs.readFileSync('$THIRDPARTY/easyprivacy.txt', 'utf8'))" \
|
||||||
> $DES/data/easyprivacy.json
|
> $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/*.js $DES/
|
||||||
cp platform/nodejs/*.json $DES/
|
cp platform/nodejs/*.json $DES/
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
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())
|
||||||
|
);
|
Loading…
Reference in New Issue