Skip to content

Commit

Permalink
build: update packages to use more modern moduleresolution options (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
michaelfaith authored Jan 8, 2025
1 parent 04f6280 commit 5da86c5
Show file tree
Hide file tree
Showing 20 changed files with 23 additions and 32 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"postbuild": "scripts/postbuild.sh",
"build:babel-fixture": "yarn workspace @compiled/babel-component-fixture build && yarn workspace @compiled/babel-component-extracted-fixture build",
"build:browser": "ttsc --build packages/tsconfig.browser.json",
"build:cjs": "ttsc --build packages/tsconfig.cjs.json",
"build:esm": "ttsc --build packages/tsconfig.json",
"build:cjs": "ttsc --build packages/tsconfig.json",
"build:esm": "ttsc --build packages/tsconfig.esm.json",
"build:inspect": "node --inspect-brk node_modules/typescript/lib/tsc.js --build packages",
"build:parcel": "ttsc --build examples/parcel/tsconfig.json && yarn workspace @compiled/parcel-app build",
"build:ssr": "CI=false && ttsc --build examples/ssr/tsconfig.json && yarn workspace @compiled/ssr-app build",
Expand Down
3 changes: 1 addition & 2 deletions packages/babel-plugin-strip-runtime/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"extends": "../tsconfig.options.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"module": "commonjs"
"outDir": "dist"
},
"references": [{ "path": "../babel-plugin" }, { "path": "../css" }]
}
5 changes: 2 additions & 3 deletions packages/babel-plugin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"extends": "../tsconfig.options.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "dist",
"rootDir": "src"
"rootDir": "src",
"outDir": "dist"
},
"references": [{ "path": "../benchmark" }, { "path": "../css" }, { "path": "../utils" }]
}
5 changes: 2 additions & 3 deletions packages/benchmark/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"extends": "../tsconfig.options.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "dist",
"rootDir": "src"
"rootDir": "src",
"outDir": "dist"
},
"references": [{ "path": "../jest" }]
}
3 changes: 1 addition & 2 deletions packages/codemods/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"extends": "../tsconfig.options.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"module": "commonjs"
"outDir": "dist"
},
"references": [{ "path": "../jest" }, { "path": "../utils" }]
}
3 changes: 1 addition & 2 deletions packages/css/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"extends": "../tsconfig.options.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"module": "commonjs"
"outDir": "dist"
},
"references": [{ "path": "../utils" }]
}
2 changes: 0 additions & 2 deletions packages/eslint-plugin/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"module": "nodenext",
"moduleResolution": "nodenext",
"target": "es2017",
"plugins": [
{
Expand Down
3 changes: 1 addition & 2 deletions packages/jest/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"extends": "../tsconfig.options.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"module": "commonjs"
"outDir": "dist"
},
"references": []
}
1 change: 0 additions & 1 deletion packages/parcel-optimizer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"module": "commonjs",
"target": "es2017"
},
"references": [{ "path": "../css" }, { "path": "../jest" }]
Expand Down
1 change: 0 additions & 1 deletion packages/parcel-transformer-external/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"module": "commonjs",
"target": "es2017"
},
"references": [{ "path": "../jest" }]
Expand Down
1 change: 0 additions & 1 deletion packages/parcel-transformer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"module": "commonjs",
"target": "es2017"
},
"references": [
Expand Down
2 changes: 2 additions & 0 deletions packages/react/tsconfig.browser.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"extends": "./tsconfig.options.json",
"compilerOptions": {
"outDir": "dist/browser",
"module": "es6",
"moduleResolution": "node",
"plugins": [
{
"transform": "ts-transform-define",
Expand Down
1 change: 0 additions & 1 deletion packages/react/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "./tsconfig.options.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "dist/cjs",
"tsBuildInfoFile": "tsconfig.cjs.tsbuildinfo"
},
Expand Down
2 changes: 2 additions & 0 deletions packages/react/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"extends": "./tsconfig.options.json",
"compilerOptions": {
"outDir": "dist/esm",
"module": "es6",
"moduleResolution": "node",
"tsBuildInfoFile": "tsconfig.esm.tsbuildinfo"
},
"references": [{ "path": "../benchmark" }, { "path": "../jest" }, { "path": "../utils" }]
Expand Down
4 changes: 0 additions & 4 deletions packages/tsconfig.cjs.json

This file was deleted.

4 changes: 4 additions & 0 deletions packages/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"files": [],
"references": [{ "path": "react/tsconfig.json" }]
}
2 changes: 1 addition & 1 deletion packages/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{ "path": "parcel-optimizer/tsconfig.json" },
{ "path": "parcel-transformer/tsconfig.json" },
{ "path": "parcel-transformer-external/tsconfig.json" },
{ "path": "react/tsconfig.json" },
{ "path": "react/tsconfig.cjs.json" },
{ "path": "utils/tsconfig.json" },
{ "path": "webpack-loader/tsconfig.json" }
]
Expand Down
4 changes: 2 additions & 2 deletions packages/tsconfig.options.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"forceConsistentCasingInFileNames": true,
"jsx": "react",
"lib": ["dom", "es2016", "es2017.object"],
"module": "es6",
"moduleResolution": "node",
"module": "nodenext",
"moduleResolution": "nodenext",
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
Expand Down
3 changes: 1 addition & 2 deletions packages/utils/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"extends": "../tsconfig.options.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"module": "commonjs"
"outDir": "dist"
},
"references": [{ "path": "../jest" }]
}
2 changes: 1 addition & 1 deletion packages/webpack-loader/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"module": "commonjs",
"target": "es2017"
},
"exclude": ["src/__fixtures__"],
"references": [
{ "path": "../babel-plugin" },
{ "path": "../babel-plugin-strip-runtime" },
Expand Down

0 comments on commit 5da86c5

Please sign in to comment.