From c7dd78989b4bfabb156b3af6187ec58575a18d44 Mon Sep 17 00:00:00 2001 From: "Jan T. Sott" Date: Sun, 3 Mar 2024 21:08:37 +0100 Subject: [PATCH] reduce bundle size --- src/channel.ts | 4 ++-- src/diagnostics.ts | 7 +++---- src/handlers.ts | 12 ++++++------ src/makensis.ts | 14 +++++++------- src/nlf.ts | 8 ++++---- src/task.ts | 14 +++++++------- src/util.ts | 32 ++++++++++++++++---------------- 7 files changed, 45 insertions(+), 46 deletions(-) diff --git a/src/channel.ts b/src/channel.ts index 6784408..a356768 100644 --- a/src/channel.ts +++ b/src/channel.ts @@ -1,3 +1,3 @@ -import vscode from 'vscode'; +import { window } from 'vscode'; -export default vscode.window.createOutputChannel('NSIS', 'makensis-log'); +export default window.createOutputChannel('NSIS', 'makensis'); diff --git a/src/diagnostics.ts b/src/diagnostics.ts index ca8fba2..223d045 100644 --- a/src/diagnostics.ts +++ b/src/diagnostics.ts @@ -2,10 +2,9 @@ import * as NSIS from 'makensis'; import { findErrors, findWarnings, getMakensisPath, getNullDevice, getPreprocessMode, getOverrideCompression, getSpawnEnv } from './util'; import { getConfig } from 'vscode-get-config'; import micromatch from 'micromatch'; -import vscode from 'vscode'; -import type { DiagnosticCollection } from '../types'; +import { type DiagnosticCollection, type TextDocument } from 'vscode'; -export async function updateDiagnostics(document: vscode.TextDocument | null, collection: vscode.DiagnosticCollection): Promise { +export async function updateDiagnostics(document: TextDocument | null, collection: DiagnosticCollection): Promise { if (!document) { return; } @@ -85,4 +84,4 @@ export async function updateDiagnostics(document: vscode.TextDocument | null, co } NSIS.events.removeAllListeners(); -} \ No newline at end of file +} diff --git a/src/handlers.ts b/src/handlers.ts index b105143..204e3f8 100644 --- a/src/handlers.ts +++ b/src/handlers.ts @@ -3,7 +3,7 @@ import { getConfig } from 'vscode-get-config'; import { platform } from 'os'; import { type CompilerOutput } from 'makensis'; import nsisChannel from './channel'; -import vscode from 'vscode'; +import { window } from 'vscode'; export async function compilerOutputHandler(data: CompilerOutput): Promise { const { showOutputView } = await getConfig('nsis'); @@ -48,10 +48,10 @@ export async function compilerExitHandler(data: CompilerOutput): Promise { nsisChannel.show(); } - const choice = await vscode.window.showWarningMessage(`Compiled with warnings`, openButton, revealButton); + const choice = await window.showWarningMessage(`Compiled with warnings`, openButton, revealButton); await buttonHandler(choice, data.outFile); } else if (showNotifications) { - const choice = await vscode.window.showInformationMessage(`Compiled successfully`, openButton, revealButton); + const choice = await window.showInformationMessage(`Compiled successfully`, openButton, revealButton); await buttonHandler(choice, data.outFile); } } else if (showNotifications) { @@ -60,7 +60,7 @@ export async function compilerExitHandler(data: CompilerOutput): Promise { } if (showNotifications) { - const choice = await vscode.window.showErrorMessage('Compilation failed, see output for details', 'Show Output'); + const choice = await window.showErrorMessage('Compilation failed, see output for details', 'Show Output'); await buttonHandler(choice); } @@ -91,9 +91,9 @@ export async function versionHandler(data: unknown): Promise { const message = `makensis ${output} (${pathToMakensis})`; if (showVersionAsInfoMessage === true) { - vscode.window.showInformationMessage(message); + window.showInformationMessage(message); } else { nsisChannel.append(message); nsisChannel.show(); } -} \ No newline at end of file +} diff --git a/src/makensis.ts b/src/makensis.ts index c02b481..29ce17f 100644 --- a/src/makensis.ts +++ b/src/makensis.ts @@ -2,7 +2,7 @@ import { compilerOutputHandler, compilerErrorHandler, compilerExitHandler, flags import { getConfig } from 'vscode-get-config'; import { sendTelemetryEvent } from './telemetry'; import * as NSIS from 'makensis'; -import vscode from 'vscode'; +import { commands, window } from 'vscode'; import { getMakensisPath, @@ -15,7 +15,7 @@ import { import nsisChannel from './channel'; export async function compile(strictMode: boolean): Promise { - const activeTextEditor = vscode.window?.activeTextEditor; + const activeTextEditor = window?.activeTextEditor; if (!activeTextEditor) { return; @@ -35,13 +35,13 @@ export async function compile(strictMode: boolean): Promise { if (isHeaderFile(document.fileName)) { if (processHeaders === "Disallow") { - const choice = await vscode.window.showWarningMessage('Compiling header files is blocked by default. You can allow it in the package settings, or mute this warning.', 'Open Settings'); + const choice = await window.showWarningMessage('Compiling header files is blocked by default. You can allow it in the package settings, or mute this warning.', 'Open Settings'); if (choice === 'Open Settings') { - vscode.commands.executeCommand('workbench.action.openSettings', '@ext:idleberg.nsis processHeaders'); + commands.executeCommand('workbench.action.openSettings', '@ext:idleberg.nsis processHeaders'); return; } } else if (processHeaders === "Disallow & Never Ask Me") { - vscode.window.setStatusBarMessage("makensis: Skipped header file", 5000); + window.setStatusBarMessage("makensis: Skipped header file", 5000); return; } } @@ -50,7 +50,7 @@ export async function compile(strictMode: boolean): Promise { await document.save(); } catch (error) { console.error('[vscode-nsis]', error instanceof Error ? error.message : error); - vscode.window.showErrorMessage('Error saving file, see console for details'); + window.showErrorMessage('Error saving file, see console for details'); return; } @@ -172,7 +172,7 @@ export async function showHelp(): Promise { }, await getSpawnEnv() ); - command = await vscode.window.showQuickPick(Object.keys(output.stdout)) || undefined; + command = await window.showQuickPick(Object.keys(output.stdout)) || undefined; if (command) { openURL(command); diff --git a/src/nlf.ts b/src/nlf.ts index 29a18a7..3a376f0 100644 --- a/src/nlf.ts +++ b/src/nlf.ts @@ -1,9 +1,9 @@ import { sendTelemetryEvent } from './telemetry'; import * as NLF from '@nsis/nlf'; -import vscode from 'vscode'; +import { workspace, window } from 'vscode'; export function convert(): void { - const editor = vscode.window.activeTextEditor; + const editor = window.activeTextEditor; if (!editor) { return; @@ -27,7 +27,7 @@ function convertNLF(document): void { output = NLF.parse(input, { stringify: true }); } catch (err) { console.error(err); - vscode.window.showErrorMessage('Conversion failed, see output for details'); + window.showErrorMessage('Conversion failed, see output for details'); hasErrors = true; } finally { sendTelemetryEvent('convertNLF', { @@ -58,5 +58,5 @@ function convertJSON(document): void { } function openNewFile(newDocument): void { - vscode.workspace.openTextDocument(newDocument).then( document => vscode.window.showTextDocument(document)); + workspace.openTextDocument(newDocument).then( document => window.showTextDocument(document)); } diff --git a/src/task.ts b/src/task.ts index 89b3649..81191d7 100644 --- a/src/task.ts +++ b/src/task.ts @@ -2,11 +2,11 @@ import { getConfig } from 'vscode-get-config'; import { getPrefix, inRange } from './util'; import { join } from 'path'; import { promises as fs } from 'fs'; -import vscode from 'vscode'; +import { workspace, window } from 'vscode'; export async function createTask(): Promise { - if (typeof vscode.workspace.workspaceFolders === 'undefined') { - return vscode.window.showErrorMessage('Task support is only available when working on a workspace folder. It is not available when editing single files.'); + if (typeof workspace.workspaceFolders === 'undefined') { + return window.showErrorMessage('Task support is only available when working on a workspace folder. It is not available when editing single files.'); } const { alwaysOpenBuildTask, compiler } = await getConfig('nsis'); @@ -43,7 +43,7 @@ export async function createTask(): Promise { }; const jsonString = JSON.stringify(taskFile, null, 2); - const dotFolder = join(vscode.workspace.workspaceFolders[0].uri.fsPath, '/.vscode'); + const dotFolder = join(workspace.workspaceFolders[0].uri.fsPath, '/.vscode'); const buildFile = join(dotFolder, 'tasks.json'); try { @@ -57,12 +57,12 @@ export async function createTask(): Promise { await fs.writeFile(buildFile, jsonString); } catch(error) { - vscode.window.showErrorMessage(error.toString()); + window.showErrorMessage(error.toString()); } if (alwaysOpenBuildTask === false) return; // Open tasks.json - const doc = await vscode.workspace.openTextDocument(buildFile) - vscode.window.showTextDocument(doc); + const doc = await workspace.openTextDocument(buildFile) + window.showTextDocument(doc); } diff --git a/src/util.ts b/src/util.ts index 441ae90..cb57d34 100644 --- a/src/util.ts +++ b/src/util.ts @@ -6,7 +6,7 @@ import { platform } from 'os'; import { resolve } from 'path'; import nsisChannel from './channel'; import open from 'open'; -import vscode from 'vscode'; +import { commands, DiagnosticSeverity, Position, Range, window, workspace } from 'vscode'; import which from 'which'; import type { DiagnosticCollection } from '../types'; @@ -61,9 +61,9 @@ export async function getMakensisPath(): Promise { return result; } catch (error) { console.error('[vscode-nsis]', error instanceof Error ? error.message : error); - const choice = await vscode.window.showWarningMessage('Please make sure that makensis is installed and exposed in your PATH environment variable. Alternatively, you can specify its path in the settings.', 'Open Settings'); + const choice = await window.showWarningMessage('Please make sure that makensis is installed and exposed in your PATH environment variable. Alternatively, you can specify its path in the settings.', 'Open Settings'); if (choice === 'Open Settings') { - vscode.commands.executeCommand('workbench.action.openSettings', '@ext:idleberg.nsis pathToMakensis'); + commands.executeCommand('workbench.action.openSettings', '@ext:idleberg.nsis pathToMakensis'); } console.error('[vscode-nsis]', error instanceof Error ? error.message : error); @@ -92,7 +92,7 @@ export function openURL(cmd: string): void { } export async function pathWarning(): Promise { - const choice = await vscode.window.showWarningMessage('makensis is not installed or missing in your PATH environmental variable', 'Download', 'Help') + const choice = await window.showWarningMessage('makensis is not installed or missing in your PATH environmental variable', 'Download', 'Help') switch (choice) { case 'Download': @@ -142,11 +142,11 @@ export async function runInstaller(outFile: string): Promise { export async function buttonHandler(choice: string, outFile?: string): Promise { switch (choice) { case 'Run': - await runInstaller(outFile); + await runInstaller(outFile!); break; case 'Reveal': - await revealInstaller(outFile); + await revealInstaller(outFile!); break; case 'Show Output': @@ -175,7 +175,7 @@ export async function getOverrideCompression(): Promise { } export function getLineLength(line: number): number { - const editorText = vscode.window.activeTextEditor?.document.getText(); + const editorText = window.activeTextEditor?.document.getText(); if (editorText && editorText.length) { const lines: string[] = editorText.split('\n'); @@ -187,11 +187,11 @@ export function getLineLength(line: number): number { } export async function showANSIDeprecationWarning(): Promise { - const choice = await vscode.window.showWarningMessage('ANSI targets are deprecated as of NSIS v3.05, consider moving to Unicode. You can mute this warning in the package settings.', 'Unicode Installer', 'Open Settings') + const choice = await window.showWarningMessage('ANSI targets are deprecated as of NSIS v3.05, consider moving to Unicode. You can mute this warning in the package settings.', 'Unicode Installer', 'Open Settings') switch (choice) { case 'Open Settings': - vscode.commands.executeCommand('workbench.action.openSettings', '@ext:idleberg.nsis muteANSIDeprecationWarning'); + commands.executeCommand('workbench.action.openSettings', '@ext:idleberg.nsis muteANSIDeprecationWarning'); break; case 'Unicode Installer': @@ -238,8 +238,8 @@ export async function findWarnings(input: string): Promise { let editor; try { - editor = vscode.window.activeTextEditor; + editor = window.activeTextEditor; } catch (err) { return null; } try { - const workspaceFolder = vscode.workspace.getWorkspaceFolder(editor.document.uri); + const workspaceFolder = workspace.getWorkspaceFolder(editor.document.uri); return workspaceFolder ? workspaceFolder.uri.fsPath : ''; } catch (error) { @@ -292,7 +292,7 @@ export async function getProjectPath(): Promise { } export async function getSpawnEnv(): Promise { - const { integrated } = vscode.workspace.getConfiguration('terminal'); + const { integrated } = workspace.getConfiguration('terminal'); const mappedPlatform = mapPlatform(); return {