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