Skip to content

Commit

Permalink
Merge branch 'main' into faucet-sendTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
holic authored Jan 2, 2024
2 parents f180370 + eb384bb commit 0f8e197
Show file tree
Hide file tree
Showing 33 changed files with 206 additions and 55 deletions.
6 changes: 6 additions & 0 deletions .changeset/grumpy-icons-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@latticexyz/world-modules": patch
"@latticexyz/world": patch
---

Added `isInstalled` and `requireNotInstalled` helpers to `Module` base contract.
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/@[email protected]/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
22 changes: 11 additions & 11 deletions packages/world-modules/gas-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallComposite",
"name": "install keys in table module",
"gasUsed": 1409435
"gasUsed": 1409529
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallGas",
"name": "install keys in table module",
"gasUsed": 1409435
"gasUsed": 1409529
},
{
"file": "test/KeysInTableModule.t.sol",
Expand All @@ -93,13 +93,13 @@
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallSingleton",
"name": "install keys in table module",
"gasUsed": 1409435
"gasUsed": 1409529
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testSetAndDeleteRecordHookCompositeGas",
"name": "install keys in table module",
"gasUsed": 1409435
"gasUsed": 1409529
},
{
"file": "test/KeysInTableModule.t.sol",
Expand All @@ -117,7 +117,7 @@
"file": "test/KeysInTableModule.t.sol",
"test": "testSetAndDeleteRecordHookGas",
"name": "install keys in table module",
"gasUsed": 1409435
"gasUsed": 1409529
},
{
"file": "test/KeysInTableModule.t.sol",
Expand All @@ -135,7 +135,7 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testGetKeysWithValueGas",
"name": "install keys with value module",
"gasUsed": 650708
"gasUsed": 650796
},
{
"file": "test/KeysWithValueModule.t.sol",
Expand All @@ -153,7 +153,7 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testInstall",
"name": "install keys with value module",
"gasUsed": 650708
"gasUsed": 650796
},
{
"file": "test/KeysWithValueModule.t.sol",
Expand All @@ -165,7 +165,7 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testSetAndDeleteRecordHook",
"name": "install keys with value module",
"gasUsed": 650708
"gasUsed": 650796
},
{
"file": "test/KeysWithValueModule.t.sol",
Expand All @@ -183,7 +183,7 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testSetField",
"name": "install keys with value module",
"gasUsed": 650708
"gasUsed": 650796
},
{
"file": "test/KeysWithValueModule.t.sol",
Expand Down Expand Up @@ -303,7 +303,7 @@
"file": "test/UniqueEntityModule.t.sol",
"test": "testInstall",
"name": "install unique entity module",
"gasUsed": 678996
"gasUsed": 679102
},
{
"file": "test/UniqueEntityModule.t.sol",
Expand All @@ -315,7 +315,7 @@
"file": "test/UniqueEntityModule.t.sol",
"test": "testInstallRoot",
"name": "installRoot unique entity module",
"gasUsed": 644433
"gasUsed": 644539
},
{
"file": "test/UniqueEntityModule.t.sol",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
import { Module } from "@latticexyz/world/src/Module.sol";
import { WorldResourceIdLib } from "@latticexyz/world/src/WorldResourceId.sol";
import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol";
import { InstalledModules } from "@latticexyz/world/src/codegen/tables/InstalledModules.sol";

import { Puppet } from "../puppet/Puppet.sol";
import { createPuppet } from "../puppet/createPuppet.sol";
Expand All @@ -32,16 +31,14 @@ contract ERC20Module is Module {

function _requireDependencies() internal view {
// Require PuppetModule to be installed
if (InstalledModules.get(PUPPET_MODULE_NAME, keccak256(new bytes(0))) == address(0)) {
if (!isInstalled(PUPPET_MODULE_NAME, new bytes(0))) {
revert Module_MissingDependency(string(bytes.concat(PUPPET_MODULE_NAME)));
}
}

function install(bytes memory args) public {
// Require the module to not be installed with these args yet
if (InstalledModules.get(MODULE_NAME, keccak256(args)) != address(0)) {
revert Module_AlreadyInstalled();
}
requireNotInstalled(MODULE_NAME, args);

// Extract args
(bytes14 namespace, ERC20MetadataData memory metadata) = abi.decode(args, (bytes14, ERC20MetadataData));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,16 @@ contract ERC721Module is Module {
return MODULE_NAME;
}

function _requireDependencies() internal {
function _requireDependencies() internal view {
// Require PuppetModule to be installed
if (InstalledModules.get(PUPPET_MODULE_NAME, keccak256(new bytes(0))) == address(0)) {
if (!isInstalled(PUPPET_MODULE_NAME, new bytes(0))) {
revert Module_MissingDependency(string(bytes.concat(PUPPET_MODULE_NAME)));
}
}

function install(bytes memory args) public {
// Require the module to not be installed with these args yet
if (InstalledModules.get(MODULE_NAME, keccak256(args)) != address(0)) {
revert Module_AlreadyInstalled();
}
requireNotInstalled(MODULE_NAME, args);

// Extract args
(bytes14 namespace, ERC721MetadataData memory metadata) = abi.decode(args, (bytes14, ERC721MetadataData));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ contract KeysInTableModule is Module {
function installRoot(bytes memory args) public override {
// Naive check to ensure this is only installed once
// TODO: only revert if there's nothing to do
if (InstalledModules.getModuleAddress(getName(), keccak256(args)) != address(0)) {
revert Module_AlreadyInstalled();
}
requireNotInstalled(getName(), args);

// Extract source table id from args
ResourceId sourceTableId = ResourceId.wrap(abi.decode(args, (bytes32)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ contract KeysWithValueModule is Module {
function installRoot(bytes memory args) public {
// Naive check to ensure this is only installed once
// TODO: only revert if there's nothing to do
if (InstalledModules.getModuleAddress(getName(), keccak256(args)) != address(0)) {
revert Module_AlreadyInstalled();
}
requireNotInstalled(getName(), args);

// Extract source table id from args
ResourceId sourceTableId = ResourceId.wrap(abi.decode(args, (bytes32)));
Expand Down
Loading

0 comments on commit 0f8e197

Please sign in to comment.