Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opt out of monkey patching .NET internals #139

Open
elringus opened this issue Jan 15, 2024 · 0 comments
Open

Opt out of monkey patching .NET internals #139

elringus opened this issue Jan 15, 2024 · 0 comments
Labels
enhancement New feature or enhancement external The issue is caused by a third-party

Comments

@elringus
Copy link
Owner

elringus commented Jan 15, 2024

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:

@elringus elringus added enhancement New feature or enhancement external The issue is caused by a third-party labels Jan 15, 2024
@elringus elringus added this to the First stable release milestone Jan 15, 2024
@elringus elringus changed the title Opt out of monkey-patching .NET internals Opt out of monkey patching .NET internals Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or enhancement external The issue is caused by a third-party
Projects
None yet
Development

No branches or pull requests

1 participant