Skip to content

Commit

Permalink
build: allow use by TypeScript projects with bundler/node16 config (
Browse files Browse the repository at this point in the history
#2084)

Co-authored-by: Kevin Ingersoll <kingersoll@gmail.com>
  • Loading branch information
tash-2s and holic authored Jan 2, 2024
1 parent 6672838 commit 5905420
Show file tree
Hide file tree
Showing 22 changed files with 63 additions and 21 deletions.
23 changes: 23 additions & 0 deletions .changeset/poor-beans-beg.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion packages/abi-ts/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/block-logs-stream/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/codegen/modules.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
declare module "prettier-plugin-solidity";
declare module "prettier-plugin-solidity" {}
2 changes: 1 addition & 1 deletion packages/common/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default defineConfig({
},
target: "esnext",
format: ["esm"],
dts: false,
dts: true,
sourcemap: true,
clean: true,
minify: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/config/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 20 additions & 1 deletion packages/dev-tools/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof createMemoryRouter>;

export const router: Router = createMemoryRouter(
createRoutesFromElements(
<Route path="/" element={<RootPage />} errorElement={<RouteError />}>
<Route index element={<SummaryPage />} />
Expand Down
2 changes: 1 addition & 1 deletion packages/dev-tools/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/faucet/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/gas-report/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/noise/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/phaserx/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol-parser/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/react/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/recs/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/schema-type/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default defineConfig({
outDir: "dist/typescript",
target: "esnext",
format: ["esm"],
dts: false,
dts: true,
sourcemap: true,
clean: true,
minify: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/services/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default defineConfig({
},
target: "esnext",
format: ["esm"],
dts: false,
dts: true,
sourcemap: true,
clean: true,
});
2 changes: 1 addition & 1 deletion packages/store-sync/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default defineConfig({
],
target: "esnext",
format: ["esm"],
dts: false,
dts: true,
sourcemap: true,
clean: true,
minify: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/store/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/world-modules/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/world/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5905420

Please sign in to comment.