read-wasm.js (1194B)
1 "use strict"; 2 3 const isNode = 4 typeof process !== "undefined" && 5 process.versions != null && 6 process.versions.node != null; 7 8 let mappingsWasm = null; 9 10 if (isNode) { 11 const fs = require("fs"); 12 const path = require("path"); 13 14 module.exports = function readWasm() { 15 return new Promise((resolve, reject) => { 16 const wasmPath = path.join(__dirname, "mappings.wasm"); 17 fs.readFile(wasmPath, null, (error, data) => { 18 if (error) { 19 reject(error); 20 return; 21 } 22 23 resolve(data.buffer); 24 }); 25 }); 26 }; 27 } else { 28 module.exports = function readWasm() { 29 if (typeof mappingsWasm === "string") { 30 return fetch(mappingsWasm) 31 .then(response => response.arrayBuffer()); 32 } 33 if (mappingsWasm instanceof ArrayBuffer) { 34 return Promise.resolve(mappingsWasm); 35 } 36 37 throw new Error("You must provide the string URL or ArrayBuffer contents " + 38 "of lib/mappings.wasm by calling " + 39 "SourceMapConsumer.initialize({ 'lib/mappings.wasm': ... }) " + 40 "before using SourceMapConsumer"); 41 }; 42 } 43 44 module.exports.initialize = input => { 45 mappingsWasm = input; 46 };