-
-
Notifications
You must be signed in to change notification settings - Fork 118
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
Add --replace
for dependency replacement
#186
Conversation
Interesting! How would you feel if we simply made a new flag called I think the ~ syntax is a little wonky :) |
69e93ba
to
2a93ed7
Compare
--replace
for dependency replacement
I think it could be refactored a bit to deduplicate the code, but it's short enough to not really be a problem. Please also update the readme with the new option |
You can even replace Caddy core using the `--replace` flag: | ||
|
||
``` | ||
$ xcaddy build \ | ||
--with github.com/caddyserver/caddy/v2=../../my-caddy-fork | ||
--replace github.com/caddyserver/caddy/v2=../../my-caddy-fork | ||
|
||
$ xcaddy build \ | ||
--with github.com/caddyserver/caddy/v2=github.com/my-user/caddy/v2@some-branch | ||
--replace github.com/caddyserver/caddy/v2=github.com/my-user/caddy/v2@some-branch | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, technically it still works with --with
cause we check for that. I think here it should show an example replacing a dep like x/net
as you're doing, it's a better example.
@@ -73,6 +74,7 @@ $ xcaddy build [<caddy_version>] | |||
|
|||
- `--output` changes the output file. | |||
- `--with` can be used multiple times to add plugins by specifying the Go module name and optionally its version, similar to `go get`. Module name is required, but specific version and/or local replacement are optional. | |||
- `--replace` can be used multiple times to replace dependencies to specific forks or local replacements. Useful in development environment to fix bugs in dependencies. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `--replace` can be used multiple times to replace dependencies to specific forks or local replacements. Useful in development environment to fix bugs in dependencies. | |
- `--replace` can be used multiple times to replace dependencies to specific forks or local replacements. Useful in development environment when trying to fix bugs in Caddy's dependencies, via a fork or local checkout. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about "--replace is like --with, but does not add a blank import to the code; it only writes a replace directive to go.mod, which is useful when developing on Caddy's dependencies that aren't Caddy modules." ?
This LGTM, but I agree with the readme suggestions to make things a little clearer. I'll merge this so we can at least tag a release with it since the code apparently works. |
Officially--with
is used to add caddy modules to a caddy build. It can be used to change dependencies for a caddy build, i.e. change caddy core to a fork, use quic-go fork.However, some dependencies can't be replaced this way, for examplegolang.org/x/net
can't be replaced this way.For dependencies this introduces a new grammar that a~
prefix to a with to mean it's a dependency instead of a module.I can't think why someone would want to name their plugin with a~
, is it even allowed by golang? It will break caddy builds for those unfortunate souls.Add
--with
option to replace dependency.Also fixed when replacing, module version is lost. According to go documents,
If the @v in old@v is omitted, a replacement without a version on the left side is added, which applies to all versions of the old module path.