Skip to content

Commit 9b26cf9

Browse files
authored
feat(replay): Export compression worker from @sentry/replay-internal (#16794)
1 parent f52ab47 commit 9b26cf9

File tree

9 files changed

+68
-5
lines changed

9 files changed

+68
-5
lines changed

packages/replay-internal/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
"types": "build/npm/types/index.d.ts",
88
"exports": {
99
"./package.json": "./package.json",
10+
"./worker-bundler": {
11+
"import": {
12+
"types": "./build/npm/types/worker-bundler.d.ts",
13+
"default": "./build/npm/esm/worker-bundler.js"
14+
},
15+
"require": {
16+
"types": "./build/npm/types/worker-bundler.d.ts",
17+
"default": "./build/npm/cjs/worker-bundler.js"
18+
}
19+
},
1020
".": {
1121
"import": {
1222
"types": "./build/npm/types/index.d.ts",

packages/replay-internal/rollup.npm.config.mjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import nodeResolve from '@rollup/plugin-node-resolve';
12
import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollup-utils';
23

34
export default makeNPMConfigVariants(
@@ -16,4 +17,15 @@ export default makeNPMConfigVariants(
1617
},
1718
},
1819
}),
20+
).concat(
21+
['esm', 'cjs'].map(format => ({
22+
input: ['./src/worker-bundler.ts'],
23+
output: {
24+
file: `./build/npm/${format}/worker-bundler.js`,
25+
strict: false,
26+
format,
27+
},
28+
treeshake: false,
29+
plugins: [nodeResolve()],
30+
})),
1931
);

packages/replay-internal/src/eventBuffer/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { getWorkerURL } from '@sentry-internal/replay-worker';
22
import { DEBUG_BUILD } from '../debug-build';
3-
import type { EventBuffer } from '../types';
3+
import type { EventBuffer, ReplayWorkerURL } from '../types';
44
import { logger } from '../util/logger';
55
import { EventBufferArray } from './EventBufferArray';
66
import { EventBufferProxy } from './EventBufferProxy';
77

88
interface CreateEventBufferParams {
99
useCompression: boolean;
10-
workerUrl?: string;
10+
workerUrl?: ReplayWorkerURL;
1111
}
1212

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

39-
function _loadWorker(customWorkerUrl?: string): EventBufferProxy | void {
39+
function _loadWorker(customWorkerUrl?: ReplayWorkerURL): EventBufferProxy | void {
4040
try {
4141
const workerUrl = customWorkerUrl || _getWorkerUrl();
4242

packages/replay-internal/src/types/replay.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ export interface ReplayNetworkOptions {
9090
networkResponseHeaders: string[];
9191
}
9292

93+
export type ReplayWorkerURL = string | URL;
94+
9395
export interface ReplayPluginOptions extends ReplayNetworkOptions {
9496
/**
9597
* The sample rate for session-long replays. 1.0 will record all sessions and
@@ -130,7 +132,7 @@ export interface ReplayPluginOptions extends ReplayNetworkOptions {
130132
* If defined, use this worker URL instead of the default included one for compression.
131133
* This will only be used if `useCompression` is not false.
132134
*/
133-
workerUrl?: string;
135+
workerUrl?: ReplayWorkerURL;
134136

135137
/**
136138
* Block all media (e.g. images, svg, video) in recordings.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@sentry-internal/replay-worker/worker-bundler';

packages/replay-worker/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@
55
"main": "build/esm/index.js",
66
"module": "build/esm/index.js",
77
"types": "build/types/index.d.ts",
8+
"exports": {
9+
"./package.json": "./package.json",
10+
"./worker-bundler": {
11+
"types": "./build/types/worker-bundler.d.ts",
12+
"default": "./build/esm/worker-bundler.js"
13+
},
14+
".": {
15+
"import": {
16+
"types": "./build/types/index.d.ts",
17+
"default": "./build/esm/index.js"
18+
},
19+
"require": {
20+
"types": "./build/types/index.d.ts",
21+
"default": "./build/cjs/index.js"
22+
}
23+
}
24+
},
825
"typesVersions": {
926
"<5.0": {
1027
"build/types/index.d.ts": [

packages/replay-worker/rollup.worker.config.mjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,24 @@ const config = defineConfig([
4848
},
4949
],
5050
},
51+
{
52+
input: ['./src/_worker.ts'],
53+
output: {
54+
file: './build/esm/worker-bundler.js',
55+
format: 'esm',
56+
},
57+
treeshake: 'smallest',
58+
plugins: [
59+
commonjs(),
60+
typescript({ tsconfig: './tsconfig.json', inlineSourceMap: false, sourceMap: false, inlineSources: false }),
61+
resolve(),
62+
terser({
63+
mangle: {
64+
module: true,
65+
},
66+
}),
67+
],
68+
},
5169
]);
5270

5371
export default config;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// This is replaced at build-time with the content from _worker.ts
2+
// This is just a placeholder so that types etc. are correct.
3+
export {};

packages/replay-worker/tsconfig.types.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"extends": "./tsconfig.json",
3-
"include": ["src/index.ts", "src/worker.ts"],
3+
"include": ["src/index.ts", "src/worker.ts", "src/worker-bundler.ts"],
44
"compilerOptions": {
55
"declaration": true,
66
"declarationMap": true,

0 commit comments

Comments
 (0)