evanw / esbuild

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

Request: support "indexed" source maps #3439

Open seanstrom opened 11 months ago

seanstrom commented 11 months ago

Hello 👋

I have a request for functionality related to how esbuild supports source maps at the moment. And in this case I would to request some additional support for source maps with the sections field, a.k.a "indexed" source maps

The reason for this request is because I'm using some tooling that compiles to JavaScript and provides a source map with this indexed source map format. And at the moment, these source maps are not supported by esbuild: https://github.com/evanw/esbuild/blob/02dae18a70b3d26dcb5b9599f02a9a36d88f809d/internal/js_parser/sourcemap_parser.go#L38-L41


But I'm hoping that it would be possible to "flatten" these indexed source maps in a way that is similar to Webpack's approach seen here. What are your thoughts? Let me know what you think 🙏

evanw commented 11 months ago

I have done a lot of work with source map infrastructure over the years and I've only ever encountered one indexed source map (by chance, on a random website). So I don't actually really have any test cases to go by. It'd be helpful for you to provide a way to reproduce your issue here (i.e. providing specific code with specific build instructions).

seanstrom commented 11 months ago

Yup yup sure thing 👍

Here's a minimal example of my specific use case of compiling from ClojureScript to JavaScript: https://github.com/seanstrom/cljs-dev-template/tree/minimal-sourcemaps-debug-esbuild

I've included some instructions inside the README of that branch, should be as simple as setting the local environment to have some dependencies like Java, Clojure, and Node. And then running some NPM scripts for compiling the source code and bundling the outputs with esbuild. If you need specific version numbers for the environment dependencies, you can reference the .tool-versions file.

If you need any help with setting up the project, please let me know 🙏

jridgewell commented 11 months ago

I have done a lot of work with source map infrastructure over the years and I've only ever encountered one indexed source map

They're definitely rare. Turbopack is the only build tool I know of that generates them purposefully (it interacts with our caching infrastructure gracefully), but we're not currently used in any npm libraries that esbuild would then have to consume. Maybe in the future they'll be more popular.

seanstrom commented 9 months ago

@evanw have you looked over the build steps and and code the I've linked? I'm wondering, is there anything else I can do to help add this functionality?

At the moment, I've also noticed that Vite is missing support for "indexed" source maps, though I have been able to patch Vite by re-using the logic that Webpack's source-map-loader uses to "flatten" these sections into a source map. Curious to get your thoughts on the flattening process since that seems to compose a single source map from all the sections, but I'm not sure how that's exactly done.

evanw commented 3 months ago

For my own benefit, here's a more minimal reproduction created from that repo (note that I don't know anything about Clojure myself):

Playground link

seanstrom commented 3 months ago

Nice stuff! Moving forward I'll try adapting my experiments into these esbuild playgrounds. And please lmk if you'd like me to test any esbuild changes, or if you'd like some help figuring out these source-map specs for sections support.