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

chore: move lockfile ffi boundary #4629

Merged
merged 18 commits into from Apr 26, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
64 changes: 23 additions & 41 deletions cli/internal/context/context.go
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/vercel/turbo/cli/internal/workspace"

"github.com/Masterminds/semver"
mapset "github.com/deckarep/golang-set"
"github.com/pyr-sh/dag"
"golang.org/x/sync/errgroup"
)
Expand Down Expand Up @@ -179,12 +178,6 @@ func BuildPackageGraph(repoRoot turbopath.AbsoluteSystemPath, rootPackageJSON *f
}
c.PackageManager = packageManager

if lockfile, err := c.PackageManager.ReadLockfile(repoRoot, rootPackageJSON); err != nil {
warnings.append(err)
} else {
c.Lockfile = lockfile
}

if err := c.resolveWorkspaceRootDeps(rootPackageJSON, &warnings); err != nil {
// TODO(Gaspar) was this the intended return error?
return nil, fmt.Errorf("could not resolve workspaces: %w", err)
Expand Down Expand Up @@ -231,6 +224,29 @@ func BuildPackageGraph(repoRoot turbopath.AbsoluteSystemPath, rootPackageJSON *f
}
c.WorkspaceInfos.PackageJSONs[util.RootPkgName] = rootPackageJSON

if lockFile, err := c.PackageManager.ReadLockfile(repoRoot, rootPackageJSON); err != nil {
warnings.append(err)
rootPackageJSON.TransitiveDeps = []lockfile.Package{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this work as just nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haven't done a full code trace, but it should. This was just copied from previous behavior.

Edit: Checked and nil works just fine here

rootPackageJSON.ExternalDepsHash = ""
} else {
c.Lockfile = lockFile
for _, pkg := range c.WorkspaceInfos.PackageJSONs {
depSet, err := lockfile.TransitiveClosure(
pkg.Dir.ToUnixPath(),
pkg.UnresolvedExternalDeps,
c.Lockfile,
)
if err != nil {
warnings.append(err)
continue
chris-olszewski marked this conversation as resolved.
Show resolved Hide resolved
}
if err := pkg.SetExternalDeps(depSet); err != nil {
return nil, err
}
}

}

return c, warnings.errorOrNil()
}

Expand All @@ -246,25 +262,6 @@ func (c *Context) resolveWorkspaceRootDeps(rootPackageJSON *fs.PackageJSON, warn
for dep, version := range pkg.Dependencies {
pkg.UnresolvedExternalDeps[dep] = version
}
if c.Lockfile != nil {
depSet, err := lockfile.TransitiveClosure(
pkg.Dir.ToUnixPath(),
pkg.UnresolvedExternalDeps,
c.Lockfile,
)
if err != nil {
warnings.append(err)
// Return early to skip using results of incomplete dep graph resolution
return nil
}
if err := pkg.SetExternalDeps(depSet); err != nil {
return err
}
} else {
pkg.TransitiveDeps = []lockfile.Package{}
pkg.ExternalDepsHash = ""
}

return nil
}

Expand Down Expand Up @@ -315,17 +312,6 @@ func (c *Context) populateWorkspaceGraphForPackageJSON(pkg *fs.PackageJSON, root
}
}

externalDeps, err := lockfile.TransitiveClosure(
pkg.Dir.ToUnixPath(),
pkg.UnresolvedExternalDeps,
c.Lockfile,
)
if err != nil {
warnings.append(err)
// reset external deps to original state
externalDeps = mapset.NewSet()
Copy link
Contributor

Choose a reason for hiding this comment

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

What was this doing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was here instead of proper control flow, if the closure calculation errored we would override the return value with an empty set. This would then get translated to pkg.TransitiveDeps = make([]lockfile.Package, 0) and nothing would get added.

}

// when there are no internal dependencies, we need to still add these leafs to the graph
if internalDepsSet.Len() == 0 {
c.WorkspaceGraph.Connect(dag.BasicEdge(pkg.Name, core.ROOT_NODE_NAME))
Expand All @@ -336,10 +322,6 @@ func (c *Context) populateWorkspaceGraphForPackageJSON(pkg *fs.PackageJSON, root
pkg.InternalDeps = append(pkg.InternalDeps, fmt.Sprintf("%v", v))
}

if err := pkg.SetExternalDeps(externalDeps); err != nil {
return err
}

sort.Strings(pkg.InternalDeps)

return nil
Expand Down