Enable extension to specify storeName for persisting data

Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
This commit is contained in:
Panu Horsmalahti committed 2023-02-03 15:40:56 +02:00
1 parent 65175377d0
commit 4849f62141
2 files changed
+15 -2

No files matched your search

@@ -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);
}
}
+14 -1
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