electron-builder-http
Advanced tools
Comparing version 13.6.0 to 13.10.0
@@ -6,4 +6,10 @@ "use strict"; | ||
}); | ||
exports.CancellationToken = undefined; | ||
exports.CancellationError = exports.CancellationToken = undefined; | ||
var _bluebirdLst; | ||
function _load_bluebirdLst() { | ||
return _bluebirdLst = _interopRequireDefault(require("bluebird-lst")); | ||
} | ||
var _events; | ||
@@ -15,3 +21,14 @@ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
class CancellationToken extends (_events || _load_events()).EventEmitter { | ||
// babel cannot compile ... correctly for super calls | ||
constructor(parent) { | ||
super(); | ||
this.parentCancelHandler = null; | ||
this._cancelled = false; | ||
if (parent != null) { | ||
this.parent = parent; | ||
} | ||
} | ||
get cancelled() { | ||
@@ -21,9 +38,7 @@ return this._cancelled || this._parent != null && this._parent.cancelled; | ||
set parent(value) { | ||
this.removeParentCancelHandler(); | ||
this._parent = value; | ||
this.parentCancelHandler = () => this.cancel(); | ||
this._parent.onCancel(this.parentCancelHandler); | ||
} | ||
// babel cannot compile ... correctly for super calls | ||
constructor() { | ||
super(); | ||
this._cancelled = false; | ||
} | ||
cancel() { | ||
@@ -34,11 +49,62 @@ this._cancelled = true; | ||
onCancel(handler) { | ||
this.once("cancel", handler); | ||
if (this.cancelled) { | ||
handler(); | ||
} else { | ||
this.once("cancel", handler); | ||
} | ||
} | ||
trackPromise(promise) { | ||
const handler = () => promise.cancel(); | ||
this.onCancel(handler); | ||
// it is important to return promise, otherwise will be unhandled rejection error on reject | ||
return promise.finally(() => this.removeListener("cancel", handler)); | ||
createPromise(callback) { | ||
if (this.cancelled) { | ||
return (_bluebirdLst || _load_bluebirdLst()).default.reject(new CancellationError()); | ||
} | ||
let cancelHandler = null; | ||
return new (_bluebirdLst || _load_bluebirdLst()).default((resolve, reject) => { | ||
let addedCancelHandler = null; | ||
cancelHandler = () => { | ||
try { | ||
if (addedCancelHandler != null) { | ||
addedCancelHandler(); | ||
addedCancelHandler = null; | ||
} | ||
} finally { | ||
reject(new CancellationError()); | ||
} | ||
}; | ||
if (this.cancelled) { | ||
cancelHandler(); | ||
return; | ||
} | ||
this.onCancel(cancelHandler); | ||
callback(resolve, reject, callback => { | ||
addedCancelHandler = callback; | ||
}); | ||
}).finally(() => { | ||
if (cancelHandler != null) { | ||
this.removeListener("cancel", cancelHandler); | ||
cancelHandler = null; | ||
} | ||
}); | ||
} | ||
removeParentCancelHandler() { | ||
const parent = this._parent; | ||
if (parent != null && this.parentCancelHandler != null) { | ||
parent.removeListener("cancel", this.parentCancelHandler); | ||
this.parentCancelHandler = null; | ||
} | ||
} | ||
dispose() { | ||
try { | ||
this.removeParentCancelHandler(); | ||
} finally { | ||
this.removeAllListeners(); | ||
this._parent = null; | ||
} | ||
} | ||
} | ||
exports.CancellationToken = CancellationToken; //# sourceMappingURL=CancellationToken.js.map | ||
exports.CancellationToken = CancellationToken; | ||
class CancellationError extends Error { | ||
constructor() { | ||
super("Cancelled"); | ||
} | ||
} | ||
exports.CancellationError = CancellationError; //# sourceMappingURL=CancellationToken.js.map |
declare module "electron-builder-http/out/CancellationToken" { | ||
/// <reference types="node" /> | ||
import { EventEmitter } from "events" | ||
import BluebirdPromise from "bluebird-lst-c" | ||
export class CancellationToken extends EventEmitter { | ||
private parentCancelHandler | ||
private _cancelled | ||
@@ -11,7 +11,13 @@ readonly cancelled: boolean | ||
parent: CancellationToken | ||
constructor() | ||
constructor(parent?: CancellationToken) | ||
cancel(): void | ||
onCancel(handler: () => any): void | ||
trackPromise(promise: BluebirdPromise<any>): BluebirdPromise<any> | ||
private onCancel(handler) | ||
createPromise<R>(callback: (resolve: (thenableOrResult?: R) => void, reject: (error?: any) => void, onCancel: (callback: () => void) => void) => void): Promise<R> | ||
private removeParentCancelHandler() | ||
dispose(): void | ||
} | ||
export class CancellationError extends Error { | ||
constructor() | ||
} | ||
} | ||
@@ -50,4 +56,23 @@ | ||
/** | ||
### `publish` | ||
Can be specified in the [config](https://github.com/electron-userland/electron-builder/wiki/Options#configuration-options) or any platform- or target- specific options. | ||
If `GH_TOKEN` is set — defaults to `[{provider: "github"}]`. | ||
If `BT_TOKEN` is set and `GH_TOKEN` is not set — defaults to `[{provider: "bintray"}]`. | ||
If `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` are set and neither `GH_TOKEN` and `BT_TOKEN` are set — defaults to `[{provider: "s3"}]`. | ||
Array of option objects. Order is important — first item will be used as a default auto-update server on Windows (NSIS). | ||
Amazon S3 — `https` must be used, so, if you use direct Amazon S3 endpoints, format `https://s3.amazonaws.com/bucket_name` [must be used](http://stackoverflow.com/a/11203685/1910191). And do not forget to make files/directories public. | ||
*/ | ||
export interface PublishConfiguration { | ||
/** | ||
The provider, one of `github`, `s3`, `bintray`, `generic`. | ||
*/ | ||
provider: PublishProvider | ||
/** | ||
The owner. | ||
*/ | ||
owner?: string | null | ||
@@ -57,3 +82,9 @@ token?: string | null | ||
/** | ||
### `publish` Generic (any HTTP(S) server) | ||
*/ | ||
export interface GenericServerOptions extends PublishConfiguration { | ||
/** | ||
The base url. e.g. `https://bucket_name.s3.amazonaws.com`. You can use `${os}` (expanded to `mac`, `linux` or `win` according to target platform) and `${arch}` macros. | ||
*/ | ||
url: string | ||
@@ -66,4 +97,15 @@ /** | ||
/** | ||
### `publish` Amazon S3 | ||
[Getting your credentials](http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/getting-your-credentials.html). | ||
*/ | ||
export interface S3Options extends PublishConfiguration { | ||
/** | ||
The bucket name. | ||
*/ | ||
bucket: string | ||
/** | ||
The directory path. Defaults to `/`. | ||
*/ | ||
path?: string | null | ||
@@ -78,2 +120,5 @@ /** | ||
acl?: "private" | "public-read" | null | ||
/** | ||
The type of storage to use for the object. One of `STANDARD`, `REDUCED_REDUNDANCY`, `STANDARD_IA`. Defaults to `STANDARD`. | ||
*/ | ||
storageClass?: "STANDARD" | "REDUCED_REDUNDANCY" | "STANDARD_IA" | null | ||
@@ -98,6 +143,23 @@ secret?: string | null | ||
/** | ||
### `publish` GitHub | ||
*/ | ||
export interface GithubOptions extends PublishConfiguration { | ||
/** | ||
The repository name. [Detected automatically](https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts#github-repository). | ||
*/ | ||
repo?: string | null | ||
/** | ||
Whether to use `v`-prefixed tag name. Defaults to `true`. | ||
*/ | ||
vPrefixedTagName?: boolean | ||
/** | ||
The host (including the port if need). Defaults to `github.com`. | ||
*/ | ||
host?: string | null | ||
/** | ||
The protocol, one of `https` or `http`. Defaults to `https`. | ||
GitHub Publisher supports only `https`. | ||
*/ | ||
protocol?: string | null | ||
@@ -108,5 +170,17 @@ } | ||
/** | ||
### `publish` Bintray | ||
*/ | ||
export interface BintrayOptions extends PublishConfiguration { | ||
/** | ||
The Bintray package name. | ||
*/ | ||
package?: string | null | ||
/** | ||
The Bintray repository name. Defaults to `generic`. | ||
*/ | ||
repo?: string | null | ||
/** | ||
The Bintray user account. Used in cases where the owner is an organization. | ||
*/ | ||
user?: string | null | ||
@@ -118,6 +192,6 @@ } | ||
/// <reference types="node" /> | ||
import { EventEmitter } from "events" | ||
import { RequestOptions } from "http" | ||
import { CancellationToken } from "electron-builder-http/out/CancellationToken" | ||
import { ProgressInfo } from "electron-builder-http/out/ProgressCallbackTransform" | ||
import { EventEmitter } from "events" | ||
import { CancellationToken } from "electron-builder-http/out/CancellationToken" | ||
@@ -176,6 +250,6 @@ export interface RequestHeaders { | ||
protected abstract doApiRequest<T>(options: REQUEST_OPTS, cancellationToken: CancellationToken, requestProcessor: (request: REQUEST, reject: (error: Error) => void) => void, redirectCount: number): Promise<T> | ||
abstract download(url: string, destination: string, options?: DownloadOptions | null): Promise<string> | ||
abstract download(url: string, destination: string, options: DownloadOptions): Promise<string> | ||
protected handleResponse(response: Response, options: RequestOptions, cancellationToken: CancellationToken, resolve: (data?: any) => void, reject: (error: Error) => void, redirectCount: number, requestProcessor: (request: REQUEST, reject: (error: Error) => void) => void): void | ||
protected abstract doRequest(options: any, callback: (response: any) => void): any | ||
protected doDownload(requestOptions: any, destination: string, redirectCount: number, options: DownloadOptions, callback: (error: Error | null) => void): void | ||
protected doDownload(requestOptions: any, destination: string, redirectCount: number, options: DownloadOptions, callback: (error: Error | null) => void, onCancel: (callback: () => void) => void): void | ||
protected addTimeOutHandler(request: any, callback: (error: Error) => void): void | ||
@@ -182,0 +256,0 @@ } |
@@ -18,6 +18,6 @@ "use strict"; | ||
var _stream; | ||
var _debug2; | ||
function _load_stream() { | ||
return _stream = require("stream"); | ||
function _load_debug() { | ||
return _debug2 = _interopRequireDefault(require("debug")); | ||
} | ||
@@ -31,2 +31,14 @@ | ||
var _jsYaml; | ||
function _load_jsYaml() { | ||
return _jsYaml = require("js-yaml"); | ||
} | ||
var _stream; | ||
function _load_stream() { | ||
return _stream = require("stream"); | ||
} | ||
var _url; | ||
@@ -38,6 +50,6 @@ | ||
var _debug2; | ||
var _CancellationToken; | ||
function _load_debug() { | ||
return _debug2 = _interopRequireDefault(require("debug")); | ||
function _load_CancellationToken() { | ||
return _CancellationToken = require("./CancellationToken"); | ||
} | ||
@@ -51,8 +63,2 @@ | ||
var _jsYaml; | ||
function _load_jsYaml() { | ||
return _jsYaml = require("js-yaml"); | ||
} | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -74,3 +80,3 @@ | ||
function download(url, destination, options) { | ||
return executorHolder.httpExecutor.download(url, destination, options); | ||
return executorHolder.httpExecutor.download(url, destination, options || { cancellationToken: new (_CancellationToken || _load_CancellationToken()).CancellationToken() }); | ||
} | ||
@@ -155,3 +161,3 @@ class HttpError extends Error { | ||
} | ||
doDownload(requestOptions, destination, redirectCount, options, callback) { | ||
doDownload(requestOptions, destination, redirectCount, options, callback, onCancel) { | ||
const request = this.doRequest(requestOptions, response => { | ||
@@ -170,3 +176,3 @@ if (response.statusCode >= 400) { | ||
port: parsedUrl.port == null ? undefined : parsedUrl.port | ||
}), destination, redirectCount++, options, callback); | ||
}), destination, redirectCount++, options, callback, onCancel); | ||
} else { | ||
@@ -177,6 +183,7 @@ callback(new Error(`Too many redirects (> ${this.maxRedirects})`)); | ||
} | ||
configurePipes(options, response, destination, callback); | ||
configurePipes(options, response, destination, callback, options.cancellationToken); | ||
}); | ||
this.addTimeOutHandler(request, callback); | ||
request.on("error", callback); | ||
onCancel(() => request.abort()); | ||
request.end(); | ||
@@ -236,3 +243,3 @@ } | ||
} | ||
function configurePipes(options, response, destination, callback) { | ||
function configurePipes(options, response, destination, callback, cancellationToken) { | ||
if (!checkSha2(safeGetHeader(response, "X-Checksum-Sha2"), options.sha2, callback)) { | ||
@@ -255,6 +262,12 @@ return; | ||
for (const stream of streams) { | ||
stream.on("error", callback); | ||
stream.on("error", error => { | ||
if (!cancellationToken.cancelled) { | ||
callback(error); | ||
} | ||
}); | ||
lastStream = lastStream.pipe(stream); | ||
} | ||
fileOut.on("finish", () => fileOut.close(callback)); | ||
fileOut.on("finish", () => { | ||
fileOut.close(callback); | ||
}); | ||
} | ||
@@ -261,0 +274,0 @@ function configureRequestOptions(options, token, method) { |
{ | ||
"name": "electron-builder-http", | ||
"version": "13.6.0", | ||
"version": "13.10.0", | ||
"main": "out/httpExecutor.js", | ||
@@ -16,5 +16,5 @@ "author": "Vladimir Krivosheev", | ||
"debug": "2.6.1", | ||
"fs-extra-p": "^3.1.0" | ||
"fs-extra-p": "^4.0.1" | ||
}, | ||
"typings": "./out/electron-builder-http.d.ts" | ||
} |
Sorry, the diff of this file is not supported yet
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
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
68719
742
+ Addedbluebird-lst@1.0.9(transitive)
+ Addedfs-extra@6.0.1(transitive)
+ Addedfs-extra-p@4.6.1(transitive)
+ Addedjsonfile@4.0.0(transitive)
+ Addeduniversalify@0.1.2(transitive)
- Removedbluebird-lst-c@1.0.6(transitive)
- Removedfs-extra@2.1.2(transitive)
- Removedfs-extra-p@3.1.0(transitive)
- Removedjsonfile@2.4.0(transitive)
Updatedfs-extra-p@^4.0.1