From bbca3a6ef0e860b2c93a56913cf5ada6e1f48ca6 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 5fa2bac372a72f..916d753be8778a 100644 --- a/src/mono/wasm/templates/templates/browser/.template.config/template.json +++ b/src/mono/wasm/templates/templates/browser/.template.config/template.json @@ -5,6 +5,7 @@ "generatorVersions": "[1.0.0.0-*)", "identity": "WebAssembly.Browser", "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 8ead39edc0f8c2..de91185d07ad03 100644 --- a/src/mono/wasm/templates/templates/console/.template.config/template.json +++ b/src/mono/wasm/templates/templates/console/.template.config/template.json @@ -4,6 +4,7 @@ "classifications": [ "Web", "WebAssembly", "Console" ], "identity": "WebAssembly.Console", "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 dc3f5f8de7142b9b046074bbf752fd60e8d3b33e 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 c9d27b9515264ead5717d88b1a11b7fd729bc07c 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 916d753be8778a..4d341936f809eb 100644 --- a/src/mono/wasm/templates/templates/browser/.template.config/template.json +++ b/src/mono/wasm/templates/templates/browser/.template.config/template.json @@ -5,7 +5,7 @@ "generatorVersions": "[1.0.0.0-*)", "identity": "WebAssembly.Browser", "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 b6b89e5d9760d847d0321f9dd5e230805b6f4566 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/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs b/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs index e96ed8b797e8c5..aa5043033906e8 100644 --- a/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs @@ -56,7 +56,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 72f36df2e603aa7130dc5e024153cec55799c118 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/Wasm.Build.Tests/WasmTemplateTests.cs | 2 +- src/mono/wasm/templates/templates/browser/main.js | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs b/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs index aa5043033906e8..015b2bda35e349 100644 --- a/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs @@ -56,7 +56,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); } 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 From 00fb5fb71e8aeb2d8b92e86a872e0c1eba5447c3 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/Wasm.Build.Tests/WasmTemplateTests.cs | 3 +-- src/mono/wasm/templates/templates/console/main.mjs | 7 ++----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs b/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs index 015b2bda35e349..131ca64a71e1f9 100644 --- a/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs @@ -55,8 +55,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); } 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();