Skip to content

Commit

Permalink
Merge pull request #1 from mayflower/avoid-rebuilds
Browse files Browse the repository at this point in the history
Avoid rebuilds
  • Loading branch information
Ma27 authored Nov 12, 2020
2 parents 37c3b7c + 0d4c0e2 commit 262592b
Show file tree
Hide file tree
Showing 16 changed files with 6,330 additions and 3,036 deletions.
29 changes: 27 additions & 2 deletions bin/yarn2nix.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Options:
--no-patch Don't patch the lockfile if hashes are missing
--lockfile=FILE Specify path to the lockfile [default: ./yarn.lock].
--builtin-fetchgit Use builtin fetchGit for git dependencies to support on-the-fly generation of yarn.nix without an internet connection
--fetch-meta=DEPS Specify dependencies where fetching dependencies is needed.
`

const options = docopt(USAGE)
Expand Down Expand Up @@ -57,10 +58,24 @@ const pkgs = R.pipe(
mapObjIndexedReturnArray((value, key) => ({
...value,
nameWithVersion: key,
alternates: [],
})),
R.uniqBy(R.prop('resolved')),
R.uniqBy(R.props(['resolved', 'version'])),
)(json.object)

Object.keys(pkgs).forEach(name => {
const resolved = pkgs[name].resolved
const name_ = pkgs[name].nameWithVersion
Object.keys(json.object).forEach(resolvedName => {
if (name_ == resolvedName) {
return
}
if (json.object[resolvedName].resolved == resolved) {
pkgs[name].alternates.push(resolvedName)
}
})
})

const fixedPkgsPromises = R.map(fixPkgAddMissingSha1, pkgs)

;(async () => {
Expand All @@ -79,9 +94,19 @@ const fixedPkgsPromises = R.map(fixPkgAddMissingSha1, pkgs)
fs.writeFileSync(options['--lockfile'], lockfile.stringify(json.object))
}

if (options['--builtin-fetchgit']) {
console.error('Using --builtin-fetchgit is currently unsupported!')
process.exit(1)
}
if (!options['--no-nix']) {
const result = await generateNix(
fixedPkgs,
options['--builtin-fetchgit'],
(options['--fetch-meta'] || "").split(","),
)

// print to stdout
console.log(generateNix(fixedPkgs, options['--builtin-fetchgit']))
console.log(result)
}
})().catch(error => {
console.error(error)
Expand Down
Loading

0 comments on commit 262592b

Please sign in to comment.