From 9cbb842199e6e3f68c415db824f37f891a362c5f Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Tue, 1 Sep 2020 12:59:16 -0400 Subject: [PATCH] fix using this in a plain function Signed-off-by: Sebastian Malton --- src/common/kube-helpers.ts | 2 +- src/main/cluster.ts | 2 +- src/main/index.ts | 2 +- src/main/kubectl.ts | 17 +++++++---------- src/main/logger.ts | 16 ++++++++++++++++ src/renderer/theme.store.ts | 2 +- webpack.dll.ts | 4 +++- webpack.main.ts | 14 ++++++++++---- webpack.renderer.ts | 5 +++-- 9 files changed, 43 insertions(+), 21 deletions(-) diff --git a/src/common/kube-helpers.ts b/src/common/kube-helpers.ts index 26e73db4a8..665f968d94 100644 --- a/src/common/kube-helpers.ts +++ b/src/common/kube-helpers.ts @@ -161,7 +161,7 @@ export async function getKubeConfigLocal(): Promise { } return yaml.safeDump(obj); } catch (err) { - logger.debug(`Cannot read local kube-config: ${err}`) + logger.debug("Cannot read local kube-config: ", err) return ""; } } diff --git a/src/main/cluster.ts b/src/main/cluster.ts index 6ba0fb1f48..c66b323319 100644 --- a/src/main/cluster.ts +++ b/src/main/cluster.ts @@ -248,7 +248,7 @@ export class Cluster implements ClusterModel { this.failureReason = null return ClusterStatus.AccessGranted; } catch (error) { - logger.error(`Failed to connect cluster "${this.contextName}": ${error}`) + logger.error(`Failed to connect cluster "${this.contextName}": `, error) if (error.statusCode) { if (error.statusCode >= 400 && error.statusCode < 500) { this.failureReason = "Invalid credentials"; diff --git a/src/main/index.ts b/src/main/index.ts index 3014b78c41..3da536e7f2 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -21,7 +21,7 @@ import logger from "./logger" const workingDir = path.join(app.getPath("appData"), appName); app.setName(appName); -if(!process.env.CICD) { +if (!process.env.CICD) { app.setPath("userData", workingDir); } diff --git a/src/main/kubectl.ts b/src/main/kubectl.ts index 249309fc32..52ccbc452b 100644 --- a/src/main/kubectl.ts +++ b/src/main/kubectl.ts @@ -100,7 +100,7 @@ elif test -f "$HOME/.bash_login"; then elif test -f "$HOME/.profile"; then . "$HOME/.profile" fi -export PATH="${this.dirname}:${helmPath}:$PATH" +export PATH="${dirname}:${helmPath}:$PATH" export KUBECONFIG="$tempkubeconfig" unset tempkubeconfig `; @@ -128,7 +128,7 @@ test -f "$OLD_ZDOTDIR/.zlogin" && . "$OLD_ZDOTDIR/.zlogin" test -f "$OLD_ZDOTDIR/.zshrc" && . "$OLD_ZDOTDIR/.zshrc" # voodoo to replace any previous occurences of kubectl path in the PATH -kubectlpath="${this.dirname}" +kubectlpath="${dirname}" helmpath="${helmPath}" p=":$kubectlpath:" d=":$PATH:" @@ -245,7 +245,7 @@ export class Kubectl { return true } catch (err) { - logger.error(`Could not copy the bundled kubectl to app-data: ${err}`) + logger.error("Could not copy the bundled kubectl to app-data: ", err) return false } } @@ -262,25 +262,22 @@ export class Kubectl { try { await this.downloadKubectl(); } catch (err) { - logger.error("Failed to write init scripts"); - logger.error(err); + logger.error("Failed to download kubectl: ", err); } } try { await this.ensureLatestInitScripts(); } catch (err) { - logger.error("Failed to write init scripts"); - logger.error(err) + logger.error("Failed to write init scripts: ", err); } logger.debug(`Releasing lock for ${this.kubectlVersion}`) await release() return true - } catch (e) { - logger.error(`Failed to get a lock for ${this.kubectlVersion}`) - logger.error(e) + } catch (err) { + logger.error(`Failed to get a lock for ${this.kubectlVersion}: `, err) return false; } } diff --git a/src/main/logger.ts b/src/main/logger.ts index eab9478bf0..0f5814a9c6 100644 --- a/src/main/logger.ts +++ b/src/main/logger.ts @@ -1,5 +1,7 @@ +import { app } from "electron"; import winston from "winston" import { isDebugging } from "../common/vars"; +import logform from "logform" const options = { colorize: true, @@ -8,8 +10,22 @@ const options = { level: isDebugging ? "debug" : "info", } +function ignoreInRenderer(...args: (() => T)[]): T[] { + return app ? args.map(f => f()) : []; +} + const logger = winston.createLogger({ format: winston.format.combine( + ...ignoreInRenderer( + () => winston.format.errors({ stack: true }), + () => winston.format(function (info: logform.TransformableInfo, opts?: any): boolean | logform.TransformableInfo { + if (info.stack) { + info.message += `\n\t${(info.stack as string).replace(/\n/g, "\n\t")}`; + delete info.stack + } + return info + })(), + ), winston.format.colorize(), winston.format.simple(), ), diff --git a/src/renderer/theme.store.ts b/src/renderer/theme.store.ts index 3cc7c352b6..7e6541ee97 100644 --- a/src/renderer/theme.store.ts +++ b/src/renderer/theme.store.ts @@ -79,7 +79,7 @@ export class ThemeStore { } return existingTheme; } catch (err) { - logger.error(`Can't load theme "${themeId}": ${err}`); + logger.error(`Can't load theme "${themeId}": `, err); } } diff --git a/webpack.dll.ts b/webpack.dll.ts index 000ba0af21..08c507b15e 100755 --- a/webpack.dll.ts +++ b/webpack.dll.ts @@ -13,7 +13,7 @@ export const packages = [ ]; export default function (): webpack.Configuration { - return { + const res: webpack.Configuration = { context: path.dirname(manifestPath), mode: isDevelopment ? "development" : "production", cache: isDevelopment, @@ -31,4 +31,6 @@ export default function (): webpack.Configuration { }) ], } + console.info('WEBPACK:dll', res) + return res } diff --git a/webpack.main.ts b/webpack.main.ts index 06c52f47dd..d0d52b25ab 100755 --- a/webpack.main.ts +++ b/webpack.main.ts @@ -3,14 +3,14 @@ import webpack from "webpack"; import ForkTsCheckerPlugin from "fork-ts-checker-webpack-plugin" import { isDevelopment, isProduction, mainDir, buildDir } from "./src/common/vars"; import nodeExternals from "webpack-node-externals"; +import TerserPlugin from "terser-webpack-plugin"; export default function (): webpack.Configuration { - console.info('WEBPACK:main', require("./src/common/vars")) - return { + const res: webpack.Configuration = { context: __dirname, target: "electron-main", mode: isProduction ? "production" : "development", - devtool: isProduction ? "source-map" : "cheap-eval-source-map", + devtool: "source-map", cache: isDevelopment, entry: { main: path.resolve(mainDir, "index.ts"), @@ -49,6 +49,12 @@ export default function (): webpack.Configuration { }, plugins: [ new ForkTsCheckerPlugin(), - ] + ], + optimization: { + minimize: isProduction, + minimizer: isProduction ? undefined : [new TerserPlugin()] + } } + console.info('WEBPACK:main', res) + return res } diff --git a/webpack.renderer.ts b/webpack.renderer.ts index b6c35535ce..e22c7c6a4b 100755 --- a/webpack.renderer.ts +++ b/webpack.renderer.ts @@ -7,8 +7,7 @@ import TerserPlugin from "terser-webpack-plugin"; import ForkTsCheckerPlugin from "fork-ts-checker-webpack-plugin" export default function (): webpack.Configuration { - console.info('WEBPACK:renderer', require("./src/common/vars")) - return { + const res: webpack.Configuration = { context: __dirname, target: "electron-renderer", devtool: "source-map", // todo: optimize in dev-mode with webpack.SourceMapDevToolPlugin @@ -157,4 +156,6 @@ export default function (): webpack.Configuration { }), ], } + console.info('WEBPACK:renderer', res) + return res } \ No newline at end of file