Skip to content

Commit 8d41656

Browse files
authored
fix(replay): Remove unused parts of pako from build (#9369)
See nodeca/pako#268, there is some issue with pako tree shaking ootb. We don't need all the inflation stuff in our bundle.
1 parent 8b7b81e commit 8d41656

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

packages/replay-worker/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@
4646
},
4747
"homepage": "https://docs.sentry.io/platforms/javascript/session-replay/",
4848
"devDependencies": {
49+
"@rollup/plugin-commonjs": "^21.0.1",
4950
"@types/pako": "^2.0.0"
5051
},
5152
"dependencies": {
52-
"pako": "^2.1.0"
53+
"pako": "2.1.0"
5354
},
5455
"engines": {
5556
"node": ">=12"

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// inspired by https://justinribeiro.com/chronicle/2020/07/17/building-module-web-workers-for-cross-browser-compatibility-with-rollup/
22

33
import resolve from '@rollup/plugin-node-resolve';
4+
import commonjs from '@rollup/plugin-commonjs';
45
import typescript from '@rollup/plugin-typescript';
56
import { defineConfig } from 'rollup';
67
import { terser } from 'rollup-plugin-terser';
@@ -28,7 +29,9 @@ const config = defineConfig([
2829
file: './build/npm/esm/worker.ts',
2930
format: 'esm',
3031
},
32+
treeshake: 'smallest',
3133
plugins: [
34+
commonjs(),
3235
typescript({ tsconfig: './tsconfig.json', inlineSourceMap: false, sourceMap: false, inlineSources: false }),
3336
resolve(),
3437
terser({

packages/replay-worker/src/Compressor.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
import { constants, Deflate, deflate } from 'pako';
1+
import type * as PakoTypes from 'pako';
2+
// @ts-expect-error no types here
3+
import * as pako from 'pako/lib/deflate.js';
4+
5+
// NOTE: We have to do this weird workaround because by default,
6+
// pako does not treeshake when importing from 'pako'.
7+
// In order to get proper tree shaking, we have to import from 'pako/lib/deflate.js',
8+
// Which is not great but works
9+
// types come from @types/pako, so we can safely use them by casting
10+
const Deflate = (pako as typeof PakoTypes).Deflate;
11+
const deflate = (pako as typeof PakoTypes).deflate;
12+
const constants = (pako as typeof PakoTypes).constants;
213

314
/**
415
* A stateful compressor that can be used to batch compress events.
@@ -7,7 +18,7 @@ export class Compressor {
718
/**
819
* pako deflator instance
920
*/
10-
public deflate: Deflate;
21+
public deflate: PakoTypes.Deflate;
1122

1223
/**
1324
* If any events have been added.

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23281,16 +23281,16 @@ pad@^3.2.0:
2328123281
dependencies:
2328223282
wcwidth "^1.0.1"
2328323283

23284+
[email protected], pako@^2.1.0:
23285+
version "2.1.0"
23286+
resolved "https://registry.yarnpkg.com/pako/-/pako-2.1.0.tgz#266cc37f98c7d883545d11335c00fbd4062c9a86"
23287+
integrity sha512-w+eufiZ1WuJYgPXbV/PO3NCMEc3xqylkKHzp8bxp1uW4qaSNQUkwmLLEc3kKsfz8lpV1F8Ht3U1Cm+9Srog2ug==
23288+
2328423289
pako@^1.0.3, pako@~1.0.5:
2328523290
version "1.0.11"
2328623291
resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.11.tgz#6c9599d340d54dfd3946380252a35705a6b992bf"
2328723292
integrity sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==
2328823293

23289-
pako@^2.1.0:
23290-
version "2.1.0"
23291-
resolved "https://registry.yarnpkg.com/pako/-/pako-2.1.0.tgz#266cc37f98c7d883545d11335c00fbd4062c9a86"
23292-
integrity sha512-w+eufiZ1WuJYgPXbV/PO3NCMEc3xqylkKHzp8bxp1uW4qaSNQUkwmLLEc3kKsfz8lpV1F8Ht3U1Cm+9Srog2ug==
23293-
2329423294
parallel-transform@^1.1.0:
2329523295
version "1.2.0"
2329623296
resolved "https://registry.yarnpkg.com/parallel-transform/-/parallel-transform-1.2.0.tgz#9049ca37d6cb2182c3b1d2c720be94d14a5814fc"

0 commit comments

Comments
 (0)