From 17d477fc43e20de15fd78810594f19139a556e9c Mon Sep 17 00:00:00 2001 From: Alex Kaminskii Date: Wed, 11 May 2022 18:27:18 +0200 Subject: [PATCH] fix+style(tracker):3.5.11 fix build & files structure --- tracker/tracker/package.json | 2 +- tracker/tracker/scripts/compile.js | 20 +++++++++---------- .../{messages/index.ts => common/messages.ts} | 4 ++-- .../src/{messages => common}/tsconfig.json | 0 tracker/tracker/src/common/types.ts | 10 ++++++++++ .../types.ts => common/webworker.ts} | 0 tracker/tracker/src/main/app/index.ts | 6 +++--- .../src/main/app/observer/iframe_observer.ts | 2 +- .../tracker/src/main/app/observer/observer.ts | 2 +- .../main/app/observer/shadow_root_observer.ts | 2 +- .../src/main/app/observer/top_observer.ts | 2 +- tracker/tracker/src/main/app/session.ts | 2 +- tracker/tracker/src/main/index.ts | 4 ++-- .../tracker/src/main/modules/connection.ts | 2 +- tracker/tracker/src/main/modules/console.ts | 2 +- tracker/tracker/src/main/modules/cssrules.ts | 2 +- tracker/tracker/src/main/modules/exception.ts | 4 ++-- tracker/tracker/src/main/modules/img.ts | 2 +- tracker/tracker/src/main/modules/input.ts | 2 +- tracker/tracker/src/main/modules/longtasks.ts | 2 +- tracker/tracker/src/main/modules/mouse.ts | 2 +- .../tracker/src/main/modules/performance.ts | 2 +- tracker/tracker/src/main/modules/scroll.ts | 2 +- tracker/tracker/src/main/modules/timing.ts | 4 ++-- tracker/tracker/src/main/modules/viewport.ts | 2 +- tracker/tracker/src/main/tsconfig.json | 2 +- tracker/tracker/src/messages/message.ts | 5 ----- tracker/tracker/src/webworker/BatchWriter.ts | 10 +++++----- .../PrimitiveWriter.ts} | 2 +- tracker/tracker/src/webworker/index.ts | 7 ++++--- tracker/tracker/src/webworker/tsconfig.json | 2 +- .../tracker/src/webworker/url-rewriter.ts.dd | 9 --------- 32 files changed, 59 insertions(+), 62 deletions(-) rename tracker/tracker/src/{messages/index.ts => common/messages.ts} (99%) rename tracker/tracker/src/{messages => common}/tsconfig.json (100%) create mode 100644 tracker/tracker/src/common/types.ts rename tracker/tracker/src/{webworker/types.ts => common/webworker.ts} (100%) delete mode 100644 tracker/tracker/src/messages/message.ts rename tracker/tracker/src/{messages/writer.ts => webworker/PrimitiveWriter.ts} (99%) delete mode 100644 tracker/tracker/src/webworker/url-rewriter.ts.dd diff --git a/tracker/tracker/package.json b/tracker/tracker/package.json index 555efe07d..22d39de12 100644 --- a/tracker/tracker/package.json +++ b/tracker/tracker/package.json @@ -1,7 +1,7 @@ { "name": "@openreplay/tracker", "description": "The OpenReplay tracker main package", - "version": "3.5.10", + "version": "3.5.11", "keywords": [ "logging", "replay" diff --git a/tracker/tracker/scripts/compile.js b/tracker/tracker/scripts/compile.js index ab0091dd5..563254016 100644 --- a/tracker/tracker/scripts/compile.js +++ b/tracker/tracker/scripts/compile.js @@ -15,31 +15,31 @@ async function main() { to: webworker.replace(/'/g, "\\'"), }); await fs.rename('build/main', 'lib'); - await fs.rename('build/messages', 'lib/messages'); + await fs.rename('build/common', 'lib/common'); await replaceInFiles({ files: 'lib/*', - from: /\.\.\/messages/g, - to: './messages', + from: /\.\.\/common/g, + to: './common', }); await replaceInFiles({ files: 'lib/**/*', - from: /\.\.\/\.\.\/messages/g, - to: '../messages', + from: /\.\.\/\.\.\/common/g, + to: '../common', }); await fs.rename('build/cjs/main', 'cjs'); - await fs.rename('build/cjs/messages', 'cjs/messages'); + await fs.rename('build/cjs/common', 'cjs/common'); await fs.writeFile('cjs/package.json', `{ "type": "commonjs" }`); await replaceInFiles({ files: 'cjs/*', - from: /\.\.\/messages/g, - to: './messages', + from: /\.\.\/common/g, + to: './common', }); await replaceInFiles({ files: 'cjs/**/*', - from: /\.\.\/\.\.\/messages/g, - to: '../messages', + from: /\.\.\/\.\.\/common/g, + to: '../common', }); } main() diff --git a/tracker/tracker/src/messages/index.ts b/tracker/tracker/src/common/messages.ts similarity index 99% rename from tracker/tracker/src/messages/index.ts rename to tracker/tracker/src/common/messages.ts index f3267bee0..140bcaac6 100644 --- a/tracker/tracker/src/messages/index.ts +++ b/tracker/tracker/src/common/messages.ts @@ -1,6 +1,6 @@ // Auto-generated, do not edit -import Message from "./message.js"; -import Writer from "./writer.js"; +import type { Writer, Message }from "./types.js"; +export default Message function bindNew( Class: C & { new(...args: A): T } diff --git a/tracker/tracker/src/messages/tsconfig.json b/tracker/tracker/src/common/tsconfig.json similarity index 100% rename from tracker/tracker/src/messages/tsconfig.json rename to tracker/tracker/src/common/tsconfig.json diff --git a/tracker/tracker/src/common/types.ts b/tracker/tracker/src/common/types.ts new file mode 100644 index 000000000..6717eb8bc --- /dev/null +++ b/tracker/tracker/src/common/types.ts @@ -0,0 +1,10 @@ +export interface Writer { + uint(n: number): boolean + int(n: number): boolean + string(s: string): boolean + boolean(b: boolean): boolean +} + +export interface Message { + encode(w: Writer): boolean; +} diff --git a/tracker/tracker/src/webworker/types.ts b/tracker/tracker/src/common/webworker.ts similarity index 100% rename from tracker/tracker/src/webworker/types.ts rename to tracker/tracker/src/common/webworker.ts diff --git a/tracker/tracker/src/main/app/index.ts b/tracker/tracker/src/main/app/index.ts index ace8ecf6e..2874a8867 100644 --- a/tracker/tracker/src/main/app/index.ts +++ b/tracker/tracker/src/main/app/index.ts @@ -1,6 +1,6 @@ +import type Message from "../../common/messages.js"; +import { Timestamp, Metadata } from "../../common/messages.js"; import { timestamp, deprecationWarn } from "../utils.js"; -import { Timestamp, Metadata } from "../../messages/index.js"; -import Message from "../../messages/message.js"; import Nodes from "./nodes.js"; import Observer from "./observer/top_observer.js"; import Sanitizer from "./sanitizer.js"; @@ -13,7 +13,7 @@ import { deviceMemory, jsHeapSizeLimit } from "../modules/performance.js"; import type { Options as ObserverOptions } from "./observer/top_observer.js"; import type { Options as SanitizerOptions } from "./sanitizer.js"; import type { Options as LoggerOptions } from "./logger.js" -import type { Options as WebworkerOptions, WorkerMessageData } from "../../webworker/types.js"; +import type { Options as WebworkerOptions, WorkerMessageData } from "../../common/webworker.js"; // TODO: Unify and clearly describe options logic diff --git a/tracker/tracker/src/main/app/observer/iframe_observer.ts b/tracker/tracker/src/main/app/observer/iframe_observer.ts index be0a7182c..1f50e588a 100644 --- a/tracker/tracker/src/main/app/observer/iframe_observer.ts +++ b/tracker/tracker/src/main/app/observer/iframe_observer.ts @@ -1,5 +1,5 @@ import Observer from "./observer.js"; -import { CreateIFrameDocument } from "../../../messages/index.js"; +import { CreateIFrameDocument } from "../../../common/messages.js"; export default class IFrameObserver extends Observer { observe(iframe: HTMLIFrameElement) { diff --git a/tracker/tracker/src/main/app/observer/observer.ts b/tracker/tracker/src/main/app/observer/observer.ts index 06823e07c..dcbba6365 100644 --- a/tracker/tracker/src/main/app/observer/observer.ts +++ b/tracker/tracker/src/main/app/observer/observer.ts @@ -8,7 +8,7 @@ import { CreateElementNode, MoveNode, RemoveNode, -} from "../../../messages/index.js"; +} from "../../../common/messages.js"; import App from "../index.js"; import { isInstance, inDocument } from "../context.js"; diff --git a/tracker/tracker/src/main/app/observer/shadow_root_observer.ts b/tracker/tracker/src/main/app/observer/shadow_root_observer.ts index 244348ea1..ea37bb30f 100644 --- a/tracker/tracker/src/main/app/observer/shadow_root_observer.ts +++ b/tracker/tracker/src/main/app/observer/shadow_root_observer.ts @@ -1,5 +1,5 @@ import Observer from "./observer.js"; -import { CreateIFrameDocument } from "../../../messages/index.js"; +import { CreateIFrameDocument } from "../../../common/messages.js"; export default class ShadowRootObserver extends Observer { observe(el: Element) { diff --git a/tracker/tracker/src/main/app/observer/top_observer.ts b/tracker/tracker/src/main/app/observer/top_observer.ts index 14bed9768..cab84b162 100644 --- a/tracker/tracker/src/main/app/observer/top_observer.ts +++ b/tracker/tracker/src/main/app/observer/top_observer.ts @@ -4,7 +4,7 @@ import type { Window } from "../context.js"; import IFrameObserver from "./iframe_observer.js"; import ShadowRootObserver from "./shadow_root_observer.js"; -import { CreateDocument } from "../../../messages/index.js"; +import { CreateDocument } from "../../../common/messages.js"; import App from "../index.js"; import { IN_BROWSER, hasOpenreplayAttribute } from '../../utils.js' diff --git a/tracker/tracker/src/main/app/session.ts b/tracker/tracker/src/main/app/session.ts index 169241aa7..602ef8280 100644 --- a/tracker/tracker/src/main/app/session.ts +++ b/tracker/tracker/src/main/app/session.ts @@ -1,5 +1,5 @@ import App, { StartOptions } from "./index.js"; -import { UserID, UserAnonymousID, Metadata } from "../../messages/index.js"; +import { UserID, UserAnonymousID, Metadata } from "../../common/messages.js"; enum ActivityState { diff --git a/tracker/tracker/src/main/index.ts b/tracker/tracker/src/main/index.ts index a55df1d1c..e1b25b43b 100644 --- a/tracker/tracker/src/main/index.ts +++ b/tracker/tracker/src/main/index.ts @@ -1,8 +1,8 @@ import App, { DEFAULT_INGEST_POINT } from "./app/index.js"; export { default as App } from './app/index.js'; -import { UserID, UserAnonymousID, Metadata, RawCustomEvent, CustomIssue } from "../messages/index.js"; -import * as _Messages from "../messages/index.js"; +import { UserID, UserAnonymousID, Metadata, RawCustomEvent, CustomIssue } from "../common/messages.js"; +import * as _Messages from "../common/messages.js"; export const Messages = _Messages; import Connection from "./modules/connection.js"; diff --git a/tracker/tracker/src/main/modules/connection.ts b/tracker/tracker/src/main/modules/connection.ts index a2767790c..72ef972f7 100644 --- a/tracker/tracker/src/main/modules/connection.ts +++ b/tracker/tracker/src/main/modules/connection.ts @@ -1,5 +1,5 @@ import App from "../app/index.js"; -import { ConnectionInformation } from "../../messages/index.js"; +import { ConnectionInformation } from "../../common/messages.js"; export default function(app: App): void { const connection: diff --git a/tracker/tracker/src/main/modules/console.ts b/tracker/tracker/src/main/modules/console.ts index 98db6c144..b6e95d14f 100644 --- a/tracker/tracker/src/main/modules/console.ts +++ b/tracker/tracker/src/main/modules/console.ts @@ -1,6 +1,6 @@ import App from "../app/index.js"; import { IN_BROWSER } from "../utils.js"; -import { ConsoleLog } from "../../messages/index.js"; +import { ConsoleLog } from "../../common/messages.js"; const printError: (e: Error) => string = IN_BROWSER && 'InstallTrigger' in window // detect Firefox diff --git a/tracker/tracker/src/main/modules/cssrules.ts b/tracker/tracker/src/main/modules/cssrules.ts index 18aa3f154..8c75a5366 100644 --- a/tracker/tracker/src/main/modules/cssrules.ts +++ b/tracker/tracker/src/main/modules/cssrules.ts @@ -1,5 +1,5 @@ import App from "../app/index.js"; -import { CSSInsertRuleURLBased, CSSDeleteRule, TechnicalInfo } from "../../messages/index.js"; +import { CSSInsertRuleURLBased, CSSDeleteRule, TechnicalInfo } from "../../common/messages.js"; export default function(app: App | null) { if (app === null) { diff --git a/tracker/tracker/src/main/modules/exception.ts b/tracker/tracker/src/main/modules/exception.ts index 848df03be..be02ca291 100644 --- a/tracker/tracker/src/main/modules/exception.ts +++ b/tracker/tracker/src/main/modules/exception.ts @@ -1,6 +1,6 @@ +import type Message from "../../common/messages.js"; import App from "../app/index.js"; -import { JSException } from "../../messages/index.js"; -import Message from "../../messages/message.js"; +import { JSException } from "../../common/messages.js"; import ErrorStackParser from 'error-stack-parser'; export interface Options { diff --git a/tracker/tracker/src/main/modules/img.ts b/tracker/tracker/src/main/modules/img.ts index 8c0f911a8..da260c414 100644 --- a/tracker/tracker/src/main/modules/img.ts +++ b/tracker/tracker/src/main/modules/img.ts @@ -1,6 +1,6 @@ import { timestamp, isURL } from "../utils.js"; import App from "../app/index.js"; -import { ResourceTiming, SetNodeAttributeURLBased, SetNodeAttribute } from "../../messages/index.js"; +import { ResourceTiming, SetNodeAttributeURLBased, SetNodeAttribute } from "../../common/messages.js"; const PLACEHOLDER_SRC = "https://static.openreplay.com/tracker/placeholder.jpeg"; diff --git a/tracker/tracker/src/main/modules/input.ts b/tracker/tracker/src/main/modules/input.ts index 0cad3c58b..546204730 100644 --- a/tracker/tracker/src/main/modules/input.ts +++ b/tracker/tracker/src/main/modules/input.ts @@ -5,7 +5,7 @@ import { hasOpenreplayAttribute, } from "../utils.js"; import App from "../app/index.js"; -import { SetInputTarget, SetInputValue, SetInputChecked } from "../../messages/index.js"; +import { SetInputTarget, SetInputValue, SetInputChecked } from "../../common/messages.js"; // TODO: take into consideration "contenteditable" attribute type TextEditableElement = HTMLInputElement | HTMLTextAreaElement diff --git a/tracker/tracker/src/main/modules/longtasks.ts b/tracker/tracker/src/main/modules/longtasks.ts index 0f3a7e82a..589c73de2 100644 --- a/tracker/tracker/src/main/modules/longtasks.ts +++ b/tracker/tracker/src/main/modules/longtasks.ts @@ -1,5 +1,5 @@ import App from "../app/index.js"; -import { LongTask } from "../../messages/index.js"; +import { LongTask } from "../../common/messages.js"; // https://w3c.github.io/performance-timeline/#the-performanceentry-interface interface TaskAttributionTiming extends PerformanceEntry { diff --git a/tracker/tracker/src/main/modules/mouse.ts b/tracker/tracker/src/main/modules/mouse.ts index b72e5dbb9..956108963 100644 --- a/tracker/tracker/src/main/modules/mouse.ts +++ b/tracker/tracker/src/main/modules/mouse.ts @@ -4,7 +4,7 @@ import { getLabelAttribute, } from "../utils.js"; import App from "../app/index.js"; -import { MouseMove, MouseClick } from "../../messages/index.js"; +import { MouseMove, MouseClick } from "../../common/messages.js"; import { getInputLabel } from "./input.js"; function _getSelector(target: Element): string { diff --git a/tracker/tracker/src/main/modules/performance.ts b/tracker/tracker/src/main/modules/performance.ts index 8eb7701eb..c7d911c9f 100644 --- a/tracker/tracker/src/main/modules/performance.ts +++ b/tracker/tracker/src/main/modules/performance.ts @@ -1,6 +1,6 @@ import App from "../app/index.js"; import { IN_BROWSER } from "../utils.js"; -import { PerformanceTrack } from "../../messages/index.js"; +import { PerformanceTrack } from "../../common/messages.js"; type Perf = { diff --git a/tracker/tracker/src/main/modules/scroll.ts b/tracker/tracker/src/main/modules/scroll.ts index f9c80e6d9..9d19ccc24 100644 --- a/tracker/tracker/src/main/modules/scroll.ts +++ b/tracker/tracker/src/main/modules/scroll.ts @@ -1,5 +1,5 @@ import App from "../app/index.js"; -import { SetViewportScroll, SetNodeScroll } from "../../messages/index.js"; +import { SetViewportScroll, SetNodeScroll } from "../../common/messages.js"; export default function (app: App): void { let documentScroll = false; diff --git a/tracker/tracker/src/main/modules/timing.ts b/tracker/tracker/src/main/modules/timing.ts index 033741838..01fbd1d0a 100644 --- a/tracker/tracker/src/main/modules/timing.ts +++ b/tracker/tracker/src/main/modules/timing.ts @@ -1,7 +1,7 @@ +import type Message from "../../common/messages.js"; import { isURL } from "../utils.js"; import App from "../app/index.js"; -import { ResourceTiming, PageLoadTiming, PageRenderTiming } from "../../messages/index.js"; -import type Message from "../../messages/message.js"; +import { ResourceTiming, PageLoadTiming, PageRenderTiming } from "../../common/messages.js"; // Inspired by https://github.com/WPO-Foundation/RUM-SpeedIndex/blob/master/src/rum-speedindex.js diff --git a/tracker/tracker/src/main/modules/viewport.ts b/tracker/tracker/src/main/modules/viewport.ts index 626eadd12..1d70a3ebf 100644 --- a/tracker/tracker/src/main/modules/viewport.ts +++ b/tracker/tracker/src/main/modules/viewport.ts @@ -3,7 +3,7 @@ import { SetPageLocation, SetViewportSize, SetPageVisibility, -} from "../../messages/index.js"; +} from "../../common/messages.js"; export default function (app: App): void { let url: string, width: number, height: number; diff --git a/tracker/tracker/src/main/tsconfig.json b/tracker/tracker/src/main/tsconfig.json index f6ac938a6..14a932c39 100644 --- a/tracker/tracker/src/main/tsconfig.json +++ b/tracker/tracker/src/main/tsconfig.json @@ -5,7 +5,7 @@ "lib": ["es6", "dom"], }, "references": [ - { "path": "../messages" } + { "path": "../common" } ], "exclude": ["app/observer"] } diff --git a/tracker/tracker/src/messages/message.ts b/tracker/tracker/src/messages/message.ts deleted file mode 100644 index aeb8619de..000000000 --- a/tracker/tracker/src/messages/message.ts +++ /dev/null @@ -1,5 +0,0 @@ -import Writer from "./writer.js"; - -export default interface Message { - encode(w: Writer): boolean; -} diff --git a/tracker/tracker/src/webworker/BatchWriter.ts b/tracker/tracker/src/webworker/BatchWriter.ts index 5f220bbec..7ddf97dbe 100644 --- a/tracker/tracker/src/webworker/BatchWriter.ts +++ b/tracker/tracker/src/webworker/BatchWriter.ts @@ -1,14 +1,14 @@ -import Writer from "../messages/writer.js"; -import Message from "../messages/message.js"; +import type Message from "../common/messages.js"; +import PrimitiveWriter from "./PrimitiveWriter.js"; import { BatchMeta, Timestamp, -} from "../messages/index.js"; +} from "../common/messages.js"; export default class BatchWriter { private nextIndex = 0 private beaconSize = 2 * 1e5 // Default 200kB - private writer = new Writer(this.beaconSize) + private writer = new PrimitiveWriter(this.beaconSize) private isEmpty = true constructor( @@ -50,7 +50,7 @@ export default class BatchWriter { } // MBTODO: tempWriter for one message? this.beaconSize = Math.min(this.beaconSize*2, this.beaconSizeLimit) - this.writer = new Writer(this.beaconSize) + this.writer = new PrimitiveWriter(this.beaconSize) this.prepareBatchMeta() } } diff --git a/tracker/tracker/src/messages/writer.ts b/tracker/tracker/src/webworker/PrimitiveWriter.ts similarity index 99% rename from tracker/tracker/src/messages/writer.ts rename to tracker/tracker/src/webworker/PrimitiveWriter.ts index 6947420bc..587291bea 100644 --- a/tracker/tracker/src/messages/writer.ts +++ b/tracker/tracker/src/webworker/PrimitiveWriter.ts @@ -59,7 +59,7 @@ const textEncoder: { encode(str: string): Uint8Array } = }, }; -export default class Writer { +export default class PrimitiveWriter { private offset: number = 0; private checkpointOffset: number = 0; private readonly data: Uint8Array; diff --git a/tracker/tracker/src/webworker/index.ts b/tracker/tracker/src/webworker/index.ts index b9640e9e2..3e9341a2d 100644 --- a/tracker/tracker/src/webworker/index.ts +++ b/tracker/tracker/src/webworker/index.ts @@ -1,13 +1,14 @@ -import Message from "../messages/message.js"; +import type Message from "../common/messages.js"; +import type { WorkerMessageData } from "../common/webworker.js"; + import { classes, SetPageVisibility, MouseMove, -} from "../messages/index.js"; +} from "../common/messages.js"; import QueueSender from "./QueueSender.js"; import BatchWriter from "./BatchWriter.js"; -import type { WorkerMessageData } from "./types.js"; const AUTO_SEND_INTERVAL = 10 * 1000 diff --git a/tracker/tracker/src/webworker/tsconfig.json b/tracker/tracker/src/webworker/tsconfig.json index 9e72f437e..6794ea55c 100644 --- a/tracker/tracker/src/webworker/tsconfig.json +++ b/tracker/tracker/src/webworker/tsconfig.json @@ -4,6 +4,6 @@ "lib": ["es6", "webworker"] }, "references": [ - { "path": "../messages" } + { "path": "../common" } ] } diff --git a/tracker/tracker/src/webworker/url-rewriter.ts.dd b/tracker/tracker/src/webworker/url-rewriter.ts.dd deleted file mode 100644 index 956448df2..000000000 --- a/tracker/tracker/src/webworker/url-rewriter.ts.dd +++ /dev/null @@ -1,9 +0,0 @@ - - - - -function getFullURL(baseURL: string, relativeURL: string) { - if (isRelative(relativeURL)) { - - } -} \ No newline at end of file