Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: abstract types to shared package #1593

Merged
merged 11 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changeset/soft-worms-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@rrweb/all": patch
"rrdom-nodejs": patch
"rrdom": patch
"rrweb-snapshot": major
"rrweb": patch
"@rrweb/rrweb-plugin-canvas-webrtc-record": patch
---

`NodeType` enum was moved from rrweb-snapshot to @rrweb/types
The following types where moved from rrweb-snapshot to @rrweb/types: `documentNode`, `documentTypeNode`, `legacyAttributes`, `textNode`, `cdataNode`, `commentNode`, `elementNode`, `serializedNode`, `serializedNodeWithId`, `serializedElementNodeWithId`, `serializedTextNodeWithId`, `IMirror`, `INode`, `mediaAttributes`, `attributes` and `DataURLOptions`
2 changes: 1 addition & 1 deletion packages/all/test/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NodeType } from 'rrweb-snapshot';
import { expect } from 'vitest';
import {
NodeType,
EventType,
IncrementalSource,
eventWithTime,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { Mirror } from 'rrweb-snapshot';
import SimplePeer from 'simple-peer-light';
import type { RecordPlugin, ICrossOriginIframeMirror } from '@rrweb/types';
import type {
RecordPlugin,
ICrossOriginIframeMirror,
IMirror,
} from '@rrweb/types';
import type { WebRTCDataChannel } from './types';

export const PLUGIN_NAME = 'rrweb/canvas-webrtc@1';
Expand All @@ -25,7 +28,7 @@ export type CrossOriginIframeMessageEventContent = {

export class RRWebPluginCanvasWebRTCRecord {
private peer: SimplePeer.Instance | null = null;
private mirror: Mirror | undefined;
private mirror: IMirror<Node> | undefined;
private crossOriginIframeMirror: ICrossOriginIframeMirror | undefined;
private streamMap: Map<number, MediaStream> = new Map();
private incomingStreams = new Set<MediaStream>();
Expand Down
2 changes: 1 addition & 1 deletion packages/rrdom-nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@
"cssstyle": "^2.3.0",
"nwsapi": "2.2.0",
"rrdom": "^2.0.0-alpha.17",
"rrweb-snapshot": "^2.0.0-alpha.17"
"@rrweb/types": "^2.0.0-alpha.17"
}
}
5 changes: 2 additions & 3 deletions packages/rrdom-nodejs/src/document-nodejs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { NodeType as RRNodeType } from 'rrweb-snapshot';
Juice10 marked this conversation as resolved.
Show resolved Hide resolved
import { NodeType as RRNodeType } from '@rrweb/types';
import type { NWSAPI } from 'nwsapi';
import type { CSSStyleDeclaration as CSSStyleDeclarationType } from 'cssstyle';
import {
Expand Down Expand Up @@ -345,7 +344,7 @@ export class RRStyleElement extends RRElement {
for (const child of this.childNodes)
if (child.RRNodeType === RRNodeType.Text)
result += (child as RRText).textContent;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment
this._sheet = cssom.parse(result);
}
return this._sheet;
Expand Down
2 changes: 1 addition & 1 deletion packages/rrdom-nodejs/test/document-nodejs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { describe, it, expect, beforeAll } from 'vitest';
import * as fs from 'fs';
import * as path from 'path';
import { NodeType as RRNodeType } from 'rrweb-snapshot';
import { NodeType as RRNodeType } from '@rrweb/types';
import {
RRCanvasElement,
RRCDATASection,
Expand Down
2 changes: 1 addition & 1 deletion packages/rrdom-nodejs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"path": "../rrdom"
},
{
"path": "../rrweb-snapshot"
"path": "../types"
}
]
}
8 changes: 3 additions & 5 deletions packages/rrdom/src/diff.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import {
NodeType as RRNodeType,
Mirror as NodeMirror,
type elementNode,
} from 'rrweb-snapshot';
import { type Mirror as NodeMirror } from 'rrweb-snapshot';
import { NodeType as RRNodeType } from '@rrweb/types';
import type {
canvasMutationData,
canvasEventWithTime,
elementNode,
inputData,
scrollData,
styleDeclarationData,
Expand Down
2 changes: 1 addition & 1 deletion packages/rrdom/src/document.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NodeType as RRNodeType } from 'rrweb-snapshot';
import { NodeType as RRNodeType } from '@rrweb/types';
import { parseCSSText, camelize, toCSSText } from './style';
export interface IRRNode {
parentElement: IRRNode | null;
Expand Down
10 changes: 3 additions & 7 deletions packages/rrdom/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import {
NodeType as RRNodeType,
createMirror as createNodeMirror,
} from 'rrweb-snapshot';
import { createMirror as createNodeMirror } from 'rrweb-snapshot';
import type { Mirror as NodeMirror } from 'rrweb-snapshot';
import { NodeType as RRNodeType } from '@rrweb/types';
import type {
Mirror as NodeMirror,
IMirror,
serializedNodeWithId,
} from 'rrweb-snapshot';
import type {
canvasMutationData,
canvasEventWithTime,
inputData,
Expand Down
19 changes: 11 additions & 8 deletions packages/rrdom/test/diff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ import * as fs from 'fs';
import * as path from 'path';
import * as puppeteer from 'puppeteer';
import { vi, MockInstance } from 'vitest';
import {
NodeType as RRNodeType,
createMirror,
Mirror as NodeMirror,
serializedNodeWithId,
} from 'rrweb-snapshot';
import { createMirror, Mirror as NodeMirror } from 'rrweb-snapshot';
import {
buildFromDom,
getDefaultSN,
Expand All @@ -27,8 +22,16 @@ import {
sameNodeType,
} from '../src/diff';
import type { IRRElement, IRRNode } from '../src/document';
import type { canvasMutationData, styleSheetRuleData } from '@rrweb/types';
import { EventType, IncrementalSource } from '@rrweb/types';
import type {
serializedNodeWithId,
canvasMutationData,
styleSheetRuleData,
} from '@rrweb/types';
import {
NodeType as RRNodeType,
EventType,
IncrementalSource,
} from '@rrweb/types';

const elementSn = {
type: RRNodeType.Element,
Expand Down
2 changes: 1 addition & 1 deletion packages/rrdom/test/diff/dialog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
*/
import { vi, MockInstance } from 'vitest';
import {
NodeType as RRNodeType,
createMirror,
Mirror as NodeMirror,
serializedNodeWithId,
} from 'rrweb-snapshot';
import { NodeType as RRNodeType } from '@rrweb/types';
import { RRDocument } from '../../src';
import { diff, ReplayerHandler } from '../../src/diff';

Expand Down
2 changes: 1 addition & 1 deletion packages/rrdom/test/document.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @jest-environment jsdom
*/
import { NodeType as RRNodeType } from 'rrweb-snapshot';
import { NodeType as RRNodeType } from '@rrweb/types';
import {
BaseRRDocument,
BaseRRDocumentType,
Expand Down
5 changes: 2 additions & 3 deletions packages/rrdom/test/virtual-dom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ import * as path from 'path';
import * as puppeteer from 'puppeteer';
import { vi } from 'vitest';
import { JSDOM } from 'jsdom';
import { buildNodeWithSN, Mirror } from 'rrweb-snapshot';
import {
buildNodeWithSN,
cdataNode,
commentNode,
documentNode,
documentTypeNode,
elementNode,
Mirror,
NodeType,
NodeType as RRNodeType,
textNode,
} from 'rrweb-snapshot';
} from '@rrweb/types';
import {
buildFromDom,
buildFromNode,
Expand Down
1 change: 1 addition & 0 deletions packages/rrweb-snapshot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
},
"homepage": "https://github.com/rrweb-io/rrweb/tree/master/packages/rrweb-snapshot#readme",
"devDependencies": {
"@rrweb/types": "^2.0.0-alpha.17",
"@rrweb/utils": "^2.0.0-alpha.17",
"@types/jsdom": "^20.0.0",
"@types/node": "^18.15.11",
Expand Down
8 changes: 3 additions & 5 deletions packages/rrweb-snapshot/src/rebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ import { mediaSelectorPlugin, pseudoClassPlugin } from './css';
import {
type serializedNodeWithId,
type serializedElementNodeWithId,
type serializedTextNodeWithId,
NodeType,
type tagMap,
type elementNode,
type BuildCache,
type legacyAttributes,
} from './types';
} from '@rrweb/types';
import { type tagMap, type BuildCache } from './types';
import { isElement, Mirror, isNodeMetaEqual } from './utils';
import postcss from 'postcss';

Expand Down Expand Up @@ -90,7 +88,7 @@ export function applyCssSplits(
hackCss: boolean,
cache: BuildCache,
): void {
const childTextNodes: serializedTextNodeWithId[] = [];
const childTextNodes = [];
for (const scn of n.childNodes) {
if (scn.type === NodeType.Text) {
childTextNodes.push(scn);
Expand Down
34 changes: 18 additions & 16 deletions packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import {
type serializedNode,
type serializedNodeWithId,
NodeType,
type attributes,
type MaskInputOptions,
type SlimDOMOptions,
type DataURLOptions,
type DialogAttributes,
type MaskTextFn,
type MaskInputFn,
type KeepIframeSrcFn,
type ICanvas,
type elementNode,
type serializedElementNodeWithId,
type mediaAttributes,
import type {
MaskInputOptions,
SlimDOMOptions,
MaskTextFn,
MaskInputFn,
KeepIframeSrcFn,
ICanvas,
DialogAttributes,
} from './types';
import { NodeType } from '@rrweb/types';
import type {
serializedNode,
serializedNodeWithId,
serializedElementNodeWithId,
elementNode,
attributes,
mediaAttributes,
DataURLOptions,
} from '@rrweb/types';
import {
Mirror,
is2DCanvasBlank,
Expand Down Expand Up @@ -280,7 +282,7 @@
// should warn? maybe a text node isn't attached to a parent node yet?
return false;
} else {
el = dom.parentElement(node)!;

Check warning on line 285 in packages/rrweb-snapshot/src/snapshot.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb-snapshot/src/snapshot.ts#L285

[@typescript-eslint/no-non-null-assertion] Forbidden non-null assertion.
}
try {
if (typeof maskTextClass === 'string') {
Expand Down Expand Up @@ -700,10 +702,10 @@
const recordInlineImage = () => {
image.removeEventListener('load', recordInlineImage);
try {
canvasService!.width = image.naturalWidth;

Check warning on line 705 in packages/rrweb-snapshot/src/snapshot.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb-snapshot/src/snapshot.ts#L705

[@typescript-eslint/no-non-null-assertion] Forbidden non-null assertion.
canvasService!.height = image.naturalHeight;

Check warning on line 706 in packages/rrweb-snapshot/src/snapshot.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb-snapshot/src/snapshot.ts#L706

[@typescript-eslint/no-non-null-assertion] Forbidden non-null assertion.
canvasCtx!.drawImage(image, 0, 0);

Check warning on line 707 in packages/rrweb-snapshot/src/snapshot.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb-snapshot/src/snapshot.ts#L707

[@typescript-eslint/no-non-null-assertion] Forbidden non-null assertion.
attributes.rr_dataURL = canvasService!.toDataURL(

Check warning on line 708 in packages/rrweb-snapshot/src/snapshot.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb-snapshot/src/snapshot.ts#L708

[@typescript-eslint/no-non-null-assertion] Forbidden non-null assertion.
dataURLOptions.type,
dataURLOptions.quality,
);
Expand Down
Loading
Loading