forked from foxglove/wasm-zstd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre.js
More file actions
32 lines (28 loc) · 1.01 KB
/
pre.js
File metadata and controls
32 lines (28 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// this file is injected into the wasm-zstd.js compiled file _before_ most of the module definition
// which gives us the opportunity to override the module resolution behavior in node
var nodePath;
if (typeof process !== "undefined") {
Module["ENVIRONMENT"] = process.env.WASM_ZSTD_ENVIRONMENT;
}
// do some manipulating of the input file path
// when running in node so the file is resolved
// relative to the module root. by default its resolved to `wasm-zstd.wasm`
// which is relative to process.cwd which is not correct
Module.locateFile = function(input) {
if (ENVIRONMENT_IS_NODE) {
// don't let emscripten js resolve the file to a relative path
nodePath = {
normalize: function(any) {
return any;
}
};
// return the full resolved path to the input file
return __dirname + "/" + input;
}
if (input.endsWith(".wasm")) {
// Dynamically required if running in a web context.
const wasm_path = require("./wasm-zstd.wasm");
return wasm_path;
}
return input;
};