-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from faissaloux/refactor-package-manager
Refactor package manager
- Loading branch information
Showing
6 changed files
with
56 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
export interface PackageManager { | ||
rootPath: string; | ||
getInstalled(packageName: string): Promise<any> | ||
getLockPath(): Promise<string> | ||
getLockPath(): string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import * as vscode from 'vscode'; | ||
|
||
export class LanguagePackageManager { | ||
constructor(protected rootPath: string) {} | ||
|
||
async lockFileContent(): Promise<string> { | ||
const lockPath = this.getLockPath(); | ||
const lockFile = vscode.Uri.file(lockPath); | ||
const lockFileContent = await vscode.workspace.fs.readFile(lockFile); | ||
|
||
return lockFileContent.toString(); | ||
} | ||
|
||
getLockPath(): string { | ||
throw new Error("Not Implemented!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,17 @@ | ||
import * as vscode from 'vscode'; | ||
import { pathJoin } from '../../util/globals'; | ||
import * as types from '../../types/types'; | ||
import { Parser } from '../../parser/parser'; | ||
import { PackageManager } from '../../interfaces/package_manager'; | ||
import { LanguagePackageManager } from '../language_package_manager'; | ||
|
||
export class Php implements PackageManager { | ||
rootPath: string; | ||
|
||
constructor(packageJsonFilePath: string) { | ||
this.rootPath = packageJsonFilePath.replace(new RegExp('composer.json$'), ''); | ||
} | ||
|
||
export class Php extends LanguagePackageManager implements PackageManager { | ||
async getInstalled(packageName: string): Promise<any> { | ||
const lockPath = await this.getLockPath(); | ||
|
||
const lockFile = vscode.Uri.file(lockPath); | ||
const lockFileContent = await vscode.workspace.fs.readFile(lockFile); | ||
|
||
const installedPackages = new Parser("composer").parse(lockFileContent.toString()); | ||
const installedPackages = new Parser("composer").parse(await this.lockFileContent()); | ||
|
||
return installedPackages.find((pkg: types.ComposerInstalledPackage) => pkg.name === packageName); | ||
} | ||
|
||
async getLockPath(): Promise<string> { | ||
override getLockPath(): string { | ||
return pathJoin(this.rootPath, 'vendor', 'composer', 'installed.json'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters