From 0f0de81a10ffc03b71d78c2fdecfd29443a5313c Mon Sep 17 00:00:00 2001 From: develar Date: Sat, 25 Mar 2017 16:35:26 +0100 Subject: [PATCH] fix: electron-updater throws "Cannot find namespace 'debug'" on TypeScript compile Close #1405 --- packages/electron-builder-http/src/httpExecutor.ts | 9 +++++---- packages/electron-builder-util/src/nodeHttpExecutor.ts | 7 +++++-- packages/electron-updater/src/electronHttpExecutor.ts | 7 +++++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/packages/electron-builder-http/src/httpExecutor.ts b/packages/electron-builder-http/src/httpExecutor.ts index 5a7b4c7047f..bef00cdc96e 100644 --- a/packages/electron-builder-http/src/httpExecutor.ts +++ b/packages/electron-builder-http/src/httpExecutor.ts @@ -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 } @@ -64,8 +66,7 @@ export class HttpError extends Error { export abstract class HttpExecutor { protected readonly maxRedirects = 10 - protected readonly debug = _debug("electron-builder") - + request(options: RequestOptions, cancellationToken: CancellationToken, data?: { [name: string]: any; } | null): Promise { configureRequestOptions(options) const encodedData = data == null ? undefined : new Buffer(JSON.stringify(data)) @@ -82,8 +83,8 @@ export abstract class HttpExecutor { abstract download(url: string, destination: string, options: DownloadOptions): Promise 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) diff --git a/packages/electron-builder-util/src/nodeHttpExecutor.ts b/packages/electron-builder-util/src/nodeHttpExecutor.ts index 43c9e8f3d73..0b003ec529b 100644 --- a/packages/electron-builder-util/src/nodeHttpExecutor.ts +++ b/packages/electron-builder-util/src/nodeHttpExecutor.ts @@ -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" @@ -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 { private httpsAgentPromise: Promise | null @@ -41,8 +44,8 @@ export class NodeHttpExecutor extends HttpExecutor(options: RequestOptions, cancellationToken: CancellationToken, requestProcessor: (request: ClientRequest, reject: (error: Error) => void) => void, redirectCount: number = 0): Promise { - 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) => { diff --git a/packages/electron-updater/src/electronHttpExecutor.ts b/packages/electron-updater/src/electronHttpExecutor.ts index bd4fcca93ef..bc463725e5a 100644 --- a/packages/electron-updater/src/electronHttpExecutor.ts +++ b/packages/electron-updater/src/electronHttpExecutor.ts @@ -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" @@ -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 { async download(url: string, destination: string, options: DownloadOptions): Promise { if (options == null || !options.skipDirCreation) { @@ -34,8 +37,8 @@ export class ElectronHttpExecutor extends HttpExecutor(options: Electron.RequestOptions, cancellationToken: CancellationToken, requestProcessor: (request: Electron.ClientRequest, reject: (error: Error) => void) => void, redirectCount: number = 0): Promise { - if (this.debug.enabled) { - this.debug(`request: ${dumpRequestOptions(options)}`) + if (debug.enabled) { + debug(`request: ${dumpRequestOptions(options)}`) } return cancellationToken.createPromise((resolve, reject, onCancel) => {