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