Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): fixed module artifactPath imports #2832

Merged
merged 9 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/smart-moose-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/cli": patch
---

Fixed imports of module artifacts via `artifactPath` and removed unused `@latticexyz/world-modules` dependency.
1 change: 1 addition & 0 deletions e2e/packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@latticexyz/schema-type": "link:../../../packages/schema-type",
"@latticexyz/store": "link:../../../packages/store",
"@latticexyz/world": "link:../../../packages/world",
"@latticexyz/world-modules": "link:../../../packages/world-modules",
"dotenv": "^16.0.3",
"ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0",
"forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1",
Expand Down
17 changes: 10 additions & 7 deletions e2e/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"@latticexyz/store": "workspace:*",
"@latticexyz/utils": "workspace:*",
"@latticexyz/world": "workspace:*",
"@latticexyz/world-modules": "workspace:*",
"abitype": "1.0.0",
"asn1.js": "^5.4.1",
"chalk": "^5.0.1",
Expand All @@ -51,6 +50,7 @@
"dotenv": "^16.0.3",
"ethers": "^5.7.2",
"execa": "^7.0.0",
"find-up": "^6.3.0",
"glob": "^8.0.3",
"openurl": "^1.1.1",
"p-queue": "^7.4.1",
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/deploy/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Abi, Address, Hex, padHex } from "viem";
import storeConfig from "@latticexyz/store/mud.config";
import worldConfig from "@latticexyz/world/mud.config";
import IBaseWorldAbi from "@latticexyz/world/out/IBaseWorld.sol/IBaseWorld.abi.json" assert { type: "json" };
import IModuleAbi from "@latticexyz/world-modules/out/IModule.sol/IModule.abi.json" assert { type: "json" };
import { Tables, configToTables } from "./configToTables";
import { helloStoreEvent } from "@latticexyz/store";
import { StoreConfig } from "@latticexyz/store/internal";
Expand All @@ -22,7 +21,7 @@ export const worldTables = configToTables(worldToV1(worldConfig));

export const worldDeployEvents = [helloStoreEvent, helloWorldEvent] as const;

export const worldAbi = [...IBaseWorldAbi, ...IModuleAbi] as const;
export const worldAbi = IBaseWorldAbi;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the IBaseWorld ABI now includes the errors we wanted from IModule ABI


// Ideally, this should be an append-only list. Before adding more versions here, be sure to add backwards-compatible support for old Store/World versions.
export const supportedStoreVersions = ["2.0.0", "2.0.1", "2.0.2"];
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/deploy/configToModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { knownModuleArtifacts } from "../utils/knownModuleArtifacts";

export async function configToModules<config extends World>(
config: config,
// TODO: remove/replace `forgeOutDir`
forgeOutDir: string,
): Promise<readonly Module[]> {
// this expects a namespaced table name when used with `resolveTableId`
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/deploy/ensureModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export async function ensureModules({
pRetry(
async () => {
try {
// append module's ABI so that we can decode any custom errors
const abi = [...worldAbi, ...mod.abi];
const moduleAddress = mod.prepareDeploy(deployerAddress, libraries).address;
return mod.installAsRoot
Expand Down
25 changes: 16 additions & 9 deletions packages/cli/src/utils/getContractArtifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ import { LibraryPlaceholder } from "../deploy/common";
import { findPlaceholders } from "./findPlaceholders";
import { z } from "zod";
import { Abi as abiSchema } from "abitype/zod";
import { createRequire } from "node:module";
import { findUp } from "find-up";

export type GetContractArtifactOptions = {
/**
* Path to `package.json` where `artifactPath`s are resolved relative to.
*
* Defaults to nearest `package.json` relative to `process.cwd()`.
*/
packageJsonPath?: string;
/**
* Import path to contract's forge/solc JSON artifact with the contract's compiled bytecode.
*
* This path is resolved using node's contract resolution, so this supports both relative file paths (`../path/to/MyModule.json`) as well as JS import paths
* (`@latticexyz/world-contracts/out/CallWithSignatureModule.sol/CallWithSignatureModule.json`).
* This path is resolved using node's module resolution relative to `configPath`, so this supports both
* relative file paths (`../path/to/MyModule.json`) as well as JS import paths (`@latticexyz/world-contracts/out/CallWithSignatureModule.sol/CallWithSignatureModule.json`).
*/
artifactPath: string;
};
Expand Down Expand Up @@ -42,17 +50,16 @@ const artifactSchema = z.object({
});

export async function getContractArtifact({
packageJsonPath,
artifactPath,
}: GetContractArtifactOptions): Promise<GetContractArtifactResult> {
let importedArtifact;
try {
importedArtifact = (
await import(artifactPath, {
with: { type: "json" },
// `with` is the new approach, but `assert` is kept for backwards-compatibility with Node 18
assert: { type: "json" },
})
).default;
const requirePath = packageJsonPath ?? (await findUp("package.json", { cwd: process.cwd() }));
if (!requirePath) throw new Error("Could not find package.json to import relative to.");

const require = createRequire(requirePath);
importedArtifact = require(artifactPath);
} catch (error) {
console.error();
console.error("Could not import contract artifact at", artifactPath);
Expand Down
Loading
Loading