1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

fix using this in a plain function

Signed-off-by: Sebastian Malton <smalton@mirantis.com>
This commit is contained in:
Sebastian Malton 2020-09-01 12:59:16 -04:00
parent df77e959a5
commit 9cbb842199
9 changed files with 43 additions and 21 deletions

View File

@ -161,7 +161,7 @@ export async function getKubeConfigLocal(): Promise<string> {
} }
return yaml.safeDump(obj); return yaml.safeDump(obj);
} catch (err) { } catch (err) {
logger.debug(`Cannot read local kube-config: ${err}`) logger.debug("Cannot read local kube-config: ", err)
return ""; return "";
} }
} }

View File

@ -248,7 +248,7 @@ export class Cluster implements ClusterModel {
this.failureReason = null this.failureReason = null
return ClusterStatus.AccessGranted; return ClusterStatus.AccessGranted;
} catch (error) { } 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) {
if (error.statusCode >= 400 && error.statusCode < 500) { if (error.statusCode >= 400 && error.statusCode < 500) {
this.failureReason = "Invalid credentials"; this.failureReason = "Invalid credentials";

View File

@ -21,7 +21,7 @@ import logger from "./logger"
const workingDir = path.join(app.getPath("appData"), appName); const workingDir = path.join(app.getPath("appData"), appName);
app.setName(appName); app.setName(appName);
if(!process.env.CICD) { if (!process.env.CICD) {
app.setPath("userData", workingDir); app.setPath("userData", workingDir);
} }

View File

@ -100,7 +100,7 @@ elif test -f "$HOME/.bash_login"; then
elif test -f "$HOME/.profile"; then elif test -f "$HOME/.profile"; then
. "$HOME/.profile" . "$HOME/.profile"
fi fi
export PATH="${this.dirname}:${helmPath}:$PATH" export PATH="${dirname}:${helmPath}:$PATH"
export KUBECONFIG="$tempkubeconfig" export KUBECONFIG="$tempkubeconfig"
unset tempkubeconfig unset tempkubeconfig
`; `;
@ -128,7 +128,7 @@ test -f "$OLD_ZDOTDIR/.zlogin" && . "$OLD_ZDOTDIR/.zlogin"
test -f "$OLD_ZDOTDIR/.zshrc" && . "$OLD_ZDOTDIR/.zshrc" test -f "$OLD_ZDOTDIR/.zshrc" && . "$OLD_ZDOTDIR/.zshrc"
# voodoo to replace any previous occurences of kubectl path in the PATH # voodoo to replace any previous occurences of kubectl path in the PATH
kubectlpath="${this.dirname}" kubectlpath="${dirname}"
helmpath="${helmPath}" helmpath="${helmPath}"
p=":$kubectlpath:" p=":$kubectlpath:"
d=":$PATH:" d=":$PATH:"
@ -245,7 +245,7 @@ export class Kubectl {
return true return true
} catch (err) { } 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 return false
} }
} }
@ -262,25 +262,22 @@ export class Kubectl {
try { try {
await this.downloadKubectl(); await this.downloadKubectl();
} catch (err) { } catch (err) {
logger.error("Failed to write init scripts"); logger.error("Failed to download kubectl: ", err);
logger.error(err);
} }
} }
try { try {
await this.ensureLatestInitScripts(); await this.ensureLatestInitScripts();
} catch (err) { } catch (err) {
logger.error("Failed to write init scripts"); logger.error("Failed to write init scripts: ", err);
logger.error(err)
} }
logger.debug(`Releasing lock for ${this.kubectlVersion}`) logger.debug(`Releasing lock for ${this.kubectlVersion}`)
await release() await release()
return true return true
} catch (e) { } catch (err) {
logger.error(`Failed to get a lock for ${this.kubectlVersion}`) logger.error(`Failed to get a lock for ${this.kubectlVersion}: `, err)
logger.error(e)
return false; return false;
} }
} }

View File

@ -1,5 +1,7 @@
import { app } from "electron";
import winston from "winston" import winston from "winston"
import { isDebugging } from "../common/vars"; import { isDebugging } from "../common/vars";
import logform from "logform"
const options = { const options = {
colorize: true, colorize: true,
@ -8,8 +10,22 @@ const options = {
level: isDebugging ? "debug" : "info", level: isDebugging ? "debug" : "info",
} }
function ignoreInRenderer<T>(...args: (() => T)[]): T[] {
return app ? args.map(f => f()) : [];
}
const logger = winston.createLogger({ const logger = winston.createLogger({
format: winston.format.combine( 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.colorize(),
winston.format.simple(), winston.format.simple(),
), ),

View File

@ -79,7 +79,7 @@ export class ThemeStore {
} }
return existingTheme; return existingTheme;
} catch (err) { } catch (err) {
logger.error(`Can't load theme "${themeId}": ${err}`); logger.error(`Can't load theme "${themeId}": `, err);
} }
} }

View File

@ -13,7 +13,7 @@ export const packages = [
]; ];
export default function (): webpack.Configuration { export default function (): webpack.Configuration {
return { const res: webpack.Configuration = {
context: path.dirname(manifestPath), context: path.dirname(manifestPath),
mode: isDevelopment ? "development" : "production", mode: isDevelopment ? "development" : "production",
cache: isDevelopment, cache: isDevelopment,
@ -31,4 +31,6 @@ export default function (): webpack.Configuration {
}) })
], ],
} }
console.info('WEBPACK:dll', res)
return res
} }

View File

@ -3,14 +3,14 @@ import webpack from "webpack";
import ForkTsCheckerPlugin from "fork-ts-checker-webpack-plugin" import ForkTsCheckerPlugin from "fork-ts-checker-webpack-plugin"
import { isDevelopment, isProduction, mainDir, buildDir } from "./src/common/vars"; import { isDevelopment, isProduction, mainDir, buildDir } from "./src/common/vars";
import nodeExternals from "webpack-node-externals"; import nodeExternals from "webpack-node-externals";
import TerserPlugin from "terser-webpack-plugin";
export default function (): webpack.Configuration { export default function (): webpack.Configuration {
console.info('WEBPACK:main', require("./src/common/vars")) const res: webpack.Configuration = {
return {
context: __dirname, context: __dirname,
target: "electron-main", target: "electron-main",
mode: isProduction ? "production" : "development", mode: isProduction ? "production" : "development",
devtool: isProduction ? "source-map" : "cheap-eval-source-map", devtool: "source-map",
cache: isDevelopment, cache: isDevelopment,
entry: { entry: {
main: path.resolve(mainDir, "index.ts"), main: path.resolve(mainDir, "index.ts"),
@ -49,6 +49,12 @@ export default function (): webpack.Configuration {
}, },
plugins: [ plugins: [
new ForkTsCheckerPlugin(), new ForkTsCheckerPlugin(),
] ],
optimization: {
minimize: isProduction,
minimizer: isProduction ? undefined : [new TerserPlugin()]
}
} }
console.info('WEBPACK:main', res)
return res
} }

View File

@ -7,8 +7,7 @@ import TerserPlugin from "terser-webpack-plugin";
import ForkTsCheckerPlugin from "fork-ts-checker-webpack-plugin" import ForkTsCheckerPlugin from "fork-ts-checker-webpack-plugin"
export default function (): webpack.Configuration { export default function (): webpack.Configuration {
console.info('WEBPACK:renderer', require("./src/common/vars")) const res: webpack.Configuration = {
return {
context: __dirname, context: __dirname,
target: "electron-renderer", target: "electron-renderer",
devtool: "source-map", // todo: optimize in dev-mode with webpack.SourceMapDevToolPlugin 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
} }