Skip to content

Commit

Permalink
fix(replay): Remove unused parts of pako from build (#9369)
Browse files Browse the repository at this point in the history
See nodeca/pako#268, there is some issue with
pako tree shaking ootb.

We don't need all the inflation stuff in our bundle.
  • Loading branch information
mydea authored Oct 27, 2023
1 parent 8b7b81e commit 8d41656
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
3 changes: 2 additions & 1 deletion packages/replay-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@
},
"homepage": "https://docs.sentry.io/platforms/javascript/session-replay/",
"devDependencies": {
"@rollup/plugin-commonjs": "^21.0.1",
"@types/pako": "^2.0.0"
},
"dependencies": {
"pako": "^2.1.0"
"pako": "2.1.0"
},
"engines": {
"node": ">=12"
Expand Down
3 changes: 3 additions & 0 deletions packages/replay-worker/rollup.worker.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// inspired by https://justinribeiro.com/chronicle/2020/07/17/building-module-web-workers-for-cross-browser-compatibility-with-rollup/

import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from '@rollup/plugin-typescript';
import { defineConfig } from 'rollup';
import { terser } from 'rollup-plugin-terser';
Expand Down Expand Up @@ -28,7 +29,9 @@ const config = defineConfig([
file: './build/npm/esm/worker.ts',
format: 'esm',
},
treeshake: 'smallest',
plugins: [
commonjs(),
typescript({ tsconfig: './tsconfig.json', inlineSourceMap: false, sourceMap: false, inlineSources: false }),
resolve(),
terser({
Expand Down
15 changes: 13 additions & 2 deletions packages/replay-worker/src/Compressor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import { constants, Deflate, deflate } from 'pako';
import type * as PakoTypes from 'pako';
// @ts-expect-error no types here
import * as pako from 'pako/lib/deflate.js';

// NOTE: We have to do this weird workaround because by default,
// pako does not treeshake when importing from 'pako'.
// In order to get proper tree shaking, we have to import from 'pako/lib/deflate.js',
// Which is not great but works
// types come from @types/pako, so we can safely use them by casting
const Deflate = (pako as typeof PakoTypes).Deflate;
const deflate = (pako as typeof PakoTypes).deflate;
const constants = (pako as typeof PakoTypes).constants;

/**
* A stateful compressor that can be used to batch compress events.
Expand All @@ -7,7 +18,7 @@ export class Compressor {
/**
* pako deflator instance
*/
public deflate: Deflate;
public deflate: PakoTypes.Deflate;

/**
* If any events have been added.
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23281,16 +23281,16 @@ pad@^3.2.0:
dependencies:
wcwidth "^1.0.1"

[email protected], pako@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/pako/-/pako-2.1.0.tgz#266cc37f98c7d883545d11335c00fbd4062c9a86"
integrity sha512-w+eufiZ1WuJYgPXbV/PO3NCMEc3xqylkKHzp8bxp1uW4qaSNQUkwmLLEc3kKsfz8lpV1F8Ht3U1Cm+9Srog2ug==

pako@^1.0.3, pako@~1.0.5:
version "1.0.11"
resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.11.tgz#6c9599d340d54dfd3946380252a35705a6b992bf"
integrity sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==

pako@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/pako/-/pako-2.1.0.tgz#266cc37f98c7d883545d11335c00fbd4062c9a86"
integrity sha512-w+eufiZ1WuJYgPXbV/PO3NCMEc3xqylkKHzp8bxp1uW4qaSNQUkwmLLEc3kKsfz8lpV1F8Ht3U1Cm+9Srog2ug==

parallel-transform@^1.1.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/parallel-transform/-/parallel-transform-1.2.0.tgz#9049ca37d6cb2182c3b1d2c720be94d14a5814fc"
Expand Down

0 comments on commit 8d41656

Please sign in to comment.