Skip to content

Commit 5da86c5

Browse files
authored
build: update packages to use more modern moduleresolution options (#1770)
* refactor: rename tsconfig.cjs.json to tsconfig.esm.json * build: update packages to use more modern moduleresolution options This change updates tsconfigs across all packages to use more up to date `module` and `moduleResolution` options. For all packages that were being built as `commonjs` modules with node `moduleResolution`, they've been updated to use `nodenext`. I also took the opportunity to re-organize the tsconfigs at the packages level to make their names more accurate. Previously the main `packages/tsconfig.json`, which is what the `build:esm` command targetted, referenced all package's tsconfigs, while a `packages/tsconfig.cjs.json` only referenced the cjs tsconfig from the react package. However, all packages' tsconfigs _except_ for the react tsconfig are building cjs. So having a command that's called `build:esm` run all cjs builds and one esm build didn't really do what the name would suggest. So I reversed that construct. Now `packages/tsconfig.json` still references all of the packages tsconfig, except for the react package, it references the `tsconfig.cjs`, and I renamed the `packages/tsconfig.cjs.json` to `packages/tsconfig.esm.json` and have it only referencing the main react package tsconfig. The net / net is that `build:esm` is only building esm output and `build:cjs` is only building cjs output. Similarly, all package level tsconfigs are inheriting from packages/tsconfig.options.json, but that config had module and moduleResolution corresponding to the tsconfig in react (the ESM one), and all of the other package tsconfigs were overriding the module and moduleResolution. So I swapped that, so that the base config has the module and moduleResolution that all but on of the packages are using, and had the react tsconfig override that to what it needed to be for esm output. This means fewer tsconfigs are needing to override those options. Lastly, I've done build comparisons for all packages and target, and they all result in the same build output as they did before these changes.
1 parent 04f6280 commit 5da86c5

File tree

20 files changed

+23
-32
lines changed

20 files changed

+23
-32
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"postbuild": "scripts/postbuild.sh",
1616
"build:babel-fixture": "yarn workspace @compiled/babel-component-fixture build && yarn workspace @compiled/babel-component-extracted-fixture build",
1717
"build:browser": "ttsc --build packages/tsconfig.browser.json",
18-
"build:cjs": "ttsc --build packages/tsconfig.cjs.json",
19-
"build:esm": "ttsc --build packages/tsconfig.json",
18+
"build:cjs": "ttsc --build packages/tsconfig.json",
19+
"build:esm": "ttsc --build packages/tsconfig.esm.json",
2020
"build:inspect": "node --inspect-brk node_modules/typescript/lib/tsc.js --build packages",
2121
"build:parcel": "ttsc --build examples/parcel/tsconfig.json && yarn workspace @compiled/parcel-app build",
2222
"build:ssr": "CI=false && ttsc --build examples/ssr/tsconfig.json && yarn workspace @compiled/ssr-app build",

packages/babel-plugin-strip-runtime/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"extends": "../tsconfig.options.json",
33
"compilerOptions": {
44
"rootDir": "src",
5-
"outDir": "dist",
6-
"module": "commonjs"
5+
"outDir": "dist"
76
},
87
"references": [{ "path": "../babel-plugin" }, { "path": "../css" }]
98
}

packages/babel-plugin/tsconfig.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
{
22
"extends": "../tsconfig.options.json",
33
"compilerOptions": {
4-
"module": "commonjs",
5-
"outDir": "dist",
6-
"rootDir": "src"
4+
"rootDir": "src",
5+
"outDir": "dist"
76
},
87
"references": [{ "path": "../benchmark" }, { "path": "../css" }, { "path": "../utils" }]
98
}

packages/benchmark/tsconfig.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
{
22
"extends": "../tsconfig.options.json",
33
"compilerOptions": {
4-
"module": "commonjs",
5-
"outDir": "dist",
6-
"rootDir": "src"
4+
"rootDir": "src",
5+
"outDir": "dist"
76
},
87
"references": [{ "path": "../jest" }]
98
}

packages/codemods/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"extends": "../tsconfig.options.json",
33
"compilerOptions": {
44
"rootDir": "src",
5-
"outDir": "dist",
6-
"module": "commonjs"
5+
"outDir": "dist"
76
},
87
"references": [{ "path": "../jest" }, { "path": "../utils" }]
98
}

