Skip to content

Commit 8a29725

Browse files
authored
build(replay): Improve replay-worker build (#7173)
1 parent f8047f6 commit 8a29725

File tree

9 files changed

+75
-84
lines changed

9 files changed

+75
-84
lines changed

packages/replay-worker/package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@
22
"name": "@sentry-internal/replay-worker",
33
"version": "7.37.2",
44
"description": "Worker for @sentry/replay",
5-
"main": "build/index.js",
6-
"module": "build/index.js",
5+
"main": "build/npm/esm/index.js",
6+
"module": "build/npm/esm/index.js",
7+
"types": "build/npm/types/index.d.ts",
78
"sideEffects": false,
89
"private": true,
910
"scripts": {
10-
"build": "yarn build:transpile",
11+
"build": "run-p build:transpile build:types",
1112
"build:transpile": "rollup -c rollup.worker.config.js",
12-
"build:types": "yarn build:transpile",
13+
"build:types": "tsc -p tsconfig.types.json",
1314
"build:dev": "yarn build",
14-
"build:watch": "run-p build:transpile:watch",
15+
"build:watch": "run-p build:transpile:watch build:types:watch",
1516
"build:dev:watch": "run-p build:watch",
1617
"build:transpile:watch": "yarn build:rollup --watch",
18+
"build:types:watch": "yarn build:types --watch",
1719
"clean": "rimraf build",
1820
"fix": "run-s fix:eslint fix:prettier",
1921
"fix:eslint": "eslint . --format stylish --fix",
@@ -36,7 +38,6 @@
3638
"homepage": "https://docs.sentry.io/platforms/javascript/session-replay/",
3739
"devDependencies": {
3840
"@types/pako": "^2.0.0",
39-
"rollup-plugin-copy": "~3.4.0",
4041
"tslib": "^1.9.3"
4142
},
4243
"dependencies": {

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

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,46 @@ import resolve from '@rollup/plugin-node-resolve';
44
import typescript from '@rollup/plugin-typescript';
55
import { defineConfig } from 'rollup';
66
import { terser } from 'rollup-plugin-terser';
7-
import copy from 'rollup-plugin-copy';
87

9-
const config = defineConfig({
10-
input: ['./src/worker.ts'],
11-
output: {
12-
dir: './build/',
13-
format: 'esm',
8+
const config = defineConfig([
9+
{
10+
input: ['./src/index.ts'],
11+
output: {
12+
dir: './build/npm/esm',
13+
format: 'esm',
14+
},
15+
external: ['./worker'],
16+
plugins: [
17+
typescript({ tsconfig: './tsconfig.json', inlineSourceMap: false, sourceMap: false, inlineSources: false }),
18+
terser({
19+
mangle: {
20+
module: true,
21+
},
22+
}),
23+
],
1424
},
15-
plugins: [
16-
typescript({ tsconfig: './tsconfig.json', inlineSourceMap: false, sourceMap: false, inlineSources: false }),
17-
resolve(),
18-
terser({
19-
mangle: {
20-
module: true,
21-
},
22-
}),
23-
{
24-
name: 'worker-to-string',
25-
renderChunk(code) {
26-
return `export default \`${code}\`;`;
27-
},
25+
{
26+
input: ['./src/_worker.ts'],
27+
output: {
28+
file: './build/npm/esm/worker.ts',
29+
format: 'esm',
2830
},
29-
copy({
30-
targets: [{ src: 'vendor/*', dest: 'build' }],
31-
}),
32-
],
33-
});
31+
plugins: [
32+
typescript({ tsconfig: './tsconfig.json', inlineSourceMap: false, sourceMap: false, inlineSources: false }),
33+
resolve(),
34+
terser({
35+
mangle: {
36+
module: true,
37+
},
38+
}),
39+
{
40+
name: 'worker-to-string',
41+
renderChunk(code) {
42+
return `export default \`${code}\`;`;
43+
},
44+
},
45+
],
46+
},
47+
]);
3448

3549
export default config;

packages/replay-worker/src/_worker.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { handleMessage } from './handleMessage';
2+
3+
addEventListener('message', handleMessage);
4+
5+
// Immediately send a message when worker loads, so we know the worker is ready
6+
// @ts-ignore this syntax is actually fine
7+
postMessage({
8+
id: undefined,
9+
method: 'init',
10+
success: true,
11+
response: undefined,
12+
});
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import workerString from './worker';
22

3-
export function getWorkerURL() {
3+
/**
4+
* Get the URL for a web worker.
5+
*/
6+
export function getWorkerURL(): string {
47
const workerBlob = new Blob([workerString]);
58
return URL.createObjectURL(workerBlob);
69
}

packages/replay-worker/src/worker.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
import { handleMessage } from './handleMessage';
2-
3-
addEventListener('message', handleMessage);
4-
5-
// Immediately send a message when worker loads, so we know the worker is ready
6-
// @ts-ignore this syntax is actually fine
7-
postMessage({
8-
id: undefined,
9-
method: 'init',
10-
success: true,
11-
response: undefined,
12-
});
1+
// This is replaced at build-time with the content from _worker.ts, wrapped as a string.
2+
// This is just a placeholder so that types etc. are correct.
3+
export default '' as string;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"include": ["src/index.ts", "src/worker.ts"],
4+
"compilerOptions": {
5+
"declaration": true,
6+
"declarationMap": true,
7+
"emitDeclarationOnly": true,
8+
"outDir": "build/npm/types"
9+
}
10+
}

packages/replay-worker/vendor/index.d.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/replay-worker/vendor/worker.d.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

yarn.lock

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3785,13 +3785,6 @@
37853785
dependencies:
37863786
"@types/node" "*"
37873787

3788-
"@types/fs-extra@^8.0.1":
3789-
version "8.1.2"
3790-
resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-8.1.2.tgz#7125cc2e4bdd9bd2fc83005ffdb1d0ba00cca61f"
3791-
integrity sha512-SvSrYXfWSc7R4eqnOzbQF4TZmfpNSM9FrSWLU3EUnWBuyZqNBOrv1B1JA3byUDPUl9z4Ab3jeZG2eDdySlgNMg==
3792-
dependencies:
3793-
"@types/node" "*"
3794-
37953788
"@types/fs-extra@^8.1.0":
37963789
version "8.1.1"
37973790
resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-8.1.1.tgz#1e49f22d09aa46e19b51c0b013cb63d0d923a068"
@@ -8204,7 +8197,7 @@ color@^3.0.0:
82048197
color-convert "^1.9.1"
82058198
color-string "^1.5.4"
82068199

8207-
colorette@^1.1.0, colorette@^1.2.1, colorette@^1.2.2:
8200+
colorette@^1.2.1, colorette@^1.2.2:
82088201
version "1.4.0"
82098202
resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.4.0.tgz#5190fbb87276259a86ad700bff2c6d6faa3fca40"
82108203
integrity sha512-Y2oEozpomLn7Q3HFP7dpww7AtMJplbM9lGZP6RDfHqmbeRjiwRg4n6VM6j4KLmRke85uWEI7JqF17f3pqdRA0g==
@@ -12657,20 +12650,6 @@ [email protected]:
1265712650
merge2 "^1.2.3"
1265812651
slash "^3.0.0"
1265912652

12660-
12661-
version "10.0.1"
12662-
resolved "https://registry.yarnpkg.com/globby/-/globby-10.0.1.tgz#4782c34cb75dd683351335c5829cc3420e606b22"
12663-
integrity sha512-sSs4inE1FB2YQiymcmTv6NWENryABjUNPeWhOvmn4SjtKybglsyPZxFB3U1/+L1bYi0rNZDqCLlHyLYDl1Pq5A==
12664-
dependencies:
12665-
"@types/glob" "^7.1.1"
12666-
array-union "^2.1.0"
12667-
dir-glob "^3.0.1"
12668-
fast-glob "^3.0.3"
12669-
glob "^7.1.3"
12670-
ignore "^5.1.1"
12671-
merge2 "^1.2.3"
12672-
slash "^3.0.0"
12673-
1267412653
[email protected], globby@^11.0.1, globby@^11.0.2, globby@^11.0.3, globby@^11.1.0:
1267512654
version "11.1.0"
1267612655
resolved "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz#bd4be98bb042f83d796f7e3811991fbe82a0d34b"
@@ -14165,11 +14144,6 @@ is-plain-object@^2.0.1, is-plain-object@^2.0.3, is-plain-object@^2.0.4:
1416514144
dependencies:
1416614145
isobject "^3.0.1"
1416714146

14168-
is-plain-object@^3.0.0:
14169-
version "3.0.1"
14170-
resolved "https://registry.yarnpkg.com/is-plain-object/-/is-plain-object-3.0.1.tgz#662d92d24c0aa4302407b0d45d21f2251c85f85b"
14171-
integrity sha512-Xnpx182SBMrr/aBik8y+GuR4U1L9FqMSojwDQwPMmxyC6bvEqly9UBCxhauBF5vNh2gwWJNX6oDV7O+OM4z34g==
14172-
1417314147
is-plain-object@^5.0.0:
1417414148
version "5.0.0"
1417514149
resolved "https://registry.yarnpkg.com/is-plain-object/-/is-plain-object-5.0.0.tgz#4427f50ab3429e9025ea7d52e9043a9ef4159344"
@@ -21149,17 +21123,6 @@ [email protected]:
2114921123
js-cleanup "^1.2.0"
2115021124
rollup-pluginutils "^2.8.2"
2115121125

21152-
rollup-plugin-copy@~3.4.0:
21153-
version "3.4.0"
21154-
resolved "https://registry.yarnpkg.com/rollup-plugin-copy/-/rollup-plugin-copy-3.4.0.tgz#f1228a3ffb66ffad8606e2f3fb7ff23141ed3286"
21155-
integrity sha512-rGUmYYsYsceRJRqLVlE9FivJMxJ7X6jDlP79fmFkL8sJs7VVMSVyA2yfyL+PGyO/vJs4A87hwhgVfz61njI+uQ==
21156-
dependencies:
21157-
"@types/fs-extra" "^8.0.1"
21158-
colorette "^1.1.0"
21159-
fs-extra "^8.1.0"
21160-
globby "10.0.1"
21161-
is-plain-object "^3.0.0"
21162-
2116321126
rollup-plugin-license@^2.6.1:
2116421127
version "2.6.1"
2116521128
resolved "https://registry.yarnpkg.com/rollup-plugin-license/-/rollup-plugin-license-2.6.1.tgz#20f15cc37950f362f8eefdc6e3a2e659d0cad9eb"

0 commit comments

Comments
 (0)