Skip to content

Commit

Permalink
fix: electron-updater throws "Cannot find namespace 'debug'" on TypeS…
Browse files Browse the repository at this point in the history
…cript compile

Close #1405
  • Loading branch information
develar committed Mar 25, 2017
1 parent b4462a2 commit 0f0de81
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
9 changes: 5 additions & 4 deletions packages/electron-builder-http/src/httpExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { parse as parseUrl } from "url"
import { CancellationToken } from "./CancellationToken"
import { ProgressCallbackTransform, ProgressInfo } from "./ProgressCallbackTransform"

const debug = _debug("electron-builder")

export interface RequestHeaders {
[key: string]: any
}
Expand Down Expand Up @@ -64,8 +66,7 @@ export class HttpError extends Error {

export abstract class HttpExecutor<REQUEST_OPTS, REQUEST> {
protected readonly maxRedirects = 10
protected readonly debug = _debug("electron-builder")


request<T>(options: RequestOptions, cancellationToken: CancellationToken, data?: { [name: string]: any; } | null): Promise<T> {
configureRequestOptions(options)
const encodedData = data == null ? undefined : new Buffer(JSON.stringify(data))
Expand All @@ -82,8 +83,8 @@ export abstract class HttpExecutor<REQUEST_OPTS, REQUEST> {
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) {
if (this.debug.enabled) {
this.debug(`Response status: ${response.statusCode} ${response.statusMessage}, request options: ${dumpRequestOptions(options)}`)
if (debug.enabled) {
debug(`Response status: ${response.statusCode} ${response.statusMessage}, request options: ${dumpRequestOptions(options)}`)
}

// we handle any other >= 400 error on request end (read detailed message in the response body)
Expand Down
7 changes: 5 additions & 2 deletions packages/electron-builder-util/src/nodeHttpExecutor.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _debug from "debug"
import { configureRequestOptions, DownloadOptions, HttpExecutor } from "electron-builder-http"
import { CancellationToken } from "electron-builder-http/out/CancellationToken"
import { ensureDir, readFile } from "fs-extra-p"
Expand All @@ -9,6 +10,8 @@ import { homedir } from "os"
import * as path from "path"
import { parse as parseUrl } from "url"

const debug = _debug("electron-builder")

export class NodeHttpExecutor extends HttpExecutor<RequestOptions, ClientRequest> {
private httpsAgentPromise: Promise<Agent> | null

Expand Down Expand Up @@ -41,8 +44,8 @@ export class NodeHttpExecutor extends HttpExecutor<RequestOptions, ClientRequest
}

doApiRequest<T>(options: RequestOptions, cancellationToken: CancellationToken, requestProcessor: (request: ClientRequest, reject: (error: Error) => void) => void, redirectCount: number = 0): Promise<T> {
if (this.debug.enabled) {
this.debug(`HTTPS request: ${JSON.stringify(options, null, 2)}`)
if (debug.enabled) {
debug(`HTTPS request: ${JSON.stringify(options, null, 2)}`)
}

return cancellationToken.createPromise((resolve, reject, onCancel) => {
Expand Down
7 changes: 5 additions & 2 deletions packages/electron-updater/src/electronHttpExecutor.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _debug from "debug"
import { net, session } from "electron"
import { configureRequestOptions, DownloadOptions, dumpRequestOptions, HttpExecutor } from "electron-builder-http"
import { CancellationToken } from "electron-builder-http/out/CancellationToken"
Expand All @@ -7,6 +8,8 @@ import { parse as parseUrl } from "url"

export const NET_SESSION_NAME = "electron-updater"

const debug = _debug("electron-builder")

export class ElectronHttpExecutor extends HttpExecutor<Electron.RequestOptions, Electron.ClientRequest> {
async download(url: string, destination: string, options: DownloadOptions): Promise<string> {
if (options == null || !options.skipDirCreation) {
Expand Down Expand Up @@ -34,8 +37,8 @@ export class ElectronHttpExecutor extends HttpExecutor<Electron.RequestOptions,
}

doApiRequest<T>(options: Electron.RequestOptions, cancellationToken: CancellationToken, requestProcessor: (request: Electron.ClientRequest, reject: (error: Error) => void) => void, redirectCount: number = 0): Promise<T> {
if (this.debug.enabled) {
this.debug(`request: ${dumpRequestOptions(options)}`)
if (debug.enabled) {
debug(`request: ${dumpRequestOptions(options)}`)
}

return cancellationToken.createPromise<T>((resolve, reject, onCancel) => {
Expand Down

0 comments on commit 0f0de81

Please sign in to comment.