#nullable enable
+using System;
using System.IO;
+using System.Text.Json.Nodes;
using Xunit.Abstractions;
namespace Wasm.Build.Tests;
if (runAnalyzers)
extraProperties += "<RunAnalyzers>true</RunAnalyzers>";
- // TODO: Can be removed after updated templates propagate in.
- string extraItems = string.Empty;
- if (template == "wasmbrowser")
- extraItems += "<WasmExtraFilesToDeploy Include=\"main.js\" />";
- else
- extraItems += "<WasmExtraFilesToDeploy Include=\"main.mjs\" />";
+ if (template == "wasmconsole")
+ {
+ UpdateRuntimeconfigTemplateForNode(_projectDir);
+ }
- AddItemsPropertiesToProject(projectfile, extraProperties, extraItems);
+ AddItemsPropertiesToProject(projectfile, extraProperties);
return projectfile;
}
+ private static void UpdateRuntimeconfigTemplateForNode(string projectDir)
+ {
+ // TODO: Can be removed once Node >= 20
+
+ string runtimeconfigTemplatePath = Path.Combine(projectDir, "runtimeconfig.template.json");
+ string runtimeconfigTemplateContent = File.ReadAllText(runtimeconfigTemplatePath);
+ var runtimeconfigTemplate = JsonObject.Parse(runtimeconfigTemplateContent);
+ if (runtimeconfigTemplate == null)
+ throw new Exception($"Unable to parse runtimeconfigtemplate at '{runtimeconfigTemplatePath}'");
+
+ var perHostConfigs = runtimeconfigTemplate?["wasmHostProperties"]?["perHostConfig"]?.AsArray();
+ if (perHostConfigs == null || perHostConfigs.Count == 0 || perHostConfigs[0] == null)
+ throw new Exception($"Unable to find perHostConfig in runtimeconfigtemplate at '{runtimeconfigTemplatePath}'");
+
+ perHostConfigs[0]!["host-args"] = new JsonArray(
+ "--experimental-wasm-simd",
+ "--experimental-wasm-eh"
+ );
+
+ File.WriteAllText(runtimeconfigTemplatePath, runtimeconfigTemplate!.ToString());
+ }
+
public (string projectDir, string buildOutput) BuildTemplateProject(BuildArgs buildArgs,
string id,
BuildProjectOptions buildProjectOptions)
### Shell environments - NodeJS & V8
While our primary target is web browsers, we have partial support for Node.JS v14 sufficient to pass most of our automated tests. We also have partial support for the D8 command-line shell, version 11 or higher, sufficient to pass most of our automated tests. Both of these environments may lack support for features that are available in the browser.
+#### NodeJS < 20
+Until node version 20, you may need to pass these arguments when running the application `--experimental-wasm-simd --experimental-wasm-eh`. When you run the application using `dotnet run`, you can add these to the runtimeconfig template
+
+```json
+"wasmHostProperties": {
+ "perHostConfig": [
+ {
+ "name": "node",
+ ...
+ "host-args": [
+ "--experimental-wasm-simd", // 👈 Enable SIMD support
+ "--experimental-wasm-eh" // 👈 Enable exception handling support
+ ]
+ }
+ ]
+}
+```
+
## Choosing the right platform target
Every end user has different needs, so the right platform for every application may differ.