1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Add explict return types

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-05-31 08:17:25 -04:00
parent 3687ac8d5f
commit 9a54a3f2f6

View File

@ -106,11 +106,11 @@ export class ExtensionDiscovery extends Singleton {
return path.join(os.homedir(), ".k8slens", "extensions"); return path.join(os.homedir(), ".k8slens", "extensions");
} }
get packageJsonPath() { get packageJsonPath(): string {
return path.join(extensionInstaller.extensionPackagesRoot, manifestFilename); return path.join(extensionInstaller.extensionPackagesRoot, manifestFilename);
} }
get inTreeTargetPath() { get inTreeTargetPath(): string {
return path.join(extensionInstaller.extensionPackagesRoot, "extensions"); 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. * Initializes the class and setups the file watcher for added/removed local extensions.
*/ */
async init() { async init(): Promise<void> {
if (ipcRenderer) { if (ipcRenderer) {
await this.initRenderer(); await this.initRenderer();
} else { } else {
@ -133,7 +133,7 @@ export class ExtensionDiscovery extends Singleton {
} }
} }
async initRenderer() { async initRenderer(): Promise<void> {
const onMessage = ({ isLoaded }: ExtensionDiscoveryChannelMessage) => { const onMessage = ({ isLoaded }: ExtensionDiscoveryChannelMessage) => {
this.isLoaded = isLoaded; this.isLoaded = isLoaded;
}; };
@ -144,7 +144,7 @@ export class ExtensionDiscovery extends Singleton {
}); });
} }
async initMain() { async initMain(): Promise<void> {
handleRequest(ExtensionDiscovery.extensionDiscoveryChannel, () => this.toJSON()); handleRequest(ExtensionDiscovery.extensionDiscoveryChannel, () => this.toJSON());
reaction(() => this.toJSON(), () => { reaction(() => this.toJSON(), () => {
@ -156,7 +156,7 @@ export class ExtensionDiscovery extends Singleton {
* Watches for added/removed local extensions. * Watches for added/removed local extensions.
* Dependencies are installed automatically after an extension folder is copied. * Dependencies are installed automatically after an extension folder is copied.
*/ */
async watchExtensions() { async watchExtensions(): Promise<void> {
logger.info(`${logModule} watching extension add/remove in ${this.localFolderPath}`); logger.info(`${logModule} watching extension add/remove in ${this.localFolderPath}`);
// Wait until .load() has been called and has been resolved // Wait until .load() has been called and has been resolved
@ -183,7 +183,7 @@ export class ExtensionDiscovery extends Singleton {
.on("unlink", this.handleWatchUnlinkEvent); .on("unlink", this.handleWatchUnlinkEvent);
} }
handleWatchFileAdd = async (manifestPath: string) => { handleWatchFileAdd = async (manifestPath: string): Promise<void> => {
// e.g. "foo/package.json" // e.g. "foo/package.json"
const relativePath = path.relative(this.localFolderPath, manifestPath); 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. * which wouldn't be fixed if the extension was reinstalled, causing the extension not to work.
* @param name e.g. "@mirantis/lens-extension-cc" * @param name e.g. "@mirantis/lens-extension-cc"
*/ */
removeSymlinkByPackageName(name: string) { removeSymlinkByPackageName(name: string): Promise<void> {
return fse.remove(this.getInstalledPath(name)); 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. * The application will detect the folder unlink and remove the extension from the UI automatically.
* @param extensionId The ID of the extension to uninstall. * @param extensionId The ID of the extension to uninstall.
*/ */
async uninstallExtension(extensionId: LensExtensionId) { async uninstallExtension(extensionId: LensExtensionId): Promise<void> {
const { manifest, absolutePath } = this.extensions.get(extensionId) ?? ExtensionLoader.getInstance().getExtension(extensionId); const { manifest, absolutePath } = this.extensions.get(extensionId) ?? ExtensionLoader.getInstance().getExtension(extensionId);
logger.info(`${logModule} Uninstalling ${manifest.name}`); logger.info(`${logModule} Uninstalling ${manifest.name}`);
@ -334,7 +334,7 @@ export class ExtensionDiscovery extends Singleton {
* Returns the symlinked path to the extension folder, * Returns the symlinked path to the extension folder,
* e.g. "/Users/<username>/Library/Application Support/Lens/node_modules/@publisher/extension" * e.g. "/Users/<username>/Library/Application Support/Lens/node_modules/@publisher/extension"
*/ */
protected getInstalledPath(name: string) { protected getInstalledPath(name: string): string {
return path.join(this.nodeModulesPath, name); return path.join(this.nodeModulesPath, name);
} }
@ -342,7 +342,7 @@ export class ExtensionDiscovery extends Singleton {
* Returns the symlinked path to the package.json, * Returns the symlinked path to the package.json,
* e.g. "/Users/<username>/Library/Application Support/Lens/node_modules/@publisher/extension/package.json" * e.g. "/Users/<username>/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); 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. * Write package.json to file system and install dependencies.
*/ */
installBundledPackages(packageJsonPath: string, extensions: InstalledExtension[]) { installBundledPackages(packageJsonPath: string, extensions: InstalledExtension[]): Promise<void> {
const dependencies = Object.fromEntries( const dependencies = Object.fromEntries(
extensions.map(extension => [extension.manifest.name, extension.absolutePath]) extensions.map(extension => [extension.manifest.name, extension.absolutePath])
); );
@ -406,11 +406,11 @@ export class ExtensionDiscovery extends Singleton {
return extensionInstaller.installPackages(packageJsonPath, { dependencies }); return extensionInstaller.installPackages(packageJsonPath, { dependencies });
} }
async installPackage(name: string) { async installPackage(name: string): Promise<void> {
return extensionInstaller.installPackage(name); return extensionInstaller.installPackage(name);
} }
async loadBundledExtensions() { async loadBundledExtensions(): Promise<InstalledExtension[]> {
const extensions: InstalledExtension[] = []; const extensions: InstalledExtension[] = [];
const folderPath = this.bundledFolderPath; const folderPath = this.bundledFolderPath;
const paths = await fse.readdir(folderPath); const paths = await fse.readdir(folderPath);
@ -479,7 +479,7 @@ export class ExtensionDiscovery extends Singleton {
}); });
} }
broadcast() { broadcast(): void {
broadcastMessage(ExtensionDiscovery.extensionDiscoveryChannel, this.toJSON()); broadcastMessage(ExtensionDiscovery.extensionDiscoveryChannel, this.toJSON());
} }
} }