Skip to content

Commit 15b344f

Browse files
authored
build(replay): Use Monorepo's rollup config to build Replay (#6343)
Update Replay's build config to use our monorepo's rollup config for building and transpiling the Replay integration. With this patch, we're introducing a breaking change because the tarball structure is going to change. However, this only breaks users who imported from package-internal paths directly and not from the top-level package. More specifically, these are the changes: * Move and rename`./config/rollup.config.core.ts` to `./rollup.npm.config.js` which now uses our `makeNPMConfigVariants` and `makeBaseNPMConfig` rollup config helper functions to create ESM and CJS transpiled JS, just like in all our other packages. For now we have to change this to JavaScript but we can ofc revisit having TS-based rollup configs in the future. * Instead of bundling everything into the `index.js` files, this config now just transpiles the individual modules. This is how we do it in all our other packages. We might have to revisit this strategy for vendoring rrweb and bundling but we can build on top of this PR to do so. * Move and rename `./config/rollup.worker.config.ts` to `./rollup.worker.config.js` (no changes) * Update eslint configs * Fix a few type errors I came across while performing these build changes * Update `package.json` scripts so that they are in line with the scripts of our other packages. This should simplify the scripts a little. * Revert #6307 as we now transpile and check/build types separately, like we do with the rest of our packages. * Revert #6341 as the`__SENTRY_DEBUG__` flag is now set in our rollup helper functions
1 parent 14e5e48 commit 15b344f

14 files changed

+70
-84
lines changed

