Skip to content

Commit 5ba75c7

Browse files
authored
chore(replay): Align and clean up tsconfig.jsons (#6308)
Align and clean up the `tsconfig.json` files in the replay package. In preparations to applying the monorepo's rollup and sucrase configs, we first align the tsconfigs. * Decouple `tsconfig.core.json` and `tsconfig.worker.json`. For now we can first focus on the core build and later on revisit the worker build config. * Remove nesting of tsconfigs * Move all tsconfigs to the package-level. Eventually, the config directory will be removed (after aligning the rollup configs) * Extend the core tsconfig from the monorepo's base tsconfig * Remove thereby redundant compiler options and entries * Tmp-fixe type errors after using the monorepo's base config * Modify Jest configs to work with the monorepo's tsconfig layout (`tsconfig.test.json`) * **Imortant**: This changes the target from es5 to es6. I think this is fine as all Sentry JS SDKs are transpiled to ES6 by default. We can discuss providing ES5 CDN bundles like we do for our other CDN bundles.
1 parent a1d1dac commit 5ba75c7

17 files changed

+77
-51
lines changed

packages/replay/.eslintrc.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = {
2525
files: ['worker/**/*.ts'],
2626
parserOptions: {
2727
// TODO: figure out if we need a worker-specific tsconfig
28-
project: ['config/tsconfig.worker.json'],
28+
project: ['tsconfig.worker.json'],
2929
},
3030
},
3131
{
@@ -66,18 +66,17 @@ module.exports = {
6666
},
6767
},
6868
{
69-
files: ['jest.setup.ts'],
69+
files: ['jest.setup.ts', 'jest.config.ts'],
70+
parserOptions: {
71+
project: ['tsconfig.test.json'],
72+
},
7073
rules: {
7174
'no-console': 'off',
7275
},
7376
},
7477
{
7578
files: ['test/**/*.ts'],
76-
parserOptions: {
77-
// TODO: remove this parserOptions object after we added a tsconfig.test.json
78-
// Replay previously didn't have a tsconfig.test.json, so for now we just the regular one.
79-
project: ['tsconfig.json'],
80-
},
79+
8180
rules: {
8281
// TODO: decide if we want to keep our '@test' import paths
8382
'import/no-unresolved': 'off',

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const config = defineConfig({
2222
external: [...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})],
2323
plugins: [
2424
typescript({
25-
tsconfig: IS_PRODUCTION ? './config/tsconfig.core.json' : './tsconfig.json',
25+
tsconfig: './tsconfig.json',
2626
}),
2727
replace({
2828
// __SENTRY_DEBUG__ should be save to replace in any case, so no checks for assignments necessary

packages/replay/config/rollup.config.worker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const config = defineConfig({
1212
format: 'esm',
1313
},
1414
plugins: [
15-
typescript({ tsconfig: './config/tsconfig.worker.json' }),
15+
typescript({ tsconfig: './tsconfig.worker.json' }),
1616
resolve(),
1717
terser({
1818
mangle: {

packages/replay/config/tsconfig.core.json

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

packages/replay/config/tsconfig.worker.json

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

packages/replay/jest.config.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
import type { Config } from '@jest/types';
22
import { pathsToModuleNameMapper } from 'ts-jest';
3+
import { jsWithTs as jsWithTsPreset } from 'ts-jest/presets';
34

4-
import { compilerOptions } from './tsconfig.json';
5+
import { compilerOptions } from './tsconfig.test.json';
56

67
export default async (): Promise<Config.InitialOptions> => {
78
return {
9+
...jsWithTsPreset,
810
verbose: true,
9-
preset: 'ts-jest/presets/js-with-ts', // needed when import worker.js
11+
globals: {
12+
'ts-jest': {
13+
tsconfig: '<rootDir>/tsconfig.test.json',
14+
},
15+
__DEBUG_BUILD__: true,
16+
},
1017
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
1118
prefix: '<rootDir>/',
1219
}),
1320
setupFilesAfterEnv: ['./jest.setup.ts'],
1421
testEnvironment: 'jsdom',
1522
testMatch: ['<rootDir>/test/**/*(*.)@(spec|test).ts'],
16-
globals: {
17-
'ts-jest': {
18-
tsconfig: '<rootDir>/tsconfig.json',
19-
},
20-
__DEBUG_BUILD__: true,
21-
},
2223
};
2324
};

packages/replay/src/createPerformanceEntry.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,14 @@ interface MemoryInfo {
3939
}
4040

4141
// Map entryType -> function to normalize data for event
42+
// @ts-ignore TODO: entry type does not fit the create* functions entry type
4243
const ENTRY_TYPES: Record<string, (entry: AllPerformanceEntry) => null | ReplayPerformanceEntry> = {
44+
// @ts-ignore TODO: entry type does not fit the create* functions entry type
4345
resource: createResourceEntry,
4446
paint: createPaintEntry,
47+
// @ts-ignore TODO: entry type does not fit the create* functions entry type
4548
navigation: createNavigationEntry,
49+
// @ts-ignore TODO: entry type does not fit the create* functions entry type
4650
['largest-contentful-paint']: createLargestContentfulPaint,
4751
};
4852

packages/replay/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class Replay implements Integration {
6666
*/
6767
public name: string = Replay.id;
6868

69-
public eventBuffer: IEventBuffer | null;
69+
public eventBuffer: IEventBuffer | null = null;
7070

7171
/**
7272
* List of PerformanceEntry from PerformanceObserver

packages/replay/src/session/types.ts

Whitespace-only changes.

packages/replay/src/util/captureInternalException.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { isInternal } from './isInternal';
55
/**
66
* Captures exceptions to Sentry only when it occurs on sentry.io
77
*/
8-
export function captureInternalException(err: Error): string | undefined {
8+
export function captureInternalException(err: Error): void {
99
if (!isInternal()) {
1010
return;
1111
}

packages/replay/src/worker/worker.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// TODO Once https://github.com/microsoft/TypeScript/issues/33094 is done (if it ever is), this file can disappear, as
2+
// it's purely a placeholder to satisfy VSCode.
3+
4+
{
5+
"extends": "../tsconfig.test.json",
6+
7+
"include": ["./**/*"]
8+
}

packages/replay/test/unit/util/isSampled.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { isSampled } from '../../../src/util/isSampled';
22

33
// Note Math.random generates a value from 0 (inclusive) to <1 (1 exclusive).
4-
const cases = [
4+
const cases: [number, number, boolean][] = [
55
[1.0, 0.9999, true],
66
[1.0, 0.0, true],
77
[1.0, 0.5, true],

packages/replay/tsconfig.json

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
{
2-
"extends": "./config/tsconfig.core.json",
2+
"extends": "../../tsconfig.json",
33
"compilerOptions": {
44
"paths": {
55
"@test": ["./test"],
66
"@test/*": ["./test/*"]
77
},
8-
"types": ["node", "jest"]
8+
"baseUrl": ".",
9+
"rootDir": ".",
10+
"types": ["node", "jest"],
11+
"module": "esnext",
12+
"noImplicitAny": true,
13+
"noEmitOnError": false,
14+
"esModuleInterop": true,
15+
"resolveJsonModule": true,
16+
"allowJs": true,
17+
"declaration": true,
18+
"declarationMap": true,
19+
"declarationDir": "./types",
20+
"strictNullChecks": true,
21+
"outDir": "./build/npm/dist"
922
},
10-
"include": ["src/**/*.ts", "test/**/*.ts", "rollup.config.ts", "jest.config.ts", "jest.setup.ts"],
23+
"include": ["src/**/*.ts"],
1124
"exclude": ["node_modules"]
1225
}

packages/replay/tsconfig.test.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
4+
"include": ["test/**/*.ts", "jest.config.ts", "jest.setup.ts"],
5+
6+
"compilerOptions": {
7+
"paths": {
8+
"@test": ["./test"],
9+
"@test/*": ["./test/*"]
10+
},
11+
"baseUrl": ".",
12+
"rootDir": ".",
13+
"types": ["node", "jest"],
14+
"noImplicitAny": false,
15+
"noImplicitThis": false,
16+
"strictPropertyInitialization": false,
17+
"resolveJsonModule": true,
18+
"allowJs": true
19+
}
20+
}

packages/replay/config/tsconfig.base.json renamed to packages/replay/tsconfig.worker.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
"esModuleInterop": true,
88
"resolveJsonModule": true,
99
"skipLibCheck": true,
10-
"target": "es5"
10+
"target": "es6",
11+
"declaration": false,
12+
"lib": ["webworker", "scripthost"],
13+
"baseUrl": "worker/src",
14+
"rootDir": "worker/src",
15+
"outDir": "src/worker"
1116
},
17+
"include": ["worker/src/worker.ts", "src/types.ts"],
1218
"exclude": ["node_modules"]
1319
}

packages/replay/worker/src/Compressor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class Compressor {
99
/**
1010
* Number of added events
1111
*/
12-
public added: number;
12+
public added: number = 0;
1313

1414
public constructor() {
1515
this.init();

0 commit comments

Comments
 (0)