mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-24 18:56:32 -05:00
fix(backend): migrate code to use the commons workspace
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
c489aacea0
commit
298b6bc205
13 changed files with 37 additions and 42 deletions
18
.github/workflows/backend-tests.yml
vendored
18
.github/workflows/backend-tests.yml
vendored
|
@ -72,14 +72,11 @@ jobs:
|
|||
- uses: actions/checkout@v3
|
||||
if: needs.changes.outputs.changed == 'true'
|
||||
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
- name: Setup node
|
||||
if: needs.changes.outputs.changed == 'true'
|
||||
uses: actions/setup-node@v3
|
||||
uses: ./.github/actions/setup-node
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
|
||||
- run: yarn install --immutable
|
||||
if: needs.changes.outputs.changed == 'true'
|
||||
NODE_VERSION: ${{ env.NODE_VERSION }}
|
||||
|
||||
- run: yarn run build
|
||||
if: needs.changes.outputs.changed == 'true'
|
||||
|
@ -93,14 +90,11 @@ jobs:
|
|||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Use Node.js ${{ env.NODEJS_VERSION }}
|
||||
- name: Setup node
|
||||
if: needs.changes.outputs.changed == 'true'
|
||||
uses: actions/setup-node@v3
|
||||
uses: ./.github/actions/setup-node
|
||||
with:
|
||||
node-version: ${{ env.NODEJS_VERSION }}
|
||||
|
||||
- run: yarn install --immutable
|
||||
if: needs.changes.outputs.changed == 'true'
|
||||
NODE_VERSION: ${{ env.NODE_VERSION }}
|
||||
|
||||
- run: yarn run test:cov
|
||||
if: needs.changes.outputs.changed == 'true'
|
||||
|
|
|
@ -26,20 +26,27 @@ USER node
|
|||
WORKDIR /usr/src/app
|
||||
|
||||
COPY --chown=node .yarn/plugins .yarn/plugins
|
||||
COPY --chown=node .yarn/patches .yarn/patches
|
||||
COPY --chown=node .yarn/releases .yarn/releases
|
||||
COPY --chown=node .yarnrc.yml .yarnrc.yml
|
||||
COPY --chown=node package.json package.json
|
||||
COPY --chown=node yarn.lock yarn.lock
|
||||
COPY --chown=node backend/package.json backend/
|
||||
COPY --chown=node commons/package.json commons/
|
||||
COPY --chown=node frontend/package.json frontend/
|
||||
|
||||
# Install dependencies first to not invalidate the cache on every source change
|
||||
RUN --mount=type=cache,sharing=locked,uid=1000,gid=1000,target=/tmp/.yarn \
|
||||
yarn install --immutable && yarn workspaces focus @hedgedoc/backend
|
||||
|
||||
COPY --chown=node commons/ commons/
|
||||
COPY --chown=node backend/nest-cli.json backend/tsconfig.json backend/tsconfig.build.json backend/
|
||||
COPY --chown=node backend/src backend/src
|
||||
|
||||
WORKDIR /usr/src/app/commons
|
||||
|
||||
RUN yarn build
|
||||
|
||||
## Stage 2a: Dev config files and tests
|
||||
FROM code-with-deps as development
|
||||
USER node
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@azure/storage-blob": "12.12.0",
|
||||
"@hedgedoc/realtime": "0.3.0",
|
||||
"@hedgedoc/commons": "workspace:commons",
|
||||
"@mrdrogdrog/optional": "1.0.0",
|
||||
"@nestjs/common": "9.2.1",
|
||||
"@nestjs/config": "2.2.0",
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
import {
|
||||
encodeDocumentDeletedMessage,
|
||||
encodeMetadataUpdatedMessage,
|
||||
} from '@hedgedoc/realtime';
|
||||
} from '@hedgedoc/commons';
|
||||
import { Mock } from 'ts-mockery';
|
||||
|
||||
import { Note } from '../../notes/note.entity';
|
||||
|
|
|
@ -6,10 +6,9 @@
|
|||
import {
|
||||
encodeDocumentDeletedMessage,
|
||||
encodeMetadataUpdatedMessage,
|
||||
} from '@hedgedoc/realtime';
|
||||
} from '@hedgedoc/commons';
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { EventEmitter } from 'events';
|
||||
import TypedEventEmitter, { EventMap } from 'typed-emitter';
|
||||
import { EventEmitter2 } from 'eventemitter2';
|
||||
import { Awareness } from 'y-protocols/awareness';
|
||||
|
||||
import { Note } from '../../notes/note.entity';
|
||||
|
@ -17,18 +16,10 @@ import { WebsocketAwareness } from './websocket-awareness';
|
|||
import { WebsocketConnection } from './websocket-connection';
|
||||
import { WebsocketDoc } from './websocket-doc';
|
||||
|
||||
export type RealtimeNoteEvents = {
|
||||
beforeDestroy: () => void;
|
||||
destroy: () => void;
|
||||
};
|
||||
|
||||
type TypedEventEmitterConstructor<T extends EventMap> =
|
||||
new () => TypedEventEmitter<T>;
|
||||
|
||||
/**
|
||||
* Represents a note currently being edited by a number of clients.
|
||||
*/
|
||||
export class RealtimeNote extends (EventEmitter as TypedEventEmitterConstructor<RealtimeNoteEvents>) {
|
||||
export class RealtimeNote extends EventEmitter2 {
|
||||
protected logger: Logger;
|
||||
private readonly websocketDoc: WebsocketDoc;
|
||||
private readonly websocketAwareness: WebsocketAwareness;
|
||||
|
|
|
@ -3,18 +3,17 @@
|
|||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { EventEmitter } from 'events';
|
||||
import { EventEmitter2 } from 'eventemitter2';
|
||||
import { Mock } from 'ts-mockery';
|
||||
import TypedEmitter from 'typed-emitter';
|
||||
|
||||
import { Note } from '../../../notes/note.entity';
|
||||
import { RealtimeNote, RealtimeNoteEvents } from '../realtime-note';
|
||||
import { RealtimeNote } from '../realtime-note';
|
||||
import { WebsocketAwareness } from '../websocket-awareness';
|
||||
import { WebsocketDoc } from '../websocket-doc';
|
||||
import { mockAwareness } from './mock-awareness';
|
||||
import { mockWebsocketDoc } from './mock-websocket-doc';
|
||||
|
||||
class MockRealtimeNote extends (EventEmitter as new () => TypedEmitter<RealtimeNoteEvents>) {
|
||||
class MockRealtimeNote extends EventEmitter2 {
|
||||
constructor(
|
||||
private note: Note,
|
||||
private doc: WebsocketDoc,
|
||||
|
|
|
@ -3,13 +3,11 @@
|
|||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { WebsocketTransporter } from '@hedgedoc/realtime';
|
||||
import { MessageTransporterEvents } from '@hedgedoc/realtime/dist/mjs/y-doc-message-transporter';
|
||||
import { EventEmitter } from 'events';
|
||||
import { WebsocketTransporter } from '@hedgedoc/commons';
|
||||
import { EventEmitter2 } from 'eventemitter2';
|
||||
import { Mock } from 'ts-mockery';
|
||||
import TypedEmitter from 'typed-emitter';
|
||||
|
||||
class MockMessageTransporter extends (EventEmitter as new () => TypedEmitter<MessageTransporterEvents>) {
|
||||
class MockMessageTransporter extends EventEmitter2 {
|
||||
setupWebsocket(): void {
|
||||
//intentionally left blank
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import * as hedgedocRealtimeModule from '@hedgedoc/realtime';
|
||||
import * as hedgedocRealtimeModule from '@hedgedoc/commons';
|
||||
import { Mock } from 'ts-mockery';
|
||||
|
||||
import { RealtimeNote } from './realtime-note';
|
||||
|
@ -12,6 +12,8 @@ import { ClientIdUpdate, WebsocketAwareness } from './websocket-awareness';
|
|||
import { WebsocketConnection } from './websocket-connection';
|
||||
import { WebsocketDoc } from './websocket-doc';
|
||||
|
||||
jest.mock('@hedgedoc/commons');
|
||||
|
||||
describe('websocket-awareness', () => {
|
||||
it('distributes content updates to other synced clients', () => {
|
||||
const mockEncodedUpdate = new Uint8Array([0, 1, 2, 3]);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { encodeAwarenessUpdateMessage } from '@hedgedoc/realtime';
|
||||
import { encodeAwarenessUpdateMessage } from '@hedgedoc/commons';
|
||||
import { Awareness } from 'y-protocols/awareness';
|
||||
|
||||
import { RealtimeNote } from './realtime-note';
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import * as hedgedocRealtimeModule from '@hedgedoc/realtime';
|
||||
import { WebsocketTransporter } from '@hedgedoc/realtime';
|
||||
import * as hedgedocRealtimeModule from '@hedgedoc/commons';
|
||||
import { WebsocketTransporter } from '@hedgedoc/commons';
|
||||
import { Mock } from 'ts-mockery';
|
||||
import WebSocket from 'ws';
|
||||
import * as yProtocolsAwarenessModule from 'y-protocols/awareness';
|
||||
|
@ -25,6 +25,8 @@ import { WebsocketDoc } from './websocket-doc';
|
|||
|
||||
import SpyInstance = jest.SpyInstance;
|
||||
|
||||
jest.mock('@hedgedoc/commons');
|
||||
|
||||
describe('websocket connection', () => {
|
||||
let mockedDoc: WebsocketDoc;
|
||||
let mockedAwareness: WebsocketAwareness;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { WebsocketTransporter } from '@hedgedoc/realtime';
|
||||
import { WebsocketTransporter } from '@hedgedoc/commons';
|
||||
import { Logger } from '@nestjs/common';
|
||||
import WebSocket from 'ws';
|
||||
import { Awareness, removeAwarenessStates } from 'y-protocols/awareness';
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import * as hedgedocRealtimeModule from '@hedgedoc/realtime';
|
||||
import * as hedgedocRealtimeModule from '@hedgedoc/commons';
|
||||
import { Mock } from 'ts-mockery';
|
||||
|
||||
import { RealtimeNote } from './realtime-note';
|
||||
|
@ -11,6 +11,8 @@ import { mockConnection } from './test-utils/mock-connection';
|
|||
import { WebsocketConnection } from './websocket-connection';
|
||||
import { WebsocketDoc } from './websocket-doc';
|
||||
|
||||
jest.mock('@hedgedoc/commons');
|
||||
|
||||
describe('websocket-doc', () => {
|
||||
it('saves the initial content', () => {
|
||||
const textContent = 'textContent';
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { encodeDocumentUpdateMessage } from '@hedgedoc/realtime';
|
||||
import { encodeDocumentUpdateMessage } from '@hedgedoc/commons';
|
||||
import { Doc } from 'yjs';
|
||||
|
||||
import { RealtimeNote } from './realtime-note';
|
||||
|
|
Loading…
Reference in a new issue