@@ -2,7 +2,7 @@ import path from 'path'
22import fsPromises from 'fs/promises'
33import { PnpmError } from '@pnpm/error'
44import { type FetchFromRegistry } from '@pnpm/fetching-types'
5- import { type BinaryFetcher , type FetchFunction } from '@pnpm/fetcher-base'
5+ import { type BinaryFetcher , type FetchFunction , type FetchResult } from '@pnpm/fetcher-base'
66import { addFilesFromDir } from '@pnpm/worker'
77import AdmZip from 'adm-zip'
88import renameOverwrite from 'rename-overwrite'
@@ -19,40 +19,43 @@ export function createBinaryFetcher (ctx: {
1919 if ( ctx . offline ) {
2020 throw new PnpmError ( 'CANNOT_DOWNLOAD_BINARY_OFFLINE' , `Cannot download binary "${ resolution . url } " because offline mode is enabled.` )
2121 }
22- const version = opts . pkg . version !
23- const manifest = {
24- name : opts . pkg . name ! ,
25- version,
26- bin : resolution . bin ,
27- }
28-
29- if ( resolution . archive === 'tarball' ) {
30- return {
31- ...await ctx . fetchFromRemoteTarball ( cafs , {
32- tarball : resolution . url ,
33- integrity : resolution . integrity ,
34- } , opts ) ,
35- manifest,
36- }
22+ let fetchResult ! : FetchResult
23+ switch ( resolution . archive ) {
24+ case 'tarball' : {
25+ fetchResult = await ctx . fetchFromRemoteTarball ( cafs , {
26+ tarball : resolution . url ,
27+ integrity : resolution . integrity ,
28+ } , opts )
29+ break
3730 }
38- if ( resolution . archive === 'zip' ) {
31+ case 'zip' : {
3932 const tempLocation = await cafs . tempDir ( )
4033 await downloadAndUnpackZip ( ctx . fetch , {
4134 url : resolution . url ,
4235 integrity : resolution . integrity ,
4336 basename : resolution . prefix ?? '' ,
4437 } , tempLocation )
45- return {
46- ...await addFilesFromDir ( {
47- storeDir : cafs . storeDir ,
48- dir : tempLocation ,
49- filesIndexFile : opts . filesIndexFile ,
50- readManifest : false ,
51- } ) ,
52- manifest,
53- }
38+ fetchResult = await addFilesFromDir ( {
39+ storeDir : cafs . storeDir ,
40+ dir : tempLocation ,
41+ filesIndexFile : opts . filesIndexFile ,
42+ readManifest : false ,
43+ } )
44+ break
45+ }
46+ default : {
47+ throw new PnpmError ( 'NOT_SUPPORTED_ARCHIVE' , `The binary fetcher doesn't support archive type ${ resolution . archive as string } ` )
48+ }
49+ }
50+ const manifest = {
51+ name : opts . pkg . name ! ,
52+ version : opts . pkg . version ! ,
53+ bin : resolution . bin ,
54+ }
55+ return {
56+ ...fetchResult ,
57+ manifest,
5458 }
55- throw new PnpmError ( 'NOT_SUPPORTED_ARCHIVE' , `The binary fetcher doesn't support archive type ${ resolution . archive as string } ` )
5659 }
5760 return {
5861 binary : fetchBinary ,
0 commit comments