From f3180fe8437224d7a568f79ff60c9e70e9b48792 Mon Sep 17 00:00:00 2001 From: David Blass Date: Thu, 30 May 2024 07:05:25 -0400 Subject: [PATCH] feat(common): export base tsconfig (#2873) Co-authored-by: Kevin Ingersoll --- .changeset/selfish-olives-yawn.md | 44 ++++++++++++++++++- packages/common/package.json | 6 ++- .../common/tsconfig.base.json | 3 +- packages/common/tsconfig.json | 3 +- packages/create-mud/scripts/copy-templates.sh | 5 ++- .../create-mud/scripts/tsconfig.base.json | 3 ++ templates/phaser/package.json | 1 + templates/phaser/tsconfig.json | 5 ++- templates/react-ecs/package.json | 1 + templates/react-ecs/tsconfig.json | 5 ++- templates/react/package.json | 1 + templates/react/tsconfig.json | 5 ++- templates/threejs/package.json | 1 + templates/threejs/tsconfig.json | 5 ++- templates/vanilla/package.json | 1 + templates/vanilla/tsconfig.json | 5 ++- tsconfig.json | 7 +-- 17 files changed, 77 insertions(+), 24 deletions(-) rename tsconfig.base.json => packages/common/tsconfig.base.json (88%) create mode 100644 packages/create-mud/scripts/tsconfig.base.json diff --git a/.changeset/selfish-olives-yawn.md b/.changeset/selfish-olives-yawn.md index a61f6664bd..a014677597 100644 --- a/.changeset/selfish-olives-yawn.md +++ b/.changeset/selfish-olives-yawn.md @@ -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" +``` diff --git a/packages/common/package.json b/packages/common/package.json index 8bc8fac019..2c9ace8c1f 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -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", diff --git a/tsconfig.base.json b/packages/common/tsconfig.base.json similarity index 88% rename from tsconfig.base.json rename to packages/common/tsconfig.base.json index 455807009a..240ac282c3 100644 --- a/tsconfig.base.json +++ b/packages/common/tsconfig.base.json @@ -18,6 +18,5 @@ "resolveJsonModule": true, "forceConsistentCasingInFileNames": true, "sourceMap": true - }, - "exclude": ["**/dist", "**/node_modules", "**/docs", "**/e2e"] + } } diff --git a/packages/common/tsconfig.json b/packages/common/tsconfig.json index 63f28b3d52..28935acb73 100644 --- a/packages/common/tsconfig.json +++ b/packages/common/tsconfig.json @@ -1,7 +1,6 @@ { - "extends": "../../tsconfig.json", + "extends": "./tsconfig.base.json", "compilerOptions": { - "lib": ["ESNext", "DOM"], "outDir": "dist" }, "include": ["src"] diff --git a/packages/create-mud/scripts/copy-templates.sh b/packages/create-mud/scripts/copy-templates.sh index 4db1c4bcde..150b36bb70 100755 --- a/packages/create-mud/scripts/copy-templates.sh +++ b/packages/create-mud/scripts/copy-templates.sh @@ -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" diff --git a/packages/create-mud/scripts/tsconfig.base.json b/packages/create-mud/scripts/tsconfig.base.json new file mode 100644 index 0000000000..258a47be3f --- /dev/null +++ b/packages/create-mud/scripts/tsconfig.base.json @@ -0,0 +1,3 @@ +{ + "extends": "@latticexyz/common/tsconfig.base.json" +} diff --git a/templates/phaser/package.json b/templates/phaser/package.json index 486caec917..2e076feba7 100644 --- a/templates/phaser/package.json +++ b/templates/phaser/package.json @@ -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", diff --git a/templates/phaser/tsconfig.json b/templates/phaser/tsconfig.json index e25d5d7d9c..fb5999af5a 100644 --- a/templates/phaser/tsconfig.json +++ b/templates/phaser/tsconfig.json @@ -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" } diff --git a/templates/react-ecs/package.json b/templates/react-ecs/package.json index 0ab782073c..741c071f75 100644 --- a/templates/react-ecs/package.json +++ b/templates/react-ecs/package.json @@ -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", diff --git a/templates/react-ecs/tsconfig.json b/templates/react-ecs/tsconfig.json index e25d5d7d9c..fb5999af5a 100644 --- a/templates/react-ecs/tsconfig.json +++ b/templates/react-ecs/tsconfig.json @@ -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" } diff --git a/templates/react/package.json b/templates/react/package.json index 7afd3b81af..5943eb528a 100644 --- a/templates/react/package.json +++ b/templates/react/package.json @@ -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", diff --git a/templates/react/tsconfig.json b/templates/react/tsconfig.json index e25d5d7d9c..fb5999af5a 100644 --- a/templates/react/tsconfig.json +++ b/templates/react/tsconfig.json @@ -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" } diff --git a/templates/threejs/package.json b/templates/threejs/package.json index a33b2735a8..1ef7c907f0 100644 --- a/templates/threejs/package.json +++ b/templates/threejs/package.json @@ -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", diff --git a/templates/threejs/tsconfig.json b/templates/threejs/tsconfig.json index e25d5d7d9c..fb5999af5a 100644 --- a/templates/threejs/tsconfig.json +++ b/templates/threejs/tsconfig.json @@ -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" } diff --git a/templates/vanilla/package.json b/templates/vanilla/package.json index 912a9c846f..09b9d29c5f 100644 --- a/templates/vanilla/package.json +++ b/templates/vanilla/package.json @@ -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", diff --git a/templates/vanilla/tsconfig.json b/templates/vanilla/tsconfig.json index e25d5d7d9c..fb5999af5a 100644 --- a/templates/vanilla/tsconfig.json +++ b/templates/vanilla/tsconfig.json @@ -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" } diff --git a/tsconfig.json b/tsconfig.json index 850d670e50..4548513f87 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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"] }