Can't do module replacement with github forks

This issue has been created since 2021-02-21.

So I want to have a replacement like:

replace => caddyfile

So I try this:

xcaddy build --with[email protected]

But it does this:

2021/02/21 07:25:03 [INFO] exec (timeout=0s): /usr/local/go/bin/go get -d -v[email protected]
go get[email protected]: malformed module path "": invalid char '='

This obviously isn't quite right, cause it never did the go mod edit -replace.

Next I tried without @caddyfile (my branch), and I get this:

2021/02/21 07:29:24 [INFO] Resolved relative replacement to /root/
2021/02/21 07:29:24 [INFO] Replace => /root/
2021/02/21 07:29:24 [INFO] exec (timeout=10s): /usr/local/go/bin/go mod edit -replace
caddy imports[email protected]: replacement directory /root/ does not exist

So xcaddy thinks that path is relative but it's not, it's a git repo.

I think to detect if it's relative, we should look if there's a . in front, so if you want to refer to something in the current dir then you do ./blah in the replacement. That should allow github module paths to work.

The workaround obviously for now is to git clone the relevant repo then use a relative path on that, but it would be nice so that people can easily test branches/PRs for plugins without cloning.

mholt wrote this answer on 2021-02-22

Hmm, wouldn't you just change the require dependency from to

francislavoie wrote this answer on 2021-02-22

No because that would imply the master branch, but if it's not on the master branch that won't work.

mholt wrote this answer on 2021-02-22

Set the version of that require directive to another branch then?

francislavoie wrote this answer on 2021-02-22

What do you mean? What would the command look like?

mholt wrote this answer on 2021-02-22

require directives consist of a module name and a version: v0.1.3

so instead of a version on the master branch, choose a different branch name.

francislavoie wrote this answer on 2021-02-22

Right but you would do that with @ in the xcaddy command, but that doesn't work. Did you miss that in the post above (2nd code block)?

mholt wrote this answer on 2021-02-22

I mean do this instead:

xcaddy build --with[email protected]
francislavoie wrote this answer on 2021-02-22

That won't work because the module in that repo is so a replace needs to happen.

mholt wrote this answer on 2021-02-22

Oh... I see... how does the go tool determine which kind of replacement to do, I wonder? (Can look into it later)

francislavoie wrote this answer on 2021-02-22

It does it just fine if you specify go mod edit -replace[email protected] but the problem is our "relative path" resolve step breaks it at the xcaddy CLI layer. (this is all explained above)

mohammed90 wrote this answer on 2021-02-22

FWIW, I started working on it last night but didn't finish it. This is where I'm at now.


