Skip to content

Commit

Permalink
feat(cli): register namespace labels (#3172)
Browse files Browse the repository at this point in the history
  • Loading branch information
holic authored Sep 12, 2024
1 parent e9c7594 commit d3acd92
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/metal-brooms-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/cli": patch
---

Along with table and system labels, the MUD deployer now registers namespace labels. Additionally, labels will only be registered if they differ from the underlying resource name.
28 changes: 23 additions & 5 deletions packages/cli/src/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ensureFunctions } from "./ensureFunctions";
import { ensureModules } from "./ensureModules";
import { ensureNamespaceOwner } from "./ensureNamespaceOwner";
import { debug } from "./debug";
import { resourceToLabel } from "@latticexyz/common";
import { resourceToHex, resourceToLabel } from "@latticexyz/common";
import { ensureContractsDeployed } from "./ensureContractsDeployed";
import { randomBytes } from "crypto";
import { ensureWorldFactory } from "./ensureWorldFactory";
Expand All @@ -19,6 +19,7 @@ import { waitForTransactions } from "./waitForTransactions";
import { ContractArtifact } from "@latticexyz/world/node";
import { World } from "@latticexyz/world";
import { deployCustomWorld } from "./deployCustomWorld";
import { uniqueBy } from "@latticexyz/common/utils";

type DeployOptions = {
config: World;
Expand Down Expand Up @@ -150,9 +151,26 @@ export async function deploy({
modules,
});

const tableTags = tables.map(({ tableId: resourceId, label }) => ({ resourceId, tag: "label", value: label }));
const systemTags = systems.flatMap(({ systemId: resourceId, label, abi, worldAbi }) => [
{ resourceId, tag: "label", value: label },
const namespaceTags = uniqueBy(
[...tables, ...systems]
// only register labels if they differ from the resource ID
.filter(({ namespace, namespaceLabel }) => namespaceLabel !== namespace)
.map(({ namespace, namespaceLabel }) => ({
resourceId: resourceToHex({ type: "namespace", namespace, name: "" }),
tag: "label",
value: namespaceLabel,
})),
(tag) => tag.resourceId,
);

const tableTags = tables
// only register labels if they differ from the resource ID
.filter((table) => table.label !== table.name)
.map(({ tableId: resourceId, label }) => ({ resourceId, tag: "label", value: label }));

const systemTags = systems.flatMap(({ name, systemId: resourceId, label, abi, worldAbi }) => [
// only register labels if they differ from the resource ID
...(label !== name ? [{ resourceId, tag: "label", value: label }] : []),
{ resourceId, tag: "abi", value: abi.join("\n") },
{ resourceId, tag: "worldAbi", value: worldAbi.join("\n") },
]);
Expand All @@ -162,7 +180,7 @@ export async function deploy({
deployerAddress,
libraries,
worldDeploy,
tags: [...tableTags, ...systemTags],
tags: [...namespaceTags, ...tableTags, ...systemTags],
valueToHex: stringToHex,
});

Expand Down

0 comments on commit d3acd92

Please sign in to comment.