Skip to content
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

hugo mod removes non-Hugo modules from go.mod #6115

Open
deanishe opened this issue Jul 26, 2019 · 21 comments
Open

hugo mod removes non-Hugo modules from go.mod #6115

deanishe opened this issue Jul 26, 2019 · 21 comments
Milestone

Comments

@deanishe
Copy link

I use mage to manage my sites (download data, publish via rsync, run pngquant on resized images…), and go mod adds mage's dependencies to go.mod.

Hugo removes them every time I run it.

How do I get Hugo modules to play nice with regular Go modules? Is there an option to make it write its dependencies to, say, hugo.mod instead of the go.mod file?

@bep
Copy link
Member

bep commented Jul 26, 2019

Is there an option to make it write its dependencies to, say, hugo.mod instead of the go.mod file?

Not that I know of, but I would be happy to be proven wrong. I would say that I cannot currently fix your problem, but I will think about it.

@bep bep modified the milestones: v0.57, v0.56.1 Jul 26, 2019
@bep
Copy link
Member

bep commented Jul 26, 2019

OK , thinking a little I think I know what we can do. I have implemented my own "tidy logic" because Go does not understand Hugo's imports. We can adjust that so:

  1. Store away the go.* content
  2. First run go tidy. In most situations this should make them empty.
  3. Apply Hugo's logic, but keep any lefovers from 2)

@deanishe
Copy link
Author

Sounds like a reasonable workaround. Shame Hugo can't use a different file.

@bep
Copy link
Member

bep commented Jul 26, 2019

Shame Hugo can't use a different file.

Or Mage.

image

I have double-checked the Go source, and go.mod is very much hardcoded ... all over the place.

I will take another round on this and check what Go does with these files on regular use, but I suspect that it will be a variant of the above and that with your setup you cannot use "go mod tidy" as that will wipe out the non-Go entries.

@deanishe
Copy link
Author

Or Mage.

It's not Mage. It's go mod doing its thing.

go.mod is very much hardcoded ... all over the place.

That certainly is very hardcoded. Oh well…

as that will wipe out the non-Go entries

I'm not currently using Hugo modules. But it appears that the presence of a go.mod file causes Hugo to run its tidy routine when building or serving.

Also, wouldn't go mod only remove Hugo's entries if you explicitly run tidy?

@bep bep modified the milestones: v0.56.1, v0.56.2, v0.56.3, v0.57, v0.58 Jul 27, 2019
@deanishe
Copy link
Author

deanishe commented Aug 6, 2019

If this isn't getting added any time soon, could you make Hugo behave the same as go mod and only remove entries from go.mod when explicitly told to do so (or at least only when hugo mod is run)?

Currently, it clears out go.mod every time I build the site or run hugo server, which means I have to undo its changes basically every time I run Hugo (and stop hugo server first, otherwise it'll just remove the entries again).

@bep bep modified the milestones: v0.57, v0.58 Aug 13, 2019
@myitcv
Copy link
Contributor

myitcv commented Aug 15, 2019

Just run into this as well. I'm not quite sure how Hugo modules are implemented, but I suspect they should be using an approach similar to the way in which tool dependencies are declared?

https://github.com/go-modules-by-example/index/blob/master/010_tools/README.md

i.e. the dependencies need to be declared in Go code if go mod tidy is to see them.

@bep bep modified the milestones: v0.58, v0.57.1 Aug 15, 2019
@bep
Copy link
Member

bep commented Aug 15, 2019

i.e. the dependencies need to be declared in Go code if go mod tidy is to see them.

Which is exactly what Hugo does (if you replace "Go code" with "Hugo source"), which is also where the problem lies.

bep added a commit that referenced this issue Aug 15, 2019
@bep
Copy link
Member

bep commented Aug 15, 2019

I have "turned off" the tidy during regular builds. WIll be in Hugo 0.57.1. You will still see this problem if you do hugo mod tidy.

@myitcv
Copy link
Contributor

myitcv commented Aug 15, 2019

which is also where the problem lies.

Just wanted to make sure we're talking about the same thing here: for go mod tidy to work, the dependencies will need to be declared in Go code.

So if you have dependencies declared in "Hugo source" then you will likely need to code generate a build-ignored .go file that also includes those dependencies:

// +build ignore

package hugodeps

import (
	_ "example.com/hugo/dep"
)

@bep
Copy link
Member

bep commented Aug 15, 2019

Just wanted to make sure we're talking about the same thing here: for go mod tidy to work, the dependencies will need to be declared in Go code.

We're obviously not. This is not about go mod tidy.

@bep bep modified the milestones: v0.113.0, v0.115.0 Jun 13, 2023
@bep bep modified the milestones: v0.115.0, v0.116.0 Jun 30, 2023
@bep bep modified the milestones: v0.116.0, v0.117.0 Aug 1, 2023
@bep bep modified the milestones: v0.117.0, v0.118.0 Aug 30, 2023
@bep bep modified the milestones: v0.118.0, v0.119.0 Sep 15, 2023
@bep bep modified the milestones: v0.119.0, v0.120.0 Oct 4, 2023
@bep bep modified the milestones: v0.120.0, v0.121.0 Oct 31, 2023
@bep bep modified the milestones: v0.121.0, v0.122.0 Dec 6, 2023
@bep bep modified the milestones: v0.122.0, v0.123.0, v0.124.0 Jan 27, 2024
@bep bep modified the milestones: v0.124.0, v0.125.0 Mar 4, 2024
@bep bep modified the milestones: v0.125.0, v0.126.0 Apr 23, 2024
@bep bep modified the milestones: v0.126.0, v0.127.0 May 15, 2024
@bep bep modified the milestones: v0.127.0, v0.128.0 Jun 8, 2024
@bep bep modified the milestones: v0.128.0, v0.129.0 Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants