Skip to content

Commit bf36d54

Browse files
authored
ref(dev): Unify typescript config files (#4178)
This PR unifies and standardizes our typescript config files, with the goal of making them easier to reason about and easier to maintain. The two key changes are the simplification of the inheritance between various `tsconfig` files and the addition of standardized templates for each type of `tsconfig` file. In the new inheritance structure, - `tsconfig.x.json` files now only exist at the package level, and all inherit from their sibling `tsconfig.json`, - package-level `tsconfig.json` files all inherit from the repo-level `tsconfig.json`, and - the repo-level `tsconfig.json` inherits from `@sentry/typescript`'s `tsconfig.json`. In other words, the inheritance tree now looks like this: ``` tsconfig.json (@sentry/typescript) | | tsconfig.json (sentry-javascript) / \ / \ packages/angular (same structure for other packages) | | tsconfig.json / | \ / | \ tsconfig.esm.json | tsconfig.test.json | tsconfig.cjs.json ``` This new structure allowed for a few other changes: - Configuration for tests has been split into a separate `tsconfig.test.json`. This allows the `include` values to be specific to either source code or tests, which in turn allows `rootDir` to be calculated automatically (as the closest common ancestor of all included files). - All `tsconfig.build.json` files have been renamed to `tsconfig.cjs.json`, for parallel naming structure with existing `tsconfig.esm.json` files. - Both `tsconfig.cjs.json` and `tsconfig.esm.json` have been boiled down to only what makes them cjs- or esm-y (their `module` value and output directory), with all package-level config moved to the package's main `tsconfig.json`. (It was previously repeated in each file). Note: technically the `module: "commonjs"` in the cjs files is redundant, since it's implied by the `target: "es5"` in `@sentry/typescript`'s tsconfig, but I decided to include it, both for parallel structure with the esm files and because, as mentioned, it's the essence of _being_ cjs. - Since everything now inherits from the repo-level `tsconfig.json`, which currently includes node types, all node types elsewhere could be (and have been) removed. Other notable changes: - `yarn` workspaces (which we already have set up) can handle the cross-package dependencies we were managing through the repo-level `paths` setting, so that setting has been removed, allowing both its accompanying `baseUrl` setting and the package-level `baseUrl` settings necessary to override the top-level `baseUrl` setting to be removed. - `declarationMap: false` has been removed from the spots that had it, since it hurts nothing to generate declaration maps and this lets us standardize on the `true` value set in `@sentry/typescript`. - All `exclude` settings have been removed, since they excluded files which were never in the in `include` in the first place. - All `include` settings have been simplified to just include everything in the relevant directory, to take advantage of typescript's default of including all `.js`, `.jsx`, `.ts`, and `.tsx` files. - `eslint` settings have been adjusted to account for the separation of the test config into its own file. - `package.json` scripts have been adjusted to account for the `build` -> `cjs` renaming. The old `es5` scripts have been retained, for backwards compatibility (I don't know of any place which uses them directly, but just in case), with a note to remove them in v7, and they now point to the new `cjs` scripts. - rollup config files were adjusted to use `tsconfig.esm.json` rather than `tsconfig.cjs.json` (obviating the need to specify the module), and the `baseUrl` and `declarationMap` settings removed from the main tsconfigs were ported to the rollup config (where they're actually necessary). I validated these changes by building bundles, cjs, and esm files both under master and this branch, and then comparing the outputs using `git diff` to verify that they were identical. The script I used can be found in the PR description.
1 parent 16b9c79 commit bf36d54

File tree

109 files changed

+649
-418
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+649
-418
lines changed

.eslintrc.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Note: All paths are relative to the directory in which eslint is being run, rather than the directory where this file
2+
// lives
3+
14
module.exports = {
25
root: true,
36
env: {
@@ -7,20 +10,18 @@ module.exports = {
710
ecmaVersion: 2018,
811
},
912
extends: ['@sentry-internal/sdk'],
10-
ignorePatterns: [
11-
'coverage/**',
12-
'build/**',
13-
'dist/**',
14-
'esm/**',
15-
'examples/**',
16-
'scripts/**',
17-
'test/manual/**',
18-
],
13+
ignorePatterns: ['coverage/**', 'build/**', 'dist/**', 'esm/**', 'examples/**', 'scripts/**', 'test/manual/**'],
1914
overrides: [
2015
{
2116
files: ['*.ts', '*.tsx', '*.d.ts'],
2217
parserOptions: {
23-
project: './tsconfig.json',
18+
project: ['tsconfig.json'],
19+
},
20+
},
21+
{
22+
files: ['test/**/*.ts', 'test/**/*.tsx'],
23+
parserOptions: {
24+
project: ['tsconfig.test.json'],
2425
},
2526
},
2627
{

packages/angular/package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@
3737
"typescript": "3.7.5"
3838
},
3939
"scripts": {
40-
"build": "run-p build:es5 build:esm",
40+
"build": "run-p build:cjs build:esm",
41+
"build:cjs": "tsc -p tsconfig.cjs.json",
4142
"build:dev": "run-s build",
42-
"build:es5": "tsc -p tsconfig.build.json",
43+
"build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***",
4344
"build:esm": "tsc -p tsconfig.esm.json",
44-
"build:watch": "run-p build:es5:watch build:esm:watch",
45+
"build:watch": "run-p build:cjs:watch build:esm:watch",
46+
"build:cjs:watch": "tsc -p tsconfig.cjs.json -w --preserveWatchOutput",
4547
"build:dev:watch": "run-s build:watch",
46-
"build:es5:watch": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
48+
"build:es5:watch": "yarn build:cjs:watch # *** backwards compatibility - remove in v7 ***",
4749
"build:esm:watch": "tsc -p tsconfig.esm.json -w --preserveWatchOutput",
4850
"circularDepCheck": "madge --circular src/index.ts",
4951
"clean": "rimraf dist esm build coverage",

packages/angular/tsconfig.build.json

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

packages/angular/tsconfig.cjs.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
4+
"compilerOptions": {
5+
"module": "commonjs",
6+
"outDir": "dist"
7+
}
8+
}

packages/angular/tsconfig.esm.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
{
2-
"extends": "../../tsconfig.esm.json",
2+
"extends": "./tsconfig.json",
3+
34
"compilerOptions": {
4-
"baseUrl": ".",
5-
"outDir": "esm",
6-
"experimentalDecorators": true
7-
},
8-
"include": ["src/**/*"]
5+
"module": "es6",
6+
"outDir": "esm"
7+
}
98
}

packages/angular/tsconfig.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
2-
"extends": "./tsconfig.build.json",
3-
"include": ["src/**/*.ts"],
4-
"exclude": ["dist"],
2+
"extends": "../../tsconfig.json",
3+
4+
"include": ["src/**/*"],
5+
56
"compilerOptions": {
6-
"rootDir": "."
7+
// package-specific options
8+
"experimentalDecorators": true
79
}
810
}

packages/angular/tsconfig.test.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
4+
"include": ["test/**/*"],
5+
6+
"compilerOptions": {
7+
// should include all types from `./tsconfig.json` plus types for all test frameworks used
8+
"types": ["jest"]
9+
10+
// other package-specific, test-specific options
11+
}
12+
}

packages/browser/package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,17 @@
5454
"webpack": "^4.30.0"
5555
},
5656
"scripts": {
57-
"build": "run-s build:es5 build:esm build:bundle",
57+
"build": "run-p build:cjs build:esm build:bundle",
5858
"build:bundle": "rollup --config",
59-
"build:dev": "run-s build:es5 build:esm",
60-
"build:es5": "tsc -p tsconfig.build.json",
59+
"build:cjs": "tsc -p tsconfig.cjs.json",
60+
"build:dev": "run-p build:cjs build:esm",
61+
"build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***",
6162
"build:esm": "tsc -p tsconfig.esm.json",
62-
"build:watch": "run-p build:es5:watch build:esm:watch build:bundle:watch",
63+
"build:watch": "run-p build:cjs:watch build:esm:watch build:bundle:watch",
6364
"build:bundle:watch": "rollup --config --watch",
64-
"build:dev:watch": "run-p build:es5:watch build:esm:watch",
65-
"build:es5:watch": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
65+
"build:cjs:watch": "tsc -p tsconfig.cjs.json -w --preserveWatchOutput",
66+
"build:es5:watch": "yarn build:cjs:watch # *** backwards compatibility - remove in v7 ***",
67+
"build:dev:watch": "run-p build:cjs:watch build:esm:watch",
6668
"build:esm:watch": "tsc -p tsconfig.esm.json -w --preserveWatchOutput",
6769
"circularDepCheck": "madge --circular src/index.ts",
6870
"clean": "rimraf dist esm build coverage .rpt2_cache",

packages/browser/rollup.config.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ const paths = {
3737

3838
const plugins = [
3939
typescript({
40-
tsconfig: 'tsconfig.build.json',
40+
tsconfig: 'tsconfig.esm.json',
4141
tsconfigOverride: {
4242
compilerOptions: {
4343
declaration: false,
4444
declarationMap: false,
45-
module: 'ES2015',
4645
paths,
46+
baseUrl: '.',
4747
},
4848
},
4949
include: ['*.ts+(|x)', '**/*.ts+(|x)', '../**/*.ts+(|x)'],
@@ -103,13 +103,13 @@ export default [
103103
},
104104
plugins: [
105105
typescript({
106-
tsconfig: 'tsconfig.build.json',
106+
tsconfig: 'tsconfig.esm.json',
107107
tsconfigOverride: {
108108
compilerOptions: {
109109
declaration: false,
110110
declarationMap: false,
111-
module: 'ES2015',
112111
paths,
112+
baseUrl: '.',
113113
target: 'es6',
114114
},
115115
},
@@ -126,13 +126,13 @@ export default [
126126
},
127127
plugins: [
128128
typescript({
129-
tsconfig: 'tsconfig.build.json',
129+
tsconfig: 'tsconfig.esm.json',
130130
tsconfigOverride: {
131131
compilerOptions: {
132132
declaration: false,
133133
declarationMap: false,
134-
module: 'ES2015',
135134
paths,
135+
baseUrl: '.',
136136
target: 'es6',
137137
},
138138
},

packages/browser/tsconfig.build.json

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

packages/browser/tsconfig.cjs.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
4+
"compilerOptions": {
5+
"module": "commonjs",
6+
"outDir": "dist"
7+
}
8+
}

packages/browser/tsconfig.esm.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"extends": "../../tsconfig.esm.json",
2+
"extends": "./tsconfig.json",
3+
34
"compilerOptions": {
4-
"baseUrl": ".",
5+
"module": "es6",
56
"outDir": "esm"
6-
},
7-
"include": ["src/**/*"]
7+
}
88
}

packages/browser/tsconfig.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"extends": "./tsconfig.build.json",
3-
"include": ["src/**/*", "test/**/*"],
4-
"exclude": ["dist"],
2+
"extends": "../../tsconfig.json",
3+
4+
"include": ["src/**/*"],
5+
56
"compilerOptions": {
6-
"rootDir": ".",
7-
"types": ["node", "mocha", "chai", "sinon", "jest"]
7+
// package-specific options
88
}
99
}

packages/browser/tsconfig.test.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
4+
"include": ["test/**/*"],
5+
6+
"compilerOptions": {
7+
// should include all types from `./tsconfig.json` plus types for all test frameworks used
8+
"types": ["node", "mocha", "chai", "sinon", "jest"]
9+
10+
// other package-specific, test-specific options
11+
}
12+
}

packages/core/package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@
3030
"typescript": "3.7.5"
3131
},
3232
"scripts": {
33-
"build": "run-p build:es5 build:esm",
33+
"build": "run-p build:cjs build:esm",
34+
"build:cjs": "tsc -p tsconfig.cjs.json",
3435
"build:dev": "run-s build",
35-
"build:es5": "tsc -p tsconfig.build.json",
36+
"build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***",
3637
"build:esm": "tsc -p tsconfig.esm.json",
37-
"build:watch": "run-p build:es5:watch build:esm:watch",
38+
"build:watch": "run-p build:cjs:watch build:esm:watch",
39+
"build:cjs:watch": "tsc -p tsconfig.cjs.json -w --preserveWatchOutput",
3840
"build:dev:watch": "run-s build:watch",
39-
"build:es5:watch": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
41+
"build:es5:watch": "yarn build:cjs:watch # *** backwards compatibility - remove in v7 ***",
4042
"build:esm:watch": "tsc -p tsconfig.esm.json -w --preserveWatchOutput",
4143
"circularDepCheck": "madge --circular src/index.ts",
4244
"clean": "rimraf dist esm coverage",

packages/core/tsconfig.build.json

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

packages/core/tsconfig.cjs.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
4+
"compilerOptions": {
5+
"module": "commonjs",
6+
"outDir": "dist"
7+
}
8+
}

packages/core/tsconfig.esm.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"extends": "../../tsconfig.esm.json",
2+
"extends": "./tsconfig.json",
3+
34
"compilerOptions": {
4-
"baseUrl": ".",
5+
"module": "es6",
56
"outDir": "esm"
6-
},
7-
"include": ["src/**/*"]
7+
}
88
}

packages/core/tsconfig.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"extends": "./tsconfig.build.json",
3-
"include": ["src/**/*.ts", "test/**/*.ts"],
4-
"exclude": ["dist"],
2+
"extends": "../../tsconfig.json",
3+
4+
"include": ["src/**/*"],
5+
56
"compilerOptions": {
6-
"rootDir": ".",
7-
"types": ["node", "jest"]
7+
// package-specific options
88
}
99
}

packages/core/tsconfig.test.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
4+
"include": ["test/**/*"],
5+
6+
"compilerOptions": {
7+
// should include all types from `./tsconfig.json` plus types for all test frameworks used
8+
"types": ["node", "jest"]
9+
10+
// other package-specific, test-specific options
11+
}
12+
}

packages/gatsby/package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,15 @@
4444
"typescript": "3.7.5"
4545
},
4646
"scripts": {
47-
"build": "run-p build:es5 build:esm",
47+
"build": "run-p build:cjs build:esm",
48+
"build:cjs": "tsc -p tsconfig.cjs.json",
4849
"build:dev": "run-s build",
49-
"build:es5": "tsc -p tsconfig.build.json",
50+
"build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***",
5051
"build:esm": "tsc -p tsconfig.esm.json",
51-
"build:watch": "run-p build:es5:watch build:esm:watch",
52+
"build:watch": "run-p build:cjs:watch build:esm:watch",
53+
"build:cjs:watch": "tsc -p tsconfig.cjs.json -w --preserveWatchOutput",
5254
"build:dev:watch": "run-s build:watch",
53-
"build:es5:watch": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
55+
"build:es5:watch": "yarn build:cjs:watch # *** backwards compatibility - remove in v7 ***",
5456
"build:esm:watch": "tsc -p tsconfig.esm.json -w --preserveWatchOutput",
5557
"circularDepCheck": "madge --circular src/index.ts",
5658
"clean": "rimraf dist esm build coverage",

packages/gatsby/tsconfig.build.json

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

packages/gatsby/tsconfig.cjs.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
4+
"compilerOptions": {
5+
"module": "commonjs",
6+
"outDir": "dist"
7+
}
8+
}

packages/gatsby/tsconfig.esm.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
{
2-
"extends": "../../tsconfig.esm.json",
2+
"extends": "./tsconfig.json",
3+
34
"compilerOptions": {
4-
"esModuleInterop": true,
5-
"baseUrl": ".",
6-
"outDir": "esm",
7-
"jsx": "react"
8-
},
9-
"include": ["src/**/*"]
5+
"module": "es6",
6+
"outDir": "esm"
7+
}
108
}

0 commit comments

Comments
 (0)