Skip to content

Commit c17b752

Browse files
authored
ref(build): Build types separately (#4724)
As part of the new bundling process, the splits the building of types off into its own build step. Key changes: - A new, types-specific tsconfig in each package, which generates types only, and a todo in the main tsconfig.json for turning off the current type generation in `dist/` and `esm/`. (It's not turned off now in order to not break anyone importing directly from those folders instead of from `@sentry/xxxx`. We'll flip the switch come v7, but for now we're just generating both.) This types tsconfig is also added to the templates. - New yarn scripts for generating types (in regular and watch versions), and the addition of this script to other build commands. - A node script for running the repo-wide `yarn:build:types` command, which solves the problem of the watch build hanging if a regular build hasn't happened first. As explained at the top of the script: > If `yarn build:types:watch` is run without types files previously having been created, the build will get stuck in an errored state. This happens because lerna runs all of the packages' `yarn build:types:watch` statements in parallel, and so packages like `@sentry/browser` will at first be missing types they import from packages like `@sentry/utils` and `@sentry/types`, causing errors to be thrown. Normally this is fine, because as the dependencies' types get built, file changes will be detected and the dependent packages' types will try again to build themselves. There might be several rounds of this, but in theory, eventually all packages should end up with an error-free build. For whatever reason, though, at a certain point the process hangs, either because changes stop being detected or because recompiles stop being triggered by detected changes. > > Either way, the process gets stuck. The solution is to run a sequential build first, because as long as there are existing files the first time the watch command runs, no subsequent changes ever cause a hang, no matter how many rounds of recompilation are needed. (It's not entirely clear why this is the case.) We only want to take the time to do that if we have to, though, so we first check all of the relevant packages to see if there are pre-existing types files. - A change to the `types` entry in all package.json files, to point to the types generated using the new tsconfig and the new scripts.
1 parent 75768e3 commit c17b752

38 files changed

+388
-59
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
"build:dev:filter": "lerna run --stream --concurrency 1 --sort build:dev --include-filtered-dependencies --include-filtered-dependents --scope",
99
"build:es5": "yarn lerna run --stream --concurrency 1 --sort build:cjs # *** backwards compatibility - remove in v7 ***",
1010
"build:esm": "lerna run --stream --concurrency 1 --sort build:esm",
11+
"build:types": "lerna run --stream --concurrency 1 --sort build:types",
1112
"build:watch": "lerna run --parallel build:watch",
1213
"build:dev:watch": "lerna run --parallel build:dev:watch",
14+
"build:types:watch": "ts-node scripts/build-types-watch.ts",
1315
"circularDepCheck": "lerna run --parallel circularDepCheck",
1416
"clean": "lerna run --parallel clean && lerna clean --yes",
1517
"codecov": "codecov",
@@ -82,6 +84,8 @@
8284
"sinon": "^7.3.2",
8385
"size-limit": "^4.5.5",
8486
"ts-jest": "^24.3.0",
87+
"ts-node": "^10.7.0",
88+
"tslib": "^2.3.1",
8589
"typedoc": "^0.18.0",
8690
"typescript": "3.7.5"
8791
},

packages/angular/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"main": "dist/index.js",
1313
"module": "esm/index.js",
14-
"types": "dist/index.d.ts",
14+
"types": "build/types/index.d.ts",
1515
"publishConfig": {
1616
"access": "public"
1717
},
@@ -33,16 +33,18 @@
3333
"@angular/router": "^10.0.3"
3434
},
3535
"scripts": {
36-
"build": "run-p build:cjs build:esm",
36+
"build": "run-p build:cjs build:esm build:types",
3737
"build:cjs": "tsc -p tsconfig.cjs.json",
3838
"build:dev": "run-s build",
3939
"build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***",
4040
"build:esm": "tsc -p tsconfig.esm.json",
41-
"build:watch": "run-p build:cjs:watch build:esm:watch",
41+
"build:types": "tsc -p tsconfig.types.json",
42+
"build:watch": "run-p build:cjs:watch build:esm:watch build:types:watch",
4243
"build:cjs:watch": "tsc -p tsconfig.cjs.json --watch",
4344
"build:dev:watch": "run-s build:watch",
4445
"build:es5:watch": "yarn build:cjs:watch # *** backwards compatibility - remove in v7 ***",
4546
"build:esm:watch": "tsc -p tsconfig.esm.json --watch",
47+
"build:types:watch": "tsc -p tsconfig.types.json --watch",
4648
"circularDepCheck": "madge --circular src/index.ts",
4749
"clean": "rimraf dist esm build coverage",
4850
"fix": "run-s fix:eslint fix:prettier",

packages/angular/tsconfig.types.json

Lines changed: 10 additions & 0 deletions
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/types"
9+
}
10+
}

