Skip to content

Commit 239f4aa

Browse files
authored
[refactor] Rename and move pkgcfg to plugins (#380)
## Summary This is a no-op refactor. Moves the pkgcfg package to puglin and moves built in plugins (json files) to top level plugins directory. ## How was it tested? * linter * tested `devbox add`
1 parent caa944e commit 239f4aa

30 files changed

+42
-42
lines changed

devbox.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"io"
99

1010
"go.jetpack.io/devbox/internal/impl"
11-
"go.jetpack.io/devbox/internal/pkgcfg"
1211
"go.jetpack.io/devbox/internal/planner/plansdk"
12+
"go.jetpack.io/devbox/internal/plugin"
1313
)
1414

1515
// Devbox provides an isolated development environment.
@@ -34,7 +34,7 @@ type Devbox interface {
3434
Remove(pkgs ...string) error
3535
RunScript(scriptName string) error
3636
RunScriptInShell(scriptName string) error
37-
Services() (pkgcfg.Services, error)
37+
Services() (plugin.Services, error)
3838
// Shell generates the devbox environment and launches nix-shell as a child
3939
// process.
4040
Shell() error

devbox.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"shell": {
77
"init_hook": "export \"GOROOT=$(go env GOROOT)\"",
88
"scripts": {
9-
"build": "go build -o dist/devbox cmd/devbox/main.go"
9+
"build": "go build -o dist/devbox cmd/devbox/main.go",
10+
"lint": "golangci-lint run"
1011
}
1112
},
1213
"nixpkgs": {

internal/impl/devbox.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import (
2222
"go.jetpack.io/devbox/internal/cuecfg"
2323
"go.jetpack.io/devbox/internal/debug"
2424
"go.jetpack.io/devbox/internal/nix"
25-
"go.jetpack.io/devbox/internal/pkgcfg"
2625
"go.jetpack.io/devbox/internal/planner"
2726
"go.jetpack.io/devbox/internal/planner/plansdk"
27+
"go.jetpack.io/devbox/internal/plugin"
2828
"golang.org/x/exp/slices"
2929
)
3030

@@ -51,7 +51,7 @@ type Devbox struct {
5151
cfg *Config
5252
// configDir is the directory where the config file (devbox.json) resides
5353
configDir string
54-
pluginManager *pkgcfg.Manager
54+
pluginManager *plugin.Manager
5555
writer io.Writer
5656
}
5757

@@ -76,7 +76,7 @@ func Open(dir string, writer io.Writer) (*Devbox, error) {
7676
box := &Devbox{
7777
cfg: cfg,
7878
configDir: cfgDir,
79-
pluginManager: pkgcfg.NewManager(),
79+
pluginManager: plugin.NewManager(),
8080
writer: writer,
8181
}
8282
return box, nil
@@ -110,13 +110,13 @@ func (d *Devbox) Add(pkgs ...string) error {
110110
return err
111111
}
112112

113-
d.pluginManager.ApplyOptions(pkgcfg.WithAddMode())
113+
d.pluginManager.ApplyOptions(plugin.WithAddMode())
114114
if err := d.ensurePackagesAreInstalled(install); err != nil {
115115
return err
116116
}
117117
if featureflag.PKGConfig.Enabled() {
118118
for _, pkg := range pkgs {
119-
if err := pkgcfg.PrintReadme(
119+
if err := plugin.PrintReadme(
120120
pkg,
121121
d.configDir,
122122
d.writer,
@@ -151,7 +151,7 @@ func (d *Devbox) Remove(pkgs ...string) error {
151151
}
152152

153153
if featureflag.PKGConfig.Enabled() {
154-
if err := pkgcfg.Remove(d.configDir, uninstalledPackages); err != nil {
154+
if err := plugin.Remove(d.configDir, uninstalledPackages); err != nil {
155155
return err
156156
}
157157
}
@@ -207,14 +207,14 @@ func (d *Devbox) Shell() error {
207207
}
208208

209209
if featureflag.PKGConfig.Enabled() {
210-
env, err := pkgcfg.Env(plan.DevPackages, d.configDir)
210+
env, err := plugin.Env(plan.DevPackages, d.configDir)
211211
if err != nil {
212212
return err
213213
}
214214
opts = append(
215215
opts,
216216
nix.WithEnvVariables(env),
217-
nix.WithPKGConfigDir(filepath.Join(d.configDir, pkgcfg.VirtenvBinPath)),
217+
nix.WithPKGConfigDir(filepath.Join(d.configDir, plugin.VirtenvBinPath)),
218218
)
219219
}
220220

@@ -295,14 +295,14 @@ func (d *Devbox) RunScript(scriptName string) error {
295295
}
296296

297297
if featureflag.PKGConfig.Enabled() {
298-
env, err := pkgcfg.Env(plan.DevPackages, d.configDir)
298+
env, err := plugin.Env(plan.DevPackages, d.configDir)
299299
if err != nil {
300300
return err
301301
}
302302
opts = append(
303303
opts,
304304
nix.WithEnvVariables(env),
305-
nix.WithPKGConfigDir(filepath.Join(d.configDir, pkgcfg.VirtenvBinPath)),
305+
nix.WithPKGConfigDir(filepath.Join(d.configDir, plugin.VirtenvBinPath)),
306306
)
307307
}
308308

@@ -340,14 +340,14 @@ func (d *Devbox) Exec(cmds ...string) error {
340340
env := []string{}
341341
virtenvBinPath := ""
342342
if featureflag.PKGConfig.Enabled() {
343-
envMap, err := pkgcfg.Env(d.cfg.Packages, d.configDir)
343+
envMap, err := plugin.Env(d.cfg.Packages, d.configDir)
344344
if err != nil {
345345
return err
346346
}
347347
for k, v := range envMap {
348348
env = append(env, fmt.Sprintf("%s=%s", k, v))
349349
}
350-
virtenvBinPath = filepath.Join(d.configDir, pkgcfg.VirtenvBinPath) + ":"
350+
virtenvBinPath = filepath.Join(d.configDir, plugin.VirtenvBinPath) + ":"
351351
}
352352
pathWithProfileBin := fmt.Sprintf("PATH=%s%s:$PATH", virtenvBinPath, profileBinDir)
353353
cmds = append([]string{pathWithProfileBin}, cmds...)
@@ -381,7 +381,7 @@ func (d *Devbox) Info(pkg string, markdown bool) error {
381381
); err != nil {
382382
return errors.WithStack(err)
383383
}
384-
return pkgcfg.PrintReadme(
384+
return plugin.PrintReadme(
385385
pkg,
386386
d.configDir,
387387
d.writer,
@@ -453,22 +453,22 @@ func (d *Devbox) saveCfg() error {
453453
return cuecfg.WriteFile(cfgPath, d.cfg)
454454
}
455455

456-
func (d *Devbox) Services() (pkgcfg.Services, error) {
457-
return pkgcfg.GetServices(d.cfg.Packages, d.configDir)
456+
func (d *Devbox) Services() (plugin.Services, error) {
457+
return plugin.GetServices(d.cfg.Packages, d.configDir)
458458
}
459459

460460
func (d *Devbox) StartService(serviceName string) error {
461461
if !IsDevboxShellEnabled() {
462462
return d.Exec("devbox", "services", "start", serviceName)
463463
}
464-
return pkgcfg.StartService(d.cfg.Packages, serviceName, d.configDir, d.writer)
464+
return plugin.StartService(d.cfg.Packages, serviceName, d.configDir, d.writer)
465465
}
466466

467467
func (d *Devbox) StopService(serviceName string) error {
468468
if !IsDevboxShellEnabled() {
469469
return d.Exec("devbox", "services", "stop", serviceName)
470470
}
471-
return pkgcfg.StopService(d.cfg.Packages, serviceName, d.configDir, d.writer)
471+
return plugin.StopService(d.cfg.Packages, serviceName, d.configDir, d.writer)
472472
}
473473

474474
func (d *Devbox) generateShellFiles() error {
@@ -523,7 +523,7 @@ func (d *Devbox) ensurePackagesAreInstalled(mode installMode) error {
523523
fmt.Println("done.")
524524

525525
if featureflag.PKGConfig.Enabled() {
526-
if err := pkgcfg.RemoveInvalidSymlinks(d.configDir); err != nil {
526+
if err := plugin.RemoveInvalidSymlinks(d.configDir); err != nil {
527527
return err
528528
}
529529
}

internal/impl/generate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ import (
1515
"github.com/pkg/errors"
1616
"go.jetpack.io/devbox/internal/boxcli/featureflag"
1717
"go.jetpack.io/devbox/internal/debug"
18-
"go.jetpack.io/devbox/internal/pkgcfg"
1918
"go.jetpack.io/devbox/internal/planner/plansdk"
19+
"go.jetpack.io/devbox/internal/plugin"
2020
)
2121

2222
//go:embed tmpl/* tmpl/.*
2323
var tmplFS embed.FS
2424

2525
var shellFiles = []string{"development.nix", "shell.nix"}
2626

27-
func generateForShell(rootPath string, plan *plansdk.ShellPlan, pluginManager *pkgcfg.Manager) error {
27+
func generateForShell(rootPath string, plan *plansdk.ShellPlan, pluginManager *plugin.Manager) error {
2828
outPath := filepath.Join(rootPath, ".devbox/gen")
2929

3030
for _, file := range shellFiles {
Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,29 @@
1-
package pkgcfg
1+
package plugin
22

33
import (
4-
"embed"
5-
"path/filepath"
64
"regexp"
75
"strings"
86

97
"github.com/pkg/errors"
8+
"go.jetpack.io/devbox/plugins"
109
)
1110

12-
const pkgCfgDir = "package-configuration"
13-
14-
//go:embed package-configuration/*
15-
var packageConfiguration embed.FS
16-
1711
func getConfigIfAny(pkg, rootDir string) (*config, error) {
18-
configFiles, err := packageConfiguration.ReadDir(pkgCfgDir)
12+
configFiles, err := plugins.BuiltIn.ReadDir(".")
1913
if err != nil {
2014
return nil, errors.WithStack(err)
2115
}
2216

2317
// Try to find perfect match first
2418
for _, file := range configFiles {
25-
if file.IsDir() {
19+
if file.IsDir() || strings.HasSuffix(file.Name(), ".go") {
2620
continue
2721
}
28-
content, err := packageConfiguration.ReadFile(
29-
filepath.Join(pkgCfgDir, file.Name()),
30-
)
22+
content, err := plugins.BuiltIn.ReadFile(file.Name())
3123
if err != nil {
3224
return nil, errors.WithStack(err)
3325
}
26+
3427
cfg, err := buildConfig(pkg, rootDir, string(content))
3528
if err != nil {
3629
return nil, errors.WithStack(err)
@@ -47,5 +40,5 @@ func getConfigIfAny(pkg, rootDir string) (*config, error) {
4740
}
4841

4942
func getFileContent(contentPath string) ([]byte, error) {
50-
return packageConfiguration.ReadFile(filepath.Join(pkgCfgDir, contentPath))
43+
return plugins.BuiltIn.ReadFile(contentPath)
5144
}

internal/pkgcfg/info.go renamed to internal/plugin/info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package pkgcfg
1+
package plugin
22

33
import (
44
"fmt"

internal/pkgcfg/manager.go renamed to internal/plugin/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package pkgcfg
1+
package plugin
22

33
type Manager struct {
44
addMode bool

internal/pkgcfg/pkgcfg.go renamed to internal/plugin/pkgcfg.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package pkgcfg
1+
package plugin
22

33
import (
44
"bytes"

internal/pkgcfg/rm.go renamed to internal/plugin/rm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package pkgcfg
1+
package plugin
22

33
import (
44
"os"

internal/pkgcfg/services.go renamed to internal/plugin/services.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package pkgcfg
1+
package plugin
22

33
import (
44
"encoding/json"

0 commit comments

Comments
 (0)