Skip to content

Commit ce17002

Browse files
authored
[lockfile] Fix built-in plugin issues (#2189)
## Summary Addresses #2187 and other issues. Fixes: * Adding a package with built-in plugin was not triggering file creation until shell/run. Now we do it on add instead. * plugin version was not getting added to lockfile on `add` and instead was getting added on next `ensureState`. Fixed this by ensuring plugin version added during add. ## How was it tested? * Installed nodejs, observed plugin version was in lockfile. * Installed nginx and observed devbox.s files were created right away
1 parent 7855f96 commit ce17002

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

internal/devbox/packages.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,16 @@ func (d *Devbox) ensureStateIsUpToDate(ctx context.Context, mode installMode) er
270270
ux.Finfo(d.stderr, "Ensuring packages are installed.\n")
271271
}
272272

273+
if mode != ensure {
274+
// Reload includes because added/removed packages might change plugins. Cases:
275+
// * New package adds built-in plugin. We wanna make sure the plugin is in config.
276+
// * Remove built-in plugin that installs multiple packages (e.g. nginx). We wanna clear them
277+
// up so they get removed from lockfile in updateLockfile
278+
if err = d.cfg.LoadRecursive(d.lockfile); err != nil {
279+
return err
280+
}
281+
}
282+
273283
if mode == install || mode == update || mode == ensure {
274284
if err := d.installPackages(ctx, mode); err != nil {
275285
return err
@@ -299,7 +309,7 @@ func (d *Devbox) ensureStateIsUpToDate(ctx context.Context, mode installMode) er
299309
}
300310

301311
// updateLockfile will ensure devbox.lock is up to date with the current state of the project.update
302-
// If recomputeState is true, then we will also update the local.lock file.
312+
// If recomputeState is true, then we will also update the state.json file.
303313
func (d *Devbox) updateLockfile(recomputeState bool) error {
304314
// Ensure we clean out packages that are no longer needed.
305315
d.lockfile.Tidy()
@@ -311,6 +321,13 @@ func (d *Devbox) updateLockfile(recomputeState bool) error {
311321
}
312322
}
313323

324+
// Update plugin versions in lockfile.
325+
for _, pluginConfig := range d.Config().IncludedPluginConfigs() {
326+
if err := d.PluginManager().UpdateLockfileVersion(pluginConfig); err != nil {
327+
return err
328+
}
329+
}
330+
314331
// Save the lockfile at the very end, after all other operations were successful.
315332
if err := d.lockfile.Save(); err != nil {
316333
return err

internal/plugin/plugin.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,20 @@ func (m *Manager) CreateFilesForConfig(cfg *Config) error {
103103
if err := m.createFile(pkg, filePath, contentPath, virtenvPath); err != nil {
104104
return err
105105
}
106-
107106
}
108107

109-
if locked != nil {
110-
locked.PluginVersion = cfg.Version
111-
}
108+
return nil
109+
}
112110

111+
func (m *Manager) UpdateLockfileVersion(cfg *Config) error {
112+
pkg := cfg.Source
113+
locked := m.lockfile.Packages[pkg.LockfileKey()]
114+
// plugins that are not triggered by packages don't have a lockfile entry
115+
// this may change if we decide to store all plugins in the lockfile
116+
if locked == nil {
117+
return nil
118+
}
119+
locked.PluginVersion = cfg.Version
113120
return m.lockfile.Save()
114121
}
115122

0 commit comments

Comments
 (0)