Browse Source

refactor(libs): consolidate messaging-internal into messaging library (#16386)

This change eliminates the circular dependency between messaging and messaging-internal libraries by merging them into a single messaging library.

Previously, messaging-internal imported from @bitwarden/messaging while messaging tried to import from @bitwarden/messaging-internal, creating an unresolvable circular dependency. This also violated Nx best practices by using cross-library file includes in tsconfig.lib.json.

Changes made:
- Moved all messaging-internal code (SubjectMessageSender, helpers, tests) into libs/messaging/src/
- Updated all imports to use relative paths instead of @bitwarden/messaging imports
- Removed the entire messaging-internal library and its configuration files
- Updated external references in apps/browser to import from @bitwarden/messaging
- Fixed libs/messaging/tsconfig.lib.json to use standard src/**/*.ts pattern
- Updated libs/common internal.ts to re-export from messaging instead of messaging-internal

The messaging library now exports both public APIs and internal implementations, which is a cleaner architecture than maintaining two separate libraries with circular dependencies.

Fixes rootDir configuration issues identified in the Nx library systematic fix project.
pull/16402/head
Addison Beck 3 months ago committed by GitHub
parent
commit
7ac75a6c52
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      .github/CODEOWNERS
  2. 2
      apps/browser/src/platform/sync/sync-service.listener.spec.ts
  3. 1
      jest.config.js
  4. 2
      libs/common/src/platform/messaging/internal.ts
  5. 5
      libs/messaging-internal/README.md
  6. 3
      libs/messaging-internal/eslint.config.mjs
  7. 10
      libs/messaging-internal/jest.config.js
  8. 11
      libs/messaging-internal/package.json
  9. 33
      libs/messaging-internal/project.json
  10. 5
      libs/messaging-internal/src/index.ts
  11. 8
      libs/messaging-internal/src/messaging-internal.spec.ts
  12. 6
      libs/messaging-internal/tsconfig.eslint.json
  13. 13
      libs/messaging-internal/tsconfig.json
  14. 10
      libs/messaging-internal/tsconfig.lib.json
  15. 10
      libs/messaging-internal/tsconfig.spec.json
  16. 4
      libs/messaging/src/helpers.spec.ts
  17. 3
      libs/messaging/src/helpers.ts
  18. 4
      libs/messaging/src/index.ts
  19. 3
      libs/messaging/src/subject-message.sender.spec.ts
  20. 4
      libs/messaging/src/subject-message.sender.ts
  21. 8
      libs/messaging/tsconfig.lib.json
  22. 1
      tsconfig.base.json

1
.github/CODEOWNERS

@ -96,7 +96,6 @@ libs/storage-core @bitwarden/team-platform-dev @@ -96,7 +96,6 @@ libs/storage-core @bitwarden/team-platform-dev
libs/logging @bitwarden/team-platform-dev
libs/storage-test-utils @bitwarden/team-platform-dev
libs/messaging @bitwarden/team-platform-dev
libs/messaging-internal @bitwarden/team-platform-dev
libs/serialization @bitwarden/team-platform-dev
libs/guid @bitwarden/team-platform-dev
libs/client-type @bitwarden/team-platform-dev

2
apps/browser/src/platform/sync/sync-service.listener.spec.ts

@ -4,7 +4,7 @@ import { Subject, firstValueFrom } from "rxjs"; @@ -4,7 +4,7 @@ import { Subject, firstValueFrom } from "rxjs";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { MessageListener, MessageSender } from "@bitwarden/common/platform/messaging";
import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";
import { tagAsExternal } from "@bitwarden/messaging-internal";
import { tagAsExternal } from "@bitwarden/messaging";
import { FullSyncMessage } from "./foreground-sync.service";
import { FULL_SYNC_FINISHED, SyncServiceListener } from "./sync-service.listener";

1
jest.config.js

@ -41,7 +41,6 @@ module.exports = { @@ -41,7 +41,6 @@ module.exports = {
"<rootDir>/libs/key-management/jest.config.js",
"<rootDir>/libs/key-management-ui/jest.config.js",
"<rootDir>/libs/logging/jest.config.js",
"<rootDir>/libs/messaging-internal/jest.config.js",
"<rootDir>/libs/messaging/jest.config.js",
"<rootDir>/libs/node/jest.config.js",
"<rootDir>/libs/platform/jest.config.js",

2
libs/common/src/platform/messaging/internal.ts

@ -1 +1 @@ @@ -1 +1 @@
export * from "@bitwarden/messaging-internal";
export { SubjectMessageSender, tagAsExternal, getCommand } from "@bitwarden/messaging";

5
libs/messaging-internal/README.md

@ -1,5 +0,0 @@ @@ -1,5 +0,0 @@
# messaging-internal
Owned by: platform
Internal details to accompany @bitwarden/messaging this library should not be consumed in non-platform code.

3
libs/messaging-internal/eslint.config.mjs

@ -1,3 +0,0 @@ @@ -1,3 +0,0 @@
import baseConfig from "../../eslint.config.mjs";
export default [...baseConfig];

10
libs/messaging-internal/jest.config.js

@ -1,10 +0,0 @@ @@ -1,10 +0,0 @@
module.exports = {
displayName: "messaging-internal",
preset: "../../jest.preset.js",
testEnvironment: "node",
transform: {
"^.+\\.[tj]s$": ["ts-jest", { tsconfig: "<rootDir>/tsconfig.spec.json" }],
},
moduleFileExtensions: ["ts", "js", "html"],
coverageDirectory: "../../coverage/libs/messaging-internal",
};

11
libs/messaging-internal/package.json

@ -1,11 +0,0 @@ @@ -1,11 +0,0 @@
{
"name": "@bitwarden/messaging-internal",
"version": "0.0.1",
"description": "Internal details to accompany @bitwarden/messaging this library should not be consumed in non-platform code.",
"private": true,
"type": "commonjs",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "GPL-3.0",
"author": "platform"
}

33
libs/messaging-internal/project.json

@ -1,33 +0,0 @@ @@ -1,33 +0,0 @@
{
"name": "messaging-internal",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/messaging-internal/src",
"projectType": "library",
"tags": [],
"targets": {
"build": {
"executor": "@nx/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/messaging-internal",
"main": "libs/messaging-internal/src/index.ts",
"tsConfig": "libs/messaging-internal/tsconfig.lib.json",
"assets": ["libs/messaging-internal/*.md"]
}
},
"lint": {
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["libs/messaging-internal/**/*.ts"]
}
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "libs/messaging-internal/jest.config.js"
}
}
}
}

5
libs/messaging-internal/src/index.ts

@ -1,5 +0,0 @@ @@ -1,5 +0,0 @@
// Built in implementations
export { SubjectMessageSender } from "./subject-message.sender";
// Helpers meant to be used only by other implementations
export { tagAsExternal, getCommand } from "./helpers";

8
libs/messaging-internal/src/messaging-internal.spec.ts

@ -1,8 +0,0 @@ @@ -1,8 +0,0 @@
import * as lib from "./index";
describe("messaging-internal", () => {
// This test will fail until something is exported from index.ts
it("should work", () => {
expect(lib).toBeDefined();
});
});

6
libs/messaging-internal/tsconfig.eslint.json

@ -1,6 +0,0 @@ @@ -1,6 +0,0 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": ["src/**/*.ts", "src/**/*.js"],
"exclude": ["**/build", "**/dist"]
}

13
libs/messaging-internal/tsconfig.json

@ -1,13 +0,0 @@ @@ -1,13 +0,0 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}

10
libs/messaging-internal/tsconfig.lib.json

@ -1,10 +0,0 @@ @@ -1,10 +0,0 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": ["node"]
},
"include": ["src/**/*.ts"],
"exclude": ["jest.config.js", "src/**/*.spec.ts"]
}

10
libs/messaging-internal/tsconfig.spec.json

