Fix bundled extensions not being loaded (#7359)

* Fix bundled extensions not being loaded

- Also show that this fixes it by added an example bundled
  extension to 'open-lens'

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix build

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Add explanatory comment for inline require

Signed-off-by: Sebastian Malton <sebastian@malton.name>

---------

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2023-03-15 18:16:09 +02:00
1 parent ae9a8c3c41
commit 2c3c88be04
51 files changed
+521 -159

No files matched your search

@@ -1,6 +0,0 @@
module.exports = {
extends: "@k8slens/eslint-config/eslint",
parserOptions: {
project: "./tsconfig.json",
},
};
@@ -0,0 +1,6 @@
{
"extends": "@k8slens/eslint-config/eslint",
"parserOptions": {
"project": "./tsconfig.json"
}
}
@@ -0,0 +1,6 @@
{
"extends": "@k8slens/eslint-config/eslint",
"parserOptions": {
"project": "./tsconfig.json"
}
}
@@ -0,0 +1,5 @@
# @k8slens/legacy-extensions
This package contains stuff related to creating Lens-applications.
Namely, this package contains information about extensions and bundled extensions of the v1 API.
@@ -0,0 +1,2 @@
export * from "./src/bundled-extension";
export * from "./src/lens-extension";
@@ -0,0 +1 @@
module.exports = require("@k8slens/jest").monorepoPackageConfig(__dirname).configForNode;
@@ -0,0 +1,39 @@
{
"name": "@k8slens/legacy-extensions",
"private": false,
"version": "1.0.0-alpha.0",
"description": "Package for Lens extensions using the v1 API",
"type": "commonjs",
"files": [
"dist"
],
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
},
"repository": {
"type": "git",
"url": "git+https://github.com/lensapp/lens.git"
},
"main": "dist/index.js",
"types": "dist/index.d.ts",
"author": {
"name": "OpenLens Authors",
"email": "info@k8slens.dev"
},
"license": "MIT",
"homepage": "https://github.com/lensapp/lens",
"scripts": {
"build": "webpack",
"dev": "webpack --mode=development --watch",
"test": "jest --coverage --runInBand",
"lint": "lens-lint",
"lint:fix": "lens-lint --fix"
},
"peerDependencies": {
"@ogre-tools/injectable": "^15.1.2"
},
"devDependencies": {
"@k8slens/eslint-config": "6.5.0-alpha.1"
}
}
@@ -0,0 +1,16 @@
import { getInjectionToken } from "@ogre-tools/injectable";
import type {
LensExtensionConstructor,
LensExtensionManifest,
} from "./lens-extension";
export interface BundledExtension {
readonly manifest: LensExtensionManifest;
main: () => LensExtensionConstructor | null;
renderer: () => LensExtensionConstructor | null;
}
export const bundledExtensionInjectionToken =
getInjectionToken<BundledExtension>({
id: "bundled-extension-path",
});
@@ -0,0 +1,63 @@
export type LensExtensionId = string;
export type LensExtensionConstructor = new (
ext: InstalledExtension
) => LegacyLensExtension;
export interface InstalledExtension {
id: LensExtensionId;
readonly manifest: LensExtensionManifest;
// Absolute path to the non-symlinked source folder,
// e.g. "/Users/user/.k8slens/extensions/helloworld"
readonly absolutePath: string;
/**
* Absolute to the symlinked package.json file
*/
readonly manifestPath: string;
readonly isBundled: boolean;
readonly isCompatible: boolean;
isEnabled: boolean;
}
export interface LegacyLensExtension {
readonly id: LensExtensionId;
readonly manifest: LensExtensionManifest;
readonly manifestPath: string;
readonly isBundled: boolean;
readonly sanitizedExtensionId: string;
readonly name: string;
readonly version: string;
readonly description: string | undefined;
readonly storeName: string;
getExtensionFileFolder(): Promise<string>;
enable(): Promise<void>;
disable(): Promise<void>;
activate(): Promise<void>;
}
export interface LensExtensionManifest {
name: string;
version: string;
description?: string;
main?: string; // path to %ext/dist/main.js
renderer?: string; // path to %ext/dist/renderer.js
/**
* Supported Lens version engine by extension could be defined in `manifest.engines.lens`
* Only MAJOR.MINOR version is taken in consideration.
*/
engines: {
lens: string; // "semver"-package format
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;
}
@@ -0,0 +1,4 @@
{
"extends": "@k8slens/typescript/config/base.json",
"include": ["**/*.ts"]
}
@@ -0,0 +1 @@
module.exports = require("@k8slens/webpack").configForNode;