From 26e9ecb14892339a39f1b6275544a13e39638f1e Mon Sep 17 00:00:00 2001 From: Janne Savolainen Date: Tue, 21 Mar 2023 10:39:55 +0200 Subject: [PATCH] Extract computed channel to own NPM package for clear dependencies Signed-off-by: Janne Savolainen --- package-lock.json | 32 +++++++++++-- .../messaging/agnostic/package.json | 7 +-- .../agnostic/src/features/actual/index.ts | 13 ------ .../messaging/computed-channel/.eslintrc.json | 6 +++ .../messaging/computed-channel/.prettierrc | 1 + .../messaging/computed-channel/index.ts | 12 +++++ .../messaging/computed-channel/jest.config.js | 1 + .../messaging/computed-channel/package.json | 45 +++++++++++++++++++ ...annel-administration-channel.injectable.ts | 6 +-- .../computed-channel.injectable.ts | 6 +-- .../computed-channel.test.tsx | 18 ++++---- ...icate-channel-observer-guard.injectable.ts | 0 .../messaging/computed-channel/src/feature.ts | 18 ++++++++ .../messaging/computed-channel/tsconfig.json | 4 ++ .../computed-channel/webpack.config.js | 1 + 15 files changed, 133 insertions(+), 37 deletions(-) create mode 100644 packages/technical-features/messaging/computed-channel/.eslintrc.json create mode 100644 packages/technical-features/messaging/computed-channel/.prettierrc create mode 100644 packages/technical-features/messaging/computed-channel/index.ts create mode 100644 packages/technical-features/messaging/computed-channel/jest.config.js create mode 100644 packages/technical-features/messaging/computed-channel/package.json rename packages/technical-features/messaging/{agnostic/src/features/actual => computed-channel/src}/computed-channel/computed-channel-administration-channel.injectable.ts (87%) rename packages/technical-features/messaging/{agnostic/src/features/actual => computed-channel/src}/computed-channel/computed-channel.injectable.ts (91%) rename packages/technical-features/messaging/{agnostic/src/features/actual => computed-channel/src}/computed-channel/computed-channel.test.tsx (97%) rename packages/technical-features/messaging/{agnostic/src/features/actual => computed-channel/src}/computed-channel/duplicate-channel-observer-guard.injectable.ts (100%) create mode 100644 packages/technical-features/messaging/computed-channel/src/feature.ts create mode 100644 packages/technical-features/messaging/computed-channel/tsconfig.json create mode 100644 packages/technical-features/messaging/computed-channel/webpack.config.js diff --git a/package-lock.json b/package-lock.json index 311c78425a..3ecbf69ca3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4685,6 +4685,10 @@ "resolved": "packages/bump-version-for-cron", "link": true }, + "node_modules/@k8slens/computed-channel": { + "resolved": "packages/technical-features/messaging/computed-channel", + "link": true + }, "node_modules/@k8slens/core": { "resolved": "packages/core", "link": true @@ -6187,6 +6191,7 @@ "version": "15.1.2", "resolved": "https://registry.npmjs.org/@ogre-tools/test-utils/-/test-utils-15.1.2.tgz", "integrity": "sha512-WGuJoHgFJCt0u5ok9BnQKSkF0J1MYPrRlr0naNUUywZgNSrPy64TqlY8AEEIe2cquUZMwe2wsv9esg+KDRUnrA==", + "dev": true, "peerDependencies": { "lodash": "^4.17.21" } @@ -34438,6 +34443,7 @@ }, "devDependencies": { "@async-fn/jest": "1.6.4", + "@k8slens/messaging-fake-bridge": "^1.0.0-alpha.1", "@material-ui/core": "^4.12.3", "@material-ui/icons": "^4.11.2", "@material-ui/lab": "^4.0.0-alpha.60", @@ -37216,20 +37222,37 @@ "version": "1.0.0-alpha.1", "license": "MIT", "devDependencies": { - "@async-fn/jest": "^1.6.4", + "@k8slens/eslint-config": "^6.5.0-alpha.1" + }, + "peerDependencies": { + "@k8slens/application": "^6.5.0-alpha.0", + "@k8slens/feature-core": "^6.5.0-alpha.0", + "@k8slens/startable-stoppable": "^1.0.0-alpha.1", + "@ogre-tools/injectable": "^15.1.2", + "@ogre-tools/injectable-extension-for-auto-registration": "^15.1.2", + "@ogre-tools/injectable-extension-for-mobx": "^15.1.2", + "lodash": "^4.17.21", + "mobx": "^6.7.0" + } + }, + "packages/technical-features/messaging/computed-channel": { + "version": "1.0.0-alpha.1", + "license": "MIT", + "devDependencies": { "@k8slens/eslint-config": "^6.5.0-alpha.1", + "@k8slens/messaging-fake-bridge": "^1.0.0-alpha.1", "type-fest": "^2.14.0" }, "peerDependencies": { "@k8slens/application": "^6.5.0-alpha.0", - "@k8slens/startable-stoppable": "^1.0.0-alpha.1", + "@k8slens/feature-core": "^6.5.0-alpha.0", + "@k8slens/messaging": "^1.0.0-alpha.1", "@ogre-tools/fp": "^15.1.2", "@ogre-tools/injectable": "^15.1.2", "@ogre-tools/injectable-extension-for-auto-registration": "^15.1.2", "@ogre-tools/injectable-extension-for-mobx": "^15.1.2", - "@ogre-tools/test-utils": "^15.1.2", "lodash": "^4.17.21", - "mobx": "^6.7.0" + "mobx": "^6.8.0" } }, "packages/technical-features/messaging/main": { @@ -37250,6 +37273,7 @@ } }, "packages/technical-features/messaging/message-bridge-fake": { + "name": "@k8slens/messaging-fake-bridge", "version": "1.0.0-alpha.1", "license": "MIT", "devDependencies": { diff --git a/packages/technical-features/messaging/agnostic/package.json b/packages/technical-features/messaging/agnostic/package.json index f522bcc246..32c4e3677d 100644 --- a/packages/technical-features/messaging/agnostic/package.json +++ b/packages/technical-features/messaging/agnostic/package.json @@ -28,19 +28,16 @@ }, "peerDependencies": { "@k8slens/application": "^6.5.0-alpha.0", + "@k8slens/feature-core": "^6.5.0-alpha.0", "@k8slens/startable-stoppable": "^1.0.0-alpha.1", - "@ogre-tools/fp": "^15.1.2", "@ogre-tools/injectable": "^15.1.2", "@ogre-tools/injectable-extension-for-auto-registration": "^15.1.2", "@ogre-tools/injectable-extension-for-mobx": "^15.1.2", - "@ogre-tools/test-utils": "^15.1.2", "lodash": "^4.17.21", "mobx": "^6.7.0" }, "devDependencies": { - "@async-fn/jest": "^1.6.4", - "@k8slens/eslint-config": "^6.5.0-alpha.1", - "type-fest": "^2.14.0" + "@k8slens/eslint-config": "^6.5.0-alpha.1" } } diff --git a/packages/technical-features/messaging/agnostic/src/features/actual/index.ts b/packages/technical-features/messaging/agnostic/src/features/actual/index.ts index 154cb2831a..e8209f26f0 100644 --- a/packages/technical-features/messaging/agnostic/src/features/actual/index.ts +++ b/packages/technical-features/messaging/agnostic/src/features/actual/index.ts @@ -4,19 +4,6 @@ export { messagingFeature } from "./feature"; export { getRequestChannel } from "./request/get-request-channel"; export { getMessageChannel } from "./message/get-message-channel"; -export { - computedChannelInjectionToken, - computedChannelObserverInjectionToken, -} from "./computed-channel/computed-channel.injectable"; - -export type { - ChannelObserver, - ComputedChannelFactory, - JsonifiableObject, - JsonifiableArray, - Jsonifiable, -} from "./computed-channel/computed-channel.injectable"; - export { requestFromChannelInjectionToken } from "./request/request-from-channel-injection-token"; export type { Channel } from "./channel.no-coverage"; diff --git a/packages/technical-features/messaging/computed-channel/.eslintrc.json b/packages/technical-features/messaging/computed-channel/.eslintrc.json new file mode 100644 index 0000000000..b15115cb69 --- /dev/null +++ b/packages/technical-features/messaging/computed-channel/.eslintrc.json @@ -0,0 +1,6 @@ +{ + "extends": "@k8slens/eslint-config/eslint", + "parserOptions": { + "project": "./tsconfig.json" + } +} diff --git a/packages/technical-features/messaging/computed-channel/.prettierrc b/packages/technical-features/messaging/computed-channel/.prettierrc new file mode 100644 index 0000000000..edd47b479e --- /dev/null +++ b/packages/technical-features/messaging/computed-channel/.prettierrc @@ -0,0 +1 @@ +"@k8slens/eslint-config/prettier" diff --git a/packages/technical-features/messaging/computed-channel/index.ts b/packages/technical-features/messaging/computed-channel/index.ts new file mode 100644 index 0000000000..4516e0b9a6 --- /dev/null +++ b/packages/technical-features/messaging/computed-channel/index.ts @@ -0,0 +1,12 @@ +export { + computedChannelInjectionToken, + computedChannelObserverInjectionToken, +} from "./src/computed-channel/computed-channel.injectable"; + +export type { + ChannelObserver, + ComputedChannelFactory, + JsonifiableObject, + JsonifiableArray, + Jsonifiable, +} from "./src/computed-channel/computed-channel.injectable"; diff --git a/packages/technical-features/messaging/computed-channel/jest.config.js b/packages/technical-features/messaging/computed-channel/jest.config.js new file mode 100644 index 0000000000..38d54ab7b6 --- /dev/null +++ b/packages/technical-features/messaging/computed-channel/jest.config.js @@ -0,0 +1 @@ +module.exports = require("@k8slens/jest").monorepoPackageConfig(__dirname).configForReact; diff --git a/packages/technical-features/messaging/computed-channel/package.json b/packages/technical-features/messaging/computed-channel/package.json new file mode 100644 index 0000000000..587e6bcc18 --- /dev/null +++ b/packages/technical-features/messaging/computed-channel/package.json @@ -0,0 +1,45 @@ +{ + "name": "@k8slens/computed-channel", + "private": false, + "version": "1.0.0-alpha.1", + "description": "MobX-like computed between channels", + "type": "commonjs", + "files": [ + "dist" + ], + "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:unit": "jest --coverage --runInBand", + "lint": "lens-lint", + "lint:fix": "lens-lint --fix" + }, + "peerDependencies": { + "@k8slens/application": "^6.5.0-alpha.0", + "@k8slens/feature-core": "^6.5.0-alpha.0", + "@k8slens/messaging": "^1.0.0-alpha.1", + "@ogre-tools/fp": "^15.1.2", + "@ogre-tools/injectable": "^15.1.2", + "@ogre-tools/injectable-extension-for-auto-registration": "^15.1.2", + "@ogre-tools/injectable-extension-for-mobx": "^15.1.2", + "lodash": "^4.17.21", + "mobx": "^6.8.0" + }, + "devDependencies": { + "@k8slens/eslint-config": "^6.5.0-alpha.1", + "@k8slens/messaging-fake-bridge": "^1.0.0-alpha.1", + "type-fest": "^2.14.0" + } +} diff --git a/packages/technical-features/messaging/agnostic/src/features/actual/computed-channel/computed-channel-administration-channel.injectable.ts b/packages/technical-features/messaging/computed-channel/src/computed-channel/computed-channel-administration-channel.injectable.ts similarity index 87% rename from packages/technical-features/messaging/agnostic/src/features/actual/computed-channel/computed-channel-administration-channel.injectable.ts rename to packages/technical-features/messaging/computed-channel/src/computed-channel/computed-channel-administration-channel.injectable.ts index 114d70e86c..b0fdb3c59f 100644 --- a/packages/technical-features/messaging/agnostic/src/features/actual/computed-channel/computed-channel-administration-channel.injectable.ts +++ b/packages/technical-features/messaging/computed-channel/src/computed-channel/computed-channel-administration-channel.injectable.ts @@ -1,10 +1,10 @@ import { reaction } from "mobx"; -import { getMessageChannelListenerInjectable } from "../message/message-channel-listener-injection-token"; -import { sendMessageToChannelInjectionToken } from "../message/message-to-channel-injection-token"; +import { getMessageChannelListenerInjectable } from "@k8slens/messaging"; +import { sendMessageToChannelInjectionToken } from "@k8slens/messaging"; import type { JsonPrimitive } from "type-fest"; import { computedChannelObserverInjectionToken } from "./computed-channel.injectable"; -import { getMessageChannel } from "../message/get-message-channel"; +import { getMessageChannel } from "@k8slens/messaging"; export type JsonifiableObject = { [Key in string]?: Jsonifiable } | { toJSON: () => Jsonifiable }; export type JsonifiableArray = readonly Jsonifiable[]; diff --git a/packages/technical-features/messaging/agnostic/src/features/actual/computed-channel/computed-channel.injectable.ts b/packages/technical-features/messaging/computed-channel/src/computed-channel/computed-channel.injectable.ts similarity index 91% rename from packages/technical-features/messaging/agnostic/src/features/actual/computed-channel/computed-channel.injectable.ts rename to packages/technical-features/messaging/computed-channel/src/computed-channel/computed-channel.injectable.ts index dd05d81dec..03f5a16aab 100644 --- a/packages/technical-features/messaging/agnostic/src/features/actual/computed-channel/computed-channel.injectable.ts +++ b/packages/technical-features/messaging/computed-channel/src/computed-channel/computed-channel.injectable.ts @@ -10,9 +10,9 @@ import { runInAction, } from "mobx"; -import type { MessageChannel } from "../message/message-channel-listener-injection-token"; -import { getMessageChannelListenerInjectable } from "../message/message-channel-listener-injection-token"; -import { sendMessageToChannelInjectionToken } from "../message/message-to-channel-injection-token"; +import type { MessageChannel } from "@k8slens/messaging"; +import { getMessageChannelListenerInjectable } from "@k8slens/messaging"; +import { sendMessageToChannelInjectionToken } from "@k8slens/messaging"; import type { JsonPrimitive } from "type-fest"; import { computedChannelAdministrationChannel } from "./computed-channel-administration-channel.injectable"; diff --git a/packages/technical-features/messaging/agnostic/src/features/actual/computed-channel/computed-channel.test.tsx b/packages/technical-features/messaging/computed-channel/src/computed-channel/computed-channel.test.tsx similarity index 97% rename from packages/technical-features/messaging/agnostic/src/features/actual/computed-channel/computed-channel.test.tsx rename to packages/technical-features/messaging/computed-channel/src/computed-channel/computed-channel.test.tsx index 5860adae82..4736fe22d4 100644 --- a/packages/technical-features/messaging/agnostic/src/features/actual/computed-channel/computed-channel.test.tsx +++ b/packages/technical-features/messaging/computed-channel/src/computed-channel/computed-channel.test.tsx @@ -1,10 +1,7 @@ import React from "react"; import { act } from "@testing-library/react"; import { createContainer, DiContainer, getInjectable } from "@ogre-tools/injectable"; -import { - getMessageBridgeFake, - MessageBridgeFake, -} from "@k8slens/messaging-fake-bridge"; +import { getMessageBridgeFake, MessageBridgeFake } from "@k8slens/messaging-fake-bridge"; import { startApplicationInjectionToken } from "@k8slens/application"; import { computed, @@ -14,11 +11,11 @@ import { reaction, runInAction, } from "mobx"; -import type { MessageChannel } from "../message/message-channel-listener-injection-token"; -import { getMessageChannelListenerInjectable } from "../message/message-channel-listener-injection-token"; +import type { MessageChannel } from "@k8slens/messaging"; +import { getMessageChannelListenerInjectable } from "@k8slens/messaging"; import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx"; import { registerFeature } from "@k8slens/feature-core"; -import { messagingFeatureForUnitTesting } from "../../unit-testing"; +import { testUtils } from "@k8slens/messaging"; import { computedChannelInjectionToken, computedChannelObserverInjectionToken, @@ -29,6 +26,7 @@ import { computedChannelAdministrationChannel, ComputedChannelAdminMessage, } from "./computed-channel-administration-channel.injectable"; +import { computedChannelFeature } from "../feature"; const testChannel: MessageChannel = { id: "some-channel-id" }; const testChannel2: MessageChannel = { id: "some-other-channel-id" }; @@ -76,8 +74,10 @@ const TestComponent = observer(({ someComputed }: { someComputed: IComputedValue }); runInAction(() => { - registerFeature(di1, messagingFeatureForUnitTesting); - registerFeature(di2, messagingFeatureForUnitTesting); + const messagingFeature = testUtils.messagingFeatureForUnitTesting; + + registerFeature(di1, messagingFeature, computedChannelFeature); + registerFeature(di2, messagingFeature, computedChannelFeature); di1.register(channelValueTestListenerInjectable); di2.register(administrationChannelTestListenerInjectable); diff --git a/packages/technical-features/messaging/agnostic/src/features/actual/computed-channel/duplicate-channel-observer-guard.injectable.ts b/packages/technical-features/messaging/computed-channel/src/computed-channel/duplicate-channel-observer-guard.injectable.ts similarity index 100% rename from packages/technical-features/messaging/agnostic/src/features/actual/computed-channel/duplicate-channel-observer-guard.injectable.ts rename to packages/technical-features/messaging/computed-channel/src/computed-channel/duplicate-channel-observer-guard.injectable.ts diff --git a/packages/technical-features/messaging/computed-channel/src/feature.ts b/packages/technical-features/messaging/computed-channel/src/feature.ts new file mode 100644 index 0000000000..179700edcc --- /dev/null +++ b/packages/technical-features/messaging/computed-channel/src/feature.ts @@ -0,0 +1,18 @@ +import { autoRegister } from "@ogre-tools/injectable-extension-for-auto-registration"; +import { getFeature } from "@k8slens/feature-core"; +import { messagingFeature } from "@k8slens/messaging"; + +export const computedChannelFeature = getFeature({ + id: "computed-channel", + + dependencies: [messagingFeature], + + register: (di) => { + autoRegister({ + di, + targetModule: module, + + getRequireContexts: () => [require.context("./", true, /\.injectable\.(ts|tsx)$/)], + }); + }, +}); diff --git a/packages/technical-features/messaging/computed-channel/tsconfig.json b/packages/technical-features/messaging/computed-channel/tsconfig.json new file mode 100644 index 0000000000..ec29a8f75f --- /dev/null +++ b/packages/technical-features/messaging/computed-channel/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "@k8slens/typescript/config/base.json", + "include": ["**/*.ts", "**/*.tsx"] +} diff --git a/packages/technical-features/messaging/computed-channel/webpack.config.js b/packages/technical-features/messaging/computed-channel/webpack.config.js new file mode 100644 index 0000000000..3183f30179 --- /dev/null +++ b/packages/technical-features/messaging/computed-channel/webpack.config.js @@ -0,0 +1 @@ +module.exports = require("@k8slens/webpack").configForNode;