Skip to content

[update] Add sync flag which syncs all dependencies to same resolved version under current working dir #1501

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 10 commits into from
Sep 25, 2023

Conversation

mikeland73
Copy link
Contributor

@mikeland73 mikeland73 commented Sep 22, 2023

Summary

Adds new devbox update --sync-lock command. It syncs all lockfiles to the same version.

I'm also thinking of adding a new --sync-from [lockfile] flag for @LucilleH's use case. Specifically that would allow a certain lockfile to take priority.

How was it tested?

devbox update --sync-lock on this repo (see lockfile changes)

return err
}

if !fi.IsDir() && filepath.Base(path) == "devbox.lock" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this going to walk all of my node_modules files, or are we excluding directories according to .gitignore somewhere

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good call. Yeah I think using .gitignore is good.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Want to add that the monorepo might have a top level .gitignore that handles all the sub directories, and individual .gitignore in each subdirectory to add more stuff to ignore

return err
}

if !fi.IsDir() && filepath.Base(path) == "devbox.lock" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

}
latestTime, err := time.Parse(time.RFC3339, latestPkg.LastModified)
if err != nil {
return err
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this error if one of the lockfile is super old and does not have LastModified in there? (or is that scenario non existent)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that ever happens, but we should handle that. I think a missing last modified should be considered old and replaced if possible.

func latestPackages() (map[string]*Package, error) {
latestPackages := make(map[string]*Package)

err := filepath.Walk(".", func(path string, fi os.FileInfo, err error) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to have a separate function that simply returns all the devbox.json file paths, so that we only walk it once? That way if a .gitignore doesn't catch a giant directory such as node_modules, at least the delay only happens once 🤷‍♀️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

@mikeland73
Copy link
Contributor Author

@LucilleH took me a bit to figure out how to handle the multi gitignores but I think I figured it out.

This runs on devbox in 1s (which has 45 devbox.lock and similar number of gitignores) and runs in 300-600ms in our front-end repo with all dependencies installed.\

PTAL


var filterFunc = func(path string) bool {
// Start at the top of the stack which has most specific gitignore.
for i := len(filterFuncStack) - 1; i >= 0; i-- {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trusting that this works as intended 😅

@mikeland73
Copy link
Contributor Author

@LucilleH it works, but the performance improvement doesn't really work. Turns out that testing (almost) every single file and directory against gitignore slows it down more than the savings of not going into every directory.

Given the complexity I lean towards removing it.

@mikeland73
Copy link
Contributor Author

There's a chance that limiting it to only directories could yield gains, but given how fast it is right now I'm tempted to remove the gitignore code and ship it.

@LucilleH
Copy link
Collaborator

LucilleH commented Sep 25, 2023

@mikeland73 sounds good. Just one more thing: can you try against the frontend repo with node_modules populated with pnpm? Just want to know how much time it takes without the gitignore

@mikeland73
Copy link
Contributor Author

@mikeland73 sounds good. Just one more thing: can you try against the frontend repo with node_modules populated with pnpm? Just want to know how much time it takes without the gitignore

Looks like there's caching of some sort at the OS level. First run is 900ms and subsequent ones are ~350ms.

@mikeland73 mikeland73 merged commit 266ccff into main Sep 25, 2023
@mikeland73 mikeland73 deleted the landau/update-sync branch September 25, 2023 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants