-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat(swc): Add a new source maps option "linked" #6817
feat(swc): Add a new source maps option "linked" #6817
Conversation
6415acf
to
089104e
Compare
This breaks with both Babel's and esbuild's definition of |
089104e
to
c662620
Compare
Thank you @jridgewell. This is a good idea, I like it. I renamed the enum Example $ swc compile input.js --out-file=output.js --source-maps=linked |
I updated the title and the initial comment. |
Is this true? I think this is a bug.. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use true
for this instead
Nevermind. I concluded |
…rom the Cargo.toml files
@kdy1 I'm not sure why the bindings are in an isolated workspace. It complicates the development. |
I know, but there's a good reason |
@realtimetodie do you think that build failure for the node binding is caused by this change?
|
@alexeagle Yes, e4d8036 broke the build. Cargo pulls the swc_core crate from the remote crate registry now, which does not contain the new changes. Before that, the build passed. This is what I meant in #6817 (comment). I think @kdy1 will bump the version manually, once this is merged. |
Ping @kdy1 - we're waiting for this one so we can release the Bazel swc integration to 1.0.0 |
There's a merge conflict |
I resolved the merge conflict. The version of the swc_core crate is now set to 0.58.0. |
6cc1160
to
233b674
Compare
I had to delete the fixture test for the linked option due to the way the test runner works. It is not possible to construct a source map path from a .swcrc configuration alone, as the initial value is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was confused while reviewing for the first time, my bad.
Please see #6817 (comment)
I think what you mean with "implicitly determined" is to generate the source maps path within the compiler from.the filename, instead of passing it down as an argument? The reason why we can't "implicitly determine" the path to the source map file is because of the cli --source-map-target option. Currently, the user can define a custom output path for the generated source maps file when using the SourceMapsConfig::Bool(true) enum. I simply adopted this feature for the new SourceMapsConfig::Linked enum too. This is the only reason why the source_maps_path is passed down to the compiler. If you say that the cli --source-map-target option should be ignored let me know. I thought you saw this part in the code. |
Yep. I mean filename + But seems like it's my bad, sorry. I didn't know that |
Ah, I got it. It simply returned the I'm sorry, I didn't think about this carefully. (I stopped thinking to work on stc while thinking about the source map path option) |
It is also my fault, I did not point this out in the initial comment when i listed the changes and features. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, and sorry.
swc-bump:
- swc --breaking
I deleted my previous comments. I was too emotional. |
Oh CI failed |
I need to revert 4b303a2. |
4b303a2
to
8aa2c05
Compare
cc @kwonoj I think this can also be implemented by adding logic like https://github.com/swc-project/cli/blob/933589ae907637afb7f0b0a43b7a24a7a920595e/src/swc/compile.ts#L30-L33 in |
I thought more about this, and I think sourceMap=true should generate |
I apologize for not writing my thoughts about the implementationin the initial post. The main reason why I put the generation of the Secondly, I thought that third party consumers of the swc crate would greatly benefit from such a new feature SourceMapsConfig::Linked. Otherwise the feature would be hidden in the cli bindings crate, which is not meant to be consumed. I understand the concerns about the new Lines 438 to 442 in 33dab56
I also want to emphasize on @jridgewell #6817 (comment). The introduction of a new "linked" option helps users, because the configuration and naming convention will be aligned with other tools. |
I thought more about this. I think an ideal solution is use The problem is that,
and
|
@kdy1 Yes, the @swc/cli needs to be patched. However, the Node.js cli can handle multiple inputs at once and concats the outputs. If we combine the SourceMapsConfig::Bool(true) option as suggested, this will create a regression because every generated output will contain an URL to a non-existent source map file For this reason, we will always need an option to generate an output and a source map without a sourceMappingURL string. Ideally, we could try to move this part from the Node.js cli into Rust. But this would require a lot of effort. |
@kdy1 The @swc/cli can be patched in such a way, that users will not require to update their configuration (from true -> "linked") and the option "linked" would be invalid in Node.js. |
I linked to #1388 which is something I will be working on after this PR, as it is a bug in the Rust cli. |
I'm against adding an option which is invalid for |
Adds a new source maps option "linked" to generate a source map file and append a sourceMappingURL comment to the end of the output, containing an URL to the generated source map file.
This is only implemented in
@swc/cli
https://github.com/swc-project/cli/blob/933589ae907637afb7f0b0a43b7a24a7a920595e/src/swc/compile.ts#L31
Possible values for the --source-maps option
false (default): Disables the source map generation.
true: Generates a source map file, but without to append a sourceMappingURL comment to the end of the output.
inline: Generates a source map file and appends a sourceMappingURL comment to the end of the output, containing the base64 encoded source map.
New
linked: Generates a source map file and appends a sourceMappingURL comment to the end of the output, containing an URL to the generated source map file.
Example
Output
Show the last line of the generated output.js file
Summary
The source map path is now known to the compiler.
Replaced the enum
with the enumSourceMapsConfig::Str
SourceMapsConfig::Inline
and the enumSourceMapsConfig::Linked
.Replaced the enum
with the enumInputSourceMap::Str
InputSourceMap::Inline
.SourceMapsConfig::default()
is now set toSourceMapsConfig::Bool(false)
to match the compiler default (source map generation is disabled by default).Added the
FromStr
trait toSourceMapsConfig
.Added the
serde::Deserializer
trait toSourceMapsConfig
.Added the
serde::Deserializer
trait toInputSourceMap
.Added tests
Improved the error message when the
SourceMapsConfig::from_str
method is usedExample
Error message
Related