Skip to content

Commit

Permalink
feat(plugins): support relative path (#4117)
Browse files Browse the repository at this point in the history
* feat(plugins): support relative path

* updates

* updates
  • Loading branch information
julienrbrt authored May 8, 2024
1 parent 5f2ffb2 commit 53573da
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion ignite/config/plugins/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions ignite/config/plugins/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 17 additions & 0 deletions ignite/services/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 53573da

Please sign in to comment.