evanw / esbuild

An extremely fast bundler for the web
https://esbuild.github.io/
MIT License
37.93k stars 1.13k forks source link

About the Golang filepath fix on wasm #3875

Open Zxilly opened 1 month ago

Zxilly commented 1 month ago

Recently I was working on my own project go-size-analyzer which contains a wasm compilation target, so I started checking for wasm related issues in the go compiler.

In this process, I noticed https://github.com/golang/go/issues/43768 , an issue that also affects my application in some way. So I wrote a patch for it https://github.com/golang/go/pull/68831.

It seems esbuild has been using go's wasm target for quite some time now, and I was wondering what your thoughts are on this fix? If this fix is merged, will it help esbuild development?

evanw commented 1 month ago

It would be wonderful if this bug in Go was finally fixed. However, I believe your fix would be irrelevant for esbuild as esbuild had to fork the entire Go file system library to avoid this bug, which was over three years ago now. Here's what esbuild does:

https://github.com/evanw/esbuild/blob/9c13ae1f06dfa909eb4a53882e3b7e4216a503fe/internal/fs/iswin_wasm.go#L17-L21

https://github.com/evanw/esbuild/blob/9c13ae1f06dfa909eb4a53882e3b7e4216a503fe/internal/fs/fs_real.go#L67-L73

Zxilly commented 1 month ago

My idea is that the user can write this logic in glue js and at the same time it will work fine by default. The esbuild hack seems to work for the most part, but operations like os.Stat("C:\") may always return err if you consider running in a browser. Considering that we now have the FileSystem API, this could be unnecessarily annoying.