Skip to content

chore(replay): Align and clean up tsconfig.jsons #6308

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 10 commits into from
Nov 29, 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
13 changes: 6 additions & 7 deletions packages/replay/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
files: ['worker/**/*.ts'],
parserOptions: {
// TODO: figure out if we need a worker-specific tsconfig
project: ['config/tsconfig.worker.json'],
project: ['tsconfig.worker.json'],
},
},
{
Expand Down Expand Up @@ -68,18 +68,17 @@ module.exports = {
},
},
{
files: ['jest.setup.ts'],
files: ['jest.setup.ts', 'jest.config.ts'],
parserOptions: {
project: ['tsconfig.test.json'],
},
rules: {
'no-console': 'off',
},
},
{
files: ['test/**/*.ts'],
parserOptions: {
// TODO: remove this parserOptions object after we added a tsconfig.test.json
// Replay previously didn't have a tsconfig.test.json, so for now we just the regular one.
project: ['tsconfig.json'],
},

rules: {
// TODO: decide if we want to keep our '@test' import paths
'import/no-unresolved': 'off',
Expand Down
2 changes: 1 addition & 1 deletion packages/replay/config/rollup.config.core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const config = defineConfig({
external: [...Object.keys(pkg.dependencies || {})],
plugins: [
typescript({
tsconfig: IS_PRODUCTION ? './config/tsconfig.core.json' : './tsconfig.json',
tsconfig: './tsconfig.json',
}),
replace({
// __SENTRY_DEBUG__ should be save to replace in any case, so no checks for assignments necessary
Expand Down
2 changes: 1 addition & 1 deletion packages/replay/config/rollup.config.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const config = defineConfig({
format: 'esm',
},
plugins: [
typescript({ tsconfig: './config/tsconfig.worker.json' }),
typescript({ tsconfig: './tsconfig.worker.json' }),
resolve(),
terser({
mangle: {
Expand Down
14 changes: 0 additions & 14 deletions packages/replay/config/tsconfig.core.json

This file was deleted.

11 changes: 0 additions & 11 deletions packages/replay/config/tsconfig.worker.json

This file was deleted.

17 changes: 9 additions & 8 deletions packages/replay/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import type { Config } from '@jest/types';
import { pathsToModuleNameMapper } from 'ts-jest';
import { jsWithTs as jsWithTsPreset } from 'ts-jest/presets';

import { compilerOptions } from './tsconfig.json';
import { compilerOptions } from './tsconfig.test.json';

export default async (): Promise<Config.InitialOptions> => {
return {
...jsWithTsPreset,
verbose: true,
preset: 'ts-jest/presets/js-with-ts', // needed when import worker.js
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.test.json',
},
__DEBUG_BUILD__: true,
},
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
prefix: '<rootDir>/',
}),
setupFilesAfterEnv: ['./jest.setup.ts'],
testEnvironment: 'jsdom',
testMatch: ['<rootDir>/test/**/*(*.)@(spec|test).ts'],
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.json',
},
__DEBUG_BUILD__: true,
},
};
};
4 changes: 4 additions & 0 deletions packages/replay/src/createPerformanceEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ interface MemoryInfo {
}

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

Expand Down
2 changes: 1 addition & 1 deletion packages/replay/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class Replay implements Integration {
*/
public name: string = Replay.id;

public eventBuffer: IEventBuffer | null;
public eventBuffer: IEventBuffer | null = null;

/**
* List of PerformanceEntry from PerformanceObserver
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion packages/replay/src/util/captureInternalException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { isInternal } from './isInternal';
/**
* Captures exceptions to Sentry only when it occurs on sentry.io
*/
export function captureInternalException(err: Error): string | undefined {
export function captureInternalException(err: Error): void {
if (!isInternal()) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/replay/src/worker/worker.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions packages/replay/test/unit/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// TODO Once https://github.com/microsoft/TypeScript/issues/33094 is done (if it ever is), this file can disappear, as
// it's purely a placeholder to satisfy VSCode.

{
"extends": "../tsconfig.test.json",

"include": ["./**/*"]
}
2 changes: 1 addition & 1 deletion packages/replay/test/unit/util/isSampled.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isSampled } from '../../../src/util/isSampled';

// Note Math.random generates a value from 0 (inclusive) to <1 (1 exclusive).
const cases = [
const cases: [number, number, boolean][] = [
[1.0, 0.9999, true],
[1.0, 0.0, true],
[1.0, 0.5, true],
Expand Down
19 changes: 16 additions & 3 deletions packages/replay/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
{
"extends": "./config/tsconfig.core.json",
"extends": "../../tsconfig.json",
"compilerOptions": {
"paths": {
"@test": ["./test"],
"@test/*": ["./test/*"]
},
"types": ["node", "jest"]
"baseUrl": ".",
"rootDir": ".",
"types": ["node", "jest"],
"module": "esnext",
"noImplicitAny": true,
"noEmitOnError": false,
"esModuleInterop": true,
"resolveJsonModule": true,
"allowJs": true,
"declaration": true,
"declarationMap": true,
"declarationDir": "./types",
"strictNullChecks": true,
"outDir": "./build/npm/dist"
},
"include": ["src/**/*.ts", "test/**/*.ts", "rollup.config.ts", "jest.config.ts", "jest.setup.ts"],
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
}
20 changes: 20 additions & 0 deletions packages/replay/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": "./tsconfig.json",

"include": ["test/**/*.ts", "jest.config.ts", "jest.setup.ts"],

"compilerOptions": {
"paths": {
"@test": ["./test"],
"@test/*": ["./test/*"]
},
"baseUrl": ".",
"rootDir": ".",
"types": ["node", "jest"],
"noImplicitAny": false,
"noImplicitThis": false,
"strictPropertyInitialization": false,
"resolveJsonModule": true,
"allowJs": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
"esModuleInterop": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"target": "es5"
"target": "es6",
"declaration": false,
"lib": ["webworker", "scripthost"],
"baseUrl": "worker/src",
"rootDir": "worker/src",
"outDir": "src/worker"
},
"include": ["worker/src/worker.ts", "src/types.ts"],
"exclude": ["node_modules"]
}
2 changes: 1 addition & 1 deletion packages/replay/worker/src/Compressor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class Compressor {
/**
* Number of added events
*/
public added: number;
public added: number = 0;

public constructor() {
this.init();
Expand Down