mirror of
https://github.com/caddyserver/xcaddy.git
synced 2025-01-22 08:36:28 +01:00
Handle package import paths that are in subfolders of Go module path
This commit is contained in:
parent
823a072ae1
commit
8266ddc40e
2 changed files with 20 additions and 4 deletions
|
@ -21,6 +21,7 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
@ -192,11 +193,20 @@ func runDev(ctx context.Context, args []string) error {
|
|||
})
|
||||
}
|
||||
|
||||
// reconcile remaining path segments; for example if a module foo/a
|
||||
// is rooted at directory path /home/foo/a, but the current directory
|
||||
// is /home/foo/a/b, then the package to import should be foo/a/b
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to determine current directory: %v", err)
|
||||
}
|
||||
importPath := path.Join(currentModule, strings.TrimPrefix(cwd, filepath.ToSlash(moduleDir)))
|
||||
|
||||
// build caddy with this module plugged in
|
||||
builder := xcaddy.Builder{
|
||||
CaddyVersion: caddyVersion,
|
||||
Plugins: []xcaddy.Dependency{
|
||||
{ModulePath: currentModule},
|
||||
{ModulePath: importPath},
|
||||
},
|
||||
Replacements: replacements,
|
||||
RaceDetector: raceDetector,
|
||||
|
|
|
@ -131,10 +131,16 @@ func (b Builder) newEnvironment(ctx context.Context) (*environment, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nextPlugin:
|
||||
for _, p := range b.Plugins {
|
||||
// if module is locally available; do not "go get" it
|
||||
if replaced[p.ModulePath] != "" {
|
||||
continue
|
||||
// if module is locally available, do not "go get" it;
|
||||
// also note that we iterate and check prefixes, because
|
||||
// a plugin package may be a subfolder of a module, i.e.
|
||||
// foo/a/plugin is within module foo/a.
|
||||
for repl := range replaced {
|
||||
if strings.HasPrefix(p.ModulePath, repl) {
|
||||
continue nextPlugin
|
||||
}
|
||||
}
|
||||
err = env.execGoGet(ctx, p.ModulePath, p.Version)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue