Skip to content
This repository was archived by the owner on Jun 14, 2021. It is now read-only.

Commit 023cfb6

Browse files
committed
1 parent ecf7c23 commit 023cfb6

File tree

8 files changed

+120
-7024
lines changed

8 files changed

+120
-7024
lines changed

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
test/wasm/* linguist-vendored=true
1+
utils/* linguist-vendored=true

package-lock.json

Lines changed: 68 additions & 5919 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"types": "lib/node/src/WebAssemblr.d.ts",
77
"scripts": {
88
"start": "tsc && node ./lib/node/src/WebAssemblr.js",
9-
"build": "tsc && tsc -p tsconfig-web.json",
9+
"build": "tsc && tsc -p tsconfig-web.json && node ./utils/append-js.js",
1010
"build:bin": "tsc && npm i -g .",
1111
"test": "jest",
1212
"preversion": "npm test",
@@ -48,6 +48,7 @@
4848
"typescript": "^4.1.3"
4949
},
5050
"dependencies": {
51+
"filehound": "^1.17.4",
5152
"yargs": "^16.2.0"
5253
}
5354
}

src/WebAssemblr.ts

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,6 @@ type t_genericObj_object = { [key: string]: {} };
55

66
const WASM_CONFIG: t_genericObj_object = {
77
env: {
8-
DYNAMICTOP_PTR: 0,
9-
STACKTOP: 0,
10-
STACK_MAX: 0,
11-
abort: function () {},
12-
enlargeMemory: function () {},
13-
getTotalMemory: function () {},
14-
abortOnCannotGrowMemory: function () {},
15-
___lock: function () {},
16-
___syscall6: function () {},
17-
___setErrNo: function () {},
18-
___syscall140: function () {},
19-
_emscripten_memcpy_big: function () {},
20-
___syscall54: function () {},
21-
___unlock: function () {},
22-
___syscall146: function () {},
23-
emscripten_resize_heap: function () {},
24-
258
memory: new WebAssembly.Memory({ initial: 512 }),
269
},
2710
wasi_snapshot_preview1: {
@@ -32,16 +15,16 @@ const WASM_CONFIG: t_genericObj_object = {
3215
},
3316
};
3417

35-
export enum TYPES {
36-
int8_t = "HEAP8",
37-
uint8_t = "HEAPU8",
38-
int16_t = "HEAP16",
39-
uint16_t = "HEAPU16",
40-
int32_t = "HEAP32",
41-
uint32_t = "HEAPU32",
42-
float = "HEAPF32",
43-
double = "HEAPF64",
44-
}
18+
export const TYPES: Record<string, string> = {
19+
int8_t: "HEAP8",
20+
uint8_t: "HEAPU8",
21+
int16_t: "HEAP16",
22+
uint16_t: "HEAPU16",
23+
int32_t: "HEAP32",
24+
uint32_t: "HEAPU32",
25+
float: "HEAPF32",
26+
double: "HEAPF64",
27+
};
4528

4629
const HEAP: { [key: string]: any } = {
4730
[TYPES.int8_t]: Int8Array, // int8_t
@@ -94,9 +77,6 @@ export class WASMlr {
9477
typeof process.versions === "object" &&
9578
typeof process.versions.node === "string";
9679

97-
let fs: t_genericObj_functions;
98-
let path: t_genericObj_functions;
99-
10080
let wasmBytes: BufferSource;
10181

10282
if (ENV_NDOE) {

tsconfig-web.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"compilerOptions": {
66
"target": "ESNext",
77
"module": "ESNext",
8-
"outDir": "./lib/web/",
9-
"lib": [ "es2015", "dom" ],
8+
"outDir": "./lib/web/",
9+
10+
"lib": [ "es2015", "dom"],
11+
"moduleResolution": "Node"
1012
},
1113
}

tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"declaration": true, /* Generates corresponding '.d.ts' file. */
1212
"outDir": "./lib/node", /* Redirect output structure to the directory. */
1313

14-
1514
/* Strict Type-Checking Options */
1615
"strict": true, /* Enable all strict type-checking options. */
1716
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */

utils/append-js.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"use strict";
2+
3+
const FileHound = require("filehound");
4+
const fs = require("fs");
5+
const path = require("path");
6+
7+
const files = FileHound.create()
8+
.paths(path.resolve(__dirname, "../lib/web/"))
9+
.discard("node_modules")
10+
.ext("js")
11+
.find();
12+
13+
console.log("Appending .js...");
14+
files.then((filePaths) => {
15+
filePaths.forEach((filepath) => {
16+
fs.readFile(filepath, "utf8", (err, data) => {
17+
if (!data.match(/import .* from/g)) {
18+
return;
19+
}
20+
let newData = data.replace(
21+
/(import .* from\s+['"])(.*)(?=['"])/g,
22+
"$1$2.js"
23+
);
24+
if (err) throw err;
25+
26+
console.log(`writing to ${filepath}`);
27+
fs.writeFile(filepath, newData, function (err) {
28+
if (err) {
29+
throw err;
30+
}
31+
console.log("complete");
32+
});
33+
});
34+
});
35+
});

0 commit comments

Comments
 (0)