If we print the command line args:
usingSystem;usingSystem.Runtime.InteropServices.JavaScript;Console.WriteLine("Hello, Console!");Console.WriteLine($"command line args: {string.Join(',',args)}");return0;publicpartialclassMyClass{[JSExport]internalstaticstringGreeting(){vartext=$"Hello, World! Greetings from node version: {GetNodeVersion()}";returntext;}[JSImport("node.process.version","main.mjs")]internalstaticpartialstringGetNodeVersion();}.. and run:
$ dotnet run x y z
WasmAppHost --runtime-config /tmp/cc/bin/Debug/net7.0/browser-wasm/AppBundle/cc.runtimeconfig.json x y z
Running: node main.mjs x y z
Using working directory: /tmp/cc/bin/Debug/net7.0/browser-wasm/AppBundle
mono_wasm_runtime_ready fe00e07a-5519-4dfe-b35a-f867dbaf2e28
Hello, World! Greetings from node version: v14.18.2
Hello, Console!
command line args: dotnet,is,great!
The command line arguments x y z were ignored, and instead we got dotnet,is,great. And that's because the main.mjs has:
awaitrunMainAndExit(config.mainAssemblyName,["dotnet","is","great!"]);
This doesn't get caught by Wasm.Build.Tests because the tests are explicitly patching the generated code
| privatevoidUpdateConsoleMainJs() |
| { |
| stringmainJsPath=Path.Combine(_projectDir!,"main.mjs"); |
| stringmainJsContent=File.ReadAllText(mainJsPath); |
| |
| mainJsContent=mainJsContent |
| .Replace(".create()",".withConsoleForwarding().create()") |
| .Replace("[\"dotnet\", \"is\", \"great!\"]","(await import(/* webpackIgnore: true */\"process\")).argv.slice(2)"); |
| |
| File.WriteAllText(mainJsPath,mainJsContent); |
| } |
And the same is done for the browser too.
We should instead:
cc @pavelsavara
If we print the command line args:
.. and run:
The command line arguments
x y zwere ignored, and instead we gotdotnet,is,great. And that's because themain.mjshas:This doesn't get caught by Wasm.Build.Tests because the tests are explicitly patching the generated code
runtime/src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs
Lines 48 to 58 in 4bd3ee5
And the same is done for the browser too.
We should instead:
cc @pavelsavara