MohammadYounes / rtlcss

Framework for transforming Cascading Style Sheets (CSS) from Left-To-Right (LTR) to Right-To-Left (RTL)
https://rtlcss.com
MIT License
1.68k stars 129 forks source link

Sourcemap weirdness #180

Closed ffoodd closed 3 years ago

ffoodd commented 3 years ago

Hi there!

I'm currently working on implementing RTL on Bootstrap v5, and while doing so I noticed that sourcemaps for RTLCSS processed files have some weirdness:

  1. a new source is mentionned, not part of our sources and not a file either;
  2. its path is URL encoded: %3Cinput%20css%202%3E (which results in <input css 2>);
  3. and AFAIK seems to be mapping to the /* rtl:raw */ directive.

So this is not really bug IMHO, however I think this should either be "customized" to mention something like "RTLCSS raw directive" or at least be mentionned somewhere in RTLCSS docs.

I'm not sure customizing sourcemaps in that case is doable, but would be really great :+1:

Thanks for your invaluable work, I'd be pleased to have some review from you one day :heart:

MohammadYounes commented 3 years ago

Hi,

Thanks for such a Great PR, It's a joy to see rtlcss has finally made it to the official bootstrap 👍

Yes, indeed, parsing CSS strings without setting its input source produces such result. Do you think it's better to have it point to the original file instead of <input ...> ?

ffoodd commented 3 years ago

If possible, I guess it'd be better indeed.

I'm wondering what you mean by "without setting its input source": is there some way to set the input on our side?

MohammadYounes commented 3 years ago

This need to be changed inside the plugin. The source can be set in postcss parse options

const root = postcss.parse(css, { from: 'a.css' })
root.source.input.from //=> "/home/ai/a.css"

const root = postcss.parse(css)
root.source.input.from //=> "<input css 1>"

see https://postcss.org/api/#input-from

MohammadYounes commented 3 years ago

@ffoodd I made a quick fix, I would appreciate it if you update to v2.6.2 and let me know the result.

ffoodd commented 3 years ago

Nice, I need to check if it suits our need.

As I said, that's not a bug at all. Thanks for your help!

ffoodd commented 3 years ago

@MohammadYounes Thanks a lot, it's really better! We now have bootstrap.rtl.css as a source <3

blimmer commented 2 years ago

For folks who find this issue trying to debug their application, here's the fix that was released in 2.6.2: https://github.com/MohammadYounes/rtlcss/commit/80c15f218ffffcb66459953e60c65a0b27b89344