packages/browser/package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"main": "dist/index.js",
1313
"module": "esm/index.js",
14-
"types": "dist/index.d.ts",
14+
"types": "build/types/index.d.ts",
1515
"publishConfig": {
1616
"access": "public"
1717
},
@@ -44,18 +44,20 @@
4444
"webpack": "^4.30.0"
4545
},
4646
"scripts": {
47-
"build": "run-p build:cjs build:esm build:bundle",
47+
"build": "run-p build:cjs build:esm build:bundle build:types",
4848
"build:bundle": "rollup --config",
4949
"build:cjs": "tsc -p tsconfig.cjs.json",
50-
"build:dev": "run-p build:cjs build:esm",
50+
"build:dev": "run-p build:cjs build:esm build:types",
5151
"build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***",
5252
"build:esm": "tsc -p tsconfig.esm.json",
53-
"build:watch": "run-p build:cjs:watch build:esm:watch build:bundle:watch",
53+
"build:types": "tsc -p tsconfig.types.json",
54+
"build:watch": "run-p build:cjs:watch build:esm:watch build:bundle:watch build:types:watch",
5455
"build:bundle:watch": "rollup --config --watch",
5556
"build:cjs:watch": "tsc -p tsconfig.cjs.json --watch",
5657
"build:es5:watch": "yarn build:cjs:watch # *** backwards compatibility - remove in v7 ***",
57-
"build:dev:watch": "run-p build:cjs:watch build:esm:watch",
58+
"build:dev:watch": "run-p build:cjs:watch build:esm:watch build:types:watch",
5859
"build:esm:watch": "tsc -p tsconfig.esm.json --watch",
60+
"build:types:watch": "tsc -p tsconfig.types.json --watch",
5961
"circularDepCheck": "madge --circular src/index.ts",
6062
"clean": "rimraf dist esm build coverage .rpt2_cache",
6163
"fix": "run-s fix:eslint fix:prettier",

packages/browser/tsconfig.types.json

Lines changed: 10 additions & 0 deletions
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/types"
9+
}
10+
}

packages/core/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"main": "dist/index.js",
1313
"module": "esm/index.js",
14-
"types": "dist/index.d.ts",
14+
"types": "build/types/index.d.ts",
1515
"publishConfig": {
1616
"access": "public"
1717
},
@@ -23,16 +23,18 @@
2323
"tslib": "^1.9.3"
2424
},
2525
"scripts": {
26-
"build": "run-p build:cjs build:esm",
26+
"build": "run-p build:cjs build:esm build:types",
2727
"build:cjs": "tsc -p tsconfig.cjs.json",
2828
"build:dev": "run-s build",
2929
"build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***",
3030
"build:esm": "tsc -p tsconfig.esm.json",
31-
"build:watch": "run-p build:cjs:watch build:esm:watch",
31+
"build:types": "tsc -p tsconfig.types.json",
32+
"build:watch": "run-p build:cjs:watch build:esm:watch build:types:watch",
3233
"build:cjs:watch": "tsc -p tsconfig.cjs.json --watch",
3334
"build:dev:watch": "run-s build:watch",
3435
"build:es5:watch": "yarn build:cjs:watch # *** backwards compatibility - remove in v7 ***",
3536
"build:esm:watch": "tsc -p tsconfig.esm.json --watch",
37+
"build:types:watch": "tsc -p tsconfig.types.json --watch",
3638
"circularDepCheck": "madge --circular src/index.ts",
3739
"clean": "rimraf dist esm coverage",
3840
"fix": "run-s fix:eslint fix:prettier",

packages/core/tsconfig.types.json

Lines changed: 10 additions & 0 deletions
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/types"
9+
}
10+
}

packages/gatsby/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
"main": "dist/index.js",
1717
"module": "esm/index.js",
18-
"types": "dist/index.d.ts",
18+
"types": "build/types/index.d.ts",
1919
"files": [
2020
"/dist",
2121
"/esm",
@@ -40,16 +40,18 @@
4040
"react": "^17.0.0"
4141
},
4242
"scripts": {
43-
"build": "run-p build:cjs build:esm",
43+
"build": "run-p build:cjs build:esm build:types",
4444
"build:cjs": "tsc -p tsconfig.cjs.json",
4545
"build:dev": "run-s build",
4646
"build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***",
4747
"build:esm": "tsc -p tsconfig.esm.json",
48-
"build:watch": "run-p build:cjs:watch build:esm:watch",
48+
"build:types": "tsc -p tsconfig.types.json",
49+
"build:watch": "run-p build:cjs:watch build:esm:watch build:types:watch",
4950
"build:cjs:watch": "tsc -p tsconfig.cjs.json --watch",
5051
"build:dev:watch": "run-s build:watch",
5152
"build:es5:watch": "yarn build:cjs:watch # *** backwards compatibility - remove in v7 ***",
5253
"build:esm:watch": "tsc -p tsconfig.esm.json --watch",
54+
"build:types:watch": "tsc -p tsconfig.types.json --watch",
5355
"circularDepCheck": "madge --circular src/index.ts",
5456
"clean": "rimraf dist esm build coverage",
5557
"fix": "run-s fix:eslint fix:prettier",

packages/gatsby/tsconfig.types.json

Lines changed: 10 additions & 0 deletions
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/types"
9+
}
10+
}

