mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-10 01:02:08 +01:00
Simplify loading of WASM modules in nodejs
This commit is contained in:
parent
5be4d5d877
commit
d5da88ea87
2 changed files with 17 additions and 26 deletions
|
@ -82,33 +82,18 @@ function applyList(name, raw) {
|
||||||
|
|
||||||
async function enableWASM() {
|
async function enableWASM() {
|
||||||
const wasmModuleFetcher = function(path) {
|
const wasmModuleFetcher = function(path) {
|
||||||
return new Promise((resolve, reject) => {
|
const require = createRequire(import.meta.url); // jshint ignore:line
|
||||||
const require = createRequire(import.meta.url); // jshint ignore:line
|
const wasm = new Uint8Array(require(`${path}.wasm.json`));
|
||||||
const fs = require('fs');
|
return globals.WebAssembly.compile(wasm);
|
||||||
fs.readFile(`${path}.wasm`, null, (err, data) => {
|
|
||||||
if ( err ) { return reject(err); }
|
|
||||||
return globals.WebAssembly.compile(data).then(module => {
|
|
||||||
resolve(module);
|
|
||||||
}).catch(reason => {
|
|
||||||
reject(reason);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const results = await Promise.all([
|
const results = await Promise.all([
|
||||||
globals.publicSuffixList.enableWASM(
|
globals.publicSuffixList.enableWASM(wasmModuleFetcher, './lib/publicsuffixlist/wasm/'),
|
||||||
wasmModuleFetcher,
|
snfe.enableWASM(wasmModuleFetcher, './js/wasm/'),
|
||||||
'./lib/publicsuffixlist/wasm/'
|
|
||||||
),
|
|
||||||
snfe.enableWASM(
|
|
||||||
wasmModuleFetcher,
|
|
||||||
'./js/wasm/'
|
|
||||||
),
|
|
||||||
]);
|
]);
|
||||||
return results.every(a => a === true);
|
return results.every(a => a === true);
|
||||||
} catch(reason) {
|
} catch(reason) {
|
||||||
console.info(reason);
|
console.log(reason);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -123,7 +108,6 @@ function pslInit(raw) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
globals.publicSuffixList.parse(raw, globals.punycode.toASCII);
|
globals.publicSuffixList.parse(raw, globals.punycode.toASCII);
|
||||||
return globals.publicSuffixList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function restart(lists, options = {}) {
|
function restart(lists, options = {}) {
|
||||||
|
|
|
@ -16,13 +16,20 @@ cp src/js/static-filtering-io.js $DES/js
|
||||||
cp src/js/text-iterators.js $DES/js
|
cp src/js/text-iterators.js $DES/js
|
||||||
cp src/js/uri-utils.js $DES/js
|
cp src/js/uri-utils.js $DES/js
|
||||||
|
|
||||||
mkdir -p $DES/js/wasm
|
|
||||||
cp src/js/wasm/* $DES/js/wasm/
|
|
||||||
|
|
||||||
mkdir -p $DES/lib
|
mkdir -p $DES/lib
|
||||||
cp -R src/lib/punycode.js $DES/lib/
|
cp -R src/lib/punycode.js $DES/lib/
|
||||||
cp -R src/lib/publicsuffixlist $DES/lib/
|
|
||||||
cp -R src/lib/regexanalyzer $DES/lib/
|
cp -R src/lib/regexanalyzer $DES/lib/
|
||||||
|
cp -R src/lib/publicsuffixlist $DES/lib/
|
||||||
|
|
||||||
|
# Convert wasm modules into json arrays
|
||||||
|
mkdir -p $DES/js/wasm
|
||||||
|
cp src/js/wasm/* $DES/js/wasm/
|
||||||
|
node -pe "JSON.stringify(Array.from(fs.readFileSync('src/js/wasm/hntrie.wasm')))" \
|
||||||
|
> $DES/js/wasm/hntrie.wasm.json
|
||||||
|
node -pe "JSON.stringify(Array.from(fs.readFileSync('src/js/wasm/biditrie.wasm')))" \
|
||||||
|
> $DES/js/wasm/biditrie.wasm.json
|
||||||
|
node -pe "JSON.stringify(Array.from(fs.readFileSync('src/lib/publicsuffixlist/wasm/publicsuffixlist.wasm')))" \
|
||||||
|
> $DES/lib/publicsuffixlist/wasm/publicsuffixlist.wasm.json
|
||||||
|
|
||||||
git submodule update --depth 1 --init
|
git submodule update --depth 1 --init
|
||||||
UASSETS=submodules/uAssets
|
UASSETS=submodules/uAssets
|
||||||
|
|
Loading…
Reference in a new issue