diff --git a/changelog.md b/changelog.md index 3b0671acdf..fabdb85078 100644 --- a/changelog.md +++ b/changelog.md @@ -6,6 +6,7 @@ - [#4108](https://github.com/ignite/cli/pull/4108) Add `xast` package (cherry-picked from [#3770](https://github.com/ignite/cli/pull/3770)) - [#4110](https://github.com/ignite/cli/pull/4110) Scaffold a consumer chain with `interchain-security` v5.0.0-rc0. +- [#4117](https://github.com/ignite/cli/pull/4117) Support relative path when installing local plugins ### Changes diff --git a/ignite/config/plugins/config.go b/ignite/config/plugins/config.go index e8b593f482..4e3ec9d494 100644 --- a/ignite/config/plugins/config.go +++ b/ignite/config/plugins/config.go @@ -83,7 +83,7 @@ func (p Plugin) IsGlobal() bool { // IsLocalPath returns true if the plugin path is a local directory. func (p Plugin) IsLocalPath() bool { - return strings.HasPrefix(p.Path, "/") + return strings.HasPrefix(p.Path, "/") || strings.HasPrefix(p.Path, ".") } // HasPath verifies if a plugin has the given path regardless of version. diff --git a/ignite/config/plugins/config_test.go b/ignite/config/plugins/config_test.go index 10a463f4b6..21c4004d1f 100644 --- a/ignite/config/plugins/config_test.go +++ b/ignite/config/plugins/config_test.go @@ -20,6 +20,8 @@ func TestPluginIsLocalPath(t *testing.T) { assert.False(t, pluginsconfig.Plugin{}.IsLocalPath()) assert.False(t, pluginsconfig.Plugin{Path: "github.com/ignite/example"}.IsLocalPath()) assert.True(t, pluginsconfig.Plugin{Path: "/home/bob/example"}.IsLocalPath()) + assert.True(t, pluginsconfig.Plugin{Path: "./example"}.IsLocalPath()) + assert.True(t, pluginsconfig.Plugin{Path: "../example"}.IsLocalPath()) } func TestPluginHasPath(t *testing.T) { diff --git a/ignite/services/plugin/plugin.go b/ignite/services/plugin/plugin.go index 17bc51934b..7db1b4ef3e 100644 --- a/ignite/services/plugin/plugin.go +++ b/ignite/services/plugin/plugin.go @@ -236,6 +236,23 @@ func (p *Plugin) load(ctx context.Context) { } if p.IsLocalPath() { + // if directory is relative, make it absolute + if !filepath.IsAbs(p.srcPath) { + wd, err := os.Getwd() + if err != nil { + p.Error = errors.Errorf("failed to get working directory: %w", err) + return + } + + srcPathAbs, err := filepath.Abs(p.srcPath) + if err != nil { + p.Error = errors.Errorf("failed to get absolute path of %s: %w", p.srcPath, err) + return + } + + p.srcPath = filepath.Join(wd, srcPathAbs) + } + // trigger rebuild for local plugin if binary is outdated if p.outdatedBinary() { p.build(ctx)