Skip to content

Opt out of monkey patching .NET internals #139

Open
@elringus

Description

@elringus

We are currently patching .NET's and Emscripten's JavaScript modules to make them compatible with JavaScript runtimes and bundlers:

File.WriteAllText(dotnet, File.ReadAllText(dotnet, Encoding.UTF8)
.Replace("import.meta.url", url)
.Replace("import(", "import(/*@vite-ignore*//*webpackIgnore:true*/"), Encoding.UTF8);
File.WriteAllText(runtime, File.ReadAllText(runtime, Encoding.UTF8)
.Replace("pt('WebAssembly resource does not have the expected content type \"application/wasm\", so falling back to slower ArrayBuffer instantiation.')", "true")
.Replace("import(", "import(/*@vite-ignore*//*webpackIgnore:true*/"), Encoding.UTF8);
File.WriteAllText(native, File.ReadAllText(native, Encoding.UTF8)
.Replace("var _scriptDir = import.meta.url", "var _scriptDir = \"file:/\"")
.Replace("require('url').fileURLToPath(new URL('./', import.meta.url))", "\"./\"")
.Replace("require(\"url\").fileURLToPath(new URL(\"./\",import.meta.url))", "\"./\"") // when aggressive trimming enabled
.Replace("new URL('dotnet.native.wasm', import.meta.url).href", "\"file:/\"")
.Replace("new URL(\"dotnet.native.wasm\",import.meta.url).href", "\"file:/\"") // when aggressive trimming enabled
.Replace("import.meta.url", url)
.Replace("import(", "import(/*@vite-ignore*//*webpackIgnore:true*/"), Encoding.UTF8);

— this is fragile and will most likely break with each new .NET release and/or WASM workload update.

Hopefully, .NET will at some point ensure the modules are compatible out of the box, so we won't have to do this:

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or enhancementexternalThe issue is caused by a third-party

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions