Skip to content

Commit 5632cad

Browse files
authored
Merge pull request #4 from cspotcode/ab/drop-browser-support
drop browser support to slim down the npm package
2 parents faefe97 + c610a3e commit 5632cad

File tree

2 files changed

+18
-38
lines changed

2 files changed

+18
-38
lines changed

lib/read-wasm.js

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,21 @@
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");
34

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+
}
513

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);
3415
});
35-
};
16+
});
17+
};
3618

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+
};

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@
5252
"files": [
5353
"/source-map.js",
5454
"/source-map.d.ts",
55-
"/lib/",
56-
"/dist/source-map.js"
55+
"/lib/"
5756
],
5857
"engines": {
5958
"node": ">= 12"

0 commit comments

Comments
 (0)