Skip to content

feat(replay): export compression worker for bundling #16794

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

Open
wants to merge 2 commits into
base: develop
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
10 changes: 10 additions & 0 deletions packages/replay-internal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
"types": "build/npm/types/index.d.ts",
"exports": {
"./package.json": "./package.json",
"./worker-bundler": {
"import": {
"types": "./build/npm/types/worker-bundler.d.ts",
"default": "./build/npm/esm/worker-bundler.js"
},
"require": {
"types": "./build/npm/types/worker-bundler.d.ts",
"default": "./build/npm/cjs/worker-bundler.js"
}
},
".": {
"import": {
"types": "./build/npm/types/index.d.ts",
Expand Down
12 changes: 12 additions & 0 deletions packages/replay-internal/rollup.npm.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import nodeResolve from '@rollup/plugin-node-resolve';
import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollup-utils';

export default makeNPMConfigVariants(
Expand All @@ -16,4 +17,15 @@ export default makeNPMConfigVariants(
},
},
}),
).concat(
['esm', 'cjs'].map(format => ({
input: ['./src/worker-bundler.ts'],
output: {
file: `./build/npm/${format}/worker-bundler.js`,
strict: false,
format,
},
treeshake: false,
plugins: [nodeResolve()],
})),
);
6 changes: 3 additions & 3 deletions packages/replay-internal/src/eventBuffer/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { getWorkerURL } from '@sentry-internal/replay-worker';
import { DEBUG_BUILD } from '../debug-build';
import type { EventBuffer } from '../types';
import type { EventBuffer, ReplayWorkerURL } from '../types';
import { logger } from '../util/logger';
import { EventBufferArray } from './EventBufferArray';
import { EventBufferProxy } from './EventBufferProxy';

interface CreateEventBufferParams {
useCompression: boolean;
workerUrl?: string;
workerUrl?: ReplayWorkerURL;
}

// Treeshakable guard to remove the code of the included compression worker
Expand Down Expand Up @@ -36,7 +36,7 @@ export function createEventBuffer({
return new EventBufferArray();
}

function _loadWorker(customWorkerUrl?: string): EventBufferProxy | void {
function _loadWorker(customWorkerUrl?: ReplayWorkerURL): EventBufferProxy | void {
try {
const workerUrl = customWorkerUrl || _getWorkerUrl();

Expand Down
4 changes: 3 additions & 1 deletion packages/replay-internal/src/types/replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ export interface ReplayNetworkOptions {
networkResponseHeaders: string[];
}

export type ReplayWorkerURL = string | URL;

export interface ReplayPluginOptions extends ReplayNetworkOptions {
/**
* The sample rate for session-long replays. 1.0 will record all sessions and
Expand Down Expand Up @@ -130,7 +132,7 @@ export interface ReplayPluginOptions extends ReplayNetworkOptions {
* If defined, use this worker URL instead of the default included one for compression.
* This will only be used if `useCompression` is not false.
*/
workerUrl?: string;
workerUrl?: ReplayWorkerURL;

/**
* Block all media (e.g. images, svg, video) in recordings.
Expand Down
1 change: 1 addition & 0 deletions packages/replay-internal/src/worker-bundler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@sentry-internal/replay-worker/worker-bundler';
17 changes: 17 additions & 0 deletions packages/replay-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@
"main": "build/esm/index.js",
"module": "build/esm/index.js",
"types": "build/types/index.d.ts",
"exports": {
"./package.json": "./package.json",
"./worker-bundler": {
"types": "./build/types/worker-bundler.d.ts",
"default": "./build/esm/worker-bundler.js"
},
".": {
"import": {
"types": "./build/types/index.d.ts",
"default": "./build/esm/index.js"
},
"require": {
"types": "./build/types/index.d.ts",
"default": "./build/cjs/index.js"
}
}
},
"typesVersions": {
"<5.0": {
"build/types/index.d.ts": [
Expand Down
18 changes: 18 additions & 0 deletions packages/replay-worker/rollup.worker.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ const config = defineConfig([
},
],
},
{
input: ['./src/_worker.ts'],
output: {
file: './build/esm/worker-bundler.js',
format: 'esm',
},
treeshake: 'smallest',
plugins: [
commonjs(),
typescript({ tsconfig: './tsconfig.json', inlineSourceMap: false, sourceMap: false, inlineSources: false }),
resolve(),
terser({
mangle: {
module: true,
},
}),
],
},
]);

export default config;
3 changes: 3 additions & 0 deletions packages/replay-worker/src/worker-bundler.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 _worker.ts
// This is just a placeholder so that types etc. are correct.
export {};
2 changes: 1 addition & 1 deletion packages/replay-worker/tsconfig.types.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "./tsconfig.json",
"include": ["src/index.ts", "src/worker.ts"],
"include": ["src/index.ts", "src/worker.ts", "src/worker-bundler.ts"],
"compilerOptions": {
"declaration": true,
"declarationMap": true,
Expand Down
Loading