Skip to content

build(replay): Use Monorepo's rollup config to build Replay #6343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .size-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,22 @@ module.exports = [
// This entry is only here temporarily and will be replaced once we have proper CDN bundles
{
name: '@sentry/replay index.js',
path: 'packages/replay/build/npm/dist/index.js',
path: 'packages/replay/build/npm/esm/index.js',
gzip: true,
limit: '100 KB',
ignore: ['@sentry/browser', '@sentry/utils', '@sentry/core', '@sentry/types'],
},
{
name: '@sentry/replay - Webpack (gzipped + minified)',
path: 'packages/replay/build/npm/dist/index.js',
path: 'packages/replay/build/npm/esm/index.js',
import: '{ Replay }',
gzip: true,
limit: '100 KB',
ignore: ['@sentry/browser', '@sentry/utils', '@sentry/core', '@sentry/types'],
},
{
name: '@sentry/replay - Webpack (minified)',
path: 'packages/replay/build/npm/dist/index.js',
path: 'packages/replay/build/npm/esm/index.js',
import: '{ Replay }',
gzip: false,
limit: '300 KB',
Expand Down
16 changes: 1 addition & 15 deletions packages/replay/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,7 @@

module.exports = {
extends: ['../../.eslintrc.js'],
ignorePatterns: [
'coverage/**',
'build/**',
'dist/**',
'cjs/**',
'esm/**',
'examples/**',
'test/manual/**',
'types/**',
// TODO: Remove these after migration
'scripts/**',
'config/**',
'config/**',
'__mocks__/**',
],
ignorePatterns: ['rollup.config.worker.js'],
overrides: [
{
files: ['worker/**/*.ts'],
Expand Down
1 change: 0 additions & 1 deletion packages/replay/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules
/*.tgz
.eslintcache
dist
build
42 changes: 0 additions & 42 deletions packages/replay/config/rollup.config.core.ts

This file was deleted.

25 changes: 12 additions & 13 deletions packages/replay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@
"name": "@sentry/replay",
"version": "7.22.0",
"description": "User replays for Sentry",
"main": "build/npm/dist/index.js",
"module": "build/npm/dist/index.es.js",
"types": "build/npm/dist/src/index.d.ts",
"main": "build/npm/cjs/index.js",
"module": "build/npm/esm/index.js",
"types": "build/npm/types/src/index.d.ts",
"sideEffects": false,
"scripts": {
"bootstrap": "yarn && cd demo && yarn #TODO: change after migration",
"build": "yarn build:extras",
"build:extras": "NODE_ENV=production yarn build:all",
"build:dev": "NODE_ENV=development yarn build:all",
"build:all": "run-s clean build:worker build:core",
"build:core": "yarn build:actualRollup --config config/rollup.config.core.ts",
"build:worker": "yarn build:actualRollup --config config/rollup.config.worker.ts",
"build:actualRollup": "rollup",
"build:watch": "NODE_ENV=production yarn build:all:watch",
"build:dev:watch": "NODE_ENV=development yarn build:all:watch",
"build:all:watch": "yarn clean && run-p \"build:worker --watch\" \"build:core --watch\"",
"build:rollup": "run-s build:worker build:core",
"build": "run-s build:worker && run-p build:core build:types",
"build:dev": "run-s build #TODO adjust after adding CDN bundles",
"build:worker": "rollup -c rollup.config.worker.js",
"build:core": "rollup -c rollup.npm.config.js",
"build:types": "tsc -p tsconfig.types.json",
"build:watch": "run-p \"build:worker --watch\" \"build:core --watch\" build:types:watch",
"build:dev:watch": "yarn build:watch #TODO adjust after adding CDN bundles",
"build:types:watch": "tsc -p tsconfig.types.json --watch",
"build:npm": "ts-node ../../scripts/prepack.ts --bundles && npm pack ./build/npm",
"circularDepCheck": "#TODO comment in after migration: madge --circular src/index.ts",
"clean": "rimraf build sentry-replay-*.tgz",
Expand Down
28 changes: 28 additions & 0 deletions packages/replay/rollup.npm.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import replace from '@rollup/plugin-replace';

import { makeBaseNPMConfig, makeNPMConfigVariants } from '../../rollup/index';

import pkg from './package.json';

export default makeNPMConfigVariants(
makeBaseNPMConfig({
hasBundles: true,
packageSpecificConfig: {
external: [...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})],
plugins: [
// TODO: Remove this - replay version will be in sync w/ SDK version
replace({
preventAssignment: true,
values: {
__SENTRY_REPLAY_VERSION__: JSON.stringify(pkg.version),
},
}),
],
output: {
// set exports to 'named' or 'auto' so that rollup doesn't warn about
// the default export in `worker/worker.js`
exports: 'named',
},
},
}),
);
2 changes: 1 addition & 1 deletion packages/replay/src/createPerformanceEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { WINDOW } from '@sentry/browser';
import { browserPerformanceTimeOrigin } from '@sentry/utils';
import { record } from 'rrweb';

import { AllPerformanceEntry } from './types';
import { AllPerformanceEntry, PerformanceNavigationTiming, PerformancePaintTiming } from './types';
import { isIngestHost } from './util/isIngestHost';

export interface ReplayPerformanceEntry {
Expand Down
14 changes: 8 additions & 6 deletions packages/replay/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ export interface WorkerRequest {

declare global {
const __SENTRY_REPLAY_VERSION__: string;

// PerformancePaintTiming is only available since TS 4.4, so for now we just define this here
// see: https://github.com/microsoft/TypeScript/blob/main/lib/lib.dom.d.ts#L10564
type PerformancePaintTiming = PerformanceEntry;
// @ts-ignore declare again, this _should_ be there but somehow is not available in worker context
type PerformanceNavigationTiming = PerformanceEntry;
}

// PerformancePaintTiming and PerformanceNavigationTiming are only available with TS 4.4 and newer
// Therefore, we're exporting them here to make them available in older TS versions
export type PerformancePaintTiming = PerformanceEntry;
export type PerformanceNavigationTiming = PerformanceEntry & {
type: string;
transferSize: number;
domComplete: number;
};
/**
* The response from the worker
*/
Expand Down
2 changes: 2 additions & 0 deletions packages/replay/src/util/dedupePerformanceEntries.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { PerformanceNavigationTiming, PerformancePaintTiming } from '../types';

const NAVIGATION_ENTRY_KEYS: Array<keyof PerformanceNavigationTiming> = [
'name',
'type',
Expand Down
2 changes: 2 additions & 0 deletions packages/replay/test/fixtures/performanceEntry/lcp.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { PerformancePaintTiming } from '../../../src/types';

export function PerformanceEntryLcp(obj?: Partial<PerformancePaintTiming>): PerformancePaintTiming {
const entry = {
name: '',
Expand Down
2 changes: 2 additions & 0 deletions packages/replay/test/fixtures/performanceEntry/navigation.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { PerformanceNavigationTiming } from '../../../src/types';

export function PerformanceEntryNavigation(obj?: Partial<PerformanceNavigationTiming>): PerformanceNavigationTiming {
const entry = {
name: 'https://sentry.io/organizations/sentry/discover/',
Expand Down
4 changes: 1 addition & 3 deletions packages/replay/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
"allowJs": true,
"declaration": true,
"declarationMap": true,
"declarationDir": "./types",
"strictNullChecks": true,
"outDir": "./build/npm/dist"
"strictNullChecks": true
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
Expand Down
10 changes: 10 additions & 0 deletions packages/replay/tsconfig.types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",

"compilerOptions": {
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"outDir": "build/npm/types"
}
}