diff options
Diffstat (limited to 'pkgs/development/tools/yarn2nix-moretea/yarn2nix/lib/fixPkgAddMissingSha1.js')
-rw-r--r-- | pkgs/development/tools/yarn2nix-moretea/yarn2nix/lib/fixPkgAddMissingSha1.js | 54 |
1 files changed, 26 insertions, 28 deletions
diff --git a/pkgs/development/tools/yarn2nix-moretea/yarn2nix/lib/fixPkgAddMissingSha1.js b/pkgs/development/tools/yarn2nix-moretea/yarn2nix/lib/fixPkgAddMissingSha1.js index 40467a68992bf..3a5867a3d22c7 100644 --- a/pkgs/development/tools/yarn2nix-moretea/yarn2nix/lib/fixPkgAddMissingSha1.js +++ b/pkgs/development/tools/yarn2nix-moretea/yarn2nix/lib/fixPkgAddMissingSha1.js @@ -1,5 +1,5 @@ -const https = require('https') -const crypto = require('crypto') +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? @@ -8,29 +8,29 @@ const crypto = require('crypto') function getSha1(url) { return new Promise((resolve, reject) => { https.get(url, res => { - const { statusCode } = res - const hash = crypto.createHash('sha1') + const { statusCode } = res; + const hash = crypto.createHash("sha1"); if (statusCode !== 200) { - const err = new Error(`Request Failed.\nStatus Code: ${statusCode}`) + const err = new Error(`Request Failed.\nStatus Code: ${statusCode}`); // consume response data to free up memory - res.resume() + res.resume(); - reject(err) + reject(err); } - res.on('data', chunk => { - hash.update(chunk) - }) + res.on("data", chunk => { + hash.update(chunk); + }); - res.on('end', () => { - resolve(hash.digest('hex')) - }) + res.on("end", () => { + resolve(hash.digest("hex")); + }); - res.on('error', reject) - }) - }) + res.on("error", reject); + }); + }); } // Object -> Object @@ -39,28 +39,26 @@ async function fixPkgAddMissingSha1(pkg) { if (!pkg.resolved) { console.error( - `yarn2nix: can't find "resolved" field for package ${ - pkg.nameWithVersion - }, you probably required it using "file:...", this feature is not supported, ignoring`, - ) - return pkg + `yarn2nix: can't find "resolved" field for package ${pkg.nameWithVersion}, you probably required it using "file:...", this feature is not supported, ignoring` + ); + return pkg; } - const [url, sha1] = pkg.resolved.split('#', 2) + const [url, sha1] = pkg.resolved.split("#", 2); - if (sha1 || url.startsWith('https://codeload.github.com')) { - return pkg + if (sha1 || url.startsWith("https://codeload.github.com")) { + return pkg; } // if there is no sha1 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 newSha1 = await getSha1(url); return { ...pkg, - resolved: `${url}#${newSha1}`, - } + resolved: `${url}#${newSha1}` + }; } -module.exports = fixPkgAddMissingSha1 +module.exports = fixPkgAddMissingSha1; |