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

Cleanup error checking, don't treat 4.X bundled extensions as compatible

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-07-15 17:53:38 -04:00
parent c8e5d9c8b8
commit 163974f013
3 changed files with 25 additions and 4 deletions

View File

@ -23,8 +23,12 @@ import semver from "semver";
import { appSemVer } from "../common/vars";
import type { LensExtensionManifest } from "./lens-extension";
export function isCompatibleExtension(manifest: LensExtensionManifest): boolean {
export function isCompatibleExtension(manifest: LensExtensionManifest, isBundled: boolean): boolean {
if (manifest.engines?.lens) {
if (isBundled) {
return true;
}
/* include Lens's prerelease tag in the matching so the extension's compatibility is not limited by it */
return semver.satisfies(appSemVer, manifest.engines.lens, { includePrerelease: true });
}

View File

@ -361,7 +361,7 @@ export class ExtensionDiscovery extends Singleton {
const extensionDir = path.dirname(manifestPath);
const npmPackage = path.join(extensionDir, `${manifest.name}-${manifest.version}.tgz`);
const absolutePath = (isProduction && await fse.pathExists(npmPackage)) ? npmPackage : extensionDir;
const isCompatible = isBundled || isCompatibleExtension(manifest);
const isCompatible = isCompatibleExtension(manifest, isBundled);
return {
id,

View File

@ -372,8 +372,14 @@ export class ExtensionLoader extends Singleton {
} catch (error) {
const safeName = inspect(extension.manifest.name, false, null, false);
if (error instanceof TypeError && error.message.match(/^Class extends value .* is not a constructor or null$/) !== null) {
console.warn(`${logModule}: ${entryPointName} for ${safeName} does not support ${packageJson.version}`);
if (isExtensionIncompatibleError(error)) {
const message = `${logModule}: ${entryPointName} for ${safeName} does not support ${packageJson.version}`;
if (ipcRenderer) {
console.warn(message, extension);
} else {
logger.warn(message, { extension });
}
} else {
const message = `${logModule}: can't load ${entryPointName} for ${safeName}`;
@ -400,3 +406,14 @@ export class ExtensionLoader extends Singleton {
return toJS(this.extensions);
}
}
const classExtendsError = /^Class extends value .* is not a constructor or null$/;
const retrieveError = /^Cannot read property .* of undefined$/;
function isExtensionIncompatibleError(error: any): boolean {
if (!(error instanceof TypeError)) {
return false;
}
return Boolean(error.message.match(classExtendsError) || error.message.match(retrieveError));
}