diff --git a/.idea/dictionaries/develar.xml b/.idea/dictionaries/develar.xml index 27590af09f1..5e2a7ff90fa 100644 --- a/.idea/dictionaries/develar.xml +++ b/.idea/dictionaries/develar.xml @@ -163,6 +163,7 @@ <w>releasify</w> <w>rels</w> <w>repos</w> + <w>revalidate</w> <w>rimraf</w> <w>scripthost</w> <w>semver</w> diff --git a/package.json b/package.json index 42f23cb4c96..fa8b14f82db 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "path-sort": "^0.1.0", "source-map-support": "^0.4.10", "ts-babel": "^1.3.5", - "tslint": "^4.3.1", + "tslint": "^4.4.2", "typescript": "^2.1.5", "whitespace": "^2.1.0" }, diff --git a/packages/electron-builder-http/src/bintray.ts b/packages/electron-builder-http/src/bintray.ts index 2881cd70a5e..4a975065e00 100644 --- a/packages/electron-builder-http/src/bintray.ts +++ b/packages/electron-builder-http/src/bintray.ts @@ -1,7 +1,7 @@ import { BintrayOptions } from "./publishOptions" import { request, configureRequestOptions } from "./httpExecutor" -export function bintrayRequest<T>(path: string, auth: string | null, data: {[name: string]: any; } | null = null, method?: string): Promise<T> { +export function bintrayRequest<T>(path: string, auth: string | null, data: {[name: string]: any; } | null = null, method?: "GET" | "DELETE" | "PUT"): Promise<T> { return request<T>(configureRequestOptions({hostname: "api.bintray.com", path: path}, auth, method), data) } diff --git a/packages/electron-builder-http/src/httpExecutor.ts b/packages/electron-builder-http/src/httpExecutor.ts index 723bca5eb44..c0b9fdadd95 100644 --- a/packages/electron-builder-http/src/httpExecutor.ts +++ b/packages/electron-builder-http/src/httpExecutor.ts @@ -63,19 +63,14 @@ export abstract class HttpExecutor<REQUEST_OPTS, REQUEST> { protected readonly debug = _debug("electron-builder") request<T>(options: RequestOptions, data?: { [name: string]: any; } | null): Promise<T> { - options = Object.assign({headers: {"User-Agent": "electron-builder"}}, options) - + configureRequestOptions(options) const encodedData = data == null ? undefined : new Buffer(JSON.stringify(data)) if (encodedData != null) { options.method = "post" - if (options.headers == null) { - options.headers = {} - } - - options.headers["Content-Type"] = "application/json" - options.headers["Content-Length"] = encodedData.length + options.headers!["Content-Type"] = "application/json" + options.headers!["Content-Length"] = encodedData.length } - return this.doApiRequest<T>(<any>options, it => (<any>it).end(encodedData), 0) + return this.doApiRequest<T>(<REQUEST_OPTS>options, it => (<any>it).end(encodedData), 0) } protected abstract doApiRequest<T>(options: REQUEST_OPTS, requestProcessor: (request: REQUEST, reject: (error: Error) => void) => void, redirectCount: number): Promise<T> @@ -270,7 +265,7 @@ function configurePipes(options: DownloadOptions, response: any, destination: st fileOut.on("finish", () => (<any>fileOut.close)(callback)) } -export function configureRequestOptions(options: RequestOptions, token: string | null, method?: string): RequestOptions { +export function configureRequestOptions(options: RequestOptions, token?: string | null, method?: "GET" | "DELETE" | "PUT"): RequestOptions { if (method != null) { options.method = method } @@ -286,6 +281,10 @@ export function configureRequestOptions(options: RequestOptions, token: string | if (headers["User-Agent"] == null) { headers["User-Agent"] = "electron-builder" } + + if ((method == null || method === "GET") || headers["Cache-Control"] == null) { + headers["Cache-Control"] = "no-cache" + } return options } diff --git a/packages/electron-builder/src/publish/BintrayPublisher.ts b/packages/electron-builder/src/publish/BintrayPublisher.ts index 462070cb9b6..ef139c55920 100644 --- a/packages/electron-builder/src/publish/BintrayPublisher.ts +++ b/packages/electron-builder/src/publish/BintrayPublisher.ts @@ -63,7 +63,6 @@ export class BintrayPublisher extends Publisher { path: `/content/${this.client.owner}/${this.client.repo}/${this.client.packageName}/${version.name}/${fileName}`, method: "PUT", headers: { - "User-Agent": "electron-builder", "Content-Length": dataLength, "X-Bintray-Override": "1", "X-Bintray-Publish": "1", diff --git a/packages/electron-builder/src/publish/gitHubPublisher.ts b/packages/electron-builder/src/publish/gitHubPublisher.ts index 9390183ba32..d65fd1188f4 100644 --- a/packages/electron-builder/src/publish/gitHubPublisher.ts +++ b/packages/electron-builder/src/publish/gitHubPublisher.ts @@ -103,7 +103,6 @@ export class GitHubPublisher extends Publisher { method: "POST", headers: { Accept: "application/vnd.github.v3+json", - "User-Agent": "electron-builder", "Content-Type": mime.lookup(fileName), "Content-Length": dataLength } @@ -180,7 +179,7 @@ export class GitHubPublisher extends Publisher { warn(`Cannot delete release ${release.id}`) } - private githubRequest<T>(path: string, token: string | null, data: {[name: string]: any; } | null = null, method?: string): Promise<T> { + private githubRequest<T>(path: string, token: string | null, data: {[name: string]: any; } | null = null, method?: "GET" | "DELETE" | "PUT"): Promise<T> { return this.httpExecutor.request<T>(configureRequestOptions({ hostname: "api.github.com", path: path, diff --git a/packages/electron-builder/src/util/nodeHttpExecutor.ts b/packages/electron-builder/src/util/nodeHttpExecutor.ts index 7b205ac2d8d..d4581bf61f9 100644 --- a/packages/electron-builder/src/util/nodeHttpExecutor.ts +++ b/packages/electron-builder/src/util/nodeHttpExecutor.ts @@ -5,7 +5,7 @@ import BluebirdPromise from "bluebird-lst-c" import * as path from "path" import { homedir } from "os" import { parse as parseIni } from "ini" -import { HttpExecutor, DownloadOptions } from "electron-builder-http" +import { HttpExecutor, DownloadOptions, configureRequestOptions } from "electron-builder-http" import { RequestOptions } from "https" import { parse as parseUrl } from "url" @@ -24,14 +24,12 @@ export class NodeHttpExecutor extends HttpExecutor<RequestOptions, ClientRequest const agent = await this.httpsAgentPromise return await new BluebirdPromise<string>((resolve, reject) => { const parsedUrl = parseUrl(url) - this.doDownload({ + this.doDownload(configureRequestOptions({ hostname: parsedUrl.hostname, path: parsedUrl.path, - headers: Object.assign({ - "User-Agent": "electron-builder" - }, options == null ? null : options.headers), + headers: (options == null ? null : options.headers) || undefined, agent: agent, - }, destination, 0, options || {}, (error: Error) => { + }), destination, 0, options || {}, (error: Error) => { if (error == null) { resolve(destination) } diff --git a/packages/electron-updater/src/AppUpdater.ts b/packages/electron-updater/src/AppUpdater.ts index 7ae16b56b87..23c242d6bac 100644 --- a/packages/electron-updater/src/AppUpdater.ts +++ b/packages/electron-updater/src/AppUpdater.ts @@ -37,11 +37,11 @@ export abstract class AppUpdater extends EventEmitter { public readonly signals = new UpdaterSignal(this) - private appUpdateConfigPath: string | null + private _appUpdateConfigPath: string | null - setUpdateConfigPath(value: string | null) { + set updateConfigPath(value: string | null) { this.clientPromise = null - this.appUpdateConfigPath = value + this._appUpdateConfigPath = value } protected updateAvailable = false @@ -232,10 +232,10 @@ export abstract class AppUpdater extends EventEmitter { abstract quitAndInstall(): void async loadUpdateConfig() { - if (this.appUpdateConfigPath == null) { - this.appUpdateConfigPath = path.join(process.resourcesPath, "app-update.yml") + if (this._appUpdateConfigPath == null) { + this._appUpdateConfigPath = path.join(process.resourcesPath, "app-update.yml") } - return safeLoad(await readFile(this.appUpdateConfigPath, "utf-8")) + return safeLoad(await readFile(this._appUpdateConfigPath, "utf-8")) } } diff --git a/packages/electron-updater/src/GenericProvider.ts b/packages/electron-updater/src/GenericProvider.ts index cc99abc87ee..72f89d95f94 100644 --- a/packages/electron-updater/src/GenericProvider.ts +++ b/packages/electron-updater/src/GenericProvider.ts @@ -22,7 +22,7 @@ export class GenericProvider extends Provider<UpdateInfo> { hostname: this.baseUrl.hostname, path: `${pathname}${this.baseUrl.search || ""}`, protocol: this.baseUrl.protocol, - headers: Object.assign({"Cache-Control": "no-cache, no-store, must-revalidate"}, this.requestHeaders) + headers: this.requestHeaders || undefined } if (this.baseUrl.port != null) { options.port = parseInt(this.baseUrl.port, 10) diff --git a/packages/electron-updater/src/NsisUpdater.ts b/packages/electron-updater/src/NsisUpdater.ts index 5e0f1128c91..6093814979a 100644 --- a/packages/electron-updater/src/NsisUpdater.ts +++ b/packages/electron-updater/src/NsisUpdater.ts @@ -24,6 +24,7 @@ export class NsisUpdater extends AppUpdater { protected async doDownloadUpdate(versionInfo: VersionInfo, fileInfo: FileInfo) { const downloadOptions: DownloadOptions = { skipDirCreation: true, + headers: this.requestHeaders || undefined, } if (this.listenerCount(DOWNLOAD_PROGRESS) > 0) { @@ -33,9 +34,6 @@ export class NsisUpdater extends AppUpdater { if (fileInfo != null && fileInfo.sha2 != null) { downloadOptions.sha2 = fileInfo.sha2 } - if (this.requestHeaders != null) { - downloadOptions.headers = this.requestHeaders - } const logger = this.logger const tempDir = await mkdtemp(`${path.join(tmpdir(), "up")}-`) diff --git a/packages/electron-updater/src/electronHttpExecutor.ts b/packages/electron-updater/src/electronHttpExecutor.ts index c456c160ee1..378717e8613 100644 --- a/packages/electron-updater/src/electronHttpExecutor.ts +++ b/packages/electron-updater/src/electronHttpExecutor.ts @@ -2,7 +2,7 @@ import { net } from "electron" import { ensureDir } from "fs-extra-p" import BluebirdPromise from "bluebird-lst-c" import * as path from "path" -import { HttpExecutor, DownloadOptions, dumpRequestOptions } from "electron-builder-http" +import { HttpExecutor, DownloadOptions, dumpRequestOptions, configureRequestOptions } from "electron-builder-http" import { parse as parseUrl } from "url" export class ElectronHttpExecutor extends HttpExecutor<Electron.RequestOptions, Electron.ClientRequest> { @@ -14,15 +14,13 @@ export class ElectronHttpExecutor extends HttpExecutor<Electron.RequestOptions, return await new BluebirdPromise<string>((resolve, reject) => { const parsedUrl = parseUrl(url) - this.doDownload({ + this.doDownload(configureRequestOptions({ protocol: parsedUrl.protocol, hostname: parsedUrl.hostname, path: parsedUrl.path, - port: parsedUrl.port ? parsedUrl.port : undefined, - headers: Object.assign({ - "User-Agent": "electron-builder" - }, options == null ? null : options.headers), - }, destination, 0, options || {}, (error: Error) => { + port: parsedUrl.port ? parseInt(parsedUrl.port, 10) : undefined, + headers: (options == null ? null : options.headers) || undefined, + }), destination, 0, options || {}, (error: Error) => { if (error == null) { resolve(destination) } diff --git a/packages/lint.js b/packages/lint.js index b67066421ed..e04c4d16b01 100644 --- a/packages/lint.js +++ b/packages/lint.js @@ -5,7 +5,7 @@ const fs = require("fs") const path = require("path") const configuration = { - "extends": "tslint:recommended", + "extends": "tslint:latest", "rules": { "no-invalid-this": [true], "member-ordering": [ @@ -60,9 +60,6 @@ const configuration = { "no-bitwise": false, "jsdoc-format": false, "no-for-in-array": true, - "prefer-const": true, - "interface-over-type-literal": true, - "no-string-throw": true, } } const options = { diff --git a/test/src/nsisUpdaterTest.ts b/test/src/nsisUpdaterTest.ts index 2d0f30ab860..36d0c7cee77 100644 --- a/test/src/nsisUpdaterTest.ts +++ b/test/src/nsisUpdaterTest.ts @@ -49,11 +49,11 @@ test("cannot find suitable file for version", async () => { test("file url", async () => { const updater = new NsisUpdater() - updater.setUpdateConfigPath(await writeUpdateConfig(<BintrayOptions>{ + updater.updateConfigPath = await writeUpdateConfig(<BintrayOptions>{ provider: "bintray", owner: "actperepo", package: "TestApp", - })) + }) const actualEvents: Array<string> = [] const expectedEvents = ["checking-for-update", "update-available", "update-downloaded"] @@ -72,10 +72,10 @@ test("file url", async () => { test("file url generic", async () => { const updater = new NsisUpdater() - updater.setUpdateConfigPath(await writeUpdateConfig(<GenericServerOptions>{ + updater.updateConfigPath = await writeUpdateConfig(<GenericServerOptions>{ provider: "generic", url: "https://develar.s3.amazonaws.com/test", - })) + }) const actualEvents = trackEvents(updater) @@ -88,11 +88,11 @@ test("file url generic", async () => { test("sha2 mismatch error event", async () => { const updater = new NsisUpdater() - updater.setUpdateConfigPath(await writeUpdateConfig(<GenericServerOptions>{ + updater.updateConfigPath = await writeUpdateConfig(<GenericServerOptions>{ provider: "generic", url: "https://develar.s3.amazonaws.com/test", channel: "beta", - })) + }) updater.logger = console const actualEvents = trackEvents(updater) @@ -106,10 +106,10 @@ test("sha2 mismatch error event", async () => { test("file url generic - manual download", async () => { const updater = new NsisUpdater() - updater.setUpdateConfigPath(await writeUpdateConfig(<GenericServerOptions>{ + updater.updateConfigPath = await writeUpdateConfig(<GenericServerOptions>{ provider: "generic", url: "https://develar.s3.amazonaws.com/test", - })) + }) updater.autoDownload = false const actualEvents = trackEvents(updater) @@ -125,10 +125,10 @@ test("file url generic - manual download", async () => { // https://github.com/electron-userland/electron-builder/issues/1045 test("checkForUpdates several times", async () => { const updater = new NsisUpdater() - updater.setUpdateConfigPath(await writeUpdateConfig(<GenericServerOptions>{ + updater.updateConfigPath = await writeUpdateConfig(<GenericServerOptions>{ provider: "generic", url: "https://develar.s3.amazonaws.com/test", - })) + }) const actualEvents = trackEvents(updater) @@ -145,11 +145,11 @@ test("checkForUpdates several times", async () => { test("file url github", async () => { const updater = new NsisUpdater() - updater.setUpdateConfigPath(await writeUpdateConfig(<GithubOptions>{ + updater.updateConfigPath = await writeUpdateConfig(<GithubOptions>{ provider: "github", owner: "develar", repo: "__test_nsis_release", - })) + }) const actualEvents: Array<string> = [] const expectedEvents = ["checking-for-update", "update-available", "update-downloaded"] @@ -177,10 +177,10 @@ test("test error", async () => { test("test download progress", async () => { const updater = new NsisUpdater() - updater.setUpdateConfigPath(await writeUpdateConfig({ + updater.updateConfigPath = await writeUpdateConfig({ provider: "generic", url: "https://develar.s3.amazonaws.com/test", - })) + }) updater.autoDownload = false const progressEvents: Array<any> = [] diff --git a/yarn.lock b/yarn.lock index f03e4e4517f..39685597019 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2767,7 +2767,7 @@ ts-babel@^1.3.5: markdown-it "^8.2.2" source-map-support "^0.4.10" -tslint@^4.3.1: +tslint@^4.4.2: version "4.4.2" resolved "https://registry.yarnpkg.com/tslint/-/tslint-4.4.2.tgz#b14cb79ae039c72471ab4c2627226b940dda19c6" dependencies: