mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
allow to define bundled extensions via appStart
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
f2cecbbcae
commit
3ed6cc3972
@ -3,7 +3,9 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import applicationInformationToken from "./vars/application-information-token.injectable";
|
import applicationInformationToken from "./vars/application-information-token.injectable";
|
||||||
|
import type { ApplicationInformation } from "./vars/application-information-token.injectable";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
applicationInformationToken,
|
applicationInformationToken,
|
||||||
|
ApplicationInformation,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -6,8 +6,9 @@
|
|||||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||||
import type packageJson from "../../../package.json";
|
import type packageJson from "../../../package.json";
|
||||||
|
|
||||||
export type ApplicationInformation = Pick<typeof packageJson, "version" | "config" | "productName" | "copyright" | "description" | "name"> & {
|
export type ApplicationInformation = Pick<typeof packageJson, "version" | "productName" | "copyright" | "description" | "name"> & {
|
||||||
build: Partial<typeof packageJson["build"]> & { publish?: unknown[] };
|
build: Partial<typeof packageJson["build"]> & { publish?: unknown[] };
|
||||||
|
config: typeof packageJson["config"] & { extensions?: string[] };
|
||||||
};
|
};
|
||||||
|
|
||||||
const applicationInformationToken = getInjectionToken<ApplicationInformation>({
|
const applicationInformationToken = getInjectionToken<ApplicationInformation>({
|
||||||
|
|||||||
@ -0,0 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import type { InstalledExtension } from "./extension-discovery";
|
||||||
|
|
||||||
|
const bundledExtensionsInjectable = getInjectable({
|
||||||
|
id: "bundled-extensions",
|
||||||
|
instantiate: (): InstalledExtension[] => [],
|
||||||
|
});
|
||||||
|
|
||||||
|
export default bundledExtensionsInjectable;
|
||||||
@ -29,6 +29,7 @@ import removePathInjectable from "../../common/fs/remove-path.injectable";
|
|||||||
import homeDirectoryPathInjectable from "../../common/os/home-directory-path.injectable";
|
import homeDirectoryPathInjectable from "../../common/os/home-directory-path.injectable";
|
||||||
import applicationInformationToken from "../../common/vars/application-information-token.injectable";
|
import applicationInformationToken from "../../common/vars/application-information-token.injectable";
|
||||||
import lensResourcesDirInjectable from "../../common/vars/lens-resources-dir.injectable";
|
import lensResourcesDirInjectable from "../../common/vars/lens-resources-dir.injectable";
|
||||||
|
import bundledExtensionsInjectable from "./bundled-extensions.injectable";
|
||||||
|
|
||||||
const extensionDiscoveryInjectable = getInjectable({
|
const extensionDiscoveryInjectable = getInjectable({
|
||||||
id: "extension-discovery",
|
id: "extension-discovery",
|
||||||
@ -59,6 +60,7 @@ const extensionDiscoveryInjectable = getInjectable({
|
|||||||
joinPaths: di.inject(joinPathsInjectable),
|
joinPaths: di.inject(joinPathsInjectable),
|
||||||
homeDirectoryPath: di.inject(homeDirectoryPathInjectable),
|
homeDirectoryPath: di.inject(homeDirectoryPathInjectable),
|
||||||
applicationInformation: di.inject(applicationInformationToken),
|
applicationInformation: di.inject(applicationInformationToken),
|
||||||
|
bundledExtensions: di.inject(bundledExtensionsInjectable),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -37,6 +37,7 @@ interface Dependencies {
|
|||||||
readonly extensionsStore: ExtensionsStore;
|
readonly extensionsStore: ExtensionsStore;
|
||||||
readonly extensionInstallationStateStore: ExtensionInstallationStateStore;
|
readonly extensionInstallationStateStore: ExtensionInstallationStateStore;
|
||||||
readonly extensionPackageRootDirectory: string;
|
readonly extensionPackageRootDirectory: string;
|
||||||
|
readonly bundledExtensions: InstalledExtension[];
|
||||||
readonly resourcesDirectory: string;
|
readonly resourcesDirectory: string;
|
||||||
readonly logger: Logger;
|
readonly logger: Logger;
|
||||||
readonly isProduction: boolean;
|
readonly isProduction: boolean;
|
||||||
@ -384,32 +385,13 @@ export class ExtensionDiscovery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async ensureExtensions(): Promise<Map<LensExtensionId, InstalledExtension>> {
|
async ensureExtensions(): Promise<Map<LensExtensionId, InstalledExtension>> {
|
||||||
const bundledExtensions = await this.loadBundledExtensions();
|
const bundledExtensions = this.dependencies.bundledExtensions;
|
||||||
const userExtensions = await this.loadFromFolder(this.localFolderPath, bundledExtensions.map((extension) => extension.manifest.name));
|
const userExtensions = await this.loadFromFolder(this.localFolderPath, bundledExtensions.map((extension) => extension.manifest.name));
|
||||||
const extensions = bundledExtensions.concat(userExtensions);
|
const extensions = bundledExtensions.concat(userExtensions);
|
||||||
|
|
||||||
return this.extensions = new Map(extensions.map(extension => [extension.id, extension]));
|
return this.extensions = new Map(extensions.map(extension => [extension.id, extension]));
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadBundledExtensions(): Promise<InstalledExtension[]> {
|
|
||||||
const extensions: InstalledExtension[] = [];
|
|
||||||
const extensionNames = this.dependencies.applicationInformation.config.extensions || [];
|
|
||||||
|
|
||||||
for (const dirName of extensionNames) {
|
|
||||||
const absPath = this.dependencies.joinPaths(__dirname, "..", "..", "node_modules", dirName);
|
|
||||||
const extension = await this.loadExtensionFromFolder(absPath, { isBundled: true });
|
|
||||||
|
|
||||||
if (!extension) {
|
|
||||||
throw new Error(`Couldn't load bundled extension: ${dirName}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
extensions.push(extension);
|
|
||||||
}
|
|
||||||
this.dependencies.logger.debug(`${logModule}: ${extensions.length} extensions loaded`, { extensions });
|
|
||||||
|
|
||||||
return extensions;
|
|
||||||
}
|
|
||||||
|
|
||||||
async loadFromFolder(folderPath: string, bundledExtensions: string[]): Promise<InstalledExtension[]> {
|
async loadFromFolder(folderPath: string, bundledExtensions: string[]): Promise<InstalledExtension[]> {
|
||||||
const extensions: InstalledExtension[] = [];
|
const extensions: InstalledExtension[] = [];
|
||||||
const paths = await this.dependencies.readDirectory(folderPath);
|
const paths = await this.dependencies.readDirectory(folderPath);
|
||||||
|
|||||||
@ -344,7 +344,7 @@ export class ExtensionLoader {
|
|||||||
const extAbsolutePath = this.dependencies.joinPaths(this.dependencies.getDirnameOfPath(extension.manifestPath), extRelativePath);
|
const extAbsolutePath = this.dependencies.joinPaths(this.dependencies.getDirnameOfPath(extension.manifestPath), extRelativePath);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return __non_webpack_require__(extAbsolutePath).default;
|
return require(/* webpackIgnore: true */ extAbsolutePath).default;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = (error instanceof Error ? error.stack : undefined) || error;
|
const message = (error instanceof Error ? error.stack : undefined) || error;
|
||||||
|
|
||||||
|
|||||||
@ -13,6 +13,7 @@ const di = getDi();
|
|||||||
|
|
||||||
startApp({
|
startApp({
|
||||||
di,
|
di,
|
||||||
|
extensions: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
export { Mobx, LensExtensions, Pty };
|
export { Mobx, LensExtensions, Pty };
|
||||||
|
|||||||
@ -5,13 +5,38 @@
|
|||||||
|
|
||||||
import type { DiContainer } from "@ogre-tools/injectable";
|
import type { DiContainer } from "@ogre-tools/injectable";
|
||||||
import startMainApplicationInjectable from "./start-main-application/start-main-application.injectable";
|
import startMainApplicationInjectable from "./start-main-application/start-main-application.injectable";
|
||||||
|
import readJsonFileInjectable from "../common/fs/read-json-file.injectable";
|
||||||
|
import joinPathsInjectable from "../common/path/join-paths.injectable";
|
||||||
|
import type { LensExtensionManifest } from "../extensions/lens-extension";
|
||||||
|
import bundledExtensionsInjectable from "../extensions/extension-discovery/bundled-extensions.injectable";
|
||||||
|
|
||||||
interface AppConfig {
|
interface AppConfig {
|
||||||
di: DiContainer;
|
di: DiContainer;
|
||||||
|
extensions: { path: string }[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function startApp(conf: AppConfig) {
|
export async function startApp(conf: AppConfig) {
|
||||||
const { di } = conf;
|
const { di, extensions } = conf;
|
||||||
|
|
||||||
return di.inject(startMainApplicationInjectable);
|
const bundledExtensions = di.inject(bundledExtensionsInjectable);
|
||||||
|
const readJson = di.inject(readJsonFileInjectable);
|
||||||
|
const joinPaths = di.inject(joinPathsInjectable);
|
||||||
|
|
||||||
|
for (const extension of extensions) {
|
||||||
|
const manifestPath = joinPaths(extension.path, "package.json");
|
||||||
|
|
||||||
|
bundledExtensions.push({
|
||||||
|
id: manifestPath,
|
||||||
|
manifest: (await readJson(manifestPath)) as unknown as LensExtensionManifest,
|
||||||
|
manifestPath,
|
||||||
|
absolutePath: extension.path,
|
||||||
|
isCompatible: true,
|
||||||
|
isBundled: true,
|
||||||
|
isEnabled: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await di.inject(startMainApplicationInjectable);
|
||||||
|
|
||||||
|
return di;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,9 +6,12 @@ import MiniCssExtractPlugin from "mini-css-extract-plugin";
|
|||||||
import nodeExternals from "webpack-node-externals";
|
import nodeExternals from "webpack-node-externals";
|
||||||
import { platform } from "os";
|
import { platform } from "os";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import type { WebpackPluginInstance } from "webpack";
|
||||||
import { DefinePlugin, optimize } from "webpack";
|
import { DefinePlugin, optimize } from "webpack";
|
||||||
import { main, renderer } from "./library";
|
import { main, renderer } from "./library";
|
||||||
import { buildDir } from "./vars";
|
import { buildDir } from "./vars";
|
||||||
|
import CircularDependencyPlugin from "circular-dependency-plugin";
|
||||||
|
import ForkTsCheckerPlugin from "fork-ts-checker-webpack-plugin";
|
||||||
|
|
||||||
const config = [
|
const config = [
|
||||||
{
|
{
|
||||||
@ -30,6 +33,12 @@ const config = [
|
|||||||
CONTEXT_MATCHER_FOR_NON_FEATURES: `/\\.injectable(\\.${platform})?\\.tsx?$/`,
|
CONTEXT_MATCHER_FOR_NON_FEATURES: `/\\.injectable(\\.${platform})?\\.tsx?$/`,
|
||||||
CONTEXT_MATCHER_FOR_FEATURES: `/\\/(main|common)\\/.+\\.injectable(\\.${platform})?\\.tsx?$/`,
|
CONTEXT_MATCHER_FOR_FEATURES: `/\\/(main|common)\\/.+\\.injectable(\\.${platform})?\\.tsx?$/`,
|
||||||
}),
|
}),
|
||||||
|
new ForkTsCheckerPlugin(),
|
||||||
|
new CircularDependencyPlugin({
|
||||||
|
cwd: __dirname,
|
||||||
|
exclude: /node_modules/,
|
||||||
|
failOnError: true,
|
||||||
|
}) as unknown as WebpackPluginInstance,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -49,7 +58,14 @@ const config = [
|
|||||||
externals: [
|
externals: [
|
||||||
nodeExternals(),
|
nodeExternals(),
|
||||||
],
|
],
|
||||||
plugins: [],
|
plugins: [
|
||||||
|
new ForkTsCheckerPlugin(),
|
||||||
|
new CircularDependencyPlugin({
|
||||||
|
cwd: __dirname,
|
||||||
|
exclude: /node_modules/,
|
||||||
|
failOnError: true,
|
||||||
|
}) as unknown as WebpackPluginInstance,
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
...renderer,
|
...renderer,
|
||||||
@ -81,6 +97,12 @@ const config = [
|
|||||||
new optimize.LimitChunkCountPlugin({
|
new optimize.LimitChunkCountPlugin({
|
||||||
maxChunks: 1,
|
maxChunks: 1,
|
||||||
}),
|
}),
|
||||||
|
new ForkTsCheckerPlugin(),
|
||||||
|
new CircularDependencyPlugin({
|
||||||
|
cwd: __dirname,
|
||||||
|
exclude: /node_modules/,
|
||||||
|
failOnError: true,
|
||||||
|
}) as unknown as WebpackPluginInstance,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@ -13,8 +13,10 @@ import { assetsFolderName, buildDir, htmlTemplate, isDevelopment, mainDir, publi
|
|||||||
import HtmlWebpackPlugin from "html-webpack-plugin";
|
import HtmlWebpackPlugin from "html-webpack-plugin";
|
||||||
import MiniCssExtractPlugin from "mini-css-extract-plugin";
|
import MiniCssExtractPlugin from "mini-css-extract-plugin";
|
||||||
|
|
||||||
|
const defaultRendererConfig = rendererConfig({ showVars: false });
|
||||||
|
|
||||||
const renderer: webpack.Configuration = ({
|
const renderer: webpack.Configuration = ({
|
||||||
...rendererConfig({ showVars: false }),
|
...defaultRendererConfig,
|
||||||
plugins: [
|
plugins: [
|
||||||
// see also: https://github.com/Microsoft/monaco-editor-webpack-plugin#options
|
// see also: https://github.com/Microsoft/monaco-editor-webpack-plugin#options
|
||||||
new MonacoWebpackPlugin({
|
new MonacoWebpackPlugin({
|
||||||
@ -52,6 +54,9 @@ const main: webpack.Configuration = ({
|
|||||||
libraryTarget: "global",
|
libraryTarget: "global",
|
||||||
path: buildDir,
|
path: buildDir,
|
||||||
},
|
},
|
||||||
|
optimization: {
|
||||||
|
minimize: false,
|
||||||
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
extensions: [".json", ".js", ".ts"],
|
extensions: [".json", ".js", ".ts"],
|
||||||
},
|
},
|
||||||
@ -59,6 +64,11 @@ const main: webpack.Configuration = ({
|
|||||||
nodeExternals(),
|
nodeExternals(),
|
||||||
],
|
],
|
||||||
module: {
|
module: {
|
||||||
|
parser: {
|
||||||
|
javascript: {
|
||||||
|
commonjsMagicComments: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
rules: [
|
rules: [
|
||||||
{
|
{
|
||||||
test: /\.node$/,
|
test: /\.node$/,
|
||||||
|
|||||||
@ -45,6 +45,11 @@ configs.push((): webpack.Configuration => {
|
|||||||
nodeExternals(),
|
nodeExternals(),
|
||||||
],
|
],
|
||||||
module: {
|
module: {
|
||||||
|
parser: {
|
||||||
|
javascript: {
|
||||||
|
commonjsMagicComments: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
rules: [
|
rules: [
|
||||||
{
|
{
|
||||||
test: /\.node$/,
|
test: /\.node$/,
|
||||||
|
|||||||
@ -71,6 +71,11 @@ export function webpackLensRenderer({ showVars = true } = {}): webpack.Configura
|
|||||||
minimize: false,
|
minimize: false,
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
|
parser: {
|
||||||
|
javascript: {
|
||||||
|
commonjsMagicComments: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
rules: [
|
rules: [
|
||||||
{
|
{
|
||||||
test: /\.node$/,
|
test: /\.node$/,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user