Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"identity": "WebAssembly.Browser.7.0",
"description": "WebAssembly Browser App",
"name": "WebAssembly Browser App",
"description": "A project template for creating a .NET app that runs on WebAssembly in a browser",
"shortName": "wasmbrowser",
"sourceName": "browser.0",
"preferNameDirectory": true,
Expand Down
11 changes: 4 additions & 7 deletions src/mono/wasm/templates/templates/browser/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@

import { dotnet } from './dotnet.js'

const is_browser = typeof window != "undefined";
if (!is_browser) throw new Error(`Expected to be running in a browser`);

const { setModuleImports, getAssemblyExports, getConfig, runMainAndExit } = await dotnet
const { setModuleImports, getAssemblyExports, getConfig } = await dotnet
.withDiagnosticTracing(false)
.withApplicationArgumentsFromQuery()
.create();

setModuleImports("main.js", {
setModuleImports('main.js', {
window: {
location: {
href: () => globalThis.window.location.href
Expand All @@ -24,5 +21,5 @@ const exports = await getAssemblyExports(config.mainAssemblyName);
const text = exports.MyClass.Greeting();
console.log(text);

document.getElementById("out").innerHTML = `${text}`;
await runMainAndExit(config.mainAssemblyName, ["dotnet", "is", "great!"]);
document.getElementById('out').innerHTML = text;
await dotnet.run();
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"identity": "WebAssembly.Console.7.0",
"description": "WebAssembly Console App",
"name": "WebAssembly Console App",
"description": "A project template for creating a .NET app that runs on WebAssembly on Node JS or V8",
"shortName": "wasmconsole",
"sourceName": "console.0",
"preferNameDirectory": true,
Expand Down
9 changes: 3 additions & 6 deletions src/mono/wasm/templates/templates/console/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@

import { dotnet } from './dotnet.js'

const is_node = typeof process === 'object' && typeof process.versions === 'object' && typeof process.versions.node === 'string';
if (!is_node) throw new Error(`This file only supports nodejs`);

const { setModuleImports, getAssemblyExports, getConfig, runMainAndExit } = await dotnet
const { setModuleImports, getAssemblyExports, getConfig } = await dotnet
.withDiagnosticTracing(false)
.create();

setModuleImports("main.mjs", {
setModuleImports('main.mjs', {
node: {
process: {
version: () => globalThis.process.version
Expand All @@ -23,4 +20,4 @@ const exports = await getAssemblyExports(config.mainAssemblyName);
const text = exports.MyClass.Greeting();
console.log(text);

await runMainAndExit(config.mainAssemblyName, ["dotnet", "is", "great!"]);
await dotnet.run();
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ private void UpdateConsoleMainJs()
string mainJsContent = File.ReadAllText(mainJsPath);

mainJsContent = mainJsContent
.Replace(".create()", ".withConsoleForwarding().create()")
.Replace("[\"dotnet\", \"is\", \"great!\"]", "(await import(/* webpackIgnore: true */\"process\")).argv.slice(2)");
.Replace(".create()", ".withConsoleForwarding().create()");

File.WriteAllText(mainJsPath, mainJsContent);
}
Expand Down