|
1 | | -if (typeof fetch === "function") { |
2 | | - // Web version of reading a wasm file into an array buffer. |
| 1 | +// Node version of reading a wasm file into an array buffer. |
| 2 | +const fs = require("fs"); |
| 3 | +const path = require("path"); |
3 | 4 |
|
4 | | - let mappingsWasmUrl = null; |
| 5 | +module.exports = function readWasm() { |
| 6 | + return new Promise((resolve, reject) => { |
| 7 | + const wasmPath = path.join(__dirname, "mappings.wasm"); |
| 8 | + fs.readFile(wasmPath, null, (error, data) => { |
| 9 | + if (error) { |
| 10 | + reject(error); |
| 11 | + return; |
| 12 | + } |
5 | 13 |
|
6 | | - module.exports = function readWasm() { |
7 | | - if (typeof mappingsWasmUrl !== "string") { |
8 | | - throw new Error("You must provide the URL of lib/mappings.wasm by calling " + |
9 | | - "SourceMapConsumer.initialize({ 'lib/mappings.wasm': ... }) " + |
10 | | - "before using SourceMapConsumer"); |
11 | | - } |
12 | | - |
13 | | - return fetch(mappingsWasmUrl) |
14 | | - .then(response => response.arrayBuffer()); |
15 | | - }; |
16 | | - |
17 | | - module.exports.initialize = url => mappingsWasmUrl = url; |
18 | | -} else { |
19 | | - // Node version of reading a wasm file into an array buffer. |
20 | | - const fs = require("fs"); |
21 | | - const path = require("path"); |
22 | | - |
23 | | - module.exports = function readWasm() { |
24 | | - return new Promise((resolve, reject) => { |
25 | | - const wasmPath = path.join(__dirname, "mappings.wasm"); |
26 | | - fs.readFile(wasmPath, null, (error, data) => { |
27 | | - if (error) { |
28 | | - reject(error); |
29 | | - return; |
30 | | - } |
31 | | - |
32 | | - resolve(data.buffer); |
33 | | - }); |
| 14 | + resolve(data.buffer); |
34 | 15 | }); |
35 | | - }; |
| 16 | + }); |
| 17 | +}; |
36 | 18 |
|
37 | | - module.exports.initialize = _ => { |
38 | | - console.debug("SourceMapConsumer.initialize is a no-op when running in node.js"); |
39 | | - }; |
40 | | -} |
| 19 | +module.exports.initialize = _ => { |
| 20 | + console.debug("SourceMapConsumer.initialize is a no-op when running in node.js"); |
| 21 | +}; |
0 commit comments