|  | 
| 3 | 3 | 
 | 
| 4 | 4 | #nullable enable | 
| 5 | 5 | 
 | 
|  | 6 | +using System; | 
| 6 | 7 | using System.IO; | 
|  | 8 | +using System.Text.Json.Nodes; | 
| 7 | 9 | using Xunit.Abstractions; | 
| 8 | 10 | 
 | 
| 9 | 11 | namespace Wasm.Build.Tests; | 
| @@ -45,18 +47,38 @@ public string CreateWasmTemplateProject(string id, string template = "wasmbrowse | 
| 45 | 47 |         if (runAnalyzers) | 
| 46 | 48 |             extraProperties += "<RunAnalyzers>true</RunAnalyzers>"; | 
| 47 | 49 | 
 | 
| 48 |  | -        // TODO: Can be removed after updated templates propagate in. | 
| 49 |  | -        string extraItems = string.Empty; | 
| 50 |  | -        if (template == "wasmbrowser") | 
| 51 |  | -            extraItems += "<WasmExtraFilesToDeploy Include=\"main.js\" />"; | 
| 52 |  | -        else | 
| 53 |  | -            extraItems += "<WasmExtraFilesToDeploy Include=\"main.mjs\" />"; | 
|  | 50 | +        if (template == "wasmconsole") | 
|  | 51 | +        { | 
|  | 52 | +            UpdateRuntimeconfigTemplateForNode(_projectDir); | 
|  | 53 | +        } | 
| 54 | 54 | 
 | 
| 55 |  | -        AddItemsPropertiesToProject(projectfile, extraProperties, extraItems); | 
|  | 55 | +        AddItemsPropertiesToProject(projectfile, extraProperties); | 
| 56 | 56 | 
 | 
| 57 | 57 |         return projectfile; | 
| 58 | 58 |     } | 
| 59 | 59 | 
 | 
|  | 60 | +    private static void UpdateRuntimeconfigTemplateForNode(string projectDir) | 
|  | 61 | +    { | 
|  | 62 | +        // TODO: Can be removed once Node >= 20 | 
|  | 63 | + | 
|  | 64 | +        string runtimeconfigTemplatePath = Path.Combine(projectDir, "runtimeconfig.template.json"); | 
|  | 65 | +        string runtimeconfigTemplateContent = File.ReadAllText(runtimeconfigTemplatePath); | 
|  | 66 | +        var runtimeconfigTemplate = JsonObject.Parse(runtimeconfigTemplateContent); | 
|  | 67 | +        if (runtimeconfigTemplate == null) | 
|  | 68 | +            throw new Exception($"Unable to parse runtimeconfigtemplate at '{runtimeconfigTemplatePath}'"); | 
|  | 69 | + | 
|  | 70 | +        var perHostConfigs = runtimeconfigTemplate?["wasmHostProperties"]?["perHostConfig"]?.AsArray(); | 
|  | 71 | +        if (perHostConfigs == null || perHostConfigs.Count == 0 || perHostConfigs[0] == null) | 
|  | 72 | +            throw new Exception($"Unable to find perHostConfig in runtimeconfigtemplate at '{runtimeconfigTemplatePath}'"); | 
|  | 73 | + | 
|  | 74 | +        perHostConfigs[0]!["host-args"] = new JsonArray( | 
|  | 75 | +            "--experimental-wasm-simd", | 
|  | 76 | +            "--experimental-wasm-eh" | 
|  | 77 | +        ); | 
|  | 78 | + | 
|  | 79 | +        File.WriteAllText(runtimeconfigTemplatePath, runtimeconfigTemplate!.ToString()); | 
|  | 80 | +    } | 
|  | 81 | + | 
| 60 | 82 |     public (string projectDir, string buildOutput) BuildTemplateProject(BuildArgs buildArgs, | 
| 61 | 83 |         string id, | 
| 62 | 84 |         BuildProjectOptions buildProjectOptions) | 
|  | 
0 commit comments