Skip to content

[plugins] Remove trigger package #1545

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

Merged
merged 1 commit into from
Oct 10, 2023
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: 0 additions & 1 deletion examples/development/php/php8.1/devbox.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"packages": [
"php81Packages.composer@latest",
"php81Extensions.xdebug@latest",
"php81Extensions.imagick@latest",
"[email protected]"
Expand Down
20 changes: 0 additions & 20 deletions examples/development/php/php8.1/devbox.lock
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,6 @@
}
}
},
"php81Packages.composer@latest": {
"last_modified": "2023-08-30T00:25:28Z",
"resolved": "github:NixOS/nixpkgs/a63a64b593dcf2fe05f7c5d666eb395950f36bc9#php81Packages.composer",
"source": "devbox-search",
"version": "2.5.8",
"systems": {
"aarch64-darwin": {
"store_path": "/nix/store/7hxmkxa9bmaplyy1ixl0yxv3j0qvxvc3-php-composer-2.5.8"
},
"aarch64-linux": {
"store_path": "/nix/store/vwrbpz9wr7blr7alx0fl3x79ym3jbdqa-php-composer-2.5.8"
},
"x86_64-darwin": {
"store_path": "/nix/store/fjy357jpj9q2bfahsgnak4mrh8y07izw-php-composer-2.5.8"
},
"x86_64-linux": {
"store_path": "/nix/store/6w2vrfjdwhr3mj1magr2rmbycln379f8-php-composer-2.5.8"
}
}
},
"[email protected]": {
"last_modified": "2023-09-04T16:24:30Z",
"plugin_version": "0.0.2",
Expand Down
9 changes: 1 addition & 8 deletions internal/impl/devbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -963,14 +963,7 @@ func (d *Devbox) InstallablePackages() []*devpkg.Package {
// packages concatenated in correct order
func (d *Devbox) AllInstallablePackages() ([]*devpkg.Package, error) {
userPackages := d.InstallablePackages()
pluginPackages, err := d.PluginManager().PluginPackages(userPackages)
if err != nil {
return nil, err
}
// We prioritize plugin packages so that the php plugin works. Not sure
// if this is behavior we want for user plugins. We may need to add an optional
// priority field to the config.
return append(pluginPackages, userPackages...), nil
return d.PluginManager().ProcessPluginPackages(userPackages)
}

func (d *Devbox) Includes() []plugin.Includable {
Expand Down
28 changes: 22 additions & 6 deletions internal/plugin/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package plugin

import (
"github.com/samber/lo"
"go.jetpack.io/devbox/internal/devpkg"
"go.jetpack.io/devbox/internal/lock"
)
Expand Down Expand Up @@ -45,16 +46,31 @@ func (m *Manager) ApplyOptions(opts ...managerOption) {
}
}

func (m *Manager) PluginPackages(inputs []*devpkg.Package) ([]*devpkg.Package, error) {
result := []*devpkg.Package{}
for _, input := range inputs {
config, err := getConfigIfAny(input, m.ProjectDir())
// ProcessPluginPackages adds and removes packages as indicated by plugins
func (m *Manager) ProcessPluginPackages(
userPackages []*devpkg.Package,
) ([]*devpkg.Package, error) {
pluginPackages := []*devpkg.Package{}
packagesToRemove := []*devpkg.Package{}
for _, pkg := range userPackages {
config, err := getConfigIfAny(pkg, m.ProjectDir())
if err != nil {
return nil, err
} else if config == nil {
continue
}
result = append(result, devpkg.PackageFromStrings(config.Packages, m.lockfile)...)
pluginPackages = append(
pluginPackages,
devpkg.PackageFromStrings(config.Packages, m.lockfile)...,
)
if config.RemoveTriggerPackage {
packagesToRemove = append(packagesToRemove, pkg)
}
}
return result, nil

netUserPackages, _ := lo.Difference(userPackages, packagesToRemove)
// We prioritize plugin packages so that the php plugin works. Not sure
// if this is behavior we want for user plugins. We may need to add an optional
// priority field to the config.
return append(pluginPackages, netUserPackages...), nil
}
3 changes: 3 additions & 0 deletions internal/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ type config struct {
Packages []string `json:"__packages"`
Env map[string]string `json:"env"`
Readme string `json:"readme"`
// If true, we remove the package that triggered this plugin from the environment
// Useful when we want to replace with flake
RemoveTriggerPackage bool `json:"__remove_trigger_package,omitempty"`

Shell struct {
// InitHook contains commands that will run at shell startup.
Expand Down
1 change: 1 addition & 0 deletions plugins/haskell.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"__packages": [
"path:{{ .Virtenv }}"
],
"__remove_trigger_package": true,
"create_files": {
"{{ .Virtenv }}/flake.nix": "haskell/flake.nix"
}
Expand Down
1 change: 1 addition & 0 deletions plugins/mariadb.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"__packages": [
"path:{{ .Virtenv }}"
],
"__remove_trigger_package": true,
"shell": {
"init_hook": [
"bash {{ .Virtenv }}/setup_db.sh"
Expand Down
1 change: 1 addition & 0 deletions plugins/mysql.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"__packages": [
"path:{{ .Virtenv }}"
],
"__remove_trigger_package": true,
"shell": {
"init_hook": [
"bash {{ .Virtenv }}/setup_db.sh"
Expand Down
1 change: 1 addition & 0 deletions plugins/php.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"path:{{ .Virtenv }}",
"path:{{ .Virtenv }}#composer"
],
"__remove_trigger_package": true,
"env": {
"PHPFPM_ERROR_LOG_FILE": "{{ .Virtenv }}/php-fpm.log",
"PHPFPM_PID_FILE": "{{ .Virtenv }}/php-fpm.pid",
Expand Down