From bb07577dc824c685245a989ebde3b9e1843fed2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 26 Sep 2022 14:11:56 +0200 Subject: [PATCH 1/6] Add template descriptions. --- .../templates/templates/browser/.template.config/template.json | 1 + .../templates/templates/console/.template.config/template.json | 1 + 2 files changed, 2 insertions(+) diff --git a/src/mono/wasm/templates/templates/browser/.template.config/template.json b/src/mono/wasm/templates/templates/browser/.template.config/template.json index b2ae216e23db65..7b149cb015c72d 100644 --- a/src/mono/wasm/templates/templates/browser/.template.config/template.json +++ b/src/mono/wasm/templates/templates/browser/.template.config/template.json @@ -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 the browser", "shortName": "wasmbrowser", "sourceName": "browser.0", "preferNameDirectory": true, diff --git a/src/mono/wasm/templates/templates/console/.template.config/template.json b/src/mono/wasm/templates/templates/console/.template.config/template.json index 1410c600679e09..e59261e64e7713 100644 --- a/src/mono/wasm/templates/templates/console/.template.config/template.json +++ b/src/mono/wasm/templates/templates/console/.template.config/template.json @@ -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, From 2954a2d5a66860e5e3962a13b8cad09004b99807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 26 Sep 2022 14:41:29 +0200 Subject: [PATCH 2/6] Unify string quotes. --- src/mono/wasm/templates/templates/browser/main.js | 10 +++++----- src/mono/wasm/templates/templates/console/main.mjs | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/mono/wasm/templates/templates/browser/main.js b/src/mono/wasm/templates/templates/browser/main.js index 32c1599749d1db..8712b0a04a8594 100644 --- a/src/mono/wasm/templates/templates/browser/main.js +++ b/src/mono/wasm/templates/templates/browser/main.js @@ -3,15 +3,15 @@ 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 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 .withDiagnosticTracing(false) .withApplicationArgumentsFromQuery() .create(); -setModuleImports("main.js", { +setModuleImports('main.js', { window: { location: { href: () => globalThis.window.location.href @@ -24,5 +24,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!"]); \ No newline at end of file +document.getElementById('out').innerHTML = text; +await runMainAndExit(config.mainAssemblyName, ['dotnet', 'is', 'great!']); \ No newline at end of file diff --git a/src/mono/wasm/templates/templates/console/main.mjs b/src/mono/wasm/templates/templates/console/main.mjs index 1072711c59c6dc..7aa2c9da66644f 100644 --- a/src/mono/wasm/templates/templates/console/main.mjs +++ b/src/mono/wasm/templates/templates/console/main.mjs @@ -10,7 +10,7 @@ const { setModuleImports, getAssemblyExports, getConfig, runMainAndExit } = awai .withDiagnosticTracing(false) .create(); -setModuleImports("main.mjs", { +setModuleImports('main.mjs', { node: { process: { version: () => globalThis.process.version @@ -23,4 +23,4 @@ const exports = await getAssemblyExports(config.mainAssemblyName); const text = exports.MyClass.Greeting(); console.log(text); -await runMainAndExit(config.mainAssemblyName, ["dotnet", "is", "great!"]); +await runMainAndExit(config.mainAssemblyName, ['dotnet', 'is', 'great!']); From 4dd23d85b4dab6e015125281ed6f550d9c76a409 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 27 Sep 2022 09:54:46 +0200 Subject: [PATCH 3/6] Reword. --- .../templates/templates/browser/.template.config/template.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/templates/templates/browser/.template.config/template.json b/src/mono/wasm/templates/templates/browser/.template.config/template.json index 7b149cb015c72d..346ea52ad7f7f3 100644 --- a/src/mono/wasm/templates/templates/browser/.template.config/template.json +++ b/src/mono/wasm/templates/templates/browser/.template.config/template.json @@ -8,7 +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 the browser", + "description": "A project template for creating a .NET app that runs on WebAssembly in a browser", "shortName": "wasmbrowser", "sourceName": "browser.0", "preferNameDirectory": true, From 63f4653c28a6aadc0324baabb79801859397ff14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 27 Sep 2022 10:04:27 +0200 Subject: [PATCH 4/6] Fix WBT. --- src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs b/src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs index 34b2405560003b..b34e44d20a9404 100644 --- a/src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs +++ b/src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs @@ -52,7 +52,7 @@ private void UpdateConsoleMainJs() mainJsContent = mainJsContent .Replace(".create()", ".withConsoleForwarding().create()") - .Replace("[\"dotnet\", \"is\", \"great!\"]", "(await import(/* webpackIgnore: true */\"process\")).argv.slice(2)"); + .Replace("['dotnet', 'is', 'great!']", "(await import(/* webpackIgnore: true */\"process\")).argv.slice(2)"); File.WriteAllText(mainJsPath, mainJsContent); } From 97dd0822e4743bcb8f282b0451851352ddbabbe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 27 Sep 2022 14:21:39 +0200 Subject: [PATCH 5/6] Feedback. --- src/mono/wasm/templates/templates/browser/main.js | 7 ++----- .../BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/mono/wasm/templates/templates/browser/main.js b/src/mono/wasm/templates/templates/browser/main.js index 8712b0a04a8594..6d9bd43f7eb7b3 100644 --- a/src/mono/wasm/templates/templates/browser/main.js +++ b/src/mono/wasm/templates/templates/browser/main.js @@ -3,10 +3,7 @@ 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(); @@ -25,4 +22,4 @@ const text = exports.MyClass.Greeting(); console.log(text); document.getElementById('out').innerHTML = text; -await runMainAndExit(config.mainAssemblyName, ['dotnet', 'is', 'great!']); \ No newline at end of file +await dotnet.run(); \ No newline at end of file diff --git a/src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs b/src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs index b34e44d20a9404..997be96e1fe126 100644 --- a/src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs +++ b/src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs @@ -52,7 +52,7 @@ private void UpdateConsoleMainJs() mainJsContent = mainJsContent .Replace(".create()", ".withConsoleForwarding().create()") - .Replace("['dotnet', 'is', 'great!']", "(await import(/* webpackIgnore: true */\"process\")).argv.slice(2)"); + .Replace("['dotnet', 'is', 'great!']", "(await import('process')).argv.slice(2)"); File.WriteAllText(mainJsPath, mainJsContent); } From c674716f9dc94f2077bc616c82e5dbc68f1bdb11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 27 Sep 2022 14:59:32 +0200 Subject: [PATCH 6/6] Feedback. --- src/mono/wasm/templates/templates/console/main.mjs | 7 ++----- .../BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs | 3 +-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/mono/wasm/templates/templates/console/main.mjs b/src/mono/wasm/templates/templates/console/main.mjs index 7aa2c9da66644f..6dd163a3741b32 100644 --- a/src/mono/wasm/templates/templates/console/main.mjs +++ b/src/mono/wasm/templates/templates/console/main.mjs @@ -3,10 +3,7 @@ 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(); @@ -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(); diff --git a/src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs b/src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs index 997be96e1fe126..1d73b75894cc7c 100644 --- a/src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs +++ b/src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs @@ -51,8 +51,7 @@ private void UpdateConsoleMainJs() string mainJsContent = File.ReadAllText(mainJsPath); mainJsContent = mainJsContent - .Replace(".create()", ".withConsoleForwarding().create()") - .Replace("['dotnet', 'is', 'great!']", "(await import('process')).argv.slice(2)"); + .Replace(".create()", ".withConsoleForwarding().create()"); File.WriteAllText(mainJsPath, mainJsContent); }