diff --git a/cmd/xcaddy/main.go b/cmd/xcaddy/main.go
index 001f462..39d8b72 100644
--- a/cmd/xcaddy/main.go
+++ b/cmd/xcaddy/main.go
@@ -76,7 +76,7 @@ func runBuild(ctx context.Context, args []string) error {
 			if repl != "" {
 				// adjust relative replacements in current working directory since our temporary module is in a different directory
-				if !filepath.IsAbs(repl) {
+				if strings.HasPrefix(repl, ".") && !filepath.IsAbs(repl) {
 					repl, err = filepath.Abs(repl)
 					if err != nil {
 						log.Fatalf("[FATAL] %v", err)
@@ -288,7 +288,9 @@ func trapSignals(ctx context.Context, cancel context.CancelFunc) {
 func splitWith(arg string) (module, version, replace string, err error) {
 	const versionSplit, replaceSplit = "@", "="
-	parts := strings.SplitN(arg, versionSplit, 2)
+	modules := strings.SplitN(arg, replaceSplit, 2)
+	parts := strings.SplitN(modules[0], versionSplit, 2)
 	module = parts[0]
 	if len(parts) == 1 {

Test run:

=== RUN   TestSplitWith
    caddyserver/xcaddy/cmd/xcaddy/main_test.go:72: Test 2: Expected module 'replace' but got '' (input='[email protected]=replace')
    caddyserver/xcaddy/cmd/xcaddy/main_test.go:72: Test 3: Expected module 'replace' but got '' (input='module=replace')
francislavoie wrote this answer on 2021-02-22

It also needs to support [email protected]

mohammed90 wrote this answer on 2021-02-22

It also needs to support [email protected]


but didn't finish it


More Details About Repo
Owner Name caddyserver
Repo Name xcaddy
Full Name caddyserver/xcaddy
Language Go
Created Date 2020-03-21
Updated Date 2022-09-22
Star Count 381
Watcher Count 14
Fork Count 72
Issue Count 3


Issue Title Created Date Comment Count Updated Date
hello Why is the default content displayed in the first page of word 1 2022-03-07 2022-09-15
Document serial number is missing. 2 2022-03-22 2022-09-13
Surface exceptions in recipes that occur in applicable tests, `visit(List, ExecutionContext)` 0 2022-09-10 2022-09-28
mockCall doesn't work when using it with expectRevert. 2 2022-06-07 2022-09-17
[Bug] pageInfo cannot be disabled 1 2022-05-29 2022-09-25
[Request] Mod Compatibility with "Friends & Foes" 0 2022-08-01 2022-09-14
main function references nonexistent location for logfile 1 2022-04-21 2022-08-29
Checkout 0 2021-03-12 2022-09-26
[PSyAD] Problem with uninitialised array accessed in loop 3 2022-02-04 2022-08-05
Error while launching Carla 0 2021-07-21 2022-09-10
'Hide My Email' does not return the privacy relay email with 'Sign in with Apple' 7 2022-07-31 2022-09-27
ModernAppsNinja Github Org Shutting Down 0 2022-03-14 2022-09-13
Unable to run in Ubuntu 16.04 1 2021-10-11 2022-09-08
Find better way to handle signing keys for Zabbix 5 2021-10-31 2022-09-17
Modelling the variance in linear regression (heteroscedasiticy) 5 2022-02-08 2022-07-14
Add install powershell or batch script to the final zip. 2 2021-10-30 2022-08-10
hyphenrules and \hyphenation 5 2021-03-15 2022-09-16
Invalid constructor input for SetNodePoolSizeRequest: xxx 4 2021-08-05 2022-09-19
Error:Cannot invoke method systemProperty() on null object 1 2016-11-21 2022-09-22
[MU4 Issue] Grace note stem custom direction in MU3 score is lost 2 2022-05-30 2022-08-20
README does not mention COPYING files 0 2021-07-06 2022-08-12
[Feature Request] Support Youtube Music mixes 4 2020-03-20 2022-07-09
Steam don't start via GUI or CLI 7 2022-06-04 2022-09-14
Move helper functions in `mass_univariate` to associated `_utils` 1 2022-05-11 2022-09-15
Different package name on Android and IOs 1 2021-07-19 2022-09-10
Resource Estimator: Generate new data 8 2022-02-07 2022-09-10
Error: Cannot find module 'default-browser-id' in v.6.5.2 16 2022-05-19 2022-09-16
How compare two strings and throw error in wrong case? 0 2022-04-19 2022-09-11
[onetrace] No SYCL kernel, using --demangle or other options yield no output 2 2022-03-15 2022-09-21
SourceRequest: Lazily provide local file path? 0 2021-04-18 2022-09-20
Download Mission triggers User callback queue overflown error 7 2021-05-18 2022-08-25
Is it normal for functions to be called multiple times in StorageProvider? 3 2020-05-27 2022-09-25
Custom guzzle logging system 0 2021-06-22 2022-09-21
nvidia-dcgm-exporter creates huge logs inside container 6 2021-05-04 2022-09-17
DCGM exporter crashes when installed by helm3 5 2021-04-29 2022-09-17
dcgm-exporter unit test depends on directly as a library 0 2021-03-30 2022-09-17
Support extracting WhiteSource data through API after the scanning. 4 2021-12-28 2022-08-07
Enable the WhiteSource native integration to other repositories under opensearch org 1 2022-01-03 2022-09-25
Support multiple webhooks 0 2021-10-05 2022-09-24
Inconsistent UI state, better renaming, action selector not working 2 2021-11-18 2022-08-23
SemiStructuredNode can't have no props 1 2020-02-24 2022-09-02
[YCQL] Full table counts using token ranges do not match data in table 5 2021-11-18 2022-02-07
HomeAssistant Update does not work 4 2021-10-09 2022-09-29
How to avoid thread block while call Futures.allAsList failed throwing exceptions 1 2022-03-31 2022-09-20
Visual Studio Tool Windows Not Snapping in FancyZones Again 2 2022-01-28 2022-09-03
[Bug] 从4.0.18开始,启动后报,fatal - TypeError: (0 , import_bundler_utils.createProxy) is not a function 1 2022-09-08 2022-09-22
zIndex on every Item 1 2021-03-24 2022-09-29
Allow scripted <route-meta/> 4 2020-02-23 2022-07-23
Flex 1.18.* version is not compatible with Composer 1.* version 0 2022-04-05 2022-09-21
pubspec.yaml packages are installed whose versions are incompatible with specified android version 2 2022-02-09 2022-09-24