diff --git a/changelog.md b/changelog.md index a5346e80d9..733312c949 100644 --- a/changelog.md +++ b/changelog.md @@ -17,6 +17,7 @@ - [#4100](https://github.com/ignite/cli/pull/4100) Set the `proto-dir` flag only for the `scaffold chain` command and use the proto path from the config - [#4110](https://github.com/ignite/cli/pull/4110) Scaffold a consumer chain with `interchain-security` v5.0.0-rc0. - [#4111](https://github.com/ignite/cli/pull/4111) Remove vuex generation +- [#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 860d075e7c..3a29f28c49 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 a2ad5809e8..2c4df2bc20 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 7cf6346a51..b482444b82 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)