[Wasm] JS modularization (#61313)
authorPavel Savara <pavelsavara@microsoft.com>
Thu, 2 Dec 2021 09:38:00 +0000 (10:38 +0100)
committerGitHub <noreply@github.com>
Thu, 2 Dec 2021 09:38:00 +0000 (10:38 +0100)
commit1bd36302b4bd1a54682e27c5ef1bc826db702e03
treed5be02c8cec226ad27c9b012b6f06243e4fe86c9
parenta61c1a3cf5a3391c8df61d5db739ba7d1674bba5
[Wasm] JS modularization (#61313)

Modularized dotnet.js
* By using emcc options MODULARIZE and EXPORT_ES6, depending on WasmEnableES6 to produce ES6 or CommonJS modules respectively.
* WasmEnableES6 enables WasmBuildNative because dotnet.js need to be re-linked
* CommonJS version is able to be loaded into global namespace and behaves as before this change.
* Added new es6/*.js and es6/*.js files which are included in dotnet.js creation.
* Key aspects are documented in src/mono/wasm/runtime/modularize-dotnet.md of this PR.
* Improved dotnet.d.ts it is now generated into version control too, so that we could observe how it evolves.
* Removed legacy --testing argument and simplified is_testing logic in the the samples.
* Added browser-es6 sample app, which uses WasmEnableES6=true to compile dotnet.js as ES6 module.
* Added browser-legacy sample, which uses dotnet.js CommonJS module and loads it into global namespace.
* Added package.json into the nupkg

Co-authored-by: Ankit Jain <radical@gmail.com>
Co-authored-by: Katelyn Gadd <kg@luminance.org>
Co-authored-by: Marek FiĊĦera <mara@neptuo.com>
62 files changed:
.gitignore
eng/liveBuilds.targets
eng/testing/tests.wasm.targets
src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props
src/mono/sample/mbr/browser/main.js
src/mono/sample/wasm/Directory.Build.targets
src/mono/sample/wasm/browser-bench/main.js
src/mono/sample/wasm/browser-es6/Program.cs [new file with mode: 0644]
src/mono/sample/wasm/browser-es6/Wasm.Browser.ES6.Sample.csproj [new file with mode: 0644]
src/mono/sample/wasm/browser-es6/index.html [new file with mode: 0644]
src/mono/sample/wasm/browser-es6/main.js [new file with mode: 0644]
src/mono/sample/wasm/browser-legacy/Program.cs [new file with mode: 0644]
src/mono/sample/wasm/browser-legacy/Wasm.Browser.LegacySample.csproj [new file with mode: 0644]
src/mono/sample/wasm/browser-legacy/index.html [new file with mode: 0644]
src/mono/sample/wasm/browser-legacy/main.js [new file with mode: 0644]
src/mono/sample/wasm/browser-profile/main.js
src/mono/sample/wasm/browser/index.html
src/mono/sample/wasm/browser/main.js
src/mono/wasm/Makefile
src/mono/wasm/build/README.md
src/mono/wasm/build/WasmApp.Native.targets
src/mono/wasm/debugger/DebuggerTestSuite/ArrayTests.cs
src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestBase.cs
src/mono/wasm/debugger/tests/debugger-test/debugger-main.js
src/mono/wasm/runtime/.eslintrc.js
src/mono/wasm/runtime/CMakeLists.txt
src/mono/wasm/runtime/buffers.ts
src/mono/wasm/runtime/cancelable-promise.ts
src/mono/wasm/runtime/cjs/dotnet.cjs.extpost.js [new file with mode: 0644]
src/mono/wasm/runtime/cjs/dotnet.cjs.lib.js [moved from src/mono/wasm/runtime/library-dotnet.js with 65% similarity]
src/mono/wasm/runtime/cjs/dotnet.cjs.post.js [new file with mode: 0644]
src/mono/wasm/runtime/cjs/dotnet.cjs.pre.js [new file with mode: 0644]
src/mono/wasm/runtime/cs-to-js.ts
src/mono/wasm/runtime/cwraps.ts
src/mono/wasm/runtime/debug.ts
src/mono/wasm/runtime/dotnet.d.ts [new file with mode: 0644]
src/mono/wasm/runtime/es6/dotnet.es6.lib.js [new file with mode: 0644]
src/mono/wasm/runtime/es6/dotnet.es6.post.js [new file with mode: 0644]
src/mono/wasm/runtime/es6/dotnet.es6.pre.js [new file with mode: 0644]
src/mono/wasm/runtime/export-types.ts
src/mono/wasm/runtime/exports.ts
src/mono/wasm/runtime/icu.ts
src/mono/wasm/runtime/imports.ts
src/mono/wasm/runtime/js-to-cs.ts
src/mono/wasm/runtime/memory.ts
src/mono/wasm/runtime/method-binding.ts
src/mono/wasm/runtime/method-calls.ts
src/mono/wasm/runtime/modularize-dotnet.md [new file with mode: 0644]
src/mono/wasm/runtime/package.json
src/mono/wasm/runtime/polyfills.ts [new file with mode: 0644]
src/mono/wasm/runtime/rollup.config.js
src/mono/wasm/runtime/roots.ts
src/mono/wasm/runtime/startup.ts
src/mono/wasm/runtime/strings.ts
src/mono/wasm/runtime/types.ts
src/mono/wasm/runtime/types/emscripten.ts [moved from src/mono/wasm/runtime/types/emscripten.d.ts with 70% similarity]
src/mono/wasm/runtime/web-socket.ts
src/mono/wasm/test-main.js
src/mono/wasm/wasm.proj
src/native/libs/System.Native/pal_random.lib.js [moved from src/native/libs/System.Native/pal_random.js with 100% similarity]
src/tests/FunctionalTests/WebAssembly/Browser/HotReload/main.js
src/tests/FunctionalTests/WebAssembly/Browser/RuntimeConfig/main.js