-
-
Notifications
You must be signed in to change notification settings - Fork 14k
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
yarn2nix: use sha512 by default #149834
yarn2nix: use sha512 by default #149834
Changes from all commits
40c96df
29ebfe6
00f76eb
3e514ab
68e24d0
6a64a46
d470626
73a58a3
a75993d
375cc41
8385afe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,14 @@ const https = require('https') | |
const crypto = require('crypto') | ||
|
||
// TODO: | ||
// make test case where getSha1 function is used, i.e. the case when resolved is without sha1? | ||
// make test case where getSha512 function is used, i.e. the case when resolved is without sha512? | ||
// consider using https://github.com/request/request-promise-native | ||
|
||
function getSha1(url) { | ||
function getSha512(url) { | ||
return new Promise((resolve, reject) => { | ||
https.get(url, res => { | ||
const { statusCode } = res | ||
const hash = crypto.createHash('sha1') | ||
const hash = crypto.createHash('sha512') | ||
|
||
if (statusCode !== 200) { | ||
const err = new Error(`Request Failed.\nStatus Code: ${statusCode}`) | ||
|
@@ -34,7 +34,7 @@ function getSha1(url) { | |
} | ||
|
||
// Object -> Object | ||
async function fixPkgAddMissingSha1(pkg) { | ||
async function fixPkgAddMissingSha512(pkg) { | ||
// local dependency | ||
|
||
if (!pkg.resolved) { | ||
|
@@ -46,21 +46,21 @@ async function fixPkgAddMissingSha1(pkg) { | |
return pkg | ||
} | ||
|
||
const [url, sha1] = pkg.resolved.split('#', 2) | ||
const [url, sha512] = pkg.resolved.split('#', 2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned, I am not sure if |
||
|
||
if (sha1 || url.startsWith('https://codeload.github.com')) { | ||
if (sha512 || url.startsWith('https://codeload.github.com')) { | ||
return pkg | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably do |
||
} | ||
|
||
// if there is no sha1 in resolved url | ||
// if there is no sha512 in resolved url | ||
// (this could happen if yarn.lock was generated by older version of yarn) | ||
// - request it from registry by https and add it to pkg | ||
const newSha1 = await getSha1(url) | ||
const newSha512 = await getSha512(url) | ||
|
||
return { | ||
...pkg, | ||
resolved: `${url}#${newSha1}`, | ||
resolved: `${url}#${newSha512}`, | ||
} | ||
Comment on lines
+62
to
63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure this is supported. At least I have not seen it anywhere. It would probably be better to use |
||
} | ||
|
||
module.exports = fixPkgAddMissingSha1 | ||
module.exports = fixPkgAddMissingSha512 |
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.
I would also add something like
as according to my understanding,
integrity
has priority over the hash inresolved
.