Skip to content

Commit f29fd6f

Browse files
[release/7.0] [wasm] Templates nits (#76373)
* Add template descriptions. * Unify string quotes. * Reword. * Fix WBT. * Feedback. * Feedback. Co-authored-by: Marek Fišera <[email protected]>
1 parent b099c69 commit f29fd6f

File tree

5 files changed

+10
-15
lines changed

5 files changed

+10
-15
lines changed

src/mono/wasm/templates/templates/browser/.template.config/template.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"identity": "WebAssembly.Browser.7.0",
99
"description": "WebAssembly Browser App",
1010
"name": "WebAssembly Browser App",
11+
"description": "A project template for creating a .NET app that runs on WebAssembly in a browser",
1112
"shortName": "wasmbrowser",
1213
"sourceName": "browser.0",
1314
"preferNameDirectory": true,

src/mono/wasm/templates/templates/browser/main.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33

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

6-
const is_browser = typeof window != "undefined";
7-
if (!is_browser) throw new Error(`Expected to be running in a browser`);
8-
9-
const { setModuleImports, getAssemblyExports, getConfig, runMainAndExit } = await dotnet
6+
const { setModuleImports, getAssemblyExports, getConfig } = await dotnet
107
.withDiagnosticTracing(false)
118
.withApplicationArgumentsFromQuery()
129
.create();
1310

14-
setModuleImports("main.js", {
11+
setModuleImports('main.js', {
1512
window: {
1613
location: {
1714
href: () => globalThis.window.location.href
@@ -24,5 +21,5 @@ const exports = await getAssemblyExports(config.mainAssemblyName);
2421
const text = exports.MyClass.Greeting();
2522
console.log(text);
2623

27-
document.getElementById("out").innerHTML = `${text}`;
28-
await runMainAndExit(config.mainAssemblyName, ["dotnet", "is", "great!"]);
24+
document.getElementById('out').innerHTML = text;
25+
await dotnet.run();

src/mono/wasm/templates/templates/console/.template.config/template.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"identity": "WebAssembly.Console.7.0",
88
"description": "WebAssembly Console App",
99
"name": "WebAssembly Console App",
10+
"description": "A project template for creating a .NET app that runs on WebAssembly on Node JS or V8",
1011
"shortName": "wasmconsole",
1112
"sourceName": "console.0",
1213
"preferNameDirectory": true,

src/mono/wasm/templates/templates/console/main.mjs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33

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

6-
const is_node = typeof process === 'object' && typeof process.versions === 'object' && typeof process.versions.node === 'string';
7-
if (!is_node) throw new Error(`This file only supports nodejs`);
8-
9-
const { setModuleImports, getAssemblyExports, getConfig, runMainAndExit } = await dotnet
6+
const { setModuleImports, getAssemblyExports, getConfig } = await dotnet
107
.withDiagnosticTracing(false)
118
.create();
129

13-
setModuleImports("main.mjs", {
10+
setModuleImports('main.mjs', {
1411
node: {
1512
process: {
1613
version: () => globalThis.process.version
@@ -23,4 +20,4 @@ const exports = await getAssemblyExports(config.mainAssemblyName);
2320
const text = exports.MyClass.Greeting();
2421
console.log(text);
2522

26-
await runMainAndExit(config.mainAssemblyName, ["dotnet", "is", "great!"]);
23+
await dotnet.run();

src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ private void UpdateConsoleMainJs()
5151
string mainJsContent = File.ReadAllText(mainJsPath);
5252

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

5756
File.WriteAllText(mainJsPath, mainJsContent);
5857
}

0 commit comments

Comments
 (0)