-
Notifications
You must be signed in to change notification settings - Fork 2.1k
(refactor) add lockfile abstraction #1789
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
(refactor) add lockfile abstraction #1789
Conversation
@chris-olszewski is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
6609272
to
72513c1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks mostly good to me. Maybe @nathanhammond can provide more comments.
// ResolvePackage Given a package and version returns the key, resolved version, and if it was found | ||
ResolvePackage(name string, version string) (string, string, bool) | ||
// AllDependencies Given a lockfile key return all (dev/optional/peer) dependencies of that package | ||
AllDependencies(key string) (map[string]string, bool) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the graph, resolved to a set.
import "io" | ||
|
||
// Lockfile Interface for general operations that work accross all lockfiles | ||
type Lockfile interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to maybe throw a graph library underneath this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As in provide a way to access the contents as a DAG? Are there any favorite graph libraries in Go world?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, not as a DAG because npm
allows cycles, but so that we're able to leverage basic graph algorithms for reduction. I think it'd be a worthwhile addition, but agreed not for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the moment this interface only deals with data operations and no IO/marshalling. I went with an interface instead of a single struct with an instant for each impl as the contents of a lockfile differ greatly between package managers. Tested pruning a yarn mono repo made with `create-turbo` and verified the lockfile produced was the same as before this commit.
Change so we build up the lockfile in memory as opposed to writing/reading an intermediate to disk. This should allow for better testing of the lockfile marshalling logic
72513c1
to
9da959d
Compare
Resolved most comments that were brought up. Few notes:
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, the abstraction at Lockfile
is going to make this so much nicer. Really looking forward to the followup PRs in this space, too.
This PR introduces a new lockfile abstraction that will allow us to easily add more lockfile support to other package managers. It also
Notable changes:
Context
now stores the lockfile interface instead of a yarn specific lockfilePackageJson
now only stores the package names as they appear in the lockfile, these will be mapped to their entries when the pruned lockfile is createdFrom my understanding of Golang I think having
Lockfile
as an interface makes sense since each package manager has a different data layout for their lockfile e.g. pnpm has 6 top level entries and yarn's top level entries are the package entries themselves.Testing:
The e2e tests cover yarn prune, but I also tested that prune produces the an identical lockfile before and after these changes on a repo created with
npx create-turbo
.