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

Add rrweb-worker package #1448

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion packages/rrdom-nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"rollup": "^2.56.3",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.31.2",
"rollup-plugin-web-worker-loader": "^1.6.1",
"ts-jest": "^27.1.3"
},
"dependencies": {
Expand Down
5 changes: 0 additions & 5 deletions packages/rrdom-nodejs/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import { terser } from 'rollup-plugin-terser';
import typescript from 'rollup-plugin-typescript2';
import webWorkerLoader from 'rollup-plugin-web-worker-loader';
import pkg from './package.json';

function toMinPath(path) {
Expand All @@ -12,10 +11,6 @@ function toMinPath(path) {
const basePlugins = [
resolve({ browser: true }),
commonjs(),

// supports bundling `web-worker:..filename` from rrweb
webWorkerLoader(),

typescript({
tsconfigOverride: { compilerOptions: { module: 'ESNext' } },
}),
Expand Down
1 change: 0 additions & 1 deletion packages/rrdom-nodejs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"include": [
"src",
"test.d.ts",
"../rrweb/src/record/workers/workers.d.ts",
"../rrweb/src/record/constructable-stylesheets.d.ts"
],
"references": [
Expand Down
1 change: 0 additions & 1 deletion packages/rrdom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"rollup": "^2.56.3",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.31.2",
"rollup-plugin-web-worker-loader": "^1.6.1",
"ts-jest": "^27.1.3"
},
"dependencies": {
Expand Down
5 changes: 0 additions & 5 deletions packages/rrdom/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import { terser } from 'rollup-plugin-terser';
import typescript from 'rollup-plugin-typescript2';
import webWorkerLoader from 'rollup-plugin-web-worker-loader';
import pkg from './package.json';

function toMinPath(path) {
Expand All @@ -12,10 +11,6 @@ function toMinPath(path) {
const basePlugins = [
resolve({ browser: true }),
commonjs(),

// supports bundling `web-worker:..filename` from rrweb
webWorkerLoader(),

typescript({
tsconfigOverride: { compilerOptions: { module: 'ESNext' } },
}),
Expand Down
1 change: 0 additions & 1 deletion packages/rrdom/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"exclude": ["test"],
"include": [
"src",
"../rrweb/src/record/workers/workers.d.ts",
"../rrweb/src/record/constructable-stylesheets.d.ts"
]
}
1 change: 0 additions & 1 deletion packages/rrweb-player/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"rollup-plugin-svelte": "^7.1.0",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.31.2",
"rollup-plugin-web-worker-loader": "^1.6.1",
"sirv-cli": "^0.4.4",
"svelte": "^3.59.2",
"svelte-check": "^3.0.1",
Expand Down
32 changes: 13 additions & 19 deletions packages/rrweb-player/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ import commonjs from '@rollup/plugin-commonjs';
import livereload from 'rollup-plugin-livereload';
import { terser } from 'rollup-plugin-terser';
import sveltePreprocess from 'svelte-preprocess';
import webWorkerLoader from 'rollup-plugin-web-worker-loader';
import typescript from 'rollup-plugin-typescript2';
import pkg from './package.json';
import css from 'rollup-plugin-css-only';

// eslint-disable-next-line no-undef
const production = !process.env.ROLLUP_WATCH;

const entries = (production
? [
{ file: pkg.module, format: 'es', css: false },
{ file: pkg.main, format: 'cjs', css: false },
{
file: pkg.unpkg,
format: 'iife',
name: 'rrwebPlayer',
css: 'style.css',
},
]
: []
const entries = (
production
? [
{ file: pkg.module, format: 'es', css: false },
{ file: pkg.main, format: 'cjs', css: false },
{
file: pkg.unpkg,
format: 'iife',
name: 'rrwebPlayer',
css: 'style.css',
},
]
: []
).concat([
{
file: 'public/bundle.js',
Expand Down Expand Up @@ -66,14 +66,8 @@ export default entries.map((output) => ({
dedupe: ['svelte'],
extensions: ['.js', '.ts', '.svelte'],
}),

commonjs(),

// supports bundling `web-worker:..filename` from rrweb
webWorkerLoader(),

typescript(),

css({
// we'll extract any component CSS out into
// a separate file — better for performance
Expand Down
1 change: 0 additions & 1 deletion packages/rrweb-player/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"node_modules/*",
"__sapper__/*",
"public/*",
"../rrweb/src/record/workers/workers.d.ts"
],
"compilerOptions": {
"composite": true
Expand Down
8 changes: 8 additions & 0 deletions packages/rrweb-worker/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

{
"extends": ["../../.eslintrc.js"],
"rules": {
"prefer-template": "off",
"@typescript-eslint/restrict-plus-operands": "off"
}
}
11 changes: 11 additions & 0 deletions packages/rrweb-worker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.vscode
.idea
node_modules
package-lock.json
*.tsbuildinfo
build
dist
es
lib
typings
temp
33 changes: 33 additions & 0 deletions packages/rrweb-worker/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "rrweb-worker",
"version": "2.0.0-alpha.12",
"main": "lib/rrweb-worker/index.cjs",
"module": "es/rrweb-worker/index.js",
"types": "typings/index.d.ts",
"sideEffects": false,
"private": true,
"scripts": {
"dev": "yarn bundle --watch",
"build:tarball": "npm pack",
"bundle": "rollup --config",
"typings": "tsc -p tsconfig.types.json",
"prepare": "npm run typings && npm run bundle",
"check-types": "tsc -noEmit",
"lint": "yarn eslint src"
},
"repository": {
"type": "git",
"url": "git+https://github.com/rrweb-io/rrweb.git"
},
"author": "Sentry",
"license": "MIT",
"bugs": {
"url": "https://github.com/rrweb-io/rrweb/issues"
},
"dependencies": {
"rrweb-snapshot": "2.0.0-alpha.12"
},
"engines": {
"node": ">=12"
}
}
83 changes: 83 additions & 0 deletions packages/rrweb-worker/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import typescript from 'rollup-plugin-typescript2';
import { defineConfig } from 'rollup';
import { terser } from 'rollup-plugin-terser';

const workerStrBaseConfig = {
input: ['./src/_image-bitmap-data-url-worker.ts'],
treeshake: 'smallest',
plugins: [
commonjs(),
typescript({
tsconfig: './tsconfig.json',
inlineSourceMap: false,
sourceMap: false,
inlineSources: false,
}),
resolve(),
terser({
mangle: {
module: true,
},
}),
{
name: 'worker-to-string',
renderChunk(code) {
return `export default \`${code}\`;`;
},
},
],
};

const indexBaseConfig = {
input: ['./src/index.ts'],
treeshake: 'smallest',
external: ['./image-bitmap-data-url-worker'],
plugins: [
typescript({
tsconfig: './tsconfig.json',
inlineSourceMap: false,
sourceMap: false,
inlineSources: false,
}),
terser({
mangle: {
module: true,
},
}),
],
};

const config = defineConfig([
{
...workerStrBaseConfig,
output: {
file: './es/rrweb-worker/image-bitmap-data-url-worker.js',
format: 'esm',
},
},
{
...workerStrBaseConfig,
output: {
file: './lib/rrweb-worker/image-bitmap-data-url-worker.cjs',
format: 'cjs',
},
},
{
...indexBaseConfig,
output: {
file: './es/rrweb-worker/index.js',
format: 'esm',
},
},
{
...indexBaseConfig,
output: {
file: './lib/rrweb-worker/index.cjs',
format: 'cjs',
},
},
]);

export default config;
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function getTransparentBlobFor(
height: number,
dataURLOptions: DataURLOptions,
): Promise<string> {
const id = `${width}-${height}`;
const id = width + '-' + height;
if ('OffscreenCanvas' in globalThis) {
if (transparentBlobMap.has(id)) return transparentBlobMap.get(id)!;
const offscreen = new OffscreenCanvas(width, height);
Expand Down
3 changes: 3 additions & 0 deletions packages/rrweb-worker/src/image-bitmap-data-url-worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This is replaced at build-time with the content from _image-bitmap-data-url-worker.ts, wrapped as a string.
// This is just a placeholder so that types etc. are correct.
export default '' as string;
9 changes: 9 additions & 0 deletions packages/rrweb-worker/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import workerString from './image-bitmap-data-url-worker';

/**
* Get the URL for a web worker.
*/
export function getImageBitmapDataUrlWorkerURL(): string {
const workerBlob = new Blob([workerString]);
return URL.createObjectURL(workerBlob);
}
33 changes: 33 additions & 0 deletions packages/rrweb-worker/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "Node",
"target": "ES2020",
"noImplicitAny": true,
"strictNullChecks": true,
"removeComments": true,
"preserveConstEnums": true,
"rootDir": "src",
"outDir": "build",
"lib": [
"webworker",
"scripthost"
],
"allowSyntheticDefaultImports": true,
"declarationMap": false,
"skipLibCheck": true,
"composite": true
},
"references": [
{
"path": "../rrweb-snapshot"
}
],
"exclude": [
"test",
"scripts"
],
"include": [
"src/**/*.ts"
]
}
9 changes: 9 additions & 0 deletions packages/rrweb-worker/tsconfig.types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"include": ["src/*.ts"],
"compilerOptions": {
"declarationMap": true,
"emitDeclarationOnly": true,
"outDir": "typings"
}
}
4 changes: 2 additions & 2 deletions packages/rrweb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
"rollup-plugin-postcss": "^3.1.1",
"rollup-plugin-rename-node-modules": "^1.3.1",
"rollup-plugin-typescript2": "^0.31.2",
"rollup-plugin-web-worker-loader": "^1.6.1",
"simple-peer-light": "^9.10.0",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
Expand All @@ -89,6 +88,7 @@
"fflate": "^0.4.4",
"mitt": "^3.0.0",
"rrdom": "^2.0.0-alpha.12",
"rrweb-snapshot": "^2.0.0-alpha.12"
"rrweb-snapshot": "^2.0.0-alpha.12",
"rrweb-worker": "^2.0.0-alpha.12"
}
}
Loading
Loading