@ -1,10 +0,0 @@ @@ -1,10 +0,0 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"moduleResolution": "node10",
"types": ["jest", "node"]
},
"include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"]
}

4
libs/messaging-internal/src/helpers.spec.ts → libs/messaging/src/helpers.spec.ts

@ -1,8 +1,8 @@ @@ -1,8 +1,8 @@
import { Subject, firstValueFrom } from "rxjs";
import { CommandDefinition, isExternalMessage, Message } from "@bitwarden/messaging";
import { getCommand, tagAsExternal } from "./helpers";
import { isExternalMessage } from "./is-external-message";
import { CommandDefinition, Message } from "./types";
describe("helpers", () => {
describe("getCommand", () => {

3
libs/messaging-internal/src/helpers.ts → libs/messaging/src/helpers.ts

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
import { map } from "rxjs";
import { CommandDefinition, EXTERNAL_SOURCE_TAG } from "@bitwarden/messaging";
import { EXTERNAL_SOURCE_TAG } from "./is-external-message";
import { CommandDefinition } from "./types";
export const getCommand = (
commandDefinition: CommandDefinition<Record<string, unknown>> | string,

4
libs/messaging/src/index.ts

@ -2,3 +2,7 @@ export { MessageListener } from "./message.listener"; @@ -2,3 +2,7 @@ export { MessageListener } from "./message.listener";
export { MessageSender } from "./message.sender";
export { Message, CommandDefinition } from "./types";
export { isExternalMessage, EXTERNAL_SOURCE_TAG } from "./is-external-message";
// Internal implementations
export { SubjectMessageSender } from "./subject-message.sender";
export { tagAsExternal, getCommand } from "./helpers";

3
libs/messaging-internal/src/subject-message.sender.spec.ts → libs/messaging/src/subject-message.sender.spec.ts

@ -1,8 +1,7 @@ @@ -1,8 +1,7 @@
import { bufferCount, firstValueFrom, Subject } from "rxjs";
import { CommandDefinition, Message } from "@bitwarden/messaging";
import { SubjectMessageSender } from "./subject-message.sender";
import { CommandDefinition, Message } from "./types";
describe("SubjectMessageSender", () => {
const subject = new Subject<Message<{ test: number }>>();

4
libs/messaging-internal/src/subject-message.sender.ts → libs/messaging/src/subject-message.sender.ts

@ -1,8 +1,8 @@ @@ -1,8 +1,8 @@
import { Subject } from "rxjs";
import { CommandDefinition, Message, MessageSender } from "@bitwarden/messaging";
import { getCommand } from "./helpers";
import { MessageSender } from "./message.sender";
import { CommandDefinition, Message } from "./types";
export class SubjectMessageSender implements MessageSender {
constructor(private readonly messagesSubject: Subject<Message<Record<string, unknown>>>) {}

8
libs/messaging/tsconfig.lib.json

@ -5,12 +5,6 @@ @@ -5,12 +5,6 @@
"declaration": true,
"types": ["node"]
},
"include": [
"src/**/*.ts",
"../messaging-internal/src/subject-message.sender.spec.ts",
"../messaging-internal/src/subject-message.sender.ts",
"../messaging-internal/src/helpers.spec.ts",
"../messaging-internal/src/helpers.ts"
],
"include": ["src/**/*.ts"],
"exclude": ["jest.config.js", "src/**/*.spec.ts"]
}

1
tsconfig.base.json

@ -45,7 +45,6 @@ @@ -45,7 +45,6 @@
"@bitwarden/key-management-ui": ["./libs/key-management-ui/src"],
"@bitwarden/logging": ["libs/logging/src"],
"@bitwarden/messaging": ["libs/messaging/src/index.ts"],
"@bitwarden/messaging-internal": ["libs/messaging-internal/src/index.ts"],
"@bitwarden/node/*": ["./libs/node/src/*"],
"@bitwarden/nx-plugin": ["libs/nx-plugin/src/index.ts"],
"@bitwarden/platform": ["./libs/platform/src"],

Loading…
Cancel
Save