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

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
FarazzShaikh committed Jan 4, 2021
1 parent ecf7c23 commit 023cfb6
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 7,024 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test/wasm/* linguist-vendored=true
utils/* linguist-vendored=true
5,987 changes: 68 additions & 5,919 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"types": "lib/node/src/WebAssemblr.d.ts",
"scripts": {
"start": "tsc && node ./lib/node/src/WebAssemblr.js",
"build": "tsc && tsc -p tsconfig-web.json",
"build": "tsc && tsc -p tsconfig-web.json && node ./utils/append-js.js",
"build:bin": "tsc && npm i -g .",
"test": "jest",
"preversion": "npm test",
Expand Down Expand Up @@ -48,6 +48,7 @@
"typescript": "^4.1.3"
},
"dependencies": {
"filehound": "^1.17.4",
"yargs": "^16.2.0"
}
}
40 changes: 10 additions & 30 deletions src/WebAssemblr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,6 @@ type t_genericObj_object = { [key: string]: {} };

const WASM_CONFIG: t_genericObj_object = {
env: {
DYNAMICTOP_PTR: 0,
STACKTOP: 0,
STACK_MAX: 0,
abort: function () {},
enlargeMemory: function () {},
getTotalMemory: function () {},
abortOnCannotGrowMemory: function () {},
___lock: function () {},
___syscall6: function () {},
___setErrNo: function () {},
___syscall140: function () {},
_emscripten_memcpy_big: function () {},
___syscall54: function () {},
___unlock: function () {},
___syscall146: function () {},
emscripten_resize_heap: function () {},

memory: new WebAssembly.Memory({ initial: 512 }),
},
wasi_snapshot_preview1: {
Expand All @@ -32,16 +15,16 @@ const WASM_CONFIG: t_genericObj_object = {
},
};

export enum TYPES {
int8_t = "HEAP8",
uint8_t = "HEAPU8",
int16_t = "HEAP16",
uint16_t = "HEAPU16",
int32_t = "HEAP32",
uint32_t = "HEAPU32",
float = "HEAPF32",
double = "HEAPF64",
}
export const TYPES: Record<string, string> = {
int8_t: "HEAP8",
uint8_t: "HEAPU8",
int16_t: "HEAP16",
uint16_t: "HEAPU16",
int32_t: "HEAP32",
uint32_t: "HEAPU32",
float: "HEAPF32",
double: "HEAPF64",
};

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

let fs: t_genericObj_functions;
let path: t_genericObj_functions;

let wasmBytes: BufferSource;

if (ENV_NDOE) {
Expand Down
6 changes: 4 additions & 2 deletions tsconfig-web.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"outDir": "./lib/web/",
"lib": [ "es2015", "dom" ],
"outDir": "./lib/web/",

"lib": [ "es2015", "dom"],
"moduleResolution": "Node"
},
}
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"declaration": true, /* Generates corresponding '.d.ts' file. */
"outDir": "./lib/node", /* Redirect output structure to the directory. */


/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
Expand Down
35 changes: 35 additions & 0 deletions utils/append-js.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"use strict";

const FileHound = require("filehound");
const fs = require("fs");
const path = require("path");

const files = FileHound.create()
.paths(path.resolve(__dirname, "../lib/web/"))
.discard("node_modules")
.ext("js")
.find();

console.log("Appending .js...");
files.then((filePaths) => {
filePaths.forEach((filepath) => {
fs.readFile(filepath, "utf8", (err, data) => {
if (!data.match(/import .* from/g)) {
return;
}
let newData = data.replace(
/(import .* from\s+['"])(.*)(?=['"])/g,
"$1$2.js"
);
if (err) throw err;

console.log(`writing to ${filepath}`);
fs.writeFile(filepath, newData, function (err) {
if (err) {
throw err;
}
console.log("complete");
});
});
});
});

0 comments on commit 023cfb6

Please sign in to comment.