mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-23 02:42:41 +01:00
Use require
instead of fs
Related feedback: - https://github.com/uBlockOrigin/uBlock-issues/issues/1664#issuecomment-888332409
This commit is contained in:
parent
22022f636f
commit
e1222d1643
@ -23,6 +23,8 @@
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
import { createRequire } from 'module';
|
||||
|
||||
import './lib/punycode.js';
|
||||
import './lib/publicsuffixlist/publicsuffixlist.js';
|
||||
|
||||
@ -88,10 +90,14 @@ function enableWASM(path) {
|
||||
}
|
||||
|
||||
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.info('Unable to populate public suffix list');
|
||||
return;
|
||||
}
|
||||
}
|
||||
globals.publicSuffixList.parse(raw, globals.punycode.toASCII);
|
||||
console.info('Public suffix list populated');
|
||||
}
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
import { readFile } from 'fs';
|
||||
import { createRequire } from 'module';
|
||||
|
||||
import {
|
||||
FilteringContext,
|
||||
@ -35,15 +35,10 @@ import {
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
function fetch(path) {
|
||||
return new Promise((resolve, reject) => {
|
||||
readFile(path, 'utf8', (err, data) => {
|
||||
if ( err ) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(data);
|
||||
}
|
||||
});
|
||||
function fetch(listName) {
|
||||
return new Promise(resolve => {
|
||||
const require = createRequire(import.meta.url); // jshint ignore:line
|
||||
resolve(require(`./data/${listName}.json`));
|
||||
});
|
||||
}
|
||||
|
||||
@ -56,13 +51,11 @@ function fetch(path) {
|
||||
}
|
||||
*/
|
||||
|
||||
await fetch('./data/effective_tld_names.dat').then(pslRaw => {
|
||||
pslInit(pslRaw);
|
||||
});
|
||||
pslInit();
|
||||
|
||||
const snfe = await Promise.all([
|
||||
fetch('./data/easylist.txt'),
|
||||
fetch('./data/easyprivacy.txt'),
|
||||
fetch('easylist'),
|
||||
fetch('easyprivacy'),
|
||||
]).then(rawLists => {
|
||||
return restart([
|
||||
{ name: 'easylist', raw: rawLists[0] },
|
||||
|
@ -21,11 +21,16 @@ cp -R src/lib/punycode.js $DES/lib/
|
||||
cp -R src/lib/publicsuffixlist $DES/lib/
|
||||
cp -R src/lib/regexanalyzer $DES/lib/
|
||||
|
||||
# https://github.com/uBlockOrigin/uBlock-issues/issues/1664#issuecomment-888332409
|
||||
THIRDPARTY=../uAssets/thirdparties/publicsuffix.org
|
||||
mkdir -p $DES/data
|
||||
cp -R ../uAssets/thirdparties/publicsuffix.org/list/* \
|
||||
$DES/data
|
||||
cp -R ../uAssets/thirdparties/easylist-downloads.adblockplus.org/* \
|
||||
$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
|
||||
|
||||
cp platform/nodejs/*.js $DES/
|
||||
cp platform/nodejs/*.json $DES/
|
||||
|
Loading…
Reference in New Issue
Block a user