@@ -158,6 +158,7 @@ class Package {
158
158
* type: 'url',
159
159
* url: string,
160
160
* sha1?: string,
161
+ * sha512?: string,
161
162
* } | {
162
163
* type: 'local',
163
164
* },
@@ -201,7 +202,7 @@ class Package {
201
202
static create (
202
203
pkgInfo ,
203
204
// @ts -ignore because there is no optionalDependencies in the type
204
- { version, resolved, dependencies = { } , optionalDependencies = { } }
205
+ { version, integrity , resolved, dependencies = { } , optionalDependencies = { } }
205
206
) {
206
207
const { scope = '' , name } = Id . parse ( pkgInfo . name ) ;
207
208
@@ -211,11 +212,17 @@ class Package {
211
212
const parsedUrl = new URL ( resolved ) ;
212
213
// prettier-ignore
213
214
if ( [ 'registry.yarnpkg.com' , 'registry.npmjs.org' ] . includes ( parsedUrl . host ) ) {
215
+ const sha1 = parsedUrl . hash . slice ( 1 ) ;
216
+ const sha512 = integrity ;
214
217
src = {
215
- sha1 : parsedUrl . hash . slice ( 1 ) , // cut off the first ('#') character
216
218
url : parsedUrl . origin + parsedUrl . pathname ,
217
219
type : 'url' ,
218
220
} ;
221
+ if ( sha512 != '' ) {
222
+ src . sha512 = sha512 ;
223
+ } else if ( sha1 != '' ) {
224
+ src . sha1 = sha1 ;
225
+ }
219
226
} else {
220
227
src = {
221
228
sha1 : undefined , // We don't provide sha in order to force to override it manually
@@ -306,7 +313,9 @@ class Package {
306
313
renderSrc ( ) {
307
314
switch ( this . src . type ) {
308
315
case 'url' :
309
- const { url, sha1 } = this . src ;
316
+ const { url, sha1, sha512 } = this . src ;
317
+ const hashKey = sha512 ? "sha512" : "sha1"
318
+ const hashValue = sha512 || sha1
310
319
// Some of the urls can look like "https://codeload.github.com/xolvio/cucumber-js/tar.gz/cf953cb5b5de30dbcc279f59e4ebff3aa040071c",
311
320
// i.e. no extention given. That's why Nix unable to recognize the type of archive so we need to have
312
321
// name specified explicitly to all Nix to infer the archive type.
@@ -339,12 +348,7 @@ class Package {
339
348
: ''
340
349
}
341
350
url = "${ url } ";
342
- ${
343
- sha1
344
- ? `sha1 = "${ sha1 } "`
345
- : `sha256 = abort ''
346
-
347
-
351
+ ${ hashKey } = ${ `"${ hashValue } "` || `abort ''
348
352
Failed to infer \`sha256\` hash of the \`${ this . renderKey ( ) } \` package source from
349
353
\`${ url } \`.
350
354
0 commit comments