@sentry/cli 2.58.4 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,19 +6,17 @@ const fs = require('fs');
6
6
  const os = require('os');
7
7
  const path = require('path');
8
8
  const crypto = require('crypto');
9
- const zlib = require('zlib');
10
9
  const stream = require('stream');
11
10
  const process = require('process');
12
11
 
13
- const fetch = require('node-fetch');
14
- const HttpsProxyAgent = require('https-proxy-agent');
12
+ const { ProxyAgent, fetch } = require('undici');
15
13
  const ProgressBar = require('progress');
16
14
  const Proxy = require('proxy-from-env');
17
15
  const which = require('which');
18
16
 
19
17
  const helper = require('../js/helper');
20
18
  const pkgInfo = require('../package.json');
21
- const Logger = require('../js/logger');
19
+ const { Logger } = require('../js/logger');
22
20
 
23
21
  const logger = new Logger(getLogStream('stderr'));
24
22
 
@@ -89,7 +87,7 @@ function getDownloadUrl(platform, arch) {
89
87
  }
90
88
 
91
89
  function createProgressBar(name, total) {
92
- const incorrectTotal = typeof total !== 'number' || Number.isNaN(total);
90
+ const incorrectTotal = typeof total !== 'number' || Number.isNaN(total) || total <= 0;
93
91
 
94
92
  if (incorrectTotal || !shouldRenderProgressBar()) {
95
93
  return {
@@ -220,7 +218,7 @@ async function downloadBinary() {
220
218
  }
221
219
 
222
220
  const proxyUrl = Proxy.getProxyForUrl(downloadUrl);
223
- const agent = proxyUrl ? new HttpsProxyAgent(proxyUrl) : null;
221
+ const dispatcher = proxyUrl ? new ProxyAgent(proxyUrl) : undefined;
224
222
 
225
223
  logger.log(`Downloading from ${downloadUrl}`);
226
224
 
@@ -231,12 +229,8 @@ async function downloadBinary() {
231
229
  let response;
232
230
  try {
233
231
  response = await fetch(downloadUrl, {
234
- agent,
235
- compress: false,
236
- headers: {
237
- 'accept-encoding': 'gzip, deflate, br',
238
- },
239
232
  redirect: 'follow',
233
+ dispatcher,
240
234
  });
241
235
  } catch (error) {
242
236
  let errorMsg = `Unable to download sentry-cli binary from ${downloadUrl}.\nError message: ${error.message}`;
@@ -254,39 +248,38 @@ async function downloadBinary() {
254
248
  throw new Error(errorMsg);
255
249
  }
256
250
 
257
- const contentEncoding = response.headers.get('content-encoding');
258
- let decompressor;
259
- if (/\bgzip\b/.test(contentEncoding)) {
260
- decompressor = zlib.createGunzip();
261
- } else if (/\bdeflate\b/.test(contentEncoding)) {
262
- decompressor = zlib.createInflate();
263
- } else if (/\bbr\b/.test(contentEncoding)) {
264
- decompressor = zlib.createBrotliDecompress();
265
- } else {
266
- decompressor = new stream.PassThrough();
267
- }
268
251
  const name = downloadUrl.match(/.*\/(.*?)$/)[1];
269
252
  let downloadedBytes = 0;
270
- const totalBytes = parseInt(response.headers.get('content-length'), 10);
253
+
254
+ // Note: content-length might not be available if response was compressed,
255
+ // as native fetch decompresses transparently
256
+ const contentLength = response.headers.get('content-length');
257
+ const totalBytes = contentLength ? parseInt(contentLength, 10) : 0;
271
258
  const progressBar = createProgressBar(name, totalBytes);
272
259
  const tempPath = getTempFile(cachedPath);
273
260
  fs.mkdirSync(path.dirname(tempPath), { recursive: true });
274
261
 
275
262
  await new Promise((resolve, reject) => {
276
- response.body
263
+ // Convert Web ReadableStream to Node.js stream
264
+ const nodeStream = stream.Readable.fromWeb(response.body);
265
+
266
+ nodeStream
277
267
  .on('error', (e) => reject(e))
278
268
  .on('data', (chunk) => {
279
269
  downloadedBytes += chunk.length;
280
- progressBar.tick(chunk.length);
270
+
271
+ if (!progressBar.complete) {
272
+ progressBar.tick(chunk.length);
273
+ }
281
274
  })
282
- .pipe(decompressor)
283
275
  .pipe(fs.createWriteStream(tempPath, { mode: '0755' }))
284
276
  .on('error', (e) => reject(e))
285
- .on('close', () => {
286
- if (downloadedBytes >= totalBytes) {
287
- resolve();
288
- } else {
277
+ .on('finish', () => {
278
+ // Check if we have a total size to validate against
279
+ if (totalBytes > 0 && downloadedBytes < totalBytes) {
289
280
  reject(new Error('connection interrupted'));
281
+ } else {
282
+ resolve();
290
283
  }
291
284
  });
292
285
  });