packages/hub/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"main": "dist/index.js",
1313
"module": "esm/index.js",
14-
"types": "dist/index.d.ts",
14+
"types": "build/types/index.d.ts",
1515
"publishConfig": {
1616
"access": "public"
1717
},
@@ -21,16 +21,18 @@
2121
"tslib": "^1.9.3"
2222
},
2323
"scripts": {
24-
"build": "run-p build:cjs build:esm",
24+
"build": "run-p build:cjs build:esm build:types",
2525
"build:cjs": "tsc -p tsconfig.cjs.json",
2626
"build:dev": "run-s build",
2727
"build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***",
2828
"build:esm": "tsc -p tsconfig.esm.json",
29-
"build:watch": "run-p build:cjs:watch build:esm:watch",
29+
"build:types": "tsc -p tsconfig.types.json",
30+
"build:watch": "run-p build:cjs:watch build:esm:watch build:types:watch",
3031
"build:cjs:watch": "tsc -p tsconfig.cjs.json --watch",
3132
"build:dev:watch": "run-s build:watch",
3233
"build:es5:watch": "yarn build:cjs:watch # *** backwards compatibility - remove in v7 ***",
3334
"build:esm:watch": "tsc -p tsconfig.esm.json --watch",
35+
"build:types:watch": "tsc -p tsconfig.types.json --watch",
3436
"circularDepCheck": "madge --circular src/index.ts",
3537
"clean": "rimraf dist esm coverage",
3638
"fix": "run-s fix:eslint fix:prettier",

packages/hub/tsconfig.types.json

Lines changed: 10 additions & 0 deletions
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/types"
9+
}
10+
}

packages/integrations/package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"main": "dist/index.js",
1616
"module": "esm/index.js",
17-
"types": "dist/index.d.ts",
17+
"types": "build/types/index.d.ts",
1818
"dependencies": {
1919
"@sentry/types": "6.18.2",
2020
"@sentry/utils": "6.18.2",
@@ -25,17 +25,19 @@
2525
"chai": "^4.1.2"
2626
},
2727
"scripts": {
28-
"build": "run-p build:cjs build:esm build:bundle",
28+
"build": "run-p build:cjs build:esm build:types build:bundle",
2929
"build:bundle": "bash scripts/buildBundles.sh",
3030
"build:cjs": "tsc -p tsconfig.cjs.json",
31-
"build:dev": "run-s build:cjs build:esm",
31+
"build:dev": "run-s build:cjs build:esm build:types",
3232
"build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***",
3333
"build:esm": "tsc -p tsconfig.esm.json",
34-
"build:watch": "run-p build:cjs:watch build:esm:watch",
34+
"build:types": "tsc -p tsconfig.types.json",
35+
"build:watch": "run-p build:cjs:watch build:esm:watch build:types:watch",
3536
"build:cjs:watch": "tsc -p tsconfig.cjs.json --watch",
3637
"build:dev:watch": "run-s build:watch",
3738
"build:es5:watch": "yarn build:cjs:watch # *** backwards compatibility - remove in v7 ***",
3839
"build:esm:watch": "tsc -p tsconfig.esm.json --watch",
40+
"build:types:watch": "tsc -p tsconfig.types.json --watch",
3941
"circularDepCheck": "madge --circular src/index.ts",
4042
"clean": "rimraf dist esm build coverage .rpt2_cache",
4143
"fix": "run-s fix:eslint fix:prettier",
Lines changed: 10 additions & 0 deletions
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/types"
9+
}
10+
}

