Last active
September 28, 2018 06:26
-
-
Save jdx/6212477f5dcf1c170af495d81f30b063 to your computer and use it in GitHub Desktop.
nd pseudocode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package lib | |
import "path/filepath" | |
type Project struct { | |
Root string | |
YarnLock interface{} | |
PackageLock interface{} | |
Dependencies []*Dependency | |
resolveJobs chan *Dependency | |
cacheJobs chan *Dist | |
} | |
type Dependency struct { | |
Name string | |
SemverRange string | |
Ancestors []string | |
} | |
type Dist struct { | |
Name string | |
Version string | |
Sha string | |
Tarball string | |
} | |
func LoadProject(root string) *Project { | |
root, err := filepath.Abs(root) | |
must(err) | |
p := &Project{Root: root} | |
go init() | |
for { | |
select { | |
case job, open := <-p.resolveJobs: | |
case job, open := <-p.cacheJobs: | |
} | |
} | |
return p | |
} | |
func init() { | |
// startResolving() // just pop them into the map | |
// startCaching() | |
// resolve(this) | |
// close(this.resolveJobs) | |
// close(this.cacheJobs) | |
// resolving is done so build the tree | |
// tree = buildIdealTree() | |
// once caching is complete: | |
// install(tree) | |
} | |
func buildTree() { | |
// input node | |
// for every dep in graph: | |
// if parent has dep, continue | |
// add to tree | |
// add all descendents as well if possible | |
// for every dep in tree: | |
// buildTree(dep) | |
} | |
func resolve() { | |
// use wait group | |
// input: name, semver range, ancestors | |
// grab manifest | |
// find appropriate version | |
// send cache job: cache(url) // probably buffer these | |
// if deps of this not in project: | |
// wg.Add(1) | |
// go resolve(name, semverRange, ancestors+1) | |
// wg.Done() | |
} | |
func install() { | |
// input: tree | |
// if this.installing: | |
// return | |
// get write lock | |
// for node in graph: | |
// go install(node) | |
// get read lock if not circular | |
// install(node.cacheDir, node.toDir) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment