Closed djalbat closed 3 years ago
Yes, I stopped adding contents because there's sources
So you are aware that this breaks Browserify and ESBuild?
Even if sources are available for the project files being bundled they will not be available for the packages in the bundle. So users cannot debug package code.
Yes. I'm aware of it.
Why do they not use sources
?
I think they should handle sources
.
Because, as I point out above, the source files referenced in sources
are not necessarily available, even for project files, and almost certainly not available for package files. Both presuppose that the development server is able to serve them and in practice this is almost never the case.
So they does not handle even if it's possible to do so? What you said can be correct for browsers, but it's not correct for bundlers.
Actually I removed sourcesContent
because I got a request from webpack developer. Webpack handles it correctly, and there's nothing blocking browserify or esbuild from handling sources, like webpack.
If you only set the sources
property rather than provide the source file by way of the sourcesContent
property, the browser has no choice but to request the source file from the development server, unless the source file is contained in the bundle itself. This, as I understand it, is never the case for any bundler. The Webpack bundler typically runs in tandem with its own development server, in fact it is difficult to differentiate the two and most developers don't even appreciate the difference. But other bundlers work standalone, so to speak, and therefore to presuppose that a browser debugging a bundle that they have created has access to the source files by way of a development server is a little mistaken, shall we say.
I agree that swc should support configuring it, but it's for users who directly uses it.
You write:
I agree that swc should support configuring it...
Does that mean you would consider putting it back? If so, I would be very grateful.
You then write:
but it's for users who directly uses it.
Forgive me but I am not quite sure what you mean here. If you mean that users will need to explicitly instruct SWC to include the sourcesContent
property then I have absolutely no problem with that.
With this in mind, currently I pass an options object to SWC with the following properties:
{
fileName,
sourceMaps
}
I could pass in something like this instead:
{
fileName,
sourceMaps,
includeSourcesContent
}
Is this along the lines of what you are suggesting?
Yes, and I expect the name of option to be inlineSourceContents
.
Okay, great. Thank you very much and thank you for all of your hard work on SWC.
By the way, it is easy for me to fix this problem for anyone using SWC with my tool. See here:
https://github.com/djalbat/watchful-cli/blob/master/bin/utilities/transpile.js#L91-L127
I call your transformFile()
API function and get an object with code
and map
properties back. So I could simply open the file myself, call transform()
instead of transformFile()
and add the source content to the map myself. But this would only fix it for my users, not everyone else.
I had to manually adjust the source map by the way to get the sources
property to work will different platforms.
Your option should probably be inlineSourcesContents
to mirror sourcesContent
.
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
SWC has always added a
sourcesContent
property to source maps in the past. For example:https://github.com/djalbat/necessary/blob/master/lib/utilities/shell.js
This project is transpiled with SWC version 1.2.52.
If you un-encode and format the source map in this file you will get:
You can clearly see the
sourcesContent
property.If I now transpile this project with the latest version 1.2.86 of SWC, I get the following source map:
You can clearly see that the
sourcesContent
property is now missing.So between versions 1.2.52 and 1.2.86 of SWC you have stopped adding the
sourcesContent
property to source maps.The
.swcrc
file is: