diff --git a/changelog.md b/changelog.md index f1e570e6bf..1fa303ff5f 100644 --- a/changelog.md +++ b/changelog.md @@ -17,7 +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 +- [#4117](https://github.com/ignite/cli/pull/4117), [#4125](https://github.com/ignite/cli/pull/4125) Support relative path when installing local plugins ### Changes diff --git a/ignite/config/plugins/config.go b/ignite/config/plugins/config.go index 3a2adf0e96..5142fd3818 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, "/") || strings.HasPrefix(p.Path, ".") + return strings.HasPrefix(p.Path, "/") || strings.HasPrefix(p.Path, ".") || strings.HasPrefix(p.Path, "~") } // HasPath verifies if a plugin has the given path regardless of version. diff --git a/ignite/services/plugin/plugin.go b/ignite/services/plugin/plugin.go index b482444b82..ac3696593a 100644 --- a/ignite/services/plugin/plugin.go +++ b/ignite/services/plugin/plugin.go @@ -142,8 +142,19 @@ func newPlugin(pluginsDir string, cp pluginsconfig.Plugin, options ...Option) *P apply(p) } - if strings.HasPrefix(pluginPath, "/") { - // This is a local plugin, check if the file exists + // This is a local plugin, check if the file exists + if tp := (&Plugin{Plugin: pluginsconfig.Plugin{Path: pluginPath}}); tp.IsLocalPath() { + // if directory is relative, make it absolute + if !filepath.IsAbs(pluginPath) { + pluginPathAbs, err := filepath.Abs(pluginPath) + if err != nil { + p.Error = errors.Errorf("failed to get absolute path of %s: %w", pluginPath, err) + return p + } + + pluginPath = pluginPathAbs + } + st, err := os.Stat(pluginPath) if err != nil { p.Error = errors.Wrapf(err, "local app path %q not found", pluginPath) @@ -157,6 +168,7 @@ func newPlugin(pluginsDir string, cp pluginsconfig.Plugin, options ...Option) *P p.name = path.Base(pluginPath) return p } + // This is a remote plugin, parse the URL if i := strings.LastIndex(pluginPath, "@"); i != -1 { // path contains a reference @@ -236,23 +248,6 @@ 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) diff --git a/ignite/services/plugin/plugin_test.go b/ignite/services/plugin/plugin_test.go index 11354c4d3b..babae27521 100644 --- a/ignite/services/plugin/plugin_test.go +++ b/ignite/services/plugin/plugin_test.go @@ -67,6 +67,16 @@ func TestNewPlugin(t *testing.T) { stderr: os.Stderr, }, }, + { + name: "ok: relative local plugin", + pluginCfg: pluginsconfig.Plugin{Path: "./testdata"}, + expectedPlugin: Plugin{ + srcPath: path.Join(wd, "testdata"), + name: "testdata", + stdout: os.Stdout, + stderr: os.Stderr, + }, + }, { name: "fail: remote plugin with only domain", pluginCfg: pluginsconfig.Plugin{Path: "github.com"},