From a6a0a6eddf8b618d3809854e226c015037fa5e69 Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 2 Sep 2020 17:54:18 +0300 Subject: [PATCH] extensions-api -- in-progress Signed-off-by: Roman --- package.json | 2 +- src/common/vars.ts | 2 ++ .../example-extension/example-extension.ts | 7 +------ src/extensions/example-extension/tsconfig.json | 6 +++--- src/extensions/extension-api.mock.d.ts | 12 ++++++++++++ types/mocks.d.ts | 1 - webpack.renderer.ts | 7 +++---- 7 files changed, 22 insertions(+), 15 deletions(-) create mode 100644 src/extensions/extension-api.mock.d.ts diff --git a/package.json b/package.json index deb531b5ac..83d27f42a6 100644 --- a/package.json +++ b/package.json @@ -15,11 +15,11 @@ "dev-run": "nodemon --watch static/build/main.js --exec \"electron --inspect .\"", "dev:main": "yarn compile:main --watch", "dev:renderer": "yarn compile:renderer --watch", + "dev:extensions": "tsc --project src/extensions/example-extension --watch", "compile": "env NODE_ENV=production concurrently yarn:compile:*", "compile:main": "webpack --config webpack.main.ts", "compile:renderer": "webpack --config webpack.renderer.ts", "compile:i18n": "lingui compile", - "compile-extensions": "tsc --project src/extensions --watch", "build:linux": "yarn compile && electron-builder --linux --dir -c.productName=Lens", "build:mac": "yarn compile && electron-builder --mac --dir -c.productName=Lens", "build:win": "yarn compile && electron-builder --win --dir -c.productName=Lens", diff --git a/src/common/vars.ts b/src/common/vars.ts index 1df1e0f5df..8cb48e83c7 100644 --- a/src/common/vars.ts +++ b/src/common/vars.ts @@ -11,6 +11,7 @@ export const isDevelopment = isDebugging || !isProduction; export const isTestEnv = !!process.env.JEST_WORKER_ID; export const appName = `${packageInfo.productName}${isDevelopment ? "Dev" : ""}` +export const extensionApiLibName = `${appName}-extensions.api` export const publicPath = "/build/" // Webpack build paths @@ -18,6 +19,7 @@ export const contextDir = process.cwd(); export const buildDir = path.join(contextDir, "static", publicPath); export const mainDir = path.join(contextDir, "src/main"); export const rendererDir = path.join(contextDir, "src/renderer"); +export const extensionsDir = path.join(contextDir, "src/extensions"); export const htmlTemplate = path.resolve(rendererDir, "template.html"); export const sassCommonVars = path.resolve(rendererDir, "components/vars.scss"); diff --git a/src/extensions/example-extension/example-extension.ts b/src/extensions/example-extension/example-extension.ts index d4aa9b5488..b712aa7b74 100644 --- a/src/extensions/example-extension/example-extension.ts +++ b/src/extensions/example-extension/example-extension.ts @@ -1,5 +1,4 @@ -// fixme: hook up generated types from extension-api.ts (tsc --declaration) -// fixme: provide compile or runtime import +// fixme: provide runtime import / webpack.resolve.alias / require.extensions (?) import { LensExtension } from "@lens/extensions"; export default class ExampleExtension extends LensExtension { @@ -8,7 +7,3 @@ export default class ExampleExtension extends LensExtension { return super.init(); } } - -export const someData = { - title: "it works" -} \ No newline at end of file diff --git a/src/extensions/example-extension/tsconfig.json b/src/extensions/example-extension/tsconfig.json index 24cd840efb..36b1518dd6 100644 --- a/src/extensions/example-extension/tsconfig.json +++ b/src/extensions/example-extension/tsconfig.json @@ -11,10 +11,10 @@ "allowJs": true, "esModuleInterop": true, "allowSyntheticDefaultImports": true, - "resolveJsonModule": true, - "declaration": true + "resolveJsonModule": true }, "include": [ - "./example-extension/example-extension.ts" + "../extension-api.mock.d.ts", + "./example-extension.ts" ] } diff --git a/src/extensions/extension-api.mock.d.ts b/src/extensions/extension-api.mock.d.ts new file mode 100644 index 0000000000..c0a452906c --- /dev/null +++ b/src/extensions/extension-api.mock.d.ts @@ -0,0 +1,12 @@ +// todo: auto-generate from ./extension-api.ts +// todo: remove when npm-available (with generated types) + +declare module "@lens/extensions" { + export = LensExtensions +} + +declare namespace LensExtensions { + export { + LensExtension, ExtensionManifest, ExtensionVersion, ExtensionId, + } from "./extension-api" +} diff --git a/types/mocks.d.ts b/types/mocks.d.ts index 7c4ef0aa75..7ddd25267b 100644 --- a/types/mocks.d.ts +++ b/types/mocks.d.ts @@ -3,7 +3,6 @@ declare module "mac-ca" declare module "win-ca" declare module "@hapi/call" declare module "@hapi/subtext" -declare module "@lens/extensions" // todo: provide types // Global path to static assets declare const __static: string; diff --git a/webpack.renderer.ts b/webpack.renderer.ts index cdae9ed374..b1f894efcf 100755 --- a/webpack.renderer.ts +++ b/webpack.renderer.ts @@ -1,4 +1,4 @@ -import { appName, htmlTemplate, isDevelopment, isProduction, buildDir, rendererDir, sassCommonVars, publicPath } from "./src/common/vars"; +import { extensionApiLibName, appName, buildDir, extensionsDir, htmlTemplate, isDevelopment, isProduction, publicPath, rendererDir, sassCommonVars } from "./src/common/vars"; import path from "path"; import webpack from "webpack"; import HtmlWebpackPlugin from "html-webpack-plugin"; @@ -16,6 +16,7 @@ export default function (): webpack.Configuration { cache: isDevelopment, entry: { [appName]: path.resolve(rendererDir, "bootstrap.tsx"), + [extensionApiLibName]: path.resolve(extensionsDir, "extension-api.ts"), // todo: use separated tsconfig.json? }, output: { publicPath: publicPath, @@ -25,9 +26,6 @@ export default function (): webpack.Configuration { libraryTarget: "commonjs2", }, resolve: { - alias: { - // "@lens/extensions": "" // todo: replace in runtime to "build/LensExtensionApi.js"? - }, extensions: [ '.js', '.jsx', '.json', '.ts', '.tsx', @@ -154,6 +152,7 @@ export default function (): webpack.Configuration { filename: `${appName}.html`, template: htmlTemplate, inject: true, + excludeChunks: [extensionApiLibName], }), new MiniCssExtractPlugin({