From 9a54a3f2f6f0dce042a47defb64c40ef35b53a5a Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Mon, 31 May 2021 08:17:25 -0400 Subject: [PATCH] Add explict return types Signed-off-by: Sebastian Malton --- src/extensions/extension-discovery.ts | 30 +++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/extensions/extension-discovery.ts b/src/extensions/extension-discovery.ts index 4beb559134..224d2932da 100644 --- a/src/extensions/extension-discovery.ts +++ b/src/extensions/extension-discovery.ts @@ -106,11 +106,11 @@ export class ExtensionDiscovery extends Singleton { return path.join(os.homedir(), ".k8slens", "extensions"); } - get packageJsonPath() { + get packageJsonPath(): string { return path.join(extensionInstaller.extensionPackagesRoot, manifestFilename); } - get inTreeTargetPath() { + get inTreeTargetPath(): string { return path.join(extensionInstaller.extensionPackagesRoot, "extensions"); } @@ -125,7 +125,7 @@ export class ExtensionDiscovery extends Singleton { /** * Initializes the class and setups the file watcher for added/removed local extensions. */ - async init() { + async init(): Promise { if (ipcRenderer) { await this.initRenderer(); } else { @@ -133,7 +133,7 @@ export class ExtensionDiscovery extends Singleton { } } - async initRenderer() { + async initRenderer(): Promise { const onMessage = ({ isLoaded }: ExtensionDiscoveryChannelMessage) => { this.isLoaded = isLoaded; }; @@ -144,7 +144,7 @@ export class ExtensionDiscovery extends Singleton { }); } - async initMain() { + async initMain(): Promise { handleRequest(ExtensionDiscovery.extensionDiscoveryChannel, () => this.toJSON()); reaction(() => this.toJSON(), () => { @@ -156,7 +156,7 @@ export class ExtensionDiscovery extends Singleton { * Watches for added/removed local extensions. * Dependencies are installed automatically after an extension folder is copied. */ - async watchExtensions() { + async watchExtensions(): Promise { logger.info(`${logModule} watching extension add/remove in ${this.localFolderPath}`); // Wait until .load() has been called and has been resolved @@ -183,7 +183,7 @@ export class ExtensionDiscovery extends Singleton { .on("unlink", this.handleWatchUnlinkEvent); } - handleWatchFileAdd = async (manifestPath: string) => { + handleWatchFileAdd = async (manifestPath: string): Promise => { // e.g. "foo/package.json" const relativePath = path.relative(this.localFolderPath, manifestPath); @@ -264,7 +264,7 @@ export class ExtensionDiscovery extends Singleton { * which wouldn't be fixed if the extension was reinstalled, causing the extension not to work. * @param name e.g. "@mirantis/lens-extension-cc" */ - removeSymlinkByPackageName(name: string) { + removeSymlinkByPackageName(name: string): Promise { return fse.remove(this.getInstalledPath(name)); } @@ -273,7 +273,7 @@ export class ExtensionDiscovery extends Singleton { * The application will detect the folder unlink and remove the extension from the UI automatically. * @param extensionId The ID of the extension to uninstall. */ - async uninstallExtension(extensionId: LensExtensionId) { + async uninstallExtension(extensionId: LensExtensionId): Promise { const { manifest, absolutePath } = this.extensions.get(extensionId) ?? ExtensionLoader.getInstance().getExtension(extensionId); logger.info(`${logModule} Uninstalling ${manifest.name}`); @@ -334,7 +334,7 @@ export class ExtensionDiscovery extends Singleton { * Returns the symlinked path to the extension folder, * e.g. "/Users//Library/Application Support/Lens/node_modules/@publisher/extension" */ - protected getInstalledPath(name: string) { + protected getInstalledPath(name: string): string { return path.join(this.nodeModulesPath, name); } @@ -342,7 +342,7 @@ export class ExtensionDiscovery extends Singleton { * Returns the symlinked path to the package.json, * e.g. "/Users//Library/Application Support/Lens/node_modules/@publisher/extension/package.json" */ - protected getInstalledManifestPath(name: string) { + protected getInstalledManifestPath(name: string): string { return path.join(this.getInstalledPath(name), manifestFilename); } @@ -398,7 +398,7 @@ export class ExtensionDiscovery extends Singleton { /** * Write package.json to file system and install dependencies. */ - installBundledPackages(packageJsonPath: string, extensions: InstalledExtension[]) { + installBundledPackages(packageJsonPath: string, extensions: InstalledExtension[]): Promise { const dependencies = Object.fromEntries( extensions.map(extension => [extension.manifest.name, extension.absolutePath]) ); @@ -406,11 +406,11 @@ export class ExtensionDiscovery extends Singleton { return extensionInstaller.installPackages(packageJsonPath, { dependencies }); } - async installPackage(name: string) { + async installPackage(name: string): Promise { return extensionInstaller.installPackage(name); } - async loadBundledExtensions() { + async loadBundledExtensions(): Promise { const extensions: InstalledExtension[] = []; const folderPath = this.bundledFolderPath; const paths = await fse.readdir(folderPath); @@ -479,7 +479,7 @@ export class ExtensionDiscovery extends Singleton { }); } - broadcast() { + broadcast(): void { broadcastMessage(ExtensionDiscovery.extensionDiscoveryChannel, this.toJSON()); } }