├── .github └── workflows │ └── build.yml ├── .gitignore ├── .vscode ├── launch.json └── settings.json ├── LICENSE.txt ├── README.md ├── etc ├── .eslintrc.json ├── .mocharc.json ├── .prettierrc.json ├── webpack.config.js └── webpack.config.test.js ├── package.json ├── src ├── callbacks.ts ├── debug.ts ├── errors.ts ├── index.ts ├── protocol.ts └── wapc-host.ts ├── test ├── browser │ ├── index.html │ ├── run.ts │ └── test.browser.ts ├── fixtures │ ├── rust_echo_string.wasm │ └── rust_host_call.wasm └── index.test.ts └── tsconfig.json /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | - release-* 8 | tags: 9 | - v* 10 | pull_request: 11 | branches: 12 | - main 13 | - release-* 14 | 15 | jobs: 16 | build: 17 | runs-on: ubuntu-latest 18 | steps: 19 | - uses: actions/checkout@v1 20 | - uses: actions/setup-node@v1 21 | with: 22 | node-version: 12 23 | registry-url: https://registry.npmjs.org/ 24 | - run: npm install 25 | - run: npm run test 26 | - run: npm run lint 27 | - run: npm run build 28 | 29 | - name: Is Release? 30 | if: startswith(github.ref, 'refs/tags/v') 31 | run: echo "DEPLOY_PACKAGE=true" >> $GITHUB_ENV 32 | 33 | - name: Publish to npm 34 | if: env.DEPLOY_PACKAGE == 'true' 35 | run: npm pack && npm publish --access public 36 | env: 37 | NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} 38 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .cache 3 | package-lock.json 4 | /dist -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Debug Mocha Tests", 9 | "type": "node", 10 | "request": "attach", 11 | "port": 9229, 12 | "protocol": "inspector", 13 | "skipFiles": ["/**"], 14 | "timeout": 5000, 15 | "stopOnEntry": false 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "mochaExplorer.files": "test/**/*.test.ts", 3 | "mochaExplorer.require": "ts-node/register", 4 | "mochaExplorer.debuggerConfig": "Debug Mocha Tests", 5 | "debug.javascript.usePreview": false, 6 | "eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"], 7 | "editor.formatOnSave": true 8 | } 9 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # waPC JavaScript Host (Node + Browser) 2 | 3 | This is the JavaScript implementation of the **waPC** standard for WebAssembly host runtimes. It allows any WebAssembly module to be loaded as a guest and receive requests for invocation as well as to make its own function requests of the host. 4 | 5 | This package defines the protocol for RPC exchange between guest (WebAssembly) modules and the host runtime. 6 | 7 | ## Who is this for? 8 | 9 | Library developers who want to load waPC-compliant WebAssembly binaries in nodejs or browser environments. The waPC protocol allows a host to execute arbitrary wasm functions without knowing the exported bindings beforehand. 10 | 11 | While waPC does not prescribe a serialization/deserialization format, MessagePack is common recommended unless you need otherwise. 12 | 13 | ## Installation 14 | 15 | ```sh 16 | $ npm install @wapc/host 17 | ``` 18 | 19 | ## Usage 20 | 21 | **Node** 22 | 23 | ```js 24 | const { instantiate } = require('@wapc/host'); 25 | const { encode, decode } = require('@msgpack/msgpack'); 26 | const { promises: fs } = require('fs'); 27 | const path = require('path'); 28 | 29 | async function main() { 30 | // Read wasm off the local disk as Uint8Array 31 | buffer = await fs.readFile(path.join(__dirname, 'fixtures', 'rust_echo_string.wasm')); 32 | 33 | // Instantiate a WapcHost with the bytes read off disk 34 | const host = await instantiate(buffer); 35 | 36 | // Encode the payload with MessagePack 37 | const payload = encode({ msg: 'hello world' }); 38 | 39 | // Invoke the operation in the wasm guest 40 | const result = await host.invoke('echo', payload); 41 | 42 | // Decode the results using MessagePack 43 | const decoded = decode(result); 44 | 45 | // log to the console 46 | console.log(`Result: ${decoded}`); 47 | } 48 | 49 | main().catch(err => console.error(err)); 50 | ``` 51 | 52 | **Browser** 53 | 54 | Browser environments can instantiate from a FetchResponse with `waPC.instantiateStreaming()`. If the browser does not support streaming wasm then waPC gracefully degrades and waits for the response to complete before instantiating. 55 | 56 | ```html 57 | 58 | 59 | 77 | ``` 78 | 79 | ## Contributing 80 | 81 | ### Running tests 82 | 83 | **Node unit tests** 84 | 85 | ```sh 86 | $ npm run test:unit 87 | ``` 88 | 89 | **Browser unit tests** 90 | 91 | ```sh 92 | $ npm run test:browser 93 | ``` 94 | 95 | ### Building 96 | 97 | ```sh 98 | $ npm run build 99 | ``` 100 | -------------------------------------------------------------------------------- /etc/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/eslintrc", 3 | "root": true, 4 | "parser": "@typescript-eslint/parser", 5 | "plugins": ["@typescript-eslint"], 6 | "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"] 7 | } 8 | -------------------------------------------------------------------------------- /etc/.mocharc.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/mocharc", 3 | "extension": ["ts"], 4 | "spec": "test/**/*.test.ts", 5 | "require": "ts-node/register" 6 | } 7 | -------------------------------------------------------------------------------- /etc/.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/prettierrc", 3 | "trailingComma": "all", 4 | "tabWidth": 2, 5 | "semi": true, 6 | "singleQuote": true, 7 | "printWidth": 120, 8 | "bracketSpacing": true, 9 | "arrowParens": "avoid" 10 | } 11 | -------------------------------------------------------------------------------- /etc/webpack.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | const path = require('path'); 3 | 4 | module.exports = { 5 | stats: { assets: false, modules: false }, 6 | mode: 'production', 7 | entry: './src/index.ts', 8 | module: { 9 | rules: [ 10 | { 11 | test: /\.tsx?$/, 12 | use: 'ts-loader', 13 | exclude: /node_modules/, 14 | }, 15 | ], 16 | }, 17 | resolve: { 18 | extensions: ['.tsx', '.ts', '.js'], 19 | }, 20 | output: { 21 | filename: 'index.bundle.js', 22 | path: path.resolve(__dirname, '..', 'dist'), 23 | library: 'waPC', 24 | }, 25 | }; 26 | -------------------------------------------------------------------------------- /etc/webpack.config.test.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | 3 | const path = require('path'); 4 | 5 | module.exports = { 6 | stats: { assets: false, modules:false }, 7 | mode: 'production', 8 | entry: './test/browser/test.browser.ts', 9 | module: { 10 | rules: [ 11 | { 12 | test: /\.tsx?$/, 13 | use: 'ts-loader', 14 | exclude: /node_modules/, 15 | }, 16 | ], 17 | }, 18 | resolve: { 19 | extensions: ['.tsx', '.ts', '.js'], 20 | }, 21 | output: { 22 | filename: 'test.bundle.js', 23 | path: path.resolve(__dirname, '..', 'dist'), 24 | }, 25 | }; 26 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@wapc/host", 3 | "description": "waPC host for node.js and the browser", 4 | "author": "jsoverson", 5 | "version": "0.0.3", 6 | "main": "dist/src/index.js", 7 | "types": "dist/src/index.d.ts", 8 | "files": [ 9 | "dist", 10 | "README.md", 11 | "test", 12 | "src" 13 | ], 14 | "scripts": { 15 | "build": "npm run build:cjs && npm run build:browser", 16 | "build:cjs": "tsc --declaration", 17 | "build:browser": "webpack-cli --config etc/webpack.config.js", 18 | "build:tests": "webpack-cli --config etc/webpack.config.test.js", 19 | "compile": "npm run clean && npm run build", 20 | "clean": "rimraf dist", 21 | "lint": "eslint src test", 22 | "prepublishOnly": "npm run compile", 23 | "format": "prettier --write 'src/**/*.ts' 'test/**/*.ts'", 24 | "watch": "npm run clean && tsc -w --declaration", 25 | "test:unit": "mocha", 26 | "test:browser": "npm run build:browser && npm run build:tests && ts-node test/browser/run.ts", 27 | "test": "npm run lint && npm run test:unit && npm run test:browser" 28 | }, 29 | "mocha": { 30 | "extends": "etc/.mocharc.json" 31 | }, 32 | "prettier": "./etc/.prettierrc.json", 33 | "eslintConfig": { 34 | "extends": "./etc/.eslintrc.json" 35 | }, 36 | "keywords": [], 37 | "license": "ISC", 38 | "devDependencies": { 39 | "@jsoverson/test-server": "^1.3.3", 40 | "@msgpack/msgpack": "^2.5.1", 41 | "@types/chai": "^4.2.16", 42 | "@types/chai-as-promised": "^7.1.3", 43 | "@types/debug": "^4.1.5", 44 | "@types/estree": "0.0.47", 45 | "@types/find-root": "^1.1.2", 46 | "@types/mocha": "^8.2.2", 47 | "@types/node": "^14.14.41", 48 | "@typescript-eslint/eslint-plugin": "^4.22.0", 49 | "@typescript-eslint/parser": "^4.22.0", 50 | "chai": "^4.3.4", 51 | "chai-as-promised": "^7.1.1", 52 | "eslint": "^7.24.0", 53 | "find-root": "^1.1.0", 54 | "mocha": "^8.3.2", 55 | "prettier": "^2.2.1", 56 | "puppeteer": "^8.0.0", 57 | "rimraf": "^3.0.2", 58 | "ts-loader": "^9.0.0", 59 | "ts-node": "^9.1.1", 60 | "typescript": "^4.2.4", 61 | "webpack": "^5.33.2", 62 | "webpack-cli": "^4.6.0" 63 | }, 64 | "dependencies": { 65 | "debug": "^4.3.1" 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/callbacks.ts: -------------------------------------------------------------------------------- 1 | import { debug } from './debug'; 2 | import { WapcProtocol } from './protocol'; 3 | import { WapcHost } from './wapc-host'; 4 | 5 | export function generateWapcImports(instance: WapcHost): WapcProtocol & WebAssembly.ModuleImports { 6 | return { 7 | __console_log(ptr: number, len: number) { 8 | debug(() => ['__console_log %o bytes @ %o', len, ptr]); 9 | const buffer = new Uint8Array(instance.getCallerMemory().buffer); 10 | const bytes = buffer.slice(ptr, ptr + len); 11 | console.log(instance.textDecoder.decode(bytes)); 12 | }, 13 | 14 | __host_call( 15 | bd_ptr: number, 16 | bd_len: number, 17 | ns_ptr: number, 18 | ns_len: number, 19 | op_ptr: number, 20 | op_len: number, 21 | ptr: number, 22 | len: number, 23 | ): number { 24 | debug(() => ['__host_call']); 25 | const mem = instance.getCallerMemory(); 26 | const buffer = new Uint8Array(mem.buffer); 27 | const binding = instance.textDecoder.decode(buffer.slice(bd_ptr, bd_ptr + bd_len)); 28 | const namespace = instance.textDecoder.decode(buffer.slice(ns_ptr, ns_ptr + ns_len)); 29 | const operation = instance.textDecoder.decode(buffer.slice(op_ptr, op_ptr + op_len)); 30 | const bytes = buffer.slice(ptr, ptr + len); 31 | debug(() => ['host_call(%o,%o,%o,[%o bytes])', binding, namespace, operation, bytes.length]); 32 | instance.state.hostError = undefined; 33 | instance.state.hostResponse = undefined; 34 | try { 35 | const result = instance.state.hostCallback(binding, namespace, operation, bytes); 36 | instance.state.hostResponse = result; 37 | return 1; 38 | } catch (e) { 39 | instance.state.hostError = '' + e; 40 | return 0; 41 | } 42 | }, 43 | 44 | __host_response(ptr: number) { 45 | debug(() => ['__host_response ptr: %o', ptr]); 46 | if (instance.state.hostResponse) { 47 | const buffer = new Uint8Array(instance.getCallerMemory().buffer); 48 | buffer.set(instance.state.hostResponse, ptr); 49 | } 50 | }, 51 | 52 | __host_response_len(): number { 53 | const len = instance.state.hostResponse?.length || 0; 54 | debug(() => ['__host_response_len %o', len]); 55 | return len; 56 | }, 57 | 58 | __host_error_len(): number { 59 | const len = instance.state.hostError?.length || 0; 60 | debug(() => ['__host_error_len ptr: %o', len]); 61 | return len; 62 | }, 63 | 64 | __host_error(ptr: number) { 65 | debug(() => ['__host_error %o', ptr]); 66 | if (instance.state.hostError) { 67 | debug(() => ['__host_error writing to mem: %o', instance.state.hostError]); 68 | const buffer = new Uint8Array(instance.getCallerMemory().buffer); 69 | buffer.set(instance.textEncoder.encode(instance.state.hostError), ptr); 70 | } 71 | }, 72 | 73 | __guest_response(ptr: number, len: number) { 74 | debug(() => ['__guest_response %o bytes @ %o', len, ptr]); 75 | instance.state.guestError = undefined; 76 | const buffer = new Uint8Array(instance.getCallerMemory().buffer); 77 | const bytes = buffer.slice(ptr, ptr + len); 78 | instance.state.guestResponse = bytes; 79 | }, 80 | 81 | __guest_error(ptr: number, len: number) { 82 | debug(() => ['__guest_error %o bytes @ %o', len, ptr]); 83 | const buffer = new Uint8Array(instance.getCallerMemory().buffer); 84 | const bytes = buffer.slice(ptr, ptr + len); 85 | const message = instance.textDecoder.decode(bytes); 86 | instance.state.guestError = message; 87 | }, 88 | 89 | __guest_request(op_ptr: number, ptr: number) { 90 | debug(() => ['__guest_request op: %o, ptr: %o', op_ptr, ptr]); 91 | const invocation = instance.state.guestRequest; 92 | if (invocation) { 93 | const memory = instance.getCallerMemory(); 94 | debug(() => ['writing invocation (%o,[%o bytes])', invocation.operation, invocation.msg.length]); 95 | const buffer = new Uint8Array(memory.buffer); 96 | buffer.set(invocation.operationEncoded, op_ptr); 97 | buffer.set(invocation.msg, ptr); 98 | } else { 99 | throw new Error( 100 | '__guest_request called without an invocation present. This is probably a bug in the library using @wapc/host.', 101 | ); 102 | } 103 | }, 104 | }; 105 | } 106 | 107 | export function generateWASIImports(instance: WapcHost): WebAssembly.ModuleImports { 108 | return { 109 | fd_write(fileDescriptor: number, iovsPtr: number, iovsLen: number, writtenPtr: number): number { 110 | // Only writing to standard out (1) is supported 111 | if (fileDescriptor != 1) { 112 | return 0; 113 | } 114 | 115 | const memory = instance.getCallerMemory(); 116 | const dv = new DataView(memory.buffer); 117 | const heap = new Uint8Array(memory.buffer); 118 | let bytesWritten = 0; 119 | 120 | while (iovsLen > 0) { 121 | iovsLen--; 122 | const base = dv.getUint32(iovsPtr, true); 123 | iovsPtr += 4; 124 | const length = dv.getUint32(iovsPtr, true); 125 | iovsPtr += 4; 126 | const stringBytes = heap.slice(base, base + length); 127 | instance.state.writer(instance.textDecoder.decode(stringBytes)); 128 | bytesWritten += length; 129 | } 130 | 131 | dv.setUint32(writtenPtr, bytesWritten, true); 132 | 133 | return bytesWritten; 134 | }, 135 | 136 | args_sizes_get(argc: number, argvBufSize: number): number { 137 | const memory = instance.getCallerMemory(); 138 | const dv = new DataView(memory.buffer); 139 | 140 | dv.setUint32(argc, 0); 141 | dv.setUint32(argvBufSize, 0); 142 | 143 | return 0; 144 | }, 145 | 146 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 147 | args_get(argv: number, argvBuf: number): number { 148 | return 0; 149 | }, 150 | }; 151 | } 152 | -------------------------------------------------------------------------------- /src/debug.ts: -------------------------------------------------------------------------------- 1 | import DEBUG from 'debug'; 2 | const _debug = DEBUG('wapc'); 3 | 4 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 5 | export function debug(cb: () => [string, ...any]): void { 6 | if (_debug.enabled) { 7 | const params = cb(); 8 | _debug(...params); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/errors.ts: -------------------------------------------------------------------------------- 1 | class TestableError extends Error { 2 | matcher() { 3 | return new RegExp(this.toString().replace(/^Error: /, '')); 4 | } 5 | } 6 | 7 | export class HostCallNotImplementedError extends TestableError { 8 | constructor(binding: string, namespace: string, operation: string) { 9 | super( 10 | `Host call not implemented. Guest called host with binding = '${binding}', namespace = '${namespace}', & operation = '${operation}'`, 11 | ); 12 | } 13 | } 14 | 15 | export class InvalidWasm extends TestableError { 16 | constructor(error: Error) { 17 | super(`Invalid wasm binary: ${error.message}`); 18 | } 19 | } 20 | 21 | export class StreamingFailure extends TestableError { 22 | constructor(error: Error) { 23 | super(`Could not instantiate from Response object: ${error.message}`); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export { instantiate, instantiateStreaming, WapcHost } from './wapc-host'; 2 | export * as errors from './errors'; 3 | 4 | -------------------------------------------------------------------------------- /src/protocol.ts: -------------------------------------------------------------------------------- 1 | export interface WapcProtocol { 2 | __console_log(ptr: number, len: number): void; 3 | __host_call( 4 | bd_ptr: number, 5 | bd_len: number, 6 | ns_ptr: number, 7 | ns_len: number, 8 | op_ptr: number, 9 | op_len: number, 10 | ptr: number, 11 | len: number, 12 | ): number; 13 | __host_response(ptr: number): void; 14 | __host_response_len(): number; 15 | __host_error_len(): number; 16 | __host_error(ptr: number): void; 17 | __guest_response(ptr: number, len: number): void; 18 | __guest_error(ptr: number, len: number): void; 19 | __guest_request(op_ptr: number, ptr: number): void; 20 | } 21 | -------------------------------------------------------------------------------- /src/wapc-host.ts: -------------------------------------------------------------------------------- 1 | import { debug } from './debug'; 2 | import { errors } from '.'; 3 | import { generateWapcImports, generateWASIImports } from './callbacks'; 4 | import { HostCallNotImplementedError } from './errors'; 5 | 6 | type HostCall = (binding: string, namespace: string, operation: string, payload: Uint8Array) => Uint8Array; 7 | type Writer = (message: string) => void; 8 | 9 | interface Invocation { 10 | operation: string; 11 | operationEncoded: Uint8Array; 12 | msg: Uint8Array; 13 | } 14 | 15 | const START = '_start'; // Linux/TinyGo initialization 16 | const WAPC_INIT = 'wapc_init'; 17 | const GUEST_CALL = '__guest_call'; 18 | 19 | class ModuleState { 20 | guestRequest?: Invocation; 21 | guestResponse?: Uint8Array; 22 | hostResponse?: Uint8Array; 23 | guestError?: string; 24 | hostError?: string; 25 | hostCallback: HostCall; 26 | writer: Writer; 27 | 28 | constructor(hostCall?: HostCall, writer?: Writer) { 29 | this.hostCallback = 30 | hostCall || 31 | ((binding, namespace, operation) => { 32 | throw new HostCallNotImplementedError(binding, namespace, operation); 33 | }); 34 | this.writer = writer || (() => undefined); 35 | } 36 | } 37 | 38 | export class WapcHost { 39 | buffer!: Uint8Array; 40 | instance!: WebAssembly.Instance; 41 | state: ModuleState; 42 | guestCall: CallableFunction; 43 | textEncoder: TextEncoder; 44 | textDecoder: TextDecoder; 45 | 46 | constructor(hostCall?: HostCall, writer?: Writer) { 47 | this.state = new ModuleState(hostCall, writer); 48 | this.textEncoder = new TextEncoder(); 49 | this.textDecoder = new TextDecoder('utf-8'); 50 | this.guestCall = () => undefined; 51 | } 52 | 53 | async instantiate(source: Uint8Array): Promise { 54 | const imports = this.getImports(); 55 | const result = await WebAssembly.instantiate(source, imports).catch(e => { 56 | throw new errors.InvalidWasm(e); 57 | }); 58 | this.initialize(result.instance); 59 | 60 | return this; 61 | } 62 | 63 | async instantiateStreaming(source: Response): Promise { 64 | const imports = this.getImports(); 65 | if (!WebAssembly.instantiateStreaming) { 66 | debug(() => [ 67 | 'WebAssembly.instantiateStreaming is not supported on this browser, wasm execution will be impacted.', 68 | ]); 69 | const bytes = new Uint8Array(await (await source).arrayBuffer()); 70 | return this.instantiate(bytes); 71 | } else { 72 | const result = await WebAssembly.instantiateStreaming(source, imports).catch(e => { 73 | throw new errors.StreamingFailure(e); 74 | }); 75 | this.initialize(result.instance); 76 | return this; 77 | } 78 | } 79 | 80 | getImports(): WebAssembly.Imports { 81 | const wasiImports = generateWASIImports(this); 82 | return { 83 | wapc: generateWapcImports(this), 84 | wasi: wasiImports, 85 | wasi_unstable: wasiImports, 86 | wasi_snapshot_preview1: wasiImports, 87 | }; 88 | } 89 | 90 | initialize(instance: WebAssembly.Instance): void { 91 | this.instance = instance; 92 | const start = this.instance.exports[START] as CallableFunction; 93 | if (start != null) { 94 | start([]); 95 | } 96 | const init = this.instance.exports[WAPC_INIT] as CallableFunction; 97 | if (init != null) { 98 | init([]); 99 | } 100 | this.guestCall = this.instance.exports[GUEST_CALL] as CallableFunction; 101 | if (this.guestCall == null) { 102 | throw new Error('WebAssembly module does not export __guest_call'); 103 | } 104 | } 105 | 106 | async invoke(operation: string, payload: Uint8Array): Promise { 107 | debug(() => [`invoke(%o, [%o bytes]`, operation, payload.length]); 108 | const operationEncoded = this.textEncoder.encode(operation); 109 | this.state.guestRequest = { operation, operationEncoded, msg: payload }; 110 | const result = this.guestCall(operationEncoded.length, payload.length); 111 | 112 | if (result === 0) { 113 | throw new Error(this.state.guestError); 114 | } else { 115 | if (!this.state.guestResponse) { 116 | throw new Error('Guest call succeeded, but guest response not set. This is a bug in @wapc/host'); 117 | } else { 118 | return this.state.guestResponse; 119 | } 120 | } 121 | } 122 | 123 | getCallerMemory(): WebAssembly.Memory { 124 | return this.instance.exports.memory as WebAssembly.Memory; 125 | } 126 | } 127 | 128 | export async function instantiate(source: Uint8Array, hostCall?: HostCall, writer?: Writer): Promise { 129 | const host = new WapcHost(hostCall, writer); 130 | return host.instantiate(source); 131 | } 132 | 133 | export async function instantiateStreaming( 134 | source: Response | Promise, 135 | hostCall?: HostCall, 136 | writer?: Writer, 137 | ): Promise { 138 | const host = new WapcHost(hostCall, writer); 139 | return host.instantiateStreaming(await source); 140 | } 141 | -------------------------------------------------------------------------------- /test/browser/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Mocha Tests 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 16 | 36 | 37 | 38 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /test/browser/run.ts: -------------------------------------------------------------------------------- 1 | import { start } from '@jsoverson/test-server'; 2 | import findRoot from 'find-root'; 3 | import puppeteer from 'puppeteer'; 4 | 5 | const __projectroot = findRoot(__dirname); 6 | 7 | (async () => { 8 | const server = await start(__projectroot); 9 | const browser = await puppeteer.launch({ headless: true }); 10 | const [page] = await browser.pages(); 11 | await page.goto(server.url('/test/browser/index.html')); 12 | await page.waitForSelector('#done'); 13 | const [successes, failures]: string[][] = await page.evaluate(() => { 14 | const win = (window as unknown) as { successes: string[]; failures: string[] }; 15 | return [win.successes, win.failures]; 16 | }); 17 | console.log(`${successes.length} successes`); 18 | if (failures.length > 0) { 19 | console.log(`${failures.length} failures`); 20 | console.log(failures.map(f => `- ${f}`).join('\n')); 21 | } 22 | await browser.close(); 23 | await server.stop(); 24 | process.exit(failures.length); 25 | })(); 26 | -------------------------------------------------------------------------------- /test/browser/test.browser.ts: -------------------------------------------------------------------------------- 1 | import chai from 'chai'; 2 | import chaiAsPromised from 'chai-as-promised'; 3 | import { encode, decode } from '@msgpack/msgpack'; 4 | import * as WapcJsApi from '../../src'; 5 | 6 | chai.use(chaiAsPromised); 7 | const expect = chai.expect; 8 | 9 | async function fetchBytes(url: string): Promise { 10 | return new Uint8Array(await (await (await fetch(url)).blob()).arrayBuffer()); 11 | } 12 | const { instantiate, WapcHost, instantiateStreaming, errors } = getApiFromWindow(); 13 | 14 | describe('WapcHost', function () { 15 | let buffer: Uint8Array; 16 | beforeEach(async () => { 17 | buffer = await fetchBytes('/test/fixtures/rust_echo_string.wasm'); 18 | }); 19 | it('should create instance', async () => { 20 | const host = await instantiate(buffer); 21 | expect(host).to.be.instanceOf(WapcHost); 22 | }); 23 | it('should invoke guest operation', async () => { 24 | const host = await instantiate(buffer); 25 | const payload = encode({ msg: 'hello world' }); 26 | const result = await host.invoke('echo', payload); 27 | expect(result).to.be.instanceOf(Uint8Array); 28 | const decoded = decode(result); 29 | expect(decoded).to.equal('hello world'); 30 | }); 31 | it('guests should be able to invoke host calls', async () => { 32 | buffer = await fetchBytes('/test/fixtures/rust_host_call.wasm'); 33 | const host = await instantiate(buffer, (binding, namespace, operation, payload) => { 34 | expect(namespace).to.equal('myNamespace'); 35 | expect(binding).to.equal('myBinding'); 36 | expect(operation).to.equal('myOperation'); 37 | const decoded = decode(payload) as string; 38 | expect(decoded).to.equal('this is the payload'); 39 | return new Uint8Array(encode(decoded.toUpperCase())); 40 | }); 41 | const payload = encode({ 42 | namespace: 'myNamespace', 43 | binding: 'myBinding', 44 | operation: 'myOperation', 45 | msg: 'this is the payload', 46 | }); 47 | const result = await host.invoke('callback', payload); 48 | expect(result).to.be.instanceOf(Uint8Array); 49 | const decoded = decode(result); 50 | expect(decoded).to.equal('THIS IS THE PAYLOAD'); 51 | }); 52 | it('should throw when running guests that invoke an unimplemented host call', async () => { 53 | buffer = await fetchBytes('/test/fixtures/rust_host_call.wasm'); 54 | const host = await instantiate(buffer); 55 | const payload = encode({ 56 | namespace: 'ns', 57 | binding: 'bind', 58 | operation: 'op', 59 | msg: 'this is the payload', 60 | }); 61 | await expect(host.invoke('callback', payload)).to.be.rejectedWith( 62 | new errors.HostCallNotImplementedError('bind', 'ns', 'op').matcher(), 63 | ); 64 | }); 65 | it('should run multiple guests', async () => { 66 | const host = await instantiate(buffer); 67 | const host2 = await instantiate(buffer); 68 | const result = await host.invoke('echo', encode({ msg: 'world' })); 69 | const decoded = decode(result); 70 | const result2 = await host2.invoke('echo', encode({ msg: 'world2' })); 71 | const decoded2 = decode(result2); 72 | expect(decoded).to.equal('world'); 73 | expect(decoded2).to.equal('world2'); 74 | }); 75 | it('should throw when passed invalid wasm', async () => { 76 | buffer = await fetchBytes('/test/fixtures/package.json'); 77 | await expect(instantiate(buffer)).to.be.rejectedWith(new errors.InvalidWasm(new Error()).matcher()); 78 | }); 79 | it('should instantiate from a Response object', async () => { 80 | // not supported in node 81 | const stream = fetch('/test/fixtures/rust_echo_string.wasm'); 82 | const host = await instantiateStreaming(stream); 83 | const payload = encode({ msg: 'hello world' }); 84 | const result = await host.invoke('echo', payload); 85 | expect(result).to.be.instanceOf(Uint8Array); 86 | const decoded = decode(result); 87 | expect(decoded).to.equal('hello world'); 88 | }); 89 | }); 90 | 91 | /** 92 | * This function is to satisfy typescript. These tests run in a browser 93 | * and take the Wapc API from the global namespace so we have to hand wave 94 | * away the window object. 95 | * */ 96 | function getApiFromWindow(): typeof WapcJsApi { 97 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 98 | const win = window as any; 99 | return win.waPC as typeof WapcJsApi; 100 | } 101 | -------------------------------------------------------------------------------- /test/fixtures/rust_echo_string.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wapc/wapc-js/0fc7c5492dd0511a3ed71a4098f74ef5478a89f9/test/fixtures/rust_echo_string.wasm -------------------------------------------------------------------------------- /test/fixtures/rust_host_call.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wapc/wapc-js/0fc7c5492dd0511a3ed71a4098f74ef5478a89f9/test/fixtures/rust_host_call.wasm -------------------------------------------------------------------------------- /test/index.test.ts: -------------------------------------------------------------------------------- 1 | import chai from 'chai'; 2 | import chaiAsPromised from 'chai-as-promised'; 3 | import { describe } from 'mocha'; 4 | import fs from 'fs'; 5 | import path from 'path'; 6 | import { encode, decode } from '@msgpack/msgpack'; 7 | 8 | chai.use(chaiAsPromised); 9 | const expect = chai.expect; 10 | 11 | import { instantiate, WapcHost, errors } from '../src'; 12 | 13 | describe('WapcHost', function () { 14 | let buffer: Buffer; 15 | beforeEach(() => { 16 | buffer = fs.readFileSync(path.join(__dirname, 'fixtures', 'rust_echo_string.wasm')); 17 | }); 18 | it('should create instance', async () => { 19 | const host = await instantiate(buffer); 20 | expect(host).to.be.instanceOf(WapcHost); 21 | }); 22 | it('should invoke guest operation', async () => { 23 | const host = await instantiate(buffer); 24 | const payload = encode({ msg: 'hello world' }); 25 | const result = await host.invoke('echo', payload); 26 | expect(result).to.be.instanceOf(Uint8Array); 27 | const decoded = decode(result); 28 | expect(decoded).to.equal('hello world'); 29 | }); 30 | it('guests should be able to invoke host calls', async () => { 31 | buffer = fs.readFileSync(path.join(__dirname, 'fixtures', 'rust_host_call.wasm')); 32 | const host = await instantiate(buffer, (binding, namespace, operation, payload) => { 33 | expect(namespace).to.equal('myNamespace'); 34 | expect(binding).to.equal('myBinding'); 35 | expect(operation).to.equal('myOperation'); 36 | const decoded = decode(payload) as string; 37 | expect(decoded).to.equal('this is the payload'); 38 | return new Uint8Array(encode(decoded.toUpperCase())); 39 | }); 40 | const payload = encode({ 41 | namespace: 'myNamespace', 42 | binding: 'myBinding', 43 | operation: 'myOperation', 44 | msg: 'this is the payload', 45 | }); 46 | const result = await host.invoke('callback', payload); 47 | expect(result).to.be.instanceOf(Uint8Array); 48 | const decoded = decode(result); 49 | expect(decoded).to.equal('THIS IS THE PAYLOAD'); 50 | }); 51 | it('should throw when running guests that invoke an unimplemented host call', async () => { 52 | buffer = fs.readFileSync(path.join(__dirname, 'fixtures', 'rust_host_call.wasm')); 53 | const host = await instantiate(buffer); 54 | const payload = encode({ 55 | namespace: 'ns', 56 | binding: 'bind', 57 | operation: 'op', 58 | msg: 'this is the payload', 59 | }); 60 | await expect(host.invoke('callback', payload)).to.be.rejectedWith( 61 | new errors.HostCallNotImplementedError('bind', 'ns', 'op').matcher(), 62 | ); 63 | }); 64 | it('should run multiple guests', async () => { 65 | const host = await instantiate(buffer); 66 | const host2 = await instantiate(buffer); 67 | const result = await host.invoke('echo', encode({ msg: 'world' })); 68 | const decoded = decode(result); 69 | const result2 = await host2.invoke('echo', encode({ msg: 'world2' })); 70 | const decoded2 = decode(result2); 71 | expect(decoded).to.equal('world'); 72 | expect(decoded2).to.equal('world2'); 73 | }); 74 | it('should throw when passed invalid wasm', async () => { 75 | buffer = fs.readFileSync(path.join(__dirname, '..', 'package.json')); 76 | await expect(instantiate(buffer)).to.be.rejectedWith(new errors.InvalidWasm(new Error()).matcher()); 77 | }); 78 | }); 79 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "include": ["src/**/*.ts", "test/**/*.ts"], 3 | "exclude": ["node_modules"], 4 | "compilerOptions": { 5 | /* Basic Options */ 6 | // "incremental": true, /* Enable incremental compilation */ 7 | "target": "ES2018" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */, 8 | "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */, 9 | "lib": ["es2018", "DOM"] /* Specify library files to be included in the compilation. */, 10 | "resolveJsonModule": true, 11 | // "allowJs": true, /* Allow javascript files to be compiled. */ 12 | // "checkJs": true, /* Report errors in .js files. */ 13 | // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ 14 | // "declaration": true, /* Generates corresponding '.d.ts' file. */ 15 | // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ 16 | "sourceMap": true /* Generates corresponding '.map' file. */, 17 | // "outFile": "./", /* Concatenate and emit output to single file. */ 18 | "outDir": "./dist" /* Redirect output structure to the directory. */, 19 | "rootDir": "./" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */, 20 | // "composite": true, /* Enable project compilation */ 21 | // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ 22 | // "removeComments": true, /* Do not emit comments to output. */ 23 | // "noEmit": true, /* Do not emit outputs. */ 24 | // "importHelpers": true, /* Import emit helpers from 'tslib'. */ 25 | // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ 26 | // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ 27 | /* Strict Type-Checking Options */ 28 | "strict": true /* Enable all strict type-checking options. */, 29 | // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ 30 | // "strictNullChecks": true, /* Enable strict null checks. */ 31 | // "strictFunctionTypes": true, /* Enable strict checking of function types. */ 32 | // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ 33 | // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ 34 | // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ 35 | // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ 36 | /* Additional Checks */ 37 | // "noUnusedLocals": true, /* Report errors on unused locals. */ 38 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 39 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 40 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 41 | /* Module Resolution Options */ 42 | // "moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */, 43 | // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ 44 | // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ 45 | // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ 46 | // "typeRoots": [], /* List of folders to include type definitions from. */ 47 | "typeRoots": ["./types", "./node_modules/@types"], 48 | // "types": [], /* Type declaration files to be included in compilation. */ 49 | // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ 50 | "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, 51 | // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ 52 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 53 | /* Source Map Options */ 54 | // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ 55 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 56 | // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ 57 | // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ 58 | /* Experimental Options */ 59 | // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ 60 | // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ 61 | /* Advanced Options */ 62 | "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ 63 | } 64 | } 65 | --------------------------------------------------------------------------------