@@ -3,10 +3,9 @@ import * as http from "http";
3
3
import { https } from "follow-redirects" ;
4
4
import * as path from "path" ;
5
5
import * as fs from "fs/promises" ;
6
- import * as unzip from "unzipper " ;
6
+ import * as tar from "tar " ;
7
7
import { exists , isTsNode } from "../util" ;
8
8
import { spawnSync } from "child_process" ;
9
- import sleep from "@hyurl/utils/sleep" ;
10
9
11
10
const nodeModulesDir = path . dirname ( path . dirname ( path . dirname ( __dirname ) ) ) ;
12
11
const hiddenDir = path . join ( nodeModulesDir , ".ngrpc" ) ;
@@ -15,21 +14,21 @@ let zipName: string | undefined;
15
14
16
15
if ( process . platform === "darwin" ) {
17
16
if ( process . arch === "arm64" ) {
18
- zipName = `ngrpc-mac-arm64.zip ` ;
17
+ zipName = `ngrpc-mac-arm64.tgz ` ;
19
18
} else if ( process . arch === "x64" ) {
20
- zipName = "ngrpc-mac-amd64.zip " ;
19
+ zipName = "ngrpc-mac-amd64.tgz " ;
21
20
}
22
21
} else if ( process . platform === "linux" ) {
23
22
if ( process . arch === "arm64" ) {
24
- zipName = `ngrpc-linux-arm64.zip ` ;
23
+ zipName = `ngrpc-linux-arm64.tgz ` ;
25
24
} else if ( process . arch === "x64" ) {
26
- zipName = "ngrpc-linux-amd64.zip " ;
25
+ zipName = "ngrpc-linux-amd64.tgz " ;
27
26
}
28
27
} else if ( process . platform === "win32" ) {
29
28
if ( process . arch === "arm64" ) {
30
- zipName = `ngrpc-linux -arm64.zip ` ;
29
+ zipName = `ngrpc-windows -arm64.tgz ` ;
31
30
} else if ( process . arch === "x64" ) {
32
- zipName = "ngrpc-linux -amd64.zip " ;
31
+ zipName = "ngrpc-windows -amd64.tgz " ;
33
32
}
34
33
}
35
34
@@ -69,20 +68,17 @@ function reportImportFailure(err?: Error) {
69
68
reportImportFailure ( new Error ( `unable to download ${ zipName } ` ) ) ;
70
69
}
71
70
72
- res . pipe ( unzip . Extract ( { path : hiddenDir } ) ) ;
73
-
74
71
await new Promise < void > ( ( resolve , reject ) => {
75
- res . on ( "error" , ( err ) => {
72
+ const out = tar . extract ( { cwd : hiddenDir } ) ;
73
+ const handleError = async ( err : Error ) => {
74
+ try { await fs . unlink ( cmdPath ) ; } catch { }
76
75
reject ( err ) ;
77
- } ) . on ( "end" , ( ) => {
78
- resolve ( ) ;
79
- } ) ;
80
- } ) ;
76
+ } ;
81
77
82
- if ( process . platform !== "win32" ) {
83
- spawnSync ( "chmod ", [ "+x" , cmdPath ] , { stdio : "inherit" } ) ;
84
- await sleep ( 100 ) ; // need to wait a while, don't know why
85
- }
78
+ res . pipe ( out ) ;
79
+ res . on ( "error ", handleError ) ;
80
+ out . on ( "error" , handleError ) . on ( "finish" , resolve ) ;
81
+ } ) ;
86
82
87
83
spawnSync ( cmdPath , process . argv . slice ( 2 ) , { stdio : "inherit" } ) ;
88
84
} else {
0 commit comments