mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Check if extension is enabled in store unless it is bundled
Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
parent
030bf91864
commit
5f1314427c
@ -6,6 +6,7 @@ import path from "path";
|
|||||||
import { getBundledExtensions } from "../common/utils/app-version";
|
import { getBundledExtensions } from "../common/utils/app-version";
|
||||||
import logger from "../main/logger";
|
import logger from "../main/logger";
|
||||||
import { extensionInstaller, PackageJson } from "./extension-installer";
|
import { extensionInstaller, PackageJson } from "./extension-installer";
|
||||||
|
import { extensionsStore } from "./extensions-store";
|
||||||
import type { LensExtensionId, LensExtensionManifest } from "./lens-extension";
|
import type { LensExtensionId, LensExtensionManifest } from "./lens-extension";
|
||||||
|
|
||||||
export interface InstalledExtension {
|
export interface InstalledExtension {
|
||||||
@ -213,24 +214,31 @@ export class ExtensionDiscovery {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async getByManifest(manifestPath: string, { isBundled = false, isEnabled = isBundled }: {
|
protected async getByManifest(manifestPath: string, { isBundled = false }: {
|
||||||
isBundled?: boolean;
|
isBundled?: boolean;
|
||||||
isEnabled?: boolean;
|
|
||||||
} = {}): Promise<InstalledExtension | null> {
|
} = {}): Promise<InstalledExtension | null> {
|
||||||
let manifestJson: LensExtensionManifest;
|
let manifestJson: LensExtensionManifest;
|
||||||
|
let isEnabled: boolean;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// check manifest file for existence
|
// check manifest file for existence
|
||||||
fs.accessSync(manifestPath, fs.constants.F_OK);
|
fs.accessSync(manifestPath, fs.constants.F_OK);
|
||||||
|
|
||||||
manifestJson = __non_webpack_require__(manifestPath);
|
manifestJson = __non_webpack_require__(manifestPath);
|
||||||
|
const installedManifestPath = path.join(this.nodeModulesPath, manifestJson.name, "package.json");
|
||||||
this.packagesJson.dependencies[manifestJson.name] = path.dirname(manifestPath);
|
this.packagesJson.dependencies[manifestJson.name] = path.dirname(manifestPath);
|
||||||
|
|
||||||
|
if (!isBundled) {
|
||||||
|
isEnabled = extensionsStore.isEnabled(installedManifestPath);
|
||||||
|
} else {
|
||||||
|
isEnabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
manifestPath: path.join(this.nodeModulesPath, manifestJson.name, "package.json"),
|
manifestPath: installedManifestPath,
|
||||||
manifest: manifestJson,
|
manifest: manifestJson,
|
||||||
isBundled,
|
isBundled,
|
||||||
isEnabled,
|
isEnabled
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`${logModule}: can't install extension at ${manifestPath}: ${error}`, { manifestJson });
|
logger.error(`${logModule}: can't install extension at ${manifestPath}: ${error}`, { manifestJson });
|
||||||
@ -316,13 +324,12 @@ export class ExtensionDiscovery {
|
|||||||
/**
|
/**
|
||||||
* Loads extension from absolute path, updates this.packagesJson to include it and returns the extension.
|
* Loads extension from absolute path, updates this.packagesJson to include it and returns the extension.
|
||||||
*/
|
*/
|
||||||
async loadExtensionFromPath(absPath: string, { isBundled = false, isEnabled = isBundled }: {
|
async loadExtensionFromPath(absPath: string, { isBundled = false }: {
|
||||||
isBundled?: boolean;
|
isBundled?: boolean;
|
||||||
isEnabled?: boolean;
|
|
||||||
} = {}): Promise<InstalledExtension | null> {
|
} = {}): Promise<InstalledExtension | null> {
|
||||||
const manifestPath = path.resolve(absPath, manifestFilename);
|
const manifestPath = path.resolve(absPath, manifestFilename);
|
||||||
|
|
||||||
return this.getByManifest(manifestPath, { isBundled, isEnabled });
|
return this.getByManifest(manifestPath, { isBundled });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user