Skip to content

Commit

Permalink
feat(common): export base tsconfig (#2873)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Ingersoll <[email protected]>
  • Loading branch information
ssalbdivad and holic authored May 30, 2024
1 parent ecc8f65 commit f3180fe
Show file tree
Hide file tree
Showing 17 changed files with 77 additions and 24 deletions.
44 changes: 43 additions & 1 deletion .changeset/selfish-olives-yawn.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,46 @@
"solhint-plugin-mud": patch
---

Removed TS source from published packages in favor of DTS in an effort to improve TS performance.
TS source has been removed from published packages in favor of DTS in an effort to improve TS performance. All packages now inherit from a base TS config in `@latticexyz/common` to allow us to continue iterating on TS performance without requiring changes in your project code.

If you have a MUD project that you're upgrading, we suggest adding a `tsconfig.json` file to your project workspace that extends this base config.

```sh
pnpm add -D @latticexyz/common
echo "{\n \"extends\": \"@latticexyz/common/tsconfig.base.json\"\n}" > tsconfig.json
```

Then in each package of your project, inherit from your workspace root's config.

For example, your TS config in `packages/contracts/tsconfig.json` might look like:

```json
{
"extends": "../../tsconfig.json"
}
```

And your TS config in `packages/client/tsconfig.json` might look like:

```json
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"types": ["vite/client"],
"target": "ESNext",
"lib": ["ESNext", "DOM"],
"jsx": "react-jsx",
"jsxImportSource": "react"
},
"include": ["src"]
}
```

You may need to adjust the above configs to include any additional TS options you've set. This config pattern may also reveal new TS errors that need to be fixed or rules disabled.

If you want to keep your existing TS configs, we recommend at least updating your `moduleResolution` setting.

```diff
-"moduleResolution": "node"
+"moduleResolution": "Bundler"
```
6 changes: 4 additions & 2 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
"./foundry": "./dist/foundry.js",
"./type-utils": "./dist/type-utils.js",
"./utils": "./dist/utils.js",
"./kms": "./dist/kms.js"
"./kms": "./dist/kms.js",
"./tsconfig.base.json": "./tsconfig.base.json"
},
"files": [
"dist"
"dist",
"tsconfig.base.json"
],
"scripts": {
"build": "pnpm run build:js",
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.base.json → packages/common/tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@
"resolveJsonModule": true,
"forceConsistentCasingInFileNames": true,
"sourceMap": true
},
"exclude": ["**/dist", "**/node_modules", "**/docs", "**/e2e"]
}
}
3 changes: 1 addition & 2 deletions packages/common/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "../../tsconfig.json",
"extends": "./tsconfig.base.json",
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"outDir": "dist"
},
"include": ["src"]
Expand Down
5 changes: 3 additions & 2 deletions packages/create-mud/scripts/copy-templates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ find ./dist/templates/* -name ".gitignore" -type f | while read -r file; do
done

# For local development, each template workspace extends the monorepo's `tsconfig.json`, which includes `paths` to resolve TS source.
# To strip out the `paths`, we replace the template workspace root `tsconfig.json` with the monorepo's `tsconfig.base.json`.
tsconfig=$(realpath "$(dirname $0)/../../../tsconfig.base.json")
# To strip out the `paths`, we replace the template workspace root `tsconfig.json` with a new base tsconfig that extends only
# @latticexyz/common/tsconfig.base.json
tsconfig=$(realpath "$(dirname $0)/tsconfig.base.json")
find ./dist/templates/*/tsconfig.json -type f | while read -r file; do
echo "Replacing $file with $tsconfig"
cp "$tsconfig" "$file"
Expand Down
3 changes: 3 additions & 0 deletions packages/create-mud/scripts/tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@latticexyz/common/tsconfig.base.json"
}
1 change: 1 addition & 0 deletions templates/phaser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"devDependencies": {
"@latticexyz/cli": "link:../../packages/cli",
"@latticexyz/common": "link:../../packages/common",
"@types/debug": "4.1.7",
"@typescript-eslint/eslint-plugin": "7.1.1",
"@typescript-eslint/parser": "7.1.1",
Expand Down
5 changes: 3 additions & 2 deletions templates/phaser/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// For local development, we extend the monorepo's `tsconfig.json`, which includes paths to resolve TS source.
// When building templates, this file will get replaced by monorepo's `tsconfig.base.json`.
// For local development, each template workspace extends the monorepo's `tsconfig.json`, which includes `paths` to resolve TS source.
// To strip out the `paths`, we replace the template workspace root `tsconfig.json` with a new base tsconfig that extends only
// @latticexyz/common/tsconfig.base.json
{
"extends": "../../tsconfig.json"
}
1 change: 1 addition & 0 deletions templates/react-ecs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"devDependencies": {
"@latticexyz/cli": "link:../../packages/cli",
"@latticexyz/common": "link:../../packages/common",
"@types/debug": "4.1.7",
"@typescript-eslint/eslint-plugin": "7.1.1",
"@typescript-eslint/parser": "7.1.1",
Expand Down
5 changes: 3 additions & 2 deletions templates/react-ecs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// For local development, we extend the monorepo's `tsconfig.json`, which includes paths to resolve TS source.
// When building templates, this file will get replaced by monorepo's `tsconfig.base.json`.
// For local development, each template workspace extends the monorepo's `tsconfig.json`, which includes `paths` to resolve TS source.
// To strip out the `paths`, we replace the template workspace root `tsconfig.json` with a new base tsconfig that extends only
// @latticexyz/common/tsconfig.base.json
{
"extends": "../../tsconfig.json"
}
1 change: 1 addition & 0 deletions templates/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"devDependencies": {
"@latticexyz/cli": "link:../../packages/cli",
"@latticexyz/common": "link:../../packages/common",
"@types/debug": "4.1.7",
"@typescript-eslint/eslint-plugin": "7.1.1",
"@typescript-eslint/parser": "7.1.1",
Expand Down
5 changes: 3 additions & 2 deletions templates/react/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// For local development, we extend the monorepo's `tsconfig.json`, which includes paths to resolve TS source.
// When building templates, this file will get replaced by monorepo's `tsconfig.base.json`.
// For local development, each template workspace extends the monorepo's `tsconfig.json`, which includes `paths` to resolve TS source.
// To strip out the `paths`, we replace the template workspace root `tsconfig.json` with a new base tsconfig that extends only
// @latticexyz/common/tsconfig.base.json
{
"extends": "../../tsconfig.json"
}
1 change: 1 addition & 0 deletions templates/threejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"devDependencies": {
"@latticexyz/cli": "link:../../packages/cli",
"@latticexyz/common": "link:../../packages/common",
"@types/debug": "4.1.7",
"@typescript-eslint/eslint-plugin": "7.1.1",
"@typescript-eslint/parser": "7.1.1",
Expand Down
5 changes: 3 additions & 2 deletions templates/threejs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// For local development, we extend the monorepo's `tsconfig.json`, which includes paths to resolve TS source.
// When building templates, this file will get replaced by monorepo's `tsconfig.base.json`.
// For local development, each template workspace extends the monorepo's `tsconfig.json`, which includes `paths` to resolve TS source.
// To strip out the `paths`, we replace the template workspace root `tsconfig.json` with a new base tsconfig that extends only
// @latticexyz/common/tsconfig.base.json
{
"extends": "../../tsconfig.json"
}
1 change: 1 addition & 0 deletions templates/vanilla/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"devDependencies": {
"@latticexyz/cli": "link:../../packages/cli",
"@latticexyz/common": "link:../../packages/common",
"@types/debug": "4.1.7",
"@typescript-eslint/eslint-plugin": "7.1.1",
"@typescript-eslint/parser": "7.1.1",
Expand Down
5 changes: 3 additions & 2 deletions templates/vanilla/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// For local development, we extend the monorepo's `tsconfig.json`, which includes paths to resolve TS source.
// When building templates, this file will get replaced by monorepo's `tsconfig.base.json`.
// For local development, each template workspace extends the monorepo's `tsconfig.json`, which includes `paths` to resolve TS source.
// To strip out the `paths`, we replace the template workspace root `tsconfig.json` with a new base tsconfig that extends only
// @latticexyz/common/tsconfig.base.json
{
"extends": "../../tsconfig.json"
}
7 changes: 2 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"extends": [
// Note that the base config gets copied over to each template workspace too
"./tsconfig.base.json",
"./tsconfig.paths.json"
]
"extends": ["./packages/common/tsconfig.base.json", "./tsconfig.paths.json"],
"exclude": ["**/dist", "**/node_modules", "**/docs", "**/e2e"]
}

0 comments on commit f3180fe

Please sign in to comment.