[Feature request] Specify sourceURL in build without stdin
- Dominant language
- Go
- Stars
- 40.1k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
Hi! I noticed some weird issues with source maps and error stacktraces when using `executeJavaScript` in the Electron APIs. This is because this is effectively the same action as pasting the passed code into DevTools.
Take the following code (adapted from my own build scripts):
```js
// build.js
import * as esbuild from "esbuild";
/** @type {import("esbuild").BuildOptions} */
const esbuildConfig = {
entryPoints: ["./input.js"],
outfile: "./output.js",
sourcemap: "inline"
};
await esbuild.build(esbuildConfig);
```
```js
// input.js
try {
throw new Error("Test error");
} catch (e) {
console.log(e);
}
```
This produces the input verbatim, plus a `//# sourceMappingURL`, which is expected. But, when running this code in my program with `executeJavaScript`, I get the following stacktrace:
```
Error: Test error
at :2:9
(my code that ran executeJavaScript follows, redacted for brevity)
```
Anonymous! Not great. The source map seems to not be loading.
Now, if I add the line `//# sourceURL=blah.js` to the end of my output script:
```
Error: Test error
at input.js:2:9
(my code that ran executeJavaScript follows, redacted for brevity)
```
There's some weird behavior going on here where specifying a sourceURL in DevTools causes it to load the source map, even if the provided URL is garbage. I don't entirely know what causes this, but **TL;DR I want to be able to specify sourceURL in build without using stdin**.
The following does not work:
```js
// build.js
import * as esbuild from "esbuild";
/** @type {import("esbuild").BuildOptions} */
const esbuildConfig = {
entryPoints: ["./input.js"],
outfile: "./output.js",
sourcemap: "inline",
sourcefile: "blah.js"
};
await esbuild.build(esbuildConfig);
```
...because it expectedly errors with `Invalid option in build() call: "sourcefile"`, because this isn't supported by esbuild.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.