.size-limit.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,22 @@ module.exports = [
6666
// This entry is only here temporarily and will be replaced once we have proper CDN bundles
6767
{
6868
name: '@sentry/replay index.js',
69-
path: 'packages/replay/build/npm/dist/index.js',
69+
path: 'packages/replay/build/npm/esm/index.js',
7070
gzip: true,
7171
limit: '100 KB',
7272
ignore: ['@sentry/browser', '@sentry/utils', '@sentry/core', '@sentry/types'],
7373
},
7474
{
7575
name: '@sentry/replay - Webpack (gzipped + minified)',
76-
path: 'packages/replay/build/npm/dist/index.js',
76+
path: 'packages/replay/build/npm/esm/index.js',
7777
import: '{ Replay }',
7878
gzip: true,
7979
limit: '100 KB',
8080
ignore: ['@sentry/browser', '@sentry/utils', '@sentry/core', '@sentry/types'],
8181
},
8282
{
8383
name: '@sentry/replay - Webpack (minified)',
84-
path: 'packages/replay/build/npm/dist/index.js',
84+
path: 'packages/replay/build/npm/esm/index.js',
8585
import: '{ Replay }',
8686
gzip: false,
8787
limit: '300 KB',

packages/replay/.eslintrc.js

+1-15
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,7 @@
55

66
module.exports = {
77
extends: ['../../.eslintrc.js'],
8-
ignorePatterns: [
9-
'coverage/**',
10-
'build/**',
11-
'dist/**',
12-
'cjs/**',
13-
'esm/**',
14-
'examples/**',
15-
'test/manual/**',
16-
'types/**',
17-
// TODO: Remove these after migration
18-
'scripts/**',
19-
'config/**',
20-
'config/**',
21-
'__mocks__/**',
22-
],
8+
ignorePatterns: ['rollup.config.worker.js'],
239
overrides: [
2410
{
2511
files: ['worker/**/*.ts'],

packages/replay/.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
node_modules
22
/*.tgz
33
.eslintcache
4-
dist
54
build

packages/replay/config/rollup.config.core.ts

-42
This file was deleted.

packages/replay/package.json

+12-13
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,21 @@
22
"name": "@sentry/replay",
33
"version": "7.22.0",
44
"description": "User replays for Sentry",
5-
"main": "build/npm/dist/index.js",
6-
"module": "build/npm/dist/index.es.js",
7-
"types": "build/npm/dist/src/index.d.ts",
5+
"main": "build/npm/cjs/index.js",
6+
"module": "build/npm/esm/index.js",
7+
"types": "build/npm/types/src/index.d.ts",
88
"sideEffects": false,
99
"scripts": {
1010
"bootstrap": "yarn && cd demo && yarn #TODO: change after migration",
11-
"build": "yarn build:extras",
12-
"build:extras": "NODE_ENV=production yarn build:all",
13-
"build:dev": "NODE_ENV=development yarn build:all",
14-
"build:all": "run-s clean build:worker build:core",
15-
"build:core": "yarn build:actualRollup --config config/rollup.config.core.ts",
16-
"build:worker": "yarn build:actualRollup --config config/rollup.config.worker.ts",
17-
"build:actualRollup": "rollup",
18-
"build:watch": "NODE_ENV=production yarn build:all:watch",
19-
"build:dev:watch": "NODE_ENV=development yarn build:all:watch",
20-
"build:all:watch": "yarn clean && run-p \"build:worker --watch\" \"build:core --watch\"",
11+
"build:rollup": "run-s build:worker build:core",
12+
"build": "run-s build:worker && run-p build:core build:types",
13+
"build:dev": "run-s build #TODO adjust after adding CDN bundles",
14+
"build:worker": "rollup -c rollup.config.worker.js",
15+
"build:core": "rollup -c rollup.npm.config.js",
16+
"build:types": "tsc -p tsconfig.types.json",
17+
"build:watch": "run-p \"build:worker --watch\" \"build:core --watch\" build:types:watch",
18+
"build:dev:watch": "yarn build:watch #TODO adjust after adding CDN bundles",
19+
"build:types:watch": "tsc -p tsconfig.types.json --watch",
2120
"build:npm": "ts-node ../../scripts/prepack.ts --bundles && npm pack ./build/npm",
2221
"circularDepCheck": "#TODO comment in after migration: madge --circular src/index.ts",
2322
"clean": "rimraf build sentry-replay-*.tgz",

packages/replay/rollup.npm.config.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import replace from '@rollup/plugin-replace';
2+
3+
import { makeBaseNPMConfig, makeNPMConfigVariants } from '../../rollup/index';
4+
5+
import pkg from './package.json';
6+
7+
export default makeNPMConfigVariants(
8+
makeBaseNPMConfig({
9+
hasBundles: true,
10+
packageSpecificConfig: {
11+
external: [...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})],
12+
plugins: [
13+
// TODO: Remove this - replay version will be in sync w/ SDK version
14+
replace({
15+
preventAssignment: true,
16+
values: {
17+
__SENTRY_REPLAY_VERSION__: JSON.stringify(pkg.version),
18+
},
19+
}),
20+
],
21+
output: {
22+
// set exports to 'named' or 'auto' so that rollup doesn't warn about
23+
// the default export in `worker/worker.js`
24+
exports: 'named',
25+
},
26+
},
27+
}),
28+
);

packages/replay/src/createPerformanceEntry.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { WINDOW } from '@sentry/browser';
22
import { browserPerformanceTimeOrigin } from '@sentry/utils';
33
import { record } from 'rrweb';
44

5-
import { AllPerformanceEntry } from './types';
5+
import { AllPerformanceEntry, PerformanceNavigationTiming, PerformancePaintTiming } from './types';
66
import { isIngestHost } from './util/isIngestHost';
77

88
export interface ReplayPerformanceEntry {

packages/replay/src/types.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,16 @@ export interface WorkerRequest {
3535

3636
declare global {
3737
const __SENTRY_REPLAY_VERSION__: string;
38-
39-
// PerformancePaintTiming is only available since TS 4.4, so for now we just define this here
40-
// see: https://github.com/microsoft/TypeScript/blob/main/lib/lib.dom.d.ts#L10564
41-
type PerformancePaintTiming = PerformanceEntry;
42-
// @ts-ignore declare again, this _should_ be there but somehow is not available in worker context
43-
type PerformanceNavigationTiming = PerformanceEntry;
4438
}
4539

40+
// PerformancePaintTiming and PerformanceNavigationTiming are only available with TS 4.4 and newer
41+
// Therefore, we're exporting them here to make them available in older TS versions
42+
export type PerformancePaintTiming = PerformanceEntry;
43+
export type PerformanceNavigationTiming = PerformanceEntry & {
44+
type: string;
45+
transferSize: number;
46+
domComplete: number;
47+
};
4648
/**
4749
* The response from the worker
4850
*/

packages/replay/src/util/dedupePerformanceEntries.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { PerformanceNavigationTiming, PerformancePaintTiming } from '../types';
2+
13
const NAVIGATION_ENTRY_KEYS: Array<keyof PerformanceNavigationTiming> = [
24
'name',
35
'type',

packages/replay/test/fixtures/performanceEntry/lcp.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { PerformancePaintTiming } from '../../../src/types';
2+
13
export function PerformanceEntryLcp(obj?: Partial<PerformancePaintTiming>): PerformancePaintTiming {
24
const entry = {
35
name: '',

packages/replay/test/fixtures/performanceEntry/navigation.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { PerformanceNavigationTiming } from '../../../src/types';
2+
13
export function PerformanceEntryNavigation(obj?: Partial<PerformanceNavigationTiming>): PerformanceNavigationTiming {
24
const entry = {
35
name: 'https://sentry.io/organizations/sentry/discover/',

packages/replay/tsconfig.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
"allowJs": true,
1717
"declaration": true,
1818
"declarationMap": true,
19-
"declarationDir": "./types",
20-
"strictNullChecks": true,
21-
"outDir": "./build/npm/dist"
19+
"strictNullChecks": true
2220
},
2321
"include": ["src/**/*.ts"],
2422
"exclude": ["node_modules"]

packages/replay/tsconfig.types.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
4+
"compilerOptions": {
5+
"declaration": true,
6+
"declarationMap": true,
7+
"emitDeclarationOnly": true,
8+
"outDir": "build/npm/types"
9+
}
10+
}

0 commit comments

Comments
 (0)