read_wasm.patch (1898B)
1 diff --git a/lib/read-wasm.js b/lib/read-wasm.js 2 index a4fb29c295516..75d7bd54153ad 100644 3 --- a/lib/read-wasm.js 4 +++ b/lib/read-wasm.js 5 @@ -1,22 +1,45 @@ 6 "use strict"; 7 8 +const isNode = 9 + typeof process !== "undefined" && 10 + process.versions != null && 11 + process.versions.node != null; 12 + 13 let mappingsWasm = null; 14 15 -module.exports = function readWasm() { 16 - if (typeof mappingsWasm === "string") { 17 - return fetch(mappingsWasm).then(response => response.arrayBuffer()); 18 - } 19 - if (mappingsWasm instanceof ArrayBuffer) { 20 - return Promise.resolve(mappingsWasm); 21 - } 22 +if (isNode) { 23 + const fs = require("fs"); 24 + const path = require("path"); 25 26 - throw new Error( 27 - "You must provide the string URL or ArrayBuffer contents " + 28 - "of lib/mappings.wasm by calling " + 29 - "SourceMapConsumer.initialize({ 'lib/mappings.wasm': ... }) " + 30 - "before using SourceMapConsumer" 31 - ); 32 -}; 33 + module.exports = function readWasm() { 34 + return new Promise((resolve, reject) => { 35 + const wasmPath = path.join(__dirname, "mappings.wasm"); 36 + fs.readFile(wasmPath, null, (error, data) => { 37 + if (error) { 38 + reject(error); 39 + return; 40 + } 41 + 42 + resolve(data.buffer); 43 + }); 44 + }); 45 + }; 46 +} else { 47 + module.exports = function readWasm() { 48 + if (typeof mappingsWasm === "string") { 49 + return fetch(mappingsWasm) 50 + .then(response => response.arrayBuffer()); 51 + } 52 + if (mappingsWasm instanceof ArrayBuffer) { 53 + return Promise.resolve(mappingsWasm); 54 + } 55 + 56 + throw new Error("You must provide the string URL or ArrayBuffer contents " + 57 + "of lib/mappings.wasm by calling " + 58 + "SourceMapConsumer.initialize({ 'lib/mappings.wasm': ... }) " + 59 + "before using SourceMapConsumer"); 60 + }; 61 +} 62 63 module.exports.initialize = input => { 64 mappingsWasm = input;