mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-22 18:32:45 +01:00
Simplify loading of WASM modules in nodejs
This commit is contained in:
parent
5be4d5d877
commit
d5da88ea87
@ -82,33 +82,18 @@ function applyList(name, raw) {
|
||||
|
||||
async function enableWASM() {
|
||||
const wasmModuleFetcher = function(path) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const require = createRequire(import.meta.url); // jshint ignore:line
|
||||
const fs = require('fs');
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
const require = createRequire(import.meta.url); // jshint ignore:line
|
||||
const wasm = new Uint8Array(require(`${path}.wasm.json`));
|
||||
return globals.WebAssembly.compile(wasm);
|
||||
};
|
||||
try {
|
||||
const results = await Promise.all([
|
||||
globals.publicSuffixList.enableWASM(
|
||||
wasmModuleFetcher,
|
||||
'./lib/publicsuffixlist/wasm/'
|
||||
),
|
||||
snfe.enableWASM(
|
||||
wasmModuleFetcher,
|
||||
'./js/wasm/'
|
||||
),
|
||||
globals.publicSuffixList.enableWASM(wasmModuleFetcher, './lib/publicsuffixlist/wasm/'),
|
||||
snfe.enableWASM(wasmModuleFetcher, './js/wasm/'),
|
||||
]);
|
||||
return results.every(a => a === true);
|
||||
} catch(reason) {
|
||||
console.info(reason);
|
||||
console.log(reason);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -123,7 +108,6 @@ function pslInit(raw) {
|
||||
}
|
||||
}
|
||||
globals.publicSuffixList.parse(raw, globals.punycode.toASCII);
|
||||
return globals.publicSuffixList;
|
||||
}
|
||||
|
||||
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/uri-utils.js $DES/js
|
||||
|
||||
mkdir -p $DES/js/wasm
|
||||
cp src/js/wasm/* $DES/js/wasm/
|
||||
|
||||
mkdir -p $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/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
|
||||
UASSETS=submodules/uAssets
|
||||
|
Loading…
Reference in New Issue
Block a user