Hugo

How to build hugo with locally modified version of Chroma

Hello,

I would like to submit a PR to Chroma. But before doing so, I would like to build Hugo using my custom Chroma version. That will help me check if the syntax highlighting issue I am attempting to fix is actually fixed.

I am building hugo using the usual go build .. command and it builds fine. But looks like it is not fetching my modified version of Chroma.

Apparently this has to do with Go Modules. So what do I need to do so that Hugo builds as usual but using the local version of only Chroma?

Thanks.

1 Like

@bep Can you help me out with this?

See https://github.com/golang/go/wiki/Modules below “replace directive”:

One sample use case is if you need to fix or investigate something in a dependency, you can have a local fork and add the something like the following in your top-level go.mod :

replace example.com/original/import/path => /your/forked/import/path

1 Like

Thank you. I’ll try that out when I get to a computer next week (in-between packing and moving right now).

I tried doing what you suggested but it failed with the error:

go: parsing …/…/alecthomas/chroma/go.mod: open /home/kmodi/go.apps/src/github.com/alecthomas/chroma/go.mod: no such file or directory
go: error loading module requirements

I added this to Hugo’s go.mod:

replace github.com/alecthomas/chroma => /home/kmodi/go.apps/src/github.com/alecthomas/chroma/

What is the value of GOPATH? You will make it easier for you if you put all your modules outside of the GOPATH. Also, you could try to get the latest Go version and see if that changes it. The above should just work.

/home/kmodi/go.apps

Hmm, let me try that.

I am already on the latest, go 1.12.

I got the same error even after pointing to my local Chroma source outside of GOPATH:

go: parsing /home/kmodi/sandbox/go/chroma/src/go.mod: open /home/kmodi/sandbox/go/chroma/src/go.mod: no such file or directory
go: error loading module requirements

I think the issue is that the Chroma repo does not have a go.mod file. Looks like the replace command can be used only for Go Modules compatible projects?

OK, I got around that after running go mod init in the local clone of Chroma repo.

Finally it’s using the local Chroma version (tested by creating an arbitrarily compile error :grin:).


Update: As I was submitting my syntax highlighting fix PR, I realized that my local master of the chroma repo was a bit behind … go.mod had been added to Chroma upstream a while back … so I wouldn’t have needed go mod init in that case.