@@ -41,6 +41,10 @@ export class RemoteNodeSetupService {
41
41
protected readonly scriptService : RemoteSetupScriptService ;
42
42
43
43
getNodeDirectoryName ( platform : RemotePlatform ) : string {
44
+ return `node-v${ REMOTE_NODE_VERSION } -${ this . getPlatformName ( platform ) } -${ platform . arch } ` ;
45
+ }
46
+
47
+ protected getPlatformName ( platform : RemotePlatform ) : string {
44
48
let platformId : string ;
45
49
if ( platform . os === OS . Type . Windows ) {
46
50
platformId = 'win' ;
@@ -49,8 +53,7 @@ export class RemoteNodeSetupService {
49
53
} else {
50
54
platformId = 'linux' ;
51
55
}
52
- const dirName = `node-v${ REMOTE_NODE_VERSION } -${ platformId } -${ platform . arch } ` ;
53
- return dirName ;
56
+ return platformId ;
54
57
}
55
58
56
59
protected validatePlatform ( platform : RemotePlatform ) : void {
@@ -67,7 +70,7 @@ export class RemoteNodeSetupService {
67
70
throw new Error ( `Invalid architecture for ${ platform . os } : '${ platform . arch } '. Only ${ supportedArch } are supported.` ) ;
68
71
}
69
72
70
- getNodeFileName ( platform : RemotePlatform ) : string {
73
+ protected getNodeFileExtension ( platform : RemotePlatform ) : string {
71
74
let fileExtension : string ;
72
75
if ( platform . os === OS . Type . Windows ) {
73
76
fileExtension = 'zip' ;
@@ -76,16 +79,20 @@ export class RemoteNodeSetupService {
76
79
} else {
77
80
fileExtension = 'tar.xz' ;
78
81
}
79
- return ` ${ this . getNodeDirectoryName ( platform ) } . ${ fileExtension } ` ;
82
+ return fileExtension ;
80
83
}
81
84
82
- async downloadNode ( platform : RemotePlatform ) : Promise < string > {
85
+ getNodeFileName ( platform : RemotePlatform ) : string {
86
+ return `${ this . getNodeDirectoryName ( platform ) } .${ this . getNodeFileExtension ( platform ) } ` ;
87
+ }
88
+
89
+ async downloadNode ( platform : RemotePlatform , downloadTemplate ?: string ) : Promise < string > {
83
90
this . validatePlatform ( platform ) ;
84
91
const fileName = this . getNodeFileName ( platform ) ;
85
92
const tmpdir = os . tmpdir ( ) ;
86
93
const localPath = path . join ( tmpdir , fileName ) ;
87
94
if ( ! await fs . pathExists ( localPath ) ) {
88
- const downloadPath = this . getDownloadPath ( fileName ) ;
95
+ const downloadPath = this . getDownloadPath ( platform , downloadTemplate ) ;
89
96
const downloadResult = await this . requestService . request ( {
90
97
url : downloadPath
91
98
} ) ;
@@ -94,18 +101,23 @@ export class RemoteNodeSetupService {
94
101
return localPath ;
95
102
}
96
103
97
- generateDownloadScript ( platform : RemotePlatform , targetPath : string ) : string {
104
+ generateDownloadScript ( platform : RemotePlatform , targetPath : string , downloadTemplate ?: string ) : string {
98
105
this . validatePlatform ( platform ) ;
99
106
const fileName = this . getNodeFileName ( platform ) ;
100
- const downloadPath = this . getDownloadPath ( fileName ) ;
107
+ const downloadPath = this . getDownloadPath ( platform , downloadTemplate ) ;
101
108
const zipPath = this . scriptService . joinPath ( platform , targetPath , fileName ) ;
102
109
const download = this . scriptService . downloadFile ( platform , downloadPath , zipPath ) ;
103
110
const unzip = this . scriptService . unzip ( platform , zipPath , targetPath ) ;
104
111
return this . scriptService . joinScript ( platform , download , unzip ) ;
105
112
}
106
113
107
- protected getDownloadPath ( fileName : string ) : string {
108
- return `https://nodejs.org/dist/v${ REMOTE_NODE_VERSION } /${ fileName } ` ;
114
+ protected getDownloadPath ( platform : RemotePlatform , downloadTemplate ?: string ) : string {
115
+ const template = downloadTemplate || 'https://nodejs.org/dist/v{version}/node-v{version}-{os}-{arch}.{ext}' ;
116
+ const downloadPath = template
117
+ . replace ( / { v e r s i o n } / g, REMOTE_NODE_VERSION )
118
+ . replace ( / { o s } / g, this . getPlatformName ( platform ) )
119
+ . replace ( / { a r c h } / g, platform . arch )
120
+ . replace ( / { e x t } / g, this . getNodeFileExtension ( platform ) ) ;
121
+ return downloadPath ;
109
122
}
110
-
111
123
}
0 commit comments