@@ -106,7 +106,7 @@ exports.getProtoc = getProtoc;
106
106
function downloadRelease ( version ) {
107
107
return __awaiter ( this , void 0 , void 0 , function * ( ) {
108
108
// Download
109
- let fileName = getFileName ( version ) ;
109
+ let fileName = getFileName ( version , osPlat , osArch ) ;
110
110
let downloadUrl = util . format ( "https://github.com/protocolbuffers/protobuf/releases/download/%s/%s" , version , fileName ) ;
111
111
process . stdout . write ( "Downloading archive: " + downloadUrl + os . EOL ) ;
112
112
let downloadPath = null ;
@@ -126,7 +126,43 @@ function downloadRelease(version) {
126
126
return yield tc . cacheDir ( extPath , "protoc" , version ) ;
127
127
} ) ;
128
128
}
129
- function getFileName ( version ) {
129
+ /**
130
+ *
131
+ * @param osArch - A string identifying operating system CPU architecture for which the Node.js binary was compiled.
132
+ * See https://nodejs.org/api/os.html#osarch for possible values.
133
+ * @returns Suffix for the protoc filename.
134
+ */
135
+ function fileNameSuffix ( osArch ) {
136
+ switch ( osArch ) {
137
+ case "x64" : {
138
+ return "x86_64" ;
139
+ }
140
+ case "arm64" : {
141
+ return "aarch_64" ;
142
+ }
143
+ case "s390x" : {
144
+ return "s390_64" ;
145
+ }
146
+ case "ppc64" : {
147
+ return "ppcle_64" ;
148
+ }
149
+ default : {
150
+ return "x86_32" ;
151
+ }
152
+ }
153
+ }
154
+ /**
155
+ * Returns the filename of the protobuf compiler.
156
+ *
157
+ * @param version - The version to download
158
+ * @param osPlat - The operating system platform for which the Node.js binary was compiled.
159
+ * See https://nodejs.org/api/os.html#osplatform for more.
160
+ * @param osArch - The operating system CPU architecture for which the Node.js binary was compiled.
161
+ * See https://nodejs.org/api/os.html#osarch for more.
162
+ * @returns The filename of the protocol buffer for the given release, platform and architecture.
163
+ *
164
+ */
165
+ function getFileName ( version , osPlat , osArch ) {
130
166
// to compose the file name, strip the leading `v` char
131
167
if ( version . startsWith ( "v" ) ) {
132
168
version = version . slice ( 1 , version . length ) ;
@@ -136,12 +172,13 @@ function getFileName(version) {
136
172
const arch = osArch == "x64" ? "64" : "32" ;
137
173
return util . format ( "protoc-%s-win%s.zip" , version , arch ) ;
138
174
}
139
- const arch = osArch == "x64" ? "x86_64" : "x86_32" ;
175
+ const suffix = fileNameSuffix ( osArch ) ;
140
176
if ( osPlat == "darwin" ) {
141
- return util . format ( "protoc-%s-osx-%s.zip" , version , arch ) ;
177
+ return util . format ( "protoc-%s-osx-%s.zip" , version , suffix ) ;
142
178
}
143
- return util . format ( "protoc-%s-linux-%s.zip" , version , arch ) ;
179
+ return util . format ( "protoc-%s-linux-%s.zip" , version , suffix ) ;
144
180
}
181
+ exports . getFileName = getFileName ;
145
182
// Retrieve a list of versions scraping tags from the Github API
146
183
function fetchVersions ( includePreReleases , repoToken ) {
147
184
return __awaiter ( this , void 0 , void 0 , function * ( ) {
@@ -156,8 +193,9 @@ function fetchVersions(includePreReleases, repoToken) {
156
193
}
157
194
let tags = [ ] ;
158
195
for ( let pageNum = 1 , morePages = true ; morePages ; pageNum ++ ) {
159
- let nextPage = ( yield rest . get ( "https://api.github.com/repos/protocolbuffers/protobuf/releases?page=" +
160
- pageNum ) ) . result || [ ] ;
196
+ let p = yield rest . get ( "https://api.github.com/repos/protocolbuffers/protobuf/releases?page=" +
197
+ pageNum ) ;
198
+ let nextPage = p . result || [ ] ;
161
199
if ( nextPage . length > 0 ) {
162
200
tags = tags . concat ( nextPage ) ;
163
201
}
0 commit comments