Skip to content

Commit 5a78938

Browse files
daibhineoghanmurrayJuice10
authored
chore: abstract types to shared package (#1593)
* chore: update types * small typing change * fix typing issue * typed node * add extra lint skip * add changeset --------- Co-authored-by: Eoghan Murray <[email protected]> Co-authored-by: Justin Halsall <[email protected]>
1 parent bd9eb70 commit 5a78938

36 files changed

+256
-250
lines changed

.changeset/soft-worms-tan.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@rrweb/all": patch
3+
"rrdom-nodejs": patch
4+
"rrdom": patch
5+
"rrweb-snapshot": major
6+
"rrweb": patch
7+
"@rrweb/rrweb-plugin-canvas-webrtc-record": patch
8+
---
9+
10+
`NodeType` enum was moved from rrweb-snapshot to @rrweb/types
11+
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`

packages/all/test/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { NodeType } from 'rrweb-snapshot';
21
import { expect } from 'vitest';
32
import {
3+
NodeType,
44
EventType,
55
IncrementalSource,
66
eventWithTime,

packages/plugins/rrweb-plugin-canvas-webrtc-record/src/index.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import type { Mirror } from 'rrweb-snapshot';
21
import SimplePeer from 'simple-peer-light';
3-
import type { RecordPlugin, ICrossOriginIframeMirror } from '@rrweb/types';
2+
import type {
3+
RecordPlugin,
4+
ICrossOriginIframeMirror,
5+
IMirror,
6+
} from '@rrweb/types';
47
import type { WebRTCDataChannel } from './types';
58

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

2629
export class RRWebPluginCanvasWebRTCRecord {
2730
private peer: SimplePeer.Instance | null = null;
28-
private mirror: Mirror | undefined;
31+
private mirror: IMirror<Node> | undefined;
2932
private crossOriginIframeMirror: ICrossOriginIframeMirror | undefined;
3033
private streamMap: Map<number, MediaStream> = new Map();
3134
private incomingStreams = new Set<MediaStream>();

packages/rrdom-nodejs/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@
5656
"cssstyle": "^2.3.0",
5757
"nwsapi": "2.2.0",
5858
"rrdom": "^2.0.0-alpha.17",
59-
"rrweb-snapshot": "^2.0.0-alpha.17"
59+
"@rrweb/types": "^2.0.0-alpha.17"
6060
}
6161
}

packages/rrdom-nodejs/src/document-nodejs.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
2-
import { NodeType as RRNodeType } from 'rrweb-snapshot';
1+
import { NodeType as RRNodeType } from '@rrweb/types';
32
import type { NWSAPI } from 'nwsapi';
43
import type { CSSStyleDeclaration as CSSStyleDeclarationType } from 'cssstyle';
54
import {
@@ -345,7 +344,7 @@ export class RRStyleElement extends RRElement {
345344
for (const child of this.childNodes)
346345
if (child.RRNodeType === RRNodeType.Text)
347346
result += (child as RRText).textContent;
348-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
347+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment
349348
this._sheet = cssom.parse(result);
350349
}
351350
return this._sheet;

packages/rrdom-nodejs/test/document-nodejs.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { describe, it, expect, beforeAll } from 'vitest';
55
import * as fs from 'fs';
66
import * as path from 'path';
7-
import { NodeType as RRNodeType } from 'rrweb-snapshot';
7+
import { NodeType as RRNodeType } from '@rrweb/types';
88
import {
99
RRCanvasElement,
1010
RRCDATASection,

packages/rrdom-nodejs/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"path": "../rrdom"
1111
},
1212
{
13-
"path": "../rrweb-snapshot"
13+
"path": "../types"
1414
}
1515
]
1616
}

packages/rrdom/src/diff.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import {
2-
NodeType as RRNodeType,
3-
Mirror as NodeMirror,
4-
type elementNode,
5-
} from 'rrweb-snapshot';
1+
import { type Mirror as NodeMirror } from 'rrweb-snapshot';
2+
import { NodeType as RRNodeType } from '@rrweb/types';
63
import type {
74
canvasMutationData,
85
canvasEventWithTime,
6+
elementNode,
97
inputData,
108
scrollData,
119
styleDeclarationData,

packages/rrdom/src/document.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NodeType as RRNodeType } from 'rrweb-snapshot';
1+
import { NodeType as RRNodeType } from '@rrweb/types';
22
import { parseCSSText, camelize, toCSSText } from './style';
33
export interface IRRNode {
44
parentElement: IRRNode | null;

packages/rrdom/src/index.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import {
2-
NodeType as RRNodeType,
3-
createMirror as createNodeMirror,
4-
} from 'rrweb-snapshot';
1+
import { createMirror as createNodeMirror } from 'rrweb-snapshot';
2+
import type { Mirror as NodeMirror } from 'rrweb-snapshot';
3+
import { NodeType as RRNodeType } from '@rrweb/types';
54
import type {
6-
Mirror as NodeMirror,
75
IMirror,
86
serializedNodeWithId,
9-
} from 'rrweb-snapshot';
10-
import type {
117
canvasMutationData,
128
canvasEventWithTime,
139
inputData,

packages/rrdom/test/diff.test.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ import * as fs from 'fs';
55
import * as path from 'path';
66
import * as puppeteer from 'puppeteer';
77
import { vi, MockInstance } from 'vitest';
8-
import {
9-
NodeType as RRNodeType,
10-
createMirror,
11-
Mirror as NodeMirror,
12-
serializedNodeWithId,
13-
} from 'rrweb-snapshot';
8+
import { createMirror, Mirror as NodeMirror } from 'rrweb-snapshot';
149
import {
1510
buildFromDom,
1611
getDefaultSN,
@@ -27,8 +22,16 @@ import {
2722
sameNodeType,
2823
} from '../src/diff';
2924
import type { IRRElement, IRRNode } from '../src/document';
30-
import type { canvasMutationData, styleSheetRuleData } from '@rrweb/types';
31-
import { EventType, IncrementalSource } from '@rrweb/types';
25+
import type {
26+
serializedNodeWithId,
27+
canvasMutationData,
28+
styleSheetRuleData,
29+
} from '@rrweb/types';
30+
import {
31+
NodeType as RRNodeType,
32+
EventType,
33+
IncrementalSource,
34+
} from '@rrweb/types';
3235

3336
const elementSn = {
3437
type: RRNodeType.Element,

packages/rrdom/test/diff/dialog.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
*/
44
import { vi, MockInstance } from 'vitest';
55
import {
6-
NodeType as RRNodeType,
76
createMirror,
87
Mirror as NodeMirror,
98
serializedNodeWithId,
109
} from 'rrweb-snapshot';
10+
import { NodeType as RRNodeType } from '@rrweb/types';
1111
import { RRDocument } from '../../src';
1212
import { diff, ReplayerHandler } from '../../src/diff';
1313

packages/rrdom/test/document.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @jest-environment jsdom
33
*/
4-
import { NodeType as RRNodeType } from 'rrweb-snapshot';
4+
import { NodeType as RRNodeType } from '@rrweb/types';
55
import {
66
BaseRRDocument,
77
BaseRRDocumentType,

packages/rrdom/test/virtual-dom.test.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@ import * as path from 'path';
66
import * as puppeteer from 'puppeteer';
77
import { vi } from 'vitest';
88
import { JSDOM } from 'jsdom';
9+
import { buildNodeWithSN, Mirror } from 'rrweb-snapshot';
910
import {
10-
buildNodeWithSN,
1111
cdataNode,
1212
commentNode,
1313
documentNode,
1414
documentTypeNode,
1515
elementNode,
16-
Mirror,
1716
NodeType,
1817
NodeType as RRNodeType,
1918
textNode,
20-
} from 'rrweb-snapshot';
19+
} from '@rrweb/types';
2120
import {
2221
buildFromDom,
2322
buildFromNode,

packages/rrweb-snapshot/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
},
5555
"homepage": "https://github.com/rrweb-io/rrweb/tree/master/packages/rrweb-snapshot#readme",
5656
"devDependencies": {
57+
"@rrweb/types": "^2.0.0-alpha.17",
5758
"@rrweb/utils": "^2.0.0-alpha.17",
5859
"@types/jsdom": "^20.0.0",
5960
"@types/node": "^18.15.11",

packages/rrweb-snapshot/src/rebuild.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ import { mediaSelectorPlugin, pseudoClassPlugin } from './css';
22
import {
33
type serializedNodeWithId,
44
type serializedElementNodeWithId,
5-
type serializedTextNodeWithId,
65
NodeType,
7-
type tagMap,
86
type elementNode,
9-
type BuildCache,
107
type legacyAttributes,
11-
} from './types';
8+
} from '@rrweb/types';
9+
import { type tagMap, type BuildCache } from './types';
1210
import { isElement, Mirror, isNodeMetaEqual } from './utils';
1311
import postcss from 'postcss';
1412

@@ -90,7 +88,7 @@ export function applyCssSplits(
9088
hackCss: boolean,
9189
cache: BuildCache,
9290
): void {
93-
const childTextNodes: serializedTextNodeWithId[] = [];
91+
const childTextNodes = [];
9492
for (const scn of n.childNodes) {
9593
if (scn.type === NodeType.Text) {
9694
childTextNodes.push(scn);

packages/rrweb-snapshot/src/snapshot.ts

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
import {
2-
type serializedNode,
3-
type serializedNodeWithId,
4-
NodeType,
5-
type attributes,
6-
type MaskInputOptions,
7-
type SlimDOMOptions,
8-
type DataURLOptions,
9-
type DialogAttributes,
10-
type MaskTextFn,
11-
type MaskInputFn,
12-
type KeepIframeSrcFn,
13-
type ICanvas,
14-
type elementNode,
15-
type serializedElementNodeWithId,
16-
type mediaAttributes,
1+
import type {
2+
MaskInputOptions,
3+
SlimDOMOptions,
4+
MaskTextFn,
5+
MaskInputFn,
6+
KeepIframeSrcFn,
7+
ICanvas,
8+
DialogAttributes,
179
} from './types';
10+
import { NodeType } from '@rrweb/types';
11+
import type {
12+
serializedNode,
13+
serializedNodeWithId,
14+
serializedElementNodeWithId,
15+
elementNode,
16+
attributes,
17+
mediaAttributes,
18+
DataURLOptions,
19+
} from '@rrweb/types';
1820
import {
1921
Mirror,
2022
is2DCanvasBlank,

0 commit comments

Comments
 (0)