@electron/get
Advanced tools
Comparing version 1.8.0 to 1.9.0
@@ -0,7 +1,19 @@ | ||
import * as got from 'got'; | ||
import { Downloader } from './Downloader'; | ||
export declare class GotDownloader implements Downloader<any> { | ||
/** | ||
* See [`got#options`](https://github.com/sindresorhus/got#options) for possible keys/values. | ||
*/ | ||
export declare type GotDownloaderOptions = got.GotOptions<string | null> & { | ||
/** | ||
* @param options - see [`got#options`](https://github.com/sindresorhus/got#options) for possible keys/values. | ||
* if defined, triggers every time `got`'s `downloadProgress` event callback is triggered. | ||
*/ | ||
download(url: string, targetFilePath: string, options?: any): Promise<void>; | ||
getProgressCallback?: (progress: got.Progress) => Promise<void>; | ||
/** | ||
* if `true`, disables the console progress bar (setting the `ELECTRON_GET_NO_PROGRESS` | ||
* environment variable to a non-empty value also does this). | ||
*/ | ||
quiet?: boolean; | ||
}; | ||
export declare class GotDownloader implements Downloader<GotDownloaderOptions> { | ||
download(url: string, targetFilePath: string, options?: GotDownloaderOptions): Promise<void>; | ||
} |
"use strict"; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) | ||
t[p[i]] = s[p[i]]; | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -6,12 +15,40 @@ const fs = require("fs-extra"); | ||
const path = require("path"); | ||
const ProgressBar = require("progress"); | ||
const PROGRESS_BAR_DELAY_IN_SECONDS = 30; | ||
class GotDownloader { | ||
/** | ||
* @param options - see [`got#options`](https://github.com/sindresorhus/got#options) for possible keys/values. | ||
*/ | ||
async download(url, targetFilePath, options) { | ||
if (!options) { | ||
options = {}; | ||
} | ||
const { quiet, getProgressCallback } = options, gotOptions = __rest(options, ["quiet", "getProgressCallback"]); | ||
let downloadCompleted = false; | ||
let bar; | ||
let progressPercent; | ||
let timeout = undefined; | ||
await fs.mkdirp(path.dirname(targetFilePath)); | ||
const writeStream = fs.createWriteStream(targetFilePath); | ||
if (!quiet || !process.env.ELECTRON_GET_NO_PROGRESS) { | ||
const start = new Date(); | ||
timeout = setTimeout(() => { | ||
if (!downloadCompleted) { | ||
bar = new ProgressBar(`Downloading ${path.basename(url)}: [:bar] :percent ETA: :eta seconds `, { | ||
curr: progressPercent, | ||
total: 100, | ||
}); | ||
// https://github.com/visionmedia/node-progress/issues/159 | ||
bar.start = start; | ||
} | ||
}, PROGRESS_BAR_DELAY_IN_SECONDS * 1000); | ||
} | ||
await new Promise((resolve, reject) => { | ||
const downloadStream = got.stream(url, options); | ||
downloadStream.pipe(writeStream); | ||
const downloadStream = got.stream(url, gotOptions); | ||
downloadStream.on('downloadProgress', async (progress) => { | ||
progressPercent = progress.percent; | ||
if (bar) { | ||
bar.update(progress.percent); | ||
} | ||
if (getProgressCallback) { | ||
await getProgressCallback(progress); | ||
} | ||
}); | ||
downloadStream.on('error', error => { | ||
@@ -28,3 +65,8 @@ if (error.name === 'HTTPError' && error.statusCode === 404) { | ||
writeStream.on('close', () => resolve()); | ||
downloadStream.pipe(writeStream); | ||
}); | ||
downloadCompleted = true; | ||
if (timeout) { | ||
clearTimeout(timeout); | ||
} | ||
} | ||
@@ -31,0 +73,0 @@ } |
@@ -0,7 +1,19 @@ | ||
import * as got from 'got'; | ||
import { Downloader } from './Downloader'; | ||
export declare class GotDownloader implements Downloader<any> { | ||
/** | ||
* See [`got#options`](https://github.com/sindresorhus/got#options) for possible keys/values. | ||
*/ | ||
export declare type GotDownloaderOptions = got.GotOptions<string | null> & { | ||
/** | ||
* @param options - see [`got#options`](https://github.com/sindresorhus/got#options) for possible keys/values. | ||
* if defined, triggers every time `got`'s `downloadProgress` event callback is triggered. | ||
*/ | ||
download(url: string, targetFilePath: string, options?: any): Promise<void>; | ||
getProgressCallback?: (progress: got.Progress) => Promise<void>; | ||
/** | ||
* if `true`, disables the console progress bar (setting the `ELECTRON_GET_NO_PROGRESS` | ||
* environment variable to a non-empty value also does this). | ||
*/ | ||
quiet?: boolean; | ||
}; | ||
export declare class GotDownloader implements Downloader<GotDownloaderOptions> { | ||
download(url: string, targetFilePath: string, options?: GotDownloaderOptions): Promise<void>; | ||
} |
@@ -0,14 +1,51 @@ | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) | ||
t[p[i]] = s[p[i]]; | ||
return t; | ||
}; | ||
import * as fs from 'fs-extra'; | ||
import * as got from 'got'; | ||
import * as path from 'path'; | ||
import * as ProgressBar from 'progress'; | ||
const PROGRESS_BAR_DELAY_IN_SECONDS = 30; | ||
export class GotDownloader { | ||
/** | ||
* @param options - see [`got#options`](https://github.com/sindresorhus/got#options) for possible keys/values. | ||
*/ | ||
async download(url, targetFilePath, options) { | ||
if (!options) { | ||
options = {}; | ||
} | ||
const { quiet, getProgressCallback } = options, gotOptions = __rest(options, ["quiet", "getProgressCallback"]); | ||
let downloadCompleted = false; | ||
let bar; | ||
let progressPercent; | ||
let timeout = undefined; | ||
await fs.mkdirp(path.dirname(targetFilePath)); | ||
const writeStream = fs.createWriteStream(targetFilePath); | ||
if (!quiet || !process.env.ELECTRON_GET_NO_PROGRESS) { | ||
const start = new Date(); | ||
timeout = setTimeout(() => { | ||
if (!downloadCompleted) { | ||
bar = new ProgressBar(`Downloading ${path.basename(url)}: [:bar] :percent ETA: :eta seconds `, { | ||
curr: progressPercent, | ||
total: 100, | ||
}); | ||
// https://github.com/visionmedia/node-progress/issues/159 | ||
bar.start = start; | ||
} | ||
}, PROGRESS_BAR_DELAY_IN_SECONDS * 1000); | ||
} | ||
await new Promise((resolve, reject) => { | ||
const downloadStream = got.stream(url, options); | ||
downloadStream.pipe(writeStream); | ||
const downloadStream = got.stream(url, gotOptions); | ||
downloadStream.on('downloadProgress', async (progress) => { | ||
progressPercent = progress.percent; | ||
if (bar) { | ||
bar.update(progress.percent); | ||
} | ||
if (getProgressCallback) { | ||
await getProgressCallback(progress); | ||
} | ||
}); | ||
downloadStream.on('error', error => { | ||
@@ -25,5 +62,10 @@ if (error.name === 'HTTPError' && error.statusCode === 404) { | ||
writeStream.on('close', () => resolve()); | ||
downloadStream.pipe(writeStream); | ||
}); | ||
downloadCompleted = true; | ||
if (timeout) { | ||
clearTimeout(timeout); | ||
} | ||
} | ||
} | ||
//# sourceMappingURL=GotDownloader.js.map |
{ | ||
"name": "@electron/get", | ||
"version": "1.8.0", | ||
"version": "1.9.0", | ||
"description": "Utility for downloading artifacts from different versions of Electron", | ||
@@ -31,2 +31,3 @@ "main": "dist/cjs/index.js", | ||
"got": "^9.6.0", | ||
"progress": "^2.0.3", | ||
"sanitize-filename": "^1.6.2", | ||
@@ -42,2 +43,3 @@ "sumchecker": "^3.0.1" | ||
"@types/node": "^12.0.2", | ||
"@types/progress": "^2.0.3", | ||
"@types/sanitize-filename": "^1.1.28", | ||
@@ -44,0 +46,0 @@ "husky": "^2.3.0", |
@@ -104,2 +104,10 @@ # @electron/get | ||
### Progress Bar | ||
By default, a progress bar is shown when downloading an artifact for more than 30 seconds. To | ||
disable, set the `ELECTRON_GET_NO_PROGRESS` environment variable to any non-empty value, or set | ||
`quiet` to `true` in `downloadOptions`. If you need to monitor progress yourself via the API, set | ||
`getProgressCallback` in `downloadOptions`, which has the same function signature as `got`'s | ||
[`downloadProgress` event callback](https://github.com/sindresorhus/got#ondownloadprogress-progress). | ||
### Proxies | ||
@@ -106,0 +114,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
70750
1044
121
9
16
19
+ Addedprogress@^2.0.3
+ Addedprogress@2.0.3(transitive)