Skip to content

Commit

Permalink
Merge pull request #148 from viperproject/separates-vscode-dependencies
Browse files Browse the repository at this point in the history
Separate VSCode Dependencies
  • Loading branch information
ArquintL authored Feb 15, 2024
2 parents 4d67177 + 146aa4d commit 18f38b2
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 43 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ module.exports = {
"indent": "off",
"jsdoc/check-alignment": "error",
"jsdoc/check-indentation": "error",
"jsdoc/newline-after-description": "error",
"linebreak-style": "off",
"max-classes-per-file": [
"error",
Expand Down
3 changes: 2 additions & 1 deletion src/dependencies/Dependency.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as path from 'path';

import { ConfirmResult, InstallResult, Location, ProgressListener, Success } from '..';
import { ConfirmResult, InstallResult, Success } from './';
import { Location, ProgressListener } from '../util';

/**
* Manages the installation for a dependency, maintaining separate installations for each source (in a folder using their name).
Expand Down
3 changes: 2 additions & 1 deletion src/dependencies/FileDownloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import got, { Headers, Options, Progress } from 'got';
import * as stream from 'stream';
import { promisify } from 'util';

import { Canceled, ConfirmResult, DependencyInstaller, InstallResult, Location, ProgressListener, Success } from '..';
import { Canceled, ConfirmResult, DependencyInstaller, InstallResult, Success } from './';
import { Location, ProgressListener } from '../util';


const pipeline = promisify(stream.pipeline);
Expand Down
3 changes: 2 additions & 1 deletion src/dependencies/GitHubZipExtractor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as path from 'path';

import { ConfirmResult, DependencyInstaller, FileDownloader, InstallerSequence, InstallResult, Location, ProgressListener, Success, ZipExtractor } from '..';
import { ConfirmResult, DependencyInstaller, FileDownloader, InstallerSequence, InstallResult, Success, ZipExtractor } from './';
import { Location, ProgressListener } from '../util';

/**
* Extension of RemoteZipExtractor with the following features:
Expand Down
2 changes: 1 addition & 1 deletion src/dependencies/InstallResult.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface InstallResult<T> {
isSuccess(): boolean
isSuccess(): boolean;
}

export class Success<T> implements InstallResult<T> {
Expand Down
3 changes: 2 additions & 1 deletion src/dependencies/InstallerSequence.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ConfirmResult, DependencyInstaller, InstallResult, Location, ProgressListener, Success } from '..';
import { ConfirmResult, DependencyInstaller, InstallResult, Success } from './';
import { Location, ProgressListener } from '../util';

export class InstallerSequence {
constructor(readonly installers: DependencyInstaller[]) {
Expand Down
3 changes: 2 additions & 1 deletion src/dependencies/LocalReference.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as fs from 'fs-extra';

import { ConfirmResult, DependencyInstaller, Location, InstallResult, ProgressListener, Success } from '..';
import { ConfirmResult, DependencyInstaller, InstallResult, Success } from './';
import { Location, ProgressListener } from '../util';

export class LocalReference implements DependencyInstaller {
constructor(
Expand Down
3 changes: 2 additions & 1 deletion src/dependencies/RemoteZipExtractor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as path from 'path';

import { ConfirmResult, DependencyInstaller, FileDownloader, Location, InstallerSequence, InstallResult, ProgressListener, Success, ZipExtractor } from '..';
import { ConfirmResult, DependencyInstaller, FileDownloader, InstallerSequence, InstallResult, Success, ZipExtractor } from './';
import { Location, ProgressListener } from '../util';

export class RemoteZipExtractor implements DependencyInstaller {
private readonly sequence: InstallerSequence;
Expand Down
5 changes: 3 additions & 2 deletions src/dependencies/ZipExtractor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as extractZip from 'extract-zip';
import * as fs from 'fs-extra';

import { Canceled, ConfirmResult, DependencyInstaller, InstallResult, Location, ProgressListener, Success } from '..';
import { Canceled, ConfirmResult, DependencyInstaller, InstallResult, Success } from './';
import { Location, ProgressListener } from '../util';

/** Extracts the zip at the location provided to `install` to a folder named `targetName`. */
export class ZipExtractor implements DependencyInstaller {
Expand Down Expand Up @@ -41,7 +42,7 @@ export class ZipExtractor implements DependencyInstaller {

// we don't usually delete the original zip since that would cause it to get re-downloaded on next install
if (this.deleteZip) {
location.remove()
location.remove();
}

return new Success(target);
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
// exports all modules of this package

export * from './dependencies';
export * from './util';
export * from './vscode-util';
2 changes: 1 addition & 1 deletion src/test/dependencies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as assert from 'assert';
import * as md5File from 'md5-file';

import { Canceled, ConfirmResult, Dependency, FileDownloader, GitHubReleaseAsset, GitHubZipExtractor, InstallerSequence, LocalReference, Success, ZipExtractor } from '..';
import { withProgressInWindow } from '../util';
import { withProgressInWindow } from '../vscode-util';

suite("dependencies", () => {

Expand Down
31 changes: 0 additions & 31 deletions src/util/Progress.ts

This file was deleted.

6 changes: 6 additions & 0 deletions src/util/ProgressListener.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Reports overall progress made within the current task.
* `fraction` is the amount of progress (out of 1).
* `step` is a user-facing short description of what is currently happening.
*/
export type ProgressListener = (fraction: number, step: string) => void;
4 changes: 3 additions & 1 deletion src/util/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// exports all modules in the current directory

export * from './Location';
export * from './Platform';
export * from './Progress';
export * from './ProgressListener';
24 changes: 24 additions & 0 deletions src/vscode-util/Progress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as vscode from 'vscode';

import { ProgressListener } from '../util';

/**
* Runs an asynchronous task, forwarding the progress it reports to the VS Code window as a notification with the given title.
* It returns the task's result, as well as whether any progress was reported at all, for your convenience.
*/
export const withProgressInWindow = async<R> (
title: string, task: (progressListener: ProgressListener) => Promise<R>
): Promise<{ result: R; didReportProgress: boolean }> => {
let lastProgress = 0;
let didReportProgress = false;
const result = await vscode.window.withProgress({
location: vscode.ProgressLocation.Notification,
title
}, (progress) => task((fraction, step) => {
didReportProgress = true;
if (fraction - lastProgress < 0.01) { return; }
progress.report({ message: step, increment: (fraction - lastProgress) * 100 });
lastProgress = fraction;
}));
return { result, didReportProgress };
};
3 changes: 3 additions & 0 deletions src/vscode-util/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// exports all modules in the current directory

export * from './Progress';

0 comments on commit 18f38b2

Please sign in to comment.