diff --git a/src/logger.ts b/src/logger.ts index 3e491bb..2c9f5b1 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -20,8 +20,8 @@ export interface LogChannelProvider { export interface LogChannel { readonly name: string; appendLine(value: string): void; - dispose(): void; - show(preserveFocus?: boolean): void; + dispose?(): void; + show?(preserveFocus?: boolean): void; } export const Logger = new (class Logger { @@ -54,7 +54,7 @@ export const Logger = new (class Logger { this.level = toOrderedLevel(this._logLevel); if (value === LogLevel.Off) { - this.output?.dispose(); + this.output?.dispose?.(); this.output = undefined; } else { this.output = this.output ?? this.provider!.createChannel(this.provider!.name); @@ -170,7 +170,7 @@ export const Logger = new (class Logger { } showOutputChannel(preserveFocus?: boolean): void { - this.output?.show(preserveFocus); + this.output?.show?.(preserveFocus); } toLoggable(o: any, sanitize?: ((key: string, value: any) => any) | undefined) { diff --git a/src/webviews/apps/shared/appBase.ts b/src/webviews/apps/shared/appBase.ts index 9e78167..6d32e81 100644 --- a/src/webviews/apps/shared/appBase.ts +++ b/src/webviews/apps/shared/appBase.ts @@ -15,6 +15,8 @@ import type { Disposable } from './events'; import type { ThemeChangeEvent } from './theme'; import { initializeAndWatchThemeColors, onDidChangeTheme } from './theme'; +declare const DEBUG: boolean; + interface VsCodeApi { postMessage(msg: unknown): void; setState(state: unknown): void; @@ -53,16 +55,10 @@ export abstract class App { appendLine: function (value: string) { console.log(`[${name}] ${value}`); }, - dispose: function () { - // noop - }, - show: function (_preserveFocus?: boolean) { - // noop - }, }; }, }, - LogLevel.Debug, + DEBUG ? LogLevel.Debug : LogLevel.Off, ); this.log(`ctor()`); diff --git a/webpack.config.js b/webpack.config.js index 9e37880..4c6182c 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -19,7 +19,7 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const path = require('path'); const { validate } = require('schema-utils'); const TerserPlugin = require('terser-webpack-plugin'); -const { WebpackError, optimize, webpack } = require('webpack'); +const { DefinePlugin, optimize, WebpackError } = require('webpack'); const WebpackRequireFromPlugin = require('webpack-require-from'); module.exports = @@ -285,6 +285,9 @@ function getWebviewsConfig(mode, env) { } : undefined, ), + new DefinePlugin({ + DEBUG: mode === 'development', + }), new ForkTsCheckerPlugin({ async: false, eslint: {