-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Less file not listed in sources sourcemap array if it contains only variables #2981
Comments
And how it's supposed to get there? The sourcemap only maps generated CSS code (selectors, properties etc.) to its corresponding Less code, and variables on there own never produce any CSS code at all. So no Unless you're also expecting just |
Do you have a source (no pun intended) for that? Everything I've seen in the spec and elsewhere says something along the lines of "An array of URLs to the original source files". I guess that's somewhat ambiguous, but to me 'variables.less' is a source file even if it doesn't directly map 1:1 with a line of code. Other compilers like Sass and Stylus also follow my interpretation of what should be in the sources array. For example with Sass:
@import "_variables.scss";
a { color: $theme-primary; }
$theme-primary: #2C3E50;
{ "sources":["/styles/main.scss","/styles/_variables.scss"] } I will explain why this is important to me because otherwise it might seem like I'm nitpicking... I'm creating a compile and live-reload tool (https://github.com/davej/piggy-in-the-middle/). It compiles less/sass/stylus/coffeescript/babel etc.. and re-compiles whenever there is a change in a source file which is read from the I'm happy to jump into the code and create a PR for this if it would be accepted 😀 |
Source Map Revision 3 Proposal, page 4.
It makes sense... But for your goal in general I'd say it's like you're trying to interpreter rather simple "mapping" table (after all this is why it's named "SourceMap") like a full-featured and comprehensive debugging-info/reflection/reverse-engineering database. (Nothing wrong, just a bit weird if the whole idea is based on a not initially intended facility).
Good for them, but others then are free to complain of rather redudant and bloating data most of users cannot ever see/use (so if it's to be interpreted like it's time for an Independend SourceMap Spec. (Ext.) fork :). P.S. Though technically, if the PR breaks nothing I see nothing wrong with it too (so changing labels). |
Thanks for that link, I read it before but missed the part about it being "used by the mappings". I wonder could this be considered anyway. I'll give a few reasons:
|
The only problem is that as soon as we start using the sourcemap as a sort-of automatically generated "project settings" file (or at least "watch-list" file), issues are starting to pile up quite quickly: for example it's not just Less (or whatever preprocessor) files may be used in the build but also others, i.e.:
According to the new approach all of these now should also be referenced in the sourcemap (I'm not even counting that some of that external stuff may also reference even more external stuff and so on and so on). |
Ok, am I better off waiting for more input on this before doing a PR? i.e. Do you think there is a good chance the PR will be rejected? By the way, my proposal would be to only include Less files. I think the Chrome screenshot I've referenced above makes a compelling case for the feature by itself. |
I'd wait for @matthew-dean opinion. |
Hmm. My understanding up to this point of using source maps was that files that don't have a direct mapping aren't listed in sources, but.... some of that understanding (or mis-understanding) may have come from trying to understand how Less generates source maps. For the most part, I think Less maps are ruleset-based. I do know that the way Less is parsed doesn't actually allow as much resolution on maps as the spec defines (because Less has always only marked the start character of a parsed object but not the end character). And part of that not seeming like a problem in the past is that developer tools typically just show ruleset mappings. As @seven-phases-max mentioned, there are sources pulled from that don't really make sense (or do they?) in the list of sources, such as fonts. There would be no mappings from point A in a On the other hand..... if a Less JS plugin rendered a Less node, being able to trace the source back to that function would be pretty amazing. @davej When I was creating my compile-as-you-go app, I originally thought about using sources as well, and probably realized I couldn't when Less returned its results. I ended up having to execute compiling in a separate spawned Node thread, and then I monkey-patched the Node FS module to assemble a list of every file that was being requested. So, long and short, if you're trying that approach, and finding the Less.js is the only one that doesn't list all sources retrieved while compiling, then it should definitely be changed. The specification doesn't spell it out entirely what should happen, especially if a section of code, in reality, has a "chain" of sources to render that one piece. On the flip side...... some decisions would need to be made. If you include the original source in sourcesContent, then binary sources would, I think, need to be excluded. However, you could still keep them in the sources key by setting the corresponding sourcesContent to null for things like fonts or images that are rendered inline. Just mentioning that because if this is added, there will need to be tests added to make sure that binary content doesn't end up in the sourcesContent when that option is set (and that it doesn't just omit that value in the sourcesContent array or mappings values leading to mis-matched mappings). So.... final opinion from me - considering the inclusion of sourcesContent is a value in the spec in the first place, it's clear that source maps are designed to be as verbose as necessary. I see no inherent harm in including every referenced source, no matter what that source might be. It's possible this would have saved me loads of time approaching this problem a few years ago similar to you're facing now. Weighing all that, I'd vote yes. |
Ideally, this should be addressed along with #2974. |
Thanks! Ok, I'll try to schedule this in over the next couple of weeks. I'm completely new to the less codebase so any pointers on where to get started when working on this, or potential gotchas. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
FYI; yes. Less is the odd one out. Webpack will fill in any missing files with their compiled result when it - rightfully - assumes that if there's nothing to chain off of, you're actually dealing with a true source file. E.g. if your less entrypoint only contains I would actually classify this as a BUG as it profoundly messes up downstream debugging tools. Which is precisely what source maps are meant for, in the first place. |
@matthew-dean When picking this up, you might as well fix another issue related to source-maps as well: Those are supposed to be URLs and failure to comply with that leads to a lot of malformed sourcemap source paths on the Windows OS, where the filesystem path separator is See e.g. mozilla/source-map#91 or mozilla/source-map#355 (Source map handling seems to be a huge mess across the board when it comes to anything within the Webpack ecosystem, it seems. It'll need fixing from front-to-back, so might as well start at the compiler itself.) |
If I import a less file that only includes variables then it does not get included in sources. Here's an example, notice that the map file at the end does not include
variables.less
as a source.main.less
variables.less
main.css.map
The text was updated successfully, but these errors were encountered: