mirror of
https://github.com/caddyserver/xcaddy.git
synced 2025-02-02 06:07:24 +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"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"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
|
// build caddy with this module plugged in
|
||||||
builder := xcaddy.Builder{
|
builder := xcaddy.Builder{
|
||||||
CaddyVersion: caddyVersion,
|
CaddyVersion: caddyVersion,
|
||||||
Plugins: []xcaddy.Dependency{
|
Plugins: []xcaddy.Dependency{
|
||||||
{ModulePath: currentModule},
|
{ModulePath: importPath},
|
||||||
},
|
},
|
||||||
Replacements: replacements,
|
Replacements: replacements,
|
||||||
RaceDetector: raceDetector,
|
RaceDetector: raceDetector,
|
||||||
|
|
|
@ -131,10 +131,16 @@ func (b Builder) newEnvironment(ctx context.Context) (*environment, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
nextPlugin:
|
||||||
for _, p := range b.Plugins {
|
for _, p := range b.Plugins {
|
||||||
// if module is locally available; do not "go get" it
|
// if module is locally available, do not "go get" it;
|
||||||
if replaced[p.ModulePath] != "" {
|
// also note that we iterate and check prefixes, because
|
||||||
continue
|
// 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)
|
err = env.execGoGet(ctx, p.ModulePath, p.Version)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue