Debugging the PHP generated LESS in More JSON SourceMap

Debugging the PHP generated LESS in More JSON SourceMap

by Gareth J Barnard -
Number of replies: 10
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hi Themers,

Whist getting ready for iMoot I noticed that the source mapping of the LESS files in Shoelace for M2.9 (now using the core PHP LESS compiler) in Chrome was not getting the correct URI for the source file, i.e:

LESS source map URI wrong

Thus if you clicked on this then the file would not be found = annoying!

So after trawling through the code I found that in '/lib/lessphp/SourceMap/Generator.php' (line 206) changing from:

$this->sources[$fileInfo['currentUri']] = $fileInfo['filename'];

to:

$this->sources[$fileInfo['currentUri']] = $fileInfo['currentUri'];

rectified this to:

LESS Source map URI corrected

which means that now clicking on the file will take you to that file and line number = useful debugging of the theme.

So, before I create a tracker etc.  Could you verify that what I've done is correct and ok please?  Or is there another solution where it is as it was but because the way the library has been set-up for 'inline' source maps that setting it otherwise would cause breakage?  But as this cannot be normally done except by editing core code that this is a good fix for Moodle.

To replicate, use Chrome with its web developer tools (F12), turn on theme designer mode and use the More theme.

Cheers,

Gareth



Average of ratings: -
In reply to Gareth J Barnard

Re: Debugging the PHP generated LESS in More JSON SourceMap

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi,

Considering that the problem you have is because you are using an alternative theme directory location, so the file name, although that in itself is correct, it is the URL that is the problem.

So if I tested this on my server I would not get that problem as my themes are in Moodle not outside in a remote place.

That said, your suggestion looks to be valid, so open a Tracker and ask at least you have seen a potential problem for Moodle Partners if nothing else, as these are the sort of organisations that use the alternative location of a theme directory, eg., Remote Learning

Cheers

Mary

In reply to Mary Evans

Re: Debugging the PHP generated LESS in More JSON SourceMap

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hi Mary,

Thank you for your reply.

This is to do with the standard 'theme' folder where themes are installed with a 'not set' for '$CFG->themedir', thus an issue for all themes that use the PHP LESS compiler in the standard place when TDM is on.

So if you were to test on your server, then you could replicate.

Cheers,

Gareth

In reply to Gareth J Barnard

Re: Debugging the PHP generated LESS in More JSON SourceMap

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Forgive me if I have this wrong, but the fact the URL of your first example is a very long URL, which has theme/theme in it. So if you are using a theme in an alternate place then you should have $CFG->themedir 

I don't use Chrome so is this true for Firefox also?

going off to check it out ... I may take some time...Ouch!

In reply to Mary Evans

Re: Debugging the PHP generated LESS in More JSON SourceMap

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hi Mary,

The URL in the first example is very long because the code is broken!  The theme I'm using is in the normal place.  The URL as you can see has a specific file system path after 'theme/theme' - as I have my HD partitioned, thus I have an 'F:'.  The second 'theme' at the start comes from about line 1083 of the 'get_css_content_from_less' method in '/lib/outputlib.php'.

This only works on Chrome as Firefox does not support source maps yet.

And... the code is clearly broken as the URL having a complete 'filename' path would need the 'file:' URL protocol prefix instead of 'http:'.

Cheers,

Gareth

In reply to Gareth J Barnard

Re: Debugging the PHP generated LESS in More JSON SourceMap

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Yep! I concur with your findings.

I learned something new today!

Thanks

Mary

In reply to Gareth J Barnard

Re: Debugging the PHP generated LESS in More JSON SourceMap

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers
In reply to Mary Evans

Re: Debugging the PHP generated LESS in More JSON SourceMap

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Thanks for looking Mary, I've actually discovered that my solution does not quite work as it gets the 'bootstrap' folder right but not 'shoelace'.  This is in relation to the root of the theme and the parent / child being a level up then down.  Something I've experienced when generating source maps when using the 'grunt' method to control the 'less' compiler too.  The tracker issue looks like the library was updated to the latest and 'played around a bit' to test.

Back to the drawing board, but have some hunches.

In reply to Gareth J Barnard

Re: Debugging the PHP generated LESS in More JSON SourceMap

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Will you still report this finding as it is wrong?

By the way I tested it using my MoreCandy theme which is a clone of More theme.

Cheers

Mary