From ede3abc43a46b1070d0b9b936e703b779b0c4dcb Mon Sep 17 00:00:00 2001 From: "Jan T. Sott" Date: Fri, 7 Jul 2023 23:53:55 +0200 Subject: [PATCH] improve typing --- src/makensis.ts | 23 +++++++++++++---------- src/util.ts | 5 +++-- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/makensis.ts b/src/makensis.ts index f6a3dcd..41d3c99 100644 --- a/src/makensis.ts +++ b/src/makensis.ts @@ -1,6 +1,5 @@ import { compilerOutputHandler, compilerErrorHandler, compilerExitHandler, flagsHandler, versionHandler } from './handlers'; import { getConfig } from 'vscode-get-config'; -import { inRange } from './util'; import * as NSIS from 'makensis'; import vscode from 'vscode'; @@ -15,18 +14,23 @@ import { import nsisChannel from './channel'; async function compile(strictMode: boolean): Promise { - // TODO Breaking change in VSCode 1.54, remove in future - const languageID = vscode.window.activeTextEditor['_documentData'] - ? vscode.window.activeTextEditor['_documentData']['_languageId'] - : vscode.window.activeTextEditor['document']['languageId']; + const activeTextEditor = vscode.window?.activeTextEditor; - if (!vscode.window.activeTextEditor || languageID !== 'nsis') { + if (!activeTextEditor) { + return; + } + + const languageID = activeTextEditor['_documentData'] + ? activeTextEditor['_documentData']['_languageId'] + : activeTextEditor['document']['languageId']; + + if (!activeTextEditor || languageID !== 'nsis') { nsisChannel.appendLine('This command is only available for NSIS files'); return; } const { compiler, processHeaders, showFlagsAsObject } = await getConfig('nsis'); - const document = vscode.window.activeTextEditor.document; + const document = activeTextEditor.document; if (isHeaderFile(document.fileName)) { if (processHeaders === "Disallow") { @@ -64,7 +68,7 @@ async function compile(strictMode: boolean): Promise { pathToMakensis: await getMakensisPath(), rawArguments: compiler.customArguments, strict: strictMode || compiler.strictMode, - verbose: inRange(compiler.verbosity, 0, 4) ? Number(compiler.verbosity) : undefined + verbose: compiler.verbosity }, await getSpawnEnv() ); @@ -73,7 +77,6 @@ async function compile(strictMode: boolean): Promise { } async function showVersion(): Promise { - const pathToMakensis = await getMakensisPath(); await nsisChannel.clear(); NSIS.events.once('exit', versionHandler); @@ -81,7 +84,7 @@ async function showVersion(): Promise { await NSIS.version( { events: true, - pathToMakensis: pathToMakensis || undefined + pathToMakensis: await getMakensisPath() }, await getSpawnEnv() ); diff --git a/src/util.ts b/src/util.ts index 2295667..1f122a1 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,5 +1,6 @@ import { constants, promises as fs } from 'fs'; import { exec, spawn } from 'child_process'; +import type { SpawnOptions } from 'node:child_process'; import { getConfig } from 'vscode-get-config'; import { platform } from 'os'; import { resolve } from 'path'; @@ -41,7 +42,7 @@ async function isWindowsCompatible(): Promise { : false; } -async function getMakensisPath(): Promise { +async function getMakensisPath(): Promise { const { compiler } = await getConfig('nsis'); const pathToMakensis = isWindows() && compiler.pathToMakensis.startsWith('"') && compiler.pathToMakensis.startsWith('"') @@ -276,7 +277,7 @@ async function getProjectPath(): Promise { } } -async function getSpawnEnv(): Promise { +async function getSpawnEnv(): Promise { const { integrated } = vscode.workspace.getConfiguration('terminal'); const mappedPlatform = mapPlatform();