Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/7.0] [wasm] Templates nits #76373

Merged
merged 6 commits into from
Sep 29, 2022
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