packages/minimal/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"main": "dist/index.js",
1313
"module": "esm/index.js",
14-
"types": "dist/index.d.ts",
14+
"types": "build/types/index.d.ts",
1515
"publishConfig": {
1616
"access": "public"
1717
},
@@ -21,16 +21,18 @@
2121
"tslib": "^1.9.3"
2222
},
2323
"scripts": {
24-
"build": "run-p build:cjs build:esm",
24+
"build": "run-p build:cjs build:esm build:types",
2525
"build:cjs": "tsc -p tsconfig.cjs.json",
2626
"build:dev": "run-s build",
2727
"build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***",
2828
"build:esm": "tsc -p tsconfig.esm.json",
29-
"build:watch": "run-p build:cjs:watch build:esm:watch",
29+
"build:types": "tsc -p tsconfig.types.json",
30+
"build:watch": "run-p build:cjs:watch build:esm:watch build:types:watch",
3031
"build:cjs:watch": "tsc -p tsconfig.cjs.json --watch",
3132
"build:dev:watch": "run-s build:watch",
3233
"build:es5:watch": "yarn build:cjs:watch # *** backwards compatibility - remove in v7 ***",
3334
"build:esm:watch": "tsc -p tsconfig.esm.json --watch",
35+
"build:types:watch": "tsc -p tsconfig.types.json --watch",
3436
"circularDepCheck": "madge --circular src/index.ts",
3537
"clean": "rimraf dist esm coverage",
3638
"fix": "run-s fix:eslint fix:prettier",

packages/minimal/tsconfig.types.json

Lines changed: 10 additions & 0 deletions
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/types"
9+
}
10+
}

packages/nextjs/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"main": "./dist/index.server.js",
1313
"module": "./esm/index.server.js",
1414
"browser": "./esm/index.client.js",
15-
"types": "./esm/index.server.d.ts",
15+
"types": "./build/types/index.server.d.ts",
1616
"publishConfig": {
1717
"access": "public"
1818
},
@@ -43,16 +43,18 @@
4343
}
4444
},
4545
"scripts": {
46-
"build": "run-p build:cjs build:esm",
46+
"build": "run-p build:cjs build:esm build:types",
4747
"build:cjs": "tsc -p tsconfig.cjs.json",
4848
"build:dev": "run-s build",
4949
"build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***",
5050
"build:esm": "tsc -p tsconfig.esm.json",
51-
"build:watch": "run-p build:cjs:watch build:esm:watch",
51+
"build:types": "tsc -p tsconfig.types.json",
52+
"build:watch": "run-p build:cjs:watch build:esm:watch build:types:watch",
5253
"build:cjs:watch": "tsc -p tsconfig.cjs.json --watch",
5354
"build:dev:watch": "run-s build:watch",
5455
"build:es5:watch": "yarn build:cjs:watch # *** backwards compatibility - remove in v7 ***",
5556
"build:esm:watch": "tsc -p tsconfig.esm.json --watch",
57+
"build:types:watch": "tsc -p tsconfig.types.json --watch",
5658
"circularDepCheck": "madge --circular src/index.client.ts && madge --circular --exclude 'config/types\\.ts' src/index.server.ts # see https://github.com/pahen/madge/issues/306",
5759
"clean": "rimraf dist esm coverage *.js *.js.map *.d.ts",
5860
"fix": "run-s fix:eslint fix:prettier",

packages/nextjs/tsconfig.types.json

Lines changed: 10 additions & 0 deletions
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/types"
9+
}
10+
}

packages/node/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"main": "dist/index.js",
1313
"module": "esm/index.js",
14-
"types": "dist/index.d.ts",
14+
"types": "build/types/index.d.ts",
1515
"publishConfig": {
1616
"access": "public"
1717
},
@@ -34,16 +34,18 @@
3434
"nock": "^13.0.5"
3535
},
3636
"scripts": {
37-
"build": "run-p build:cjs build:esm",
37+
"build": "run-p build:cjs build:esm build:types",
3838
"build:cjs": "tsc -p tsconfig.cjs.json",
3939
"build:dev": "run-s build",
4040
"build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***",
4141
"build:esm": "tsc -p tsconfig.esm.json",
42-
"build:watch": "run-p build:cjs:watch build:esm:watch",
42+
"build:types": "tsc -p tsconfig.types.json",
43+
"build:watch": "run-p build:cjs:watch build:esm:watch build:types:watch",
4344
"build:cjs:watch": "tsc -p tsconfig.cjs.json --watch",
4445
"build:dev:watch": "run-s build:watch",
4546
"build:es5:watch": "yarn build:cjs:watch # *** backwards compatibility - remove in v7 ***",
4647
"build:esm:watch": "tsc -p tsconfig.esm.json --watch",
48+
"build:types:watch": "tsc -p tsconfig.types.json --watch",
4749
"circularDepCheck": "madge --circular src/index.ts",
4850
"clean": "rimraf dist esm coverage",
4951
"fix": "run-s fix:eslint fix:prettier",

packages/node/tsconfig.types.json

Lines changed: 10 additions & 0 deletions
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/types"
9+
}
10+
}

0 commit comments

Comments
 (0)