From 590542030e7500f8d3cce6e54e4961d9f8a1a6d5 Mon Sep 17 00:00:00 2001 From: tash-2s <81064017+tash-2s@users.noreply.github.com> Date: Tue, 2 Jan 2024 04:22:59 -0600 Subject: [PATCH] build: allow use by TypeScript projects with `bundler`/`node16` config (#2084) Co-authored-by: Kevin Ingersoll --- .changeset/poor-beans-beg.md | 23 +++++++++++++++++++++++ packages/abi-ts/tsup.config.ts | 2 +- packages/block-logs-stream/tsup.config.ts | 2 +- packages/common/src/codegen/modules.d.ts | 2 +- packages/common/tsup.config.ts | 2 +- packages/config/tsup.config.ts | 2 +- packages/dev-tools/src/router.tsx | 21 ++++++++++++++++++++- packages/dev-tools/tsup.config.ts | 2 +- packages/faucet/tsup.config.ts | 2 +- packages/gas-report/tsup.config.ts | 2 +- packages/noise/tsup.config.ts | 2 +- packages/phaserx/tsup.config.ts | 2 +- packages/protocol-parser/tsup.config.ts | 2 +- packages/react/tsup.config.ts | 2 +- packages/recs/tsup.config.ts | 2 +- packages/schema-type/tsup.config.ts | 2 +- packages/services/tsup.config.ts | 2 +- packages/store-sync/tsup.config.ts | 2 +- packages/store/tsup.config.ts | 2 +- packages/utils/tsup.config.ts | 2 +- packages/world-modules/tsup.config.ts | 2 +- packages/world/tsup.config.ts | 2 +- 22 files changed, 63 insertions(+), 21 deletions(-) create mode 100644 .changeset/poor-beans-beg.md diff --git a/.changeset/poor-beans-beg.md b/.changeset/poor-beans-beg.md new file mode 100644 index 0000000000..f6e3e38427 --- /dev/null +++ b/.changeset/poor-beans-beg.md @@ -0,0 +1,23 @@ +--- +"@latticexyz/abi-ts": patch +"@latticexyz/block-logs-stream": patch +"@latticexyz/common": patch +"@latticexyz/config": patch +"@latticexyz/dev-tools": patch +"@latticexyz/faucet": patch +"@latticexyz/gas-report": patch +"@latticexyz/noise": patch +"@latticexyz/phaserx": patch +"@latticexyz/protocol-parser": patch +"@latticexyz/react": patch +"@latticexyz/recs": patch +"@latticexyz/schema-type": patch +"@latticexyz/services": patch +"@latticexyz/store-sync": patch +"@latticexyz/store": patch +"@latticexyz/utils": patch +"@latticexyz/world-modules": patch +"@latticexyz/world": patch +--- + +TS packages now generate their respective `.d.ts` type definition files for better compatibility when using MUD with `moduleResolution` set to `bundler` or `node16` and fixes issues around missing type declarations for dependent packages. diff --git a/packages/abi-ts/tsup.config.ts b/packages/abi-ts/tsup.config.ts index b622829fd1..783fa85248 100644 --- a/packages/abi-ts/tsup.config.ts +++ b/packages/abi-ts/tsup.config.ts @@ -4,7 +4,7 @@ export default defineConfig({ entry: ["src/index.ts", "src/abi-ts.ts"], target: "esnext", format: ["esm"], - dts: false, + dts: true, sourcemap: true, clean: true, minify: true, diff --git a/packages/block-logs-stream/tsup.config.ts b/packages/block-logs-stream/tsup.config.ts index b755469f90..52bdfceee6 100644 --- a/packages/block-logs-stream/tsup.config.ts +++ b/packages/block-logs-stream/tsup.config.ts @@ -4,7 +4,7 @@ export default defineConfig({ entry: ["src/index.ts"], target: "esnext", format: ["esm"], - dts: false, + dts: true, sourcemap: true, clean: true, minify: true, diff --git a/packages/common/src/codegen/modules.d.ts b/packages/common/src/codegen/modules.d.ts index 12ea8e2ce5..b1d4173a03 100644 --- a/packages/common/src/codegen/modules.d.ts +++ b/packages/common/src/codegen/modules.d.ts @@ -1 +1 @@ -declare module "prettier-plugin-solidity"; +declare module "prettier-plugin-solidity" {} diff --git a/packages/common/tsup.config.ts b/packages/common/tsup.config.ts index 9432329d41..ba8ccf3917 100644 --- a/packages/common/tsup.config.ts +++ b/packages/common/tsup.config.ts @@ -12,7 +12,7 @@ export default defineConfig({ }, target: "esnext", format: ["esm"], - dts: false, + dts: true, sourcemap: true, clean: true, minify: true, diff --git a/packages/config/tsup.config.ts b/packages/config/tsup.config.ts index 6166e27182..ea905447a9 100644 --- a/packages/config/tsup.config.ts +++ b/packages/config/tsup.config.ts @@ -4,7 +4,7 @@ export default defineConfig({ entry: ["src/library/index.ts", "src/register/index.ts", "src/node/index.ts"], target: "esnext", format: ["esm"], - dts: false, + dts: true, sourcemap: true, clean: true, minify: true, diff --git a/packages/dev-tools/src/router.tsx b/packages/dev-tools/src/router.tsx index c2f78f4d64..6b50736e01 100644 --- a/packages/dev-tools/src/router.tsx +++ b/packages/dev-tools/src/router.tsx @@ -9,7 +9,26 @@ import { ComponentData } from "./recs/ComponentData"; import { TablesPage } from "./zustand/TablesPage"; import { TableData } from "./zustand/TableData"; -export const router = createMemoryRouter( +/* +This workaround is necessary to pass `tsc --declaration`. Without it, the following error occurs: + +``` +error TS2742: The inferred type of 'router' cannot be named without a reference to '.pnpm/@remix-run+router@1.6.0/node_modules/@remix-run/router'. +This is likely not portable. A type annotation is necessary. +``` + +This `tsc --declaration` issue arises under the following combined conditions: + +1. pnpm is the package manager. +2. The source uses a function from the dependency package (this time, react-router-dom's createMemoryRouter) and relies on type inference for its return type. +3. The inferred return type originates from a package that is not a direct dependency of the source (this time, @remix-run/router's Router). +4. The dependency package containing the function (react-router-dom) does not re-export the function's return type (Router). + +See https://github.com/microsoft/TypeScript/issues/47663#issuecomment-1519138189 +*/ +type Router = ReturnType; + +export const router: Router = createMemoryRouter( createRoutesFromElements( } errorElement={}> } /> diff --git a/packages/dev-tools/tsup.config.ts b/packages/dev-tools/tsup.config.ts index 5814bb1770..7189afad8e 100644 --- a/packages/dev-tools/tsup.config.ts +++ b/packages/dev-tools/tsup.config.ts @@ -16,7 +16,7 @@ export default defineConfig({ entry: ["src/index.ts"], target: "esnext", format: ["esm"], - dts: false, + dts: true, sourcemap: true, clean: true, minify: true, diff --git a/packages/faucet/tsup.config.ts b/packages/faucet/tsup.config.ts index 385f3fc274..cadbc2f970 100644 --- a/packages/faucet/tsup.config.ts +++ b/packages/faucet/tsup.config.ts @@ -4,7 +4,7 @@ export default defineConfig({ entry: ["src/index.ts", "bin/faucet-server.ts"], target: "esnext", format: ["esm"], - dts: false, + dts: true, sourcemap: true, clean: true, minify: true, diff --git a/packages/gas-report/tsup.config.ts b/packages/gas-report/tsup.config.ts index fafcaa7177..289314bad7 100644 --- a/packages/gas-report/tsup.config.ts +++ b/packages/gas-report/tsup.config.ts @@ -4,7 +4,7 @@ export default defineConfig({ entry: ["ts/index.ts", "ts/gas-report.ts"], target: "esnext", format: ["esm"], - dts: false, + dts: true, sourcemap: true, clean: true, minify: true, diff --git a/packages/noise/tsup.config.ts b/packages/noise/tsup.config.ts index 264a5bbff8..5837375692 100644 --- a/packages/noise/tsup.config.ts +++ b/packages/noise/tsup.config.ts @@ -4,7 +4,7 @@ export default defineConfig({ entry: ["ts/index.ts"], target: "esnext", format: ["esm"], - dts: false, + dts: true, sourcemap: true, clean: true, minify: true, diff --git a/packages/phaserx/tsup.config.ts b/packages/phaserx/tsup.config.ts index b755469f90..52bdfceee6 100644 --- a/packages/phaserx/tsup.config.ts +++ b/packages/phaserx/tsup.config.ts @@ -4,7 +4,7 @@ export default defineConfig({ entry: ["src/index.ts"], target: "esnext", format: ["esm"], - dts: false, + dts: true, sourcemap: true, clean: true, minify: true, diff --git a/packages/protocol-parser/tsup.config.ts b/packages/protocol-parser/tsup.config.ts index b755469f90..52bdfceee6 100644 --- a/packages/protocol-parser/tsup.config.ts +++ b/packages/protocol-parser/tsup.config.ts @@ -4,7 +4,7 @@ export default defineConfig({ entry: ["src/index.ts"], target: "esnext", format: ["esm"], - dts: false, + dts: true, sourcemap: true, clean: true, minify: true, diff --git a/packages/react/tsup.config.ts b/packages/react/tsup.config.ts index b755469f90..52bdfceee6 100644 --- a/packages/react/tsup.config.ts +++ b/packages/react/tsup.config.ts @@ -4,7 +4,7 @@ export default defineConfig({ entry: ["src/index.ts"], target: "esnext", format: ["esm"], - dts: false, + dts: true, sourcemap: true, clean: true, minify: true, diff --git a/packages/recs/tsup.config.ts b/packages/recs/tsup.config.ts index 71d48b47ec..faf54cff78 100644 --- a/packages/recs/tsup.config.ts +++ b/packages/recs/tsup.config.ts @@ -4,7 +4,7 @@ export default defineConfig({ entry: ["src/index.ts", "src/deprecated/index.ts"], target: "esnext", format: ["esm"], - dts: false, + dts: true, sourcemap: true, clean: true, minify: true, diff --git a/packages/schema-type/tsup.config.ts b/packages/schema-type/tsup.config.ts index 4d1fd9f68a..4ae11283a7 100644 --- a/packages/schema-type/tsup.config.ts +++ b/packages/schema-type/tsup.config.ts @@ -5,7 +5,7 @@ export default defineConfig({ outDir: "dist/typescript", target: "esnext", format: ["esm"], - dts: false, + dts: true, sourcemap: true, clean: true, minify: true, diff --git a/packages/services/tsup.config.ts b/packages/services/tsup.config.ts index b57079441a..ed5646e5d5 100644 --- a/packages/services/tsup.config.ts +++ b/packages/services/tsup.config.ts @@ -6,7 +6,7 @@ export default defineConfig({ }, target: "esnext", format: ["esm"], - dts: false, + dts: true, sourcemap: true, clean: true, }); diff --git a/packages/store-sync/tsup.config.ts b/packages/store-sync/tsup.config.ts index 184fc6c6ff..a6442c1a4a 100644 --- a/packages/store-sync/tsup.config.ts +++ b/packages/store-sync/tsup.config.ts @@ -13,7 +13,7 @@ export default defineConfig({ ], target: "esnext", format: ["esm"], - dts: false, + dts: true, sourcemap: true, clean: true, minify: true, diff --git a/packages/store/tsup.config.ts b/packages/store/tsup.config.ts index e46c0dc59d..031a8e4cb2 100644 --- a/packages/store/tsup.config.ts +++ b/packages/store/tsup.config.ts @@ -4,7 +4,7 @@ export default defineConfig({ entry: ["mud.config.ts", "ts/index.ts", "ts/codegen/index.ts", "ts/config/index.ts", "ts/register/index.ts"], target: "esnext", format: ["esm"], - dts: false, + dts: true, sourcemap: true, clean: true, minify: true, diff --git a/packages/utils/tsup.config.ts b/packages/utils/tsup.config.ts index b755469f90..52bdfceee6 100644 --- a/packages/utils/tsup.config.ts +++ b/packages/utils/tsup.config.ts @@ -4,7 +4,7 @@ export default defineConfig({ entry: ["src/index.ts"], target: "esnext", format: ["esm"], - dts: false, + dts: true, sourcemap: true, clean: true, minify: true, diff --git a/packages/world-modules/tsup.config.ts b/packages/world-modules/tsup.config.ts index d2aa3e215e..b9ae6d4212 100644 --- a/packages/world-modules/tsup.config.ts +++ b/packages/world-modules/tsup.config.ts @@ -4,7 +4,7 @@ export default defineConfig({ entry: ["mud.config.ts"], target: "esnext", format: ["esm"], - dts: false, + dts: true, sourcemap: true, clean: true, minify: true, diff --git a/packages/world/tsup.config.ts b/packages/world/tsup.config.ts index 4d76cecf16..d7d1d07098 100644 --- a/packages/world/tsup.config.ts +++ b/packages/world/tsup.config.ts @@ -4,7 +4,7 @@ export default defineConfig({ entry: ["mud.config.ts", "ts/index.ts", "ts/register/index.ts", "ts/node/index.ts"], target: "esnext", format: ["esm"], - dts: false, + dts: true, sourcemap: true, clean: true, minify: true,