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

Enable extension to specify storeName for persisting data

Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
This commit is contained in:
Panu Horsmalahti 2023-02-03 15:39:53 +02:00
parent 65175377d0
commit 4849f62141
2 changed files with 15 additions and 2 deletions

View File

@ -92,6 +92,6 @@ export abstract class ExtensionStore<T extends object> extends BaseStore<T> {
protected cwd() {
assert(this.extension, "must call this.load() first");
return path.join(super.cwd(), "extension-store", this.extension.name);
return path.join(super.cwd(), "extension-store", this.extension.storeName);
}
}

View File

@ -27,6 +27,10 @@ export interface LensExtensionManifest extends PackageJson {
npm?: string;
node?: string;
};
// Specify extension name used for persisting data.
// Useful if extension is renamed but the data should not be lost.
storeName?: string;
}
export const lensExtensionDependencies = Symbol("lens-extension-dependencies");
@ -62,7 +66,10 @@ export class LensExtension<
constructor({ id, manifest, manifestPath, isBundled }: InstalledExtension) {
makeObservable(this);
// id is the name of the manifest
this.id = id;
this.manifest = manifest;
this.manifestPath = manifestPath;
this.isBundled = !!isBundled;
@ -80,6 +87,11 @@ export class LensExtension<
return this.manifest.description;
}
// Name of extension for persisting data
get storeName() {
return this.manifest.storeName || this.name;
}
/**
* @ignore
*/
@ -93,7 +105,8 @@ export class LensExtension<
* folder name.
*/
async getExtensionFileFolder(): Promise<string> {
return this[lensExtensionDependencies].fileSystemProvisionerStore.requestDirectory(this.id);
// storeName is read from the manifest and has a fallback to the manifest name, which equals id
return this[lensExtensionDependencies].fileSystemProvisionerStore.requestDirectory(this.storeName);
}
@action