@coherentglobal/wasm-runner 0.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +263 -0
- package/dist/browser/template/main.template.d.ts +1 -0
- package/dist/browser/template/main.template.js +13 -0
- package/dist/browser/template/main.template.js.map +1 -0
- package/dist/browser/template/runtime.template.d.ts +1 -0
- package/dist/browser/template/runtime.template.js +926 -0
- package/dist/browser/template/runtime.template.js.map +1 -0
- package/dist/browser/template/worker.template.d.ts +3 -0
- package/dist/browser/template/worker.template.js +39 -0
- package/dist/browser/template/worker.template.js.map +1 -0
- package/dist/browser/template.d.ts +1 -0
- package/dist/browser/template.js +14 -0
- package/dist/browser/template.js.map +1 -0
- package/dist/browser.d.ts +63 -0
- package/dist/browser.js +308 -0
- package/dist/browser.js.map +1 -0
- package/dist/error.d.ts +56 -0
- package/dist/error.js +112 -0
- package/dist/error.js.map +1 -0
- package/dist/node/template/main.template.ejs +70 -0
- package/dist/node.d.ts +66 -0
- package/dist/node.js +375 -0
- package/dist/node.js.map +1 -0
- package/dist/types.d.ts +32 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +15 -0
- package/dist/utils.js +122 -0
- package/dist/utils.js.map +1 -0
- package/package.json +79 -0
- package/tsconfig.json +22 -0
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const ENVIRONMENT_IS_WEB: boolean;
|
|
2
|
+
export declare const ENVIRONMENT_IS_NODE: boolean;
|
|
3
|
+
export declare function isPath(str: string): Promise<boolean>;
|
|
4
|
+
export declare function isHttpURL(str: string): boolean;
|
|
5
|
+
export declare function isBrowser(): false | (Window & typeof globalThis);
|
|
6
|
+
export declare function isWasmSupported(): boolean;
|
|
7
|
+
export declare function isWorkerSupported(): {
|
|
8
|
+
new (scriptURL: string | URL, options?: WorkerOptions): Worker;
|
|
9
|
+
prototype: Worker;
|
|
10
|
+
};
|
|
11
|
+
export declare function isCompatible(): void;
|
|
12
|
+
export declare function jsString2workerURL(str: string): string;
|
|
13
|
+
export declare function fn2workerURL(fn: any): string;
|
|
14
|
+
export declare const isEmpty: (obj: any) => boolean;
|
|
15
|
+
export declare function addScript(src: any): void;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.addScript = exports.isEmpty = exports.fn2workerURL = exports.jsString2workerURL = exports.isCompatible = exports.isWorkerSupported = exports.isWasmSupported = exports.isBrowser = exports.isHttpURL = exports.isPath = exports.ENVIRONMENT_IS_NODE = exports.ENVIRONMENT_IS_WEB = void 0;
|
|
16
|
+
const fs_1 = __importDefault(require("fs"));
|
|
17
|
+
const url_1 = __importDefault(require("url"));
|
|
18
|
+
const error_1 = __importDefault(require("./error"));
|
|
19
|
+
exports.ENVIRONMENT_IS_WEB = typeof window === "object";
|
|
20
|
+
exports.ENVIRONMENT_IS_NODE = typeof process === "object" &&
|
|
21
|
+
typeof process.versions === "object" &&
|
|
22
|
+
typeof process.versions.node === "string";
|
|
23
|
+
function isPath(str) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
try {
|
|
26
|
+
const stats = yield fs_1.default.promises.stat(str);
|
|
27
|
+
return stats.isFile();
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
exports.isPath = isPath;
|
|
35
|
+
function isHttpURL(str) {
|
|
36
|
+
let urlInstance;
|
|
37
|
+
try {
|
|
38
|
+
if (exports.ENVIRONMENT_IS_NODE) {
|
|
39
|
+
urlInstance = new url_1.default.URL(str);
|
|
40
|
+
}
|
|
41
|
+
if (exports.ENVIRONMENT_IS_WEB) {
|
|
42
|
+
urlInstance = new URL(str);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
return urlInstance.protocol === "http:" || urlInstance.protocol === "https:";
|
|
49
|
+
}
|
|
50
|
+
exports.isHttpURL = isHttpURL;
|
|
51
|
+
function isBrowser() {
|
|
52
|
+
try {
|
|
53
|
+
// eslint-disable-next-line no-undef
|
|
54
|
+
return window;
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.isBrowser = isBrowser;
|
|
61
|
+
function isWasmSupported() {
|
|
62
|
+
try {
|
|
63
|
+
if (typeof WebAssembly === "object" &&
|
|
64
|
+
// eslint-disable-next-line no-undef
|
|
65
|
+
typeof WebAssembly.instantiate === "function") {
|
|
66
|
+
// eslint-disable-next-line no-undef
|
|
67
|
+
const module = new WebAssembly.Module(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00));
|
|
68
|
+
// eslint-disable-next-line no-undef
|
|
69
|
+
if (module instanceof WebAssembly.Module)
|
|
70
|
+
// eslint-disable-next-line no-undef
|
|
71
|
+
return new WebAssembly.Instance(module) instanceof WebAssembly.Instance;
|
|
72
|
+
}
|
|
73
|
+
// eslint-disable-next-line no-empty
|
|
74
|
+
}
|
|
75
|
+
catch (e) { }
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
exports.isWasmSupported = isWasmSupported;
|
|
79
|
+
function isWorkerSupported() {
|
|
80
|
+
// eslint-disable-next-line no-undef
|
|
81
|
+
return window.Worker;
|
|
82
|
+
}
|
|
83
|
+
exports.isWorkerSupported = isWorkerSupported;
|
|
84
|
+
function isCompatible() {
|
|
85
|
+
if (!isBrowser()) {
|
|
86
|
+
throw new error_1.default.NotSupportedError("Javascript Browser Environment");
|
|
87
|
+
}
|
|
88
|
+
if (!isWasmSupported()) {
|
|
89
|
+
throw new error_1.default.NotSupportedError("WebAssembly");
|
|
90
|
+
}
|
|
91
|
+
if (!isWorkerSupported) {
|
|
92
|
+
throw new error_1.default.NotSupportedError("Web Worker");
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.isCompatible = isCompatible;
|
|
96
|
+
function jsString2workerURL(str) {
|
|
97
|
+
// eslint-disable-next-line no-undef
|
|
98
|
+
const blob = new Blob([str], { type: "text/javascript" });
|
|
99
|
+
return URL.createObjectURL(blob);
|
|
100
|
+
}
|
|
101
|
+
exports.jsString2workerURL = jsString2workerURL;
|
|
102
|
+
function fn2workerURL(fn) {
|
|
103
|
+
// eslint-disable-next-line no-undef
|
|
104
|
+
const blob = new Blob([`(${fn.toString()})()`], {
|
|
105
|
+
type: "text/javascript",
|
|
106
|
+
});
|
|
107
|
+
return URL.createObjectURL(blob);
|
|
108
|
+
}
|
|
109
|
+
exports.fn2workerURL = fn2workerURL;
|
|
110
|
+
const isEmpty = (obj) => [Object, Array].includes((obj || {}).constructor) &&
|
|
111
|
+
!Object.entries(obj || {}).length;
|
|
112
|
+
exports.isEmpty = isEmpty;
|
|
113
|
+
function addScript(src) {
|
|
114
|
+
// eslint-disable-next-line no-undef
|
|
115
|
+
const s = document.createElement("script");
|
|
116
|
+
s.setAttribute("src", src);
|
|
117
|
+
s.setAttribute("async", "true");
|
|
118
|
+
// eslint-disable-next-line no-undef
|
|
119
|
+
document.body.appendChild(s);
|
|
120
|
+
}
|
|
121
|
+
exports.addScript = addScript;
|
|
122
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,8CAAsB;AACtB,oDAAuC;AAE1B,QAAA,kBAAkB,GAAG,OAAO,MAAM,KAAK,QAAQ,CAAC;AAChD,QAAA,mBAAmB,GAC9B,OAAO,OAAO,KAAK,QAAQ;IAC3B,OAAO,OAAO,CAAC,QAAQ,KAAK,QAAQ;IACpC,OAAO,OAAO,CAAC,QAAQ,CAAC,IAAI,KAAK,QAAQ,CAAC;AAE5C,SAAsB,MAAM,CAAC,GAAW;;QACtC,IAAI;YACF,MAAM,KAAK,GAAG,MAAM,YAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC1C,OAAO,KAAK,CAAC,MAAM,EAAE,CAAC;SACvB;QAAC,OAAO,GAAG,EAAE;YACZ,OAAO,KAAK,CAAC;SACd;IACH,CAAC;CAAA;AAPD,wBAOC;AAED,SAAgB,SAAS,CAAC,GAAW;IACnC,IAAI,WAAW,CAAC;IAEhB,IAAI;QACF,IAAI,2BAAmB,EAAE;YACvB,WAAW,GAAG,IAAI,aAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;SAChC;QACD,IAAI,0BAAkB,EAAE;YACtB,WAAW,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;SAC5B;KACF;IAAC,OAAO,GAAG,EAAE;QACZ,OAAO,KAAK,CAAC;KACd;IAED,OAAO,WAAW,CAAC,QAAQ,KAAK,OAAO,IAAI,WAAW,CAAC,QAAQ,KAAK,QAAQ,CAAC;AAC/E,CA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M runner for Javascript and Node.js",
|
|
5
|
+
"main": "dist/node.js",
|
|
6
|
+
"browser": "dist/browser.js",
|
|
7
|
+
"repository": "git@github.com:CoherentCapital/wasm-runner-js.git",
|
|
8
|
+
"author": "Coherent Global",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"lint": "eslint ./src --fix",
|
|
12
|
+
"format": "prettier --write .",
|
|
13
|
+
"build:ts": "tsc --declaration && cp -R ./src/node ./dist",
|
|
14
|
+
"build:template": "node tools/create-template.js",
|
|
15
|
+
"build": "yarn compress && yarn build:template && yarn build:ts",
|
|
16
|
+
"bundle": "yarn compress && yarn build:template && yarn bundle:full && yarn bundle:min",
|
|
17
|
+
"compress:runtime": "terser --compress --mangle --comments false src/browser/template/runtime.template.js > src/browser/template/runtime.template.min.js",
|
|
18
|
+
"compress:worker": "terser --compress --mangle --comments false src/browser/template/worker.template.js > src/browser/template/worker.template.min.js",
|
|
19
|
+
"compress": "yarn compress:runtime && yarn compress:worker",
|
|
20
|
+
"bundle:full": "browserify src/browser.ts --standalone CoherentGlobal -p [ tsify ] > lib/wasmrunner.js",
|
|
21
|
+
"bundle:min": "browserify src/browser.ts --standalone CoherentGlobal -p [ tsify ] | terser --compress --mangle --comments false > lib/wasmrunner.min.js",
|
|
22
|
+
"prep:samples:simple-html": "yarn bundle && cp ./lib/wasmrunner.js example/simple-html/ && cp ./lib/wasmrunner.min.js example/simple-html/"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@babel/cli": "^7.15.7",
|
|
26
|
+
"@babel/core": "^7.15.5",
|
|
27
|
+
"@babel/plugin-transform-runtime": "^7.16.0",
|
|
28
|
+
"@babel/preset-env": "^7.15.6",
|
|
29
|
+
"babel-eslint": "^10.1.0",
|
|
30
|
+
"babelify": "^10.0.0",
|
|
31
|
+
"browserify": "^17.0.0",
|
|
32
|
+
"eslint": "^8.2.0",
|
|
33
|
+
"eslint-config-airbnb": "19.0.1",
|
|
34
|
+
"eslint-config-node": "^4.1.0",
|
|
35
|
+
"eslint-config-prettier": "^8.3.0",
|
|
36
|
+
"eslint-plugin-import": "^2.25.3",
|
|
37
|
+
"eslint-plugin-jsx-a11y": "^6.5.1",
|
|
38
|
+
"eslint-plugin-node": "^11.1.0",
|
|
39
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
40
|
+
"eslint-plugin-react": "^7.27.1",
|
|
41
|
+
"eslint-plugin-react-hooks": "^4.3.0",
|
|
42
|
+
"jest": "^27.3.1",
|
|
43
|
+
"prettier": "^2.5.0",
|
|
44
|
+
"replace": "^1.2.1",
|
|
45
|
+
"terser": "^5.9.0",
|
|
46
|
+
"typescript": "^4.5.4"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@babel/runtime": "^7.16.0",
|
|
50
|
+
"cuid": "^2.1.8",
|
|
51
|
+
"ejs": "^3.1.6",
|
|
52
|
+
"got": "^11.8.3",
|
|
53
|
+
"jszip": "^3.7.1",
|
|
54
|
+
"node-worker-threads-pool": "^1.5.1",
|
|
55
|
+
"tmp": "^0.2.1",
|
|
56
|
+
"tsify": "^5.0.4",
|
|
57
|
+
"unzipper": "^0.10.11"
|
|
58
|
+
},
|
|
59
|
+
"browserify": {
|
|
60
|
+
"transform": [
|
|
61
|
+
[
|
|
62
|
+
"babelify",
|
|
63
|
+
{
|
|
64
|
+
"presets": [
|
|
65
|
+
"@babel/preset-env"
|
|
66
|
+
],
|
|
67
|
+
"plugins": [
|
|
68
|
+
[
|
|
69
|
+
"@babel/plugin-transform-runtime",
|
|
70
|
+
{
|
|
71
|
+
"regenerator": true
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"target": "es6",
|
|
5
|
+
"esModuleInterop": true,
|
|
6
|
+
"allowSyntheticDefaultImports": true,
|
|
7
|
+
"noImplicitAny": false,
|
|
8
|
+
"moduleResolution": "node",
|
|
9
|
+
"sourceMap": true,
|
|
10
|
+
"outDir": "dist",
|
|
11
|
+
"allowJs": true,
|
|
12
|
+
"baseUrl": ".",
|
|
13
|
+
"paths": {
|
|
14
|
+
"*": [
|
|
15
|
+
"node_modules/*"
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"include": [
|
|
20
|
+
"src"
|
|
21
|
+
]
|
|
22
|
+
}
|