Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugins): support relative path #4117

Merged
merged 6 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
}

// trigger rebuild for local plugin if binary is outdated
if p.outdatedBinary() {
p.build(ctx)
Expand Down
Loading