diff --git a/src/diagnostics.ts b/src/diagnostics.ts index 223d045..54fd2ef 100644 --- a/src/diagnostics.ts +++ b/src/diagnostics.ts @@ -1,4 +1,4 @@ -import * as NSIS from 'makensis'; +import { compile } from 'makensis'; import { findErrors, findWarnings, getMakensisPath, getNullDevice, getPreprocessMode, getOverrideCompression, getSpawnEnv } from './util'; import { getConfig } from 'vscode-get-config'; import micromatch from 'micromatch'; @@ -36,7 +36,7 @@ export async function updateDiagnostics(document: TextDocument | null, collectio return; } - const options: NSIS.CompilerOptions = { + const options: Makensis.CompilerOptions = { verbose: 2, pathToMakensis, postExecute: [ @@ -61,7 +61,7 @@ export async function updateDiagnostics(document: TextDocument | null, collectio let output; try { - output = await NSIS.compile(document.fileName, options, await getSpawnEnv()); + output = await compile(document.fileName, options, await getSpawnEnv()); } catch (error) { console.error('[vscode-nsis]', error instanceof Error ? error.message : error); } @@ -82,6 +82,4 @@ export async function updateDiagnostics(document: TextDocument | null, collectio } else { collection.clear(); } - - NSIS.events.removeAllListeners(); } diff --git a/src/handlers.ts b/src/handlers.ts index 204e3f8..032797b 100644 --- a/src/handlers.ts +++ b/src/handlers.ts @@ -11,7 +11,7 @@ export async function compilerOutputHandler(data: CompilerOutput): Promise nsisChannel.appendLine(data.line); if (showOutputView === 'Always') { - nsisChannel.show(); + nsisChannel.show(true); } } @@ -21,7 +21,7 @@ export async function compilerErrorHandler(data: CompilerOutput): Promise nsisChannel.appendLine(data.line); if (showOutputView === 'On Errors') { - nsisChannel.show(); + nsisChannel.show(true); } } @@ -30,7 +30,7 @@ export async function compilerExitHandler(data: CompilerOutput): Promise { if (data['status'] === 0) { if (showOutputView === 'Always') { - nsisChannel.show(); + nsisChannel.show(true); } const outfileExists = await fileExists(String(data.outFile)); @@ -45,7 +45,7 @@ export async function compilerExitHandler(data: CompilerOutput): Promise { if (data['warnings'] && showNotifications) { if (showOutputView === 'On Warnings & Errors') { - nsisChannel.show(); + nsisChannel.show(true); } const choice = await window.showWarningMessage(`Compiled with warnings`, openButton, revealButton); @@ -56,7 +56,7 @@ export async function compilerExitHandler(data: CompilerOutput): Promise { } } else if (showNotifications) { if (showOutputView !== 'Never') { - nsisChannel.show(); + nsisChannel.show(true); } if (showNotifications) { @@ -80,7 +80,7 @@ export async function flagsHandler(data: unknown): Promise { ); nsisChannel.append(message); - nsisChannel.show(); + nsisChannel.show(true); } export async function versionHandler(data: unknown): Promise { @@ -94,6 +94,6 @@ export async function versionHandler(data: unknown): Promise { window.showInformationMessage(message); } else { nsisChannel.append(message); - nsisChannel.show(); + nsisChannel.show(true); } } diff --git a/src/makensis.ts b/src/makensis.ts index 72c312d..a93ec06 100644 --- a/src/makensis.ts +++ b/src/makensis.ts @@ -55,10 +55,6 @@ export async function compile(strictMode: boolean): Promise { nsisChannel.clear(); - NSIS.events.on('stdout', async data => await compilerOutputHandler(data)); - NSIS.events.on('stderr', async data => await compilerErrorHandler(data)); - NSIS.events.once('exit', async data => await compilerExitHandler(data)); - try { await NSIS.compile( document.fileName, @@ -66,6 +62,9 @@ export async function compile(strictMode: boolean): Promise { env: await getProjectPath() || false, events: true, json: showFlagsAsObject, + onData: async data => await compilerOutputHandler(data), + onError: async data => await compilerErrorHandler(data), + onClose: async data => await compilerExitHandler(data), pathToMakensis: await getMakensisPath(), rawArguments: compiler.customArguments, strict: strictMode || compiler.strictMode, @@ -76,19 +75,16 @@ export async function compile(strictMode: boolean): Promise { } catch (error) { console.error('[vscode-nsis]', error instanceof Error ? error.message : error); } - - NSIS.events.removeAllListeners(); } export async function showVersion(): Promise { await nsisChannel.clear(); - NSIS.events.once('exit', versionHandler); - try { await NSIS.version( { events: true, + onClose: async data => await versionHandler(data), pathToMakensis: await getMakensisPath() }, await getSpawnEnv() @@ -97,8 +93,6 @@ export async function showVersion(): Promise { } catch (error) { console.error('[vscode-nsis]', error instanceof Error ? error.message : error); } - - NSIS.events.removeAllListeners(); } export async function showCompilerFlags(): Promise { @@ -107,13 +101,12 @@ export async function showCompilerFlags(): Promise { await nsisChannel.clear(); - NSIS.events.once('exit', flagsHandler); - try { await NSIS.headerInfo( { events: true, json: showFlagsAsObject || false, + onClose: flagsHandler, pathToMakensis: pathToMakensis || undefined }, await getSpawnEnv() @@ -121,8 +114,6 @@ export async function showCompilerFlags(): Promise { } catch (error) { console.error('[vscode-nsis]', error instanceof Error ? error.message : error); } - - NSIS.events.removeAllListeners(); } export async function showHelp(): Promise { @@ -157,6 +148,4 @@ export async function showHelp(): Promise { } catch (error) { console.error('[vscode-nsis]', error instanceof error ? error.message : error); } - - NSIS.events.removeAllListeners(); } diff --git a/src/util.ts b/src/util.ts index cb57d34..ef59565 100644 --- a/src/util.ts +++ b/src/util.ts @@ -150,7 +150,7 @@ export async function buttonHandler(choice: string, outFile?: string): Promise