packages/css/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"extends": "../tsconfig.options.json",
33
"compilerOptions": {
44
"rootDir": "src",
5-
"outDir": "dist",
6-
"module": "commonjs"
5+
"outDir": "dist"
76
},
87
"references": [{ "path": "../utils" }]
98
}

packages/eslint-plugin/tsconfig.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
"compilerOptions": {
44
"rootDir": "src",
55
"outDir": "dist",
6-
"module": "nodenext",
7-
"moduleResolution": "nodenext",
86
"target": "es2017",
97
"plugins": [
108
{

packages/jest/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"extends": "../tsconfig.options.json",
33
"compilerOptions": {
44
"rootDir": "src",
5-
"outDir": "dist",
6-
"module": "commonjs"
5+
"outDir": "dist"
76
},
87
"references": []
98
}

packages/parcel-optimizer/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"compilerOptions": {
44
"rootDir": "src",
55
"outDir": "dist",
6-
"module": "commonjs",
76
"target": "es2017"
87
},
98
"references": [{ "path": "../css" }, { "path": "../jest" }]

packages/parcel-transformer-external/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"compilerOptions": {
44
"rootDir": "src",
55
"outDir": "dist",
6-
"module": "commonjs",
76
"target": "es2017"
87
},
98
"references": [{ "path": "../jest" }]

packages/parcel-transformer/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"compilerOptions": {
44
"rootDir": "src",
55
"outDir": "dist",
6-
"module": "commonjs",
76
"target": "es2017"
87
},
98
"references": [

packages/react/tsconfig.browser.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"extends": "./tsconfig.options.json",
33
"compilerOptions": {
44
"outDir": "dist/browser",
5+
"module": "es6",
6+
"moduleResolution": "node",
57
"plugins": [
68
{
79
"transform": "ts-transform-define",

packages/react/tsconfig.cjs.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"extends": "./tsconfig.options.json",
33
"compilerOptions": {
4-
"module": "commonjs",
54
"outDir": "dist/cjs",
65
"tsBuildInfoFile": "tsconfig.cjs.tsbuildinfo"
76
},

packages/react/tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"extends": "./tsconfig.options.json",
33
"compilerOptions": {
44
"outDir": "dist/esm",
5+
"module": "es6",
6+
"moduleResolution": "node",
57
"tsBuildInfoFile": "tsconfig.esm.tsbuildinfo"
68
},
79
"references": [{ "path": "../benchmark" }, { "path": "../jest" }, { "path": "../utils" }]

packages/tsconfig.cjs.json

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

packages/tsconfig.esm.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"files": [],
3+
"references": [{ "path": "react/tsconfig.json" }]
4+
}

packages/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
{ "path": "parcel-optimizer/tsconfig.json" },
1212
{ "path": "parcel-transformer/tsconfig.json" },
1313
{ "path": "parcel-transformer-external/tsconfig.json" },
14-
{ "path": "react/tsconfig.json" },
14+
{ "path": "react/tsconfig.cjs.json" },
1515
{ "path": "utils/tsconfig.json" },
1616
{ "path": "webpack-loader/tsconfig.json" }
1717
]

packages/tsconfig.options.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"forceConsistentCasingInFileNames": true,
88
"jsx": "react",
99
"lib": ["dom", "es2016", "es2017.object"],
10-
"module": "es6",
11-
"moduleResolution": "node",
10+
"module": "nodenext",
11+
"moduleResolution": "nodenext",
1212
"noImplicitReturns": true,
1313
"noImplicitThis": true,
1414
"noUnusedLocals": true,

packages/utils/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"extends": "../tsconfig.options.json",
33
"compilerOptions": {
44
"rootDir": "src",
5-
"outDir": "dist",
6-
"module": "commonjs"
5+
"outDir": "dist"
76
},
87
"references": [{ "path": "../jest" }]
98
}

packages/webpack-loader/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"compilerOptions": {
44
"rootDir": "src",
55
"outDir": "dist",
6-
"module": "commonjs",
76
"target": "es2017"
87
},
8+
"exclude": ["src/__fixtures__"],
99
"references": [
1010
{ "path": "../babel-plugin" },
1111
{ "path": "../babel-plugin-strip-runtime" },

0 commit comments

Comments
 (0)