Skip to content

Commit

Permalink
yarn2nix: use yarn lockfile integrity field whenever possible
Browse files Browse the repository at this point in the history
Whenever available use the SRI hashes from the integrity field to create
the fetchurl calls instead of entirely relying on the `resolved` sha1
which may or may not exist with recent yarn versions.

Related issues:

- nix-community/yarn2nix#125
- NixOS#77238
  • Loading branch information
AmineChikhaoui authored and jsoo1 committed Nov 6, 2022
1 parent 8add073 commit 40986ba
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ const result = []

readFile
.on('line', line => {
const arr = line.match(/^ {2}resolved "([^#]+)#([^"]+)"$/)
const arr = line.match(/^ {2}resolved "([^#]+)(#[^"]+)?"$/)

if (arr !== null) {
const [_, url, shaOrRev] = arr

const fileName = urlToName(url)

result.push(` resolved "${fileName}#${shaOrRev}"`)
result.push(` resolved "${fileName}${shaOrRev ?? ''}"`)
} else {
result.push(line)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function fetchgit(fileName, url, rev, branch, builtinFetchGit) {

function fetchLockedDep(builtinFetchGit) {
return function (pkg) {
const { nameWithVersion, resolved } = pkg
const { integrity, nameWithVersion, resolved } = pkg

if (!resolved) {
console.error(
Expand Down Expand Up @@ -102,14 +102,14 @@ function fetchLockedDep(builtinFetchGit) {
return fetchgit(fileName, urlForGit, rev, branch || 'master', builtinFetchGit)
}

const sha = sha1OrRev
const [algo, hash] = integrity ? integrity.split('-') : ['sha1', sha1OrRev]

return ` {
name = "${fileName}";
path = fetchurl {
name = "${fileName}";
url = "${url}";
sha1 = "${sha}";
${algo} = "${hash}";
};
}`
}
Expand Down

0 comments on commit 40986ba

Please sign in to comment.