Skip to content

Commit

Permalink
improve typing
Browse files Browse the repository at this point in the history
  • Loading branch information
idleberg committed Jul 7, 2023
1 parent ae31717 commit ede3abc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
23 changes: 13 additions & 10 deletions src/makensis.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -15,18 +14,23 @@ import {
import nsisChannel from './channel';

async function compile(strictMode: boolean): Promise<void> {
// 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") {
Expand Down Expand Up @@ -64,7 +68,7 @@ async function compile(strictMode: boolean): Promise<void> {
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()
);
Expand All @@ -73,15 +77,14 @@ async function compile(strictMode: boolean): Promise<void> {
}

async function showVersion(): Promise<void> {
const pathToMakensis = await getMakensisPath();
await nsisChannel.clear();

NSIS.events.once('exit', versionHandler);

await NSIS.version(
{
events: true,
pathToMakensis: pathToMakensis || undefined
pathToMakensis: await getMakensisPath()
},
await getSpawnEnv()
);
Expand Down
5 changes: 3 additions & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -41,7 +42,7 @@ async function isWindowsCompatible(): Promise<boolean> {
: false;
}

async function getMakensisPath(): Promise<string | void> {
async function getMakensisPath(): Promise<string | undefined> {
const { compiler } = await getConfig('nsis');

const pathToMakensis = isWindows() && compiler.pathToMakensis.startsWith('"') && compiler.pathToMakensis.startsWith('"')
Expand Down Expand Up @@ -276,7 +277,7 @@ async function getProjectPath(): Promise<null | string> {
}
}

async function getSpawnEnv(): Promise<unknown> {
async function getSpawnEnv(): Promise<SpawnOptions> {
const { integrated } = vscode.workspace.getConfiguration('terminal');
const mappedPlatform = mapPlatform();

Expand Down

0 comments on commit ede3abc

Please sign in to comment.