From 843298a042a9639ae7c7d05651feb4f3ce266024 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Wed, 20 Mar 2024 22:41:20 +0000 Subject: [PATCH] chore: update world imports (#2487) --- e2e/packages/contracts/mud.config.ts | 2 +- .../minimal/packages/contracts/mud.config.ts | 2 +- .../packages/plugin-example/.gitignore | 5 --- .../packages/plugin-example/package.json | 41 ------------------- .../plugin-example/ts/library/config.ts | 11 ----- .../plugin-example/ts/library/defaults.ts | 3 -- .../plugin-example/ts/library/index.ts | 3 -- .../plugin-example/ts/library/types.ts | 10 ----- .../ts/register/configExtensions.ts | 18 -------- .../plugin-example/ts/register/index.ts | 7 ---- .../ts/register/typeExtensions.ts | 32 --------------- .../packages/plugin-example/tsconfig.json | 19 --------- .../packages/plugin-example/tsup.config.ts | 11 ----- .../packages/contracts/mud.config.ts | 2 +- packages/cli/src/build.ts | 3 +- packages/cli/src/commands/build.ts | 2 +- packages/cli/src/commands/dev-contracts.ts | 2 +- packages/cli/src/commands/trace.ts | 3 +- packages/cli/src/commands/worldgen.ts | 2 +- packages/cli/src/runDeploy.ts | 3 +- packages/world-modules/mud.config.ts | 2 +- packages/world-modules/ts/scripts/worldgen.ts | 2 +- .../phaser/packages/contracts/mud.config.ts | 2 +- .../packages/contracts/mud.config.ts | 2 +- .../react/packages/contracts/mud.config.ts | 2 +- .../threejs/packages/contracts/mud.config.ts | 2 +- .../vanilla/packages/contracts/mud.config.ts | 2 +- test/mock-game-contracts/mud.config.ts | 2 +- 28 files changed, 20 insertions(+), 177 deletions(-) delete mode 100644 examples/minimal/packages/plugin-example/.gitignore delete mode 100644 examples/minimal/packages/plugin-example/package.json delete mode 100644 examples/minimal/packages/plugin-example/ts/library/config.ts delete mode 100644 examples/minimal/packages/plugin-example/ts/library/defaults.ts delete mode 100644 examples/minimal/packages/plugin-example/ts/library/index.ts delete mode 100644 examples/minimal/packages/plugin-example/ts/library/types.ts delete mode 100644 examples/minimal/packages/plugin-example/ts/register/configExtensions.ts delete mode 100644 examples/minimal/packages/plugin-example/ts/register/index.ts delete mode 100644 examples/minimal/packages/plugin-example/ts/register/typeExtensions.ts delete mode 100644 examples/minimal/packages/plugin-example/tsconfig.json delete mode 100644 examples/minimal/packages/plugin-example/tsup.config.ts diff --git a/e2e/packages/contracts/mud.config.ts b/e2e/packages/contracts/mud.config.ts index d82882c295..35af3f6a37 100644 --- a/e2e/packages/contracts/mud.config.ts +++ b/e2e/packages/contracts/mud.config.ts @@ -1,4 +1,4 @@ -import { defineWorld } from "@latticexyz/world/config/v2"; +import { defineWorld } from "@latticexyz/world"; export default defineWorld({ tables: { diff --git a/examples/minimal/packages/contracts/mud.config.ts b/examples/minimal/packages/contracts/mud.config.ts index 56860f5861..68b53a991a 100644 --- a/examples/minimal/packages/contracts/mud.config.ts +++ b/examples/minimal/packages/contracts/mud.config.ts @@ -1,4 +1,4 @@ -import { defineWorld } from "@latticexyz/world/config/v2"; +import { defineWorld } from "@latticexyz/world"; import { resolveTableId } from "@latticexyz/config/library"; export default defineWorld({ diff --git a/examples/minimal/packages/plugin-example/.gitignore b/examples/minimal/packages/plugin-example/.gitignore deleted file mode 100644 index 8556908b69..0000000000 --- a/examples/minimal/packages/plugin-example/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -dist/ -out/ -cache/ -node_modules/ -artifacts/ diff --git a/examples/minimal/packages/plugin-example/package.json b/examples/minimal/packages/plugin-example/package.json deleted file mode 100644 index 9e1558d858..0000000000 --- a/examples/minimal/packages/plugin-example/package.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "name": "plugin-example", - "version": "0.0.0", - "private": true, - "license": "MIT", - "type": "module", - "exports": { - ".": "./dist/ts/library/index.js", - "./register": "./dist/ts/register/index.js" - }, - "typesVersions": { - "*": { - "index": [ - "./ts/library/index.ts" - ], - "register": [ - "./ts/register/index.ts" - ] - } - }, - "scripts": { - "build": "pnpm run build:js", - "build:js": "tsup", - "clean": "pnpm run clean:js", - "clean:js": "rimraf dist", - "test": "tsc --noEmit" - }, - "dependencies": { - "@latticexyz/common": "link:../../../../packages/common", - "@latticexyz/config": "link:../../../../packages/config", - "@latticexyz/store": "link:../../../../packages/store", - "@latticexyz/world": "link:../../../../packages/world", - "zod": "^3.21.4" - }, - "devDependencies": { - "@types/node": "^18.15.11", - "rimraf": "^3.0.2", - "tsup": "^6.7.0", - "typescript": "5.4.2" - } -} diff --git a/examples/minimal/packages/plugin-example/ts/library/config.ts b/examples/minimal/packages/plugin-example/ts/library/config.ts deleted file mode 100644 index 7c21728c7f..0000000000 --- a/examples/minimal/packages/plugin-example/ts/library/config.ts +++ /dev/null @@ -1,11 +0,0 @@ -// configExtensions.ts -import { z } from "zod"; -import { DEFAULTS } from "./defaults"; - -// (if your zod schema is complicated, you should put it in a separate library with any other logic) -export const zMyPluginConfig = z - .object({ - myNewConfigOption: z.boolean().default(DEFAULTS.myNewConfigOption), - }) - // Catchall preserves other plugins' options - .catchall(z.any()); diff --git a/examples/minimal/packages/plugin-example/ts/library/defaults.ts b/examples/minimal/packages/plugin-example/ts/library/defaults.ts deleted file mode 100644 index 61ff913653..0000000000 --- a/examples/minimal/packages/plugin-example/ts/library/defaults.ts +++ /dev/null @@ -1,3 +0,0 @@ -export const DEFAULTS = { - myNewConfigOption: true, -} as const; diff --git a/examples/minimal/packages/plugin-example/ts/library/index.ts b/examples/minimal/packages/plugin-example/ts/library/index.ts deleted file mode 100644 index 5867998163..0000000000 --- a/examples/minimal/packages/plugin-example/ts/library/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from "./defaults"; -export * from "./config"; -export * from "./types"; diff --git a/examples/minimal/packages/plugin-example/ts/library/types.ts b/examples/minimal/packages/plugin-example/ts/library/types.ts deleted file mode 100644 index d83d249712..0000000000 --- a/examples/minimal/packages/plugin-example/ts/library/types.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { z } from "zod"; -import { zMyPluginConfig } from "./config"; - -// zod doesn't preserve doc comments -export interface MyPluginUserConfig { - /** Add a description for your option */ - myNewConfigOption?: boolean; -} - -export type MyPluginConfig = z.output; diff --git a/examples/minimal/packages/plugin-example/ts/register/configExtensions.ts b/examples/minimal/packages/plugin-example/ts/register/configExtensions.ts deleted file mode 100644 index 4e5bd7ac33..0000000000 --- a/examples/minimal/packages/plugin-example/ts/register/configExtensions.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { extendMUDCoreConfig, fromZodErrorCustom } from "@latticexyz/config/library"; -import { ZodError } from "zod"; -import { zMyPluginConfig } from "../library"; - -extendMUDCoreConfig((config) => { - // This function gets called within mudConfig. - // The call order of config extenders depends on the order of their imports. - // Any config validation and transformation should be placed here. - try { - return zMyPluginConfig.parse(config); - } catch (error) { - if (error instanceof ZodError) { - throw fromZodErrorCustom(error, "MyPluginConfig Validation Error"); - } else { - throw error; - } - } -}); diff --git a/examples/minimal/packages/plugin-example/ts/register/index.ts b/examples/minimal/packages/plugin-example/ts/register/index.ts deleted file mode 100644 index 92ea4688eb..0000000000 --- a/examples/minimal/packages/plugin-example/ts/register/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -// Importing this file has side-effects for MUD config, -// and the order of imports is important in relation to other plugins -// (store should usually be the first plugin, followed by world) - -// Extend core config and types -import "./configExtensions"; -import "./typeExtensions"; diff --git a/examples/minimal/packages/plugin-example/ts/register/typeExtensions.ts b/examples/minimal/packages/plugin-example/ts/register/typeExtensions.ts deleted file mode 100644 index dff95c32ce..0000000000 --- a/examples/minimal/packages/plugin-example/ts/register/typeExtensions.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { OrDefaults } from "@latticexyz/common/type-utils"; -import { MUDCoreUserConfig } from "@latticexyz/config/library"; -import { DEFAULTS, MyPluginUserConfig, MyPluginConfig } from "../library"; - -import "@latticexyz/world/register"; - -// Inject the plugin options into the core config. -// Re-exporting an interface of an existing module merges them, adding new options to the interface. -// (typescript has no way to override types) -declare module "@latticexyz/config/library" { - // Extend the user config type, which represents the config as written by the users. - // Most things are optional here. - // eslint-disable-next-line @typescript-eslint/no-empty-interface - export interface MUDCoreUserConfig extends MyPluginUserConfig {} - - // Also extend the config type, which represents the configuration after it has been resolved. - // It should not have any optional properties, with the default values applied instead. - // Other plugins may receive this resolved config as their input. - // eslint-disable-next-line @typescript-eslint/no-empty-interface - export interface MUDCoreConfig extends MyPluginConfig {} -} - -declare module "@latticexyz/store/register" { - // eslint-disable-next-line @typescript-eslint/no-empty-interface - export interface ExpandMUDUserConfig - extends OrDefaults< - T, - { - myNewConfigOption: typeof DEFAULTS.myNewConfigOption; - } - > {} -} diff --git a/examples/minimal/packages/plugin-example/tsconfig.json b/examples/minimal/packages/plugin-example/tsconfig.json deleted file mode 100644 index 0600b17e05..0000000000 --- a/examples/minimal/packages/plugin-example/tsconfig.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "compilerOptions": { - /* Visit https://aka.ms/tsconfig.json to read more about this file */ - "target": "es2021", - "types": ["node"], - "module": "esnext", - "moduleResolution": "node", - "declaration": true, - "sourceMap": true, - "outDir": "dist", - "isolatedModules": true, - "allowSyntheticDefaultImports": true, - "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, - "strict": true, - "skipLibCheck": true - }, - "include": ["ts"] -} diff --git a/examples/minimal/packages/plugin-example/tsup.config.ts b/examples/minimal/packages/plugin-example/tsup.config.ts deleted file mode 100644 index c13db6face..0000000000 --- a/examples/minimal/packages/plugin-example/tsup.config.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { defineConfig } from "tsup"; - -export default defineConfig({ - entry: ["ts/library/index.ts", "ts/register/index.ts"], - target: "esnext", - format: ["esm"], - dts: false, - sourcemap: true, - clean: true, - minify: true, -}); diff --git a/examples/multiple-accounts/packages/contracts/mud.config.ts b/examples/multiple-accounts/packages/contracts/mud.config.ts index f3bf22fc9c..d195c151da 100644 --- a/examples/multiple-accounts/packages/contracts/mud.config.ts +++ b/examples/multiple-accounts/packages/contracts/mud.config.ts @@ -1,4 +1,4 @@ -import { defineWorld } from "@latticexyz/world/config/v2"; +import { defineWorld } from "@latticexyz/world"; export default defineWorld({ namespace: "LastCall", diff --git a/packages/cli/src/build.ts b/packages/cli/src/build.ts index d89c700583..d359e5af28 100644 --- a/packages/cli/src/build.ts +++ b/packages/cli/src/build.ts @@ -2,7 +2,8 @@ import { existsSync, readFileSync, writeFileSync } from "node:fs"; import path from "node:path"; import { tablegen } from "@latticexyz/store/codegen"; import { worldgen } from "@latticexyz/world/node"; -import { World as WorldConfig, worldToV1 } from "@latticexyz/world/config/v2"; +import { World as WorldConfig } from "@latticexyz/world"; +import { worldToV1 } from "@latticexyz/world/config/v2"; import { forge, getForgeConfig, getRemappings } from "@latticexyz/common/foundry"; import { getExistingContracts } from "./utils/getExistingContracts"; import { debug as parentDebug } from "./debug"; diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.ts index 5ea6382d52..b36477243f 100644 --- a/packages/cli/src/commands/build.ts +++ b/packages/cli/src/commands/build.ts @@ -1,6 +1,6 @@ import type { CommandModule } from "yargs"; import { loadConfig } from "@latticexyz/config/node"; -import { World as WorldConfig } from "@latticexyz/world/config/v2"; +import { World as WorldConfig } from "@latticexyz/world"; import { getSrcDirectory } from "@latticexyz/common/foundry"; import { build } from "../build"; diff --git a/packages/cli/src/commands/dev-contracts.ts b/packages/cli/src/commands/dev-contracts.ts index 6ceaf97949..53c5572693 100644 --- a/packages/cli/src/commands/dev-contracts.ts +++ b/packages/cli/src/commands/dev-contracts.ts @@ -4,7 +4,7 @@ import chalk from "chalk"; import chokidar from "chokidar"; import { loadConfig, resolveConfigPath } from "@latticexyz/config/node"; import path from "path"; -import { World as WorldConfig } from "@latticexyz/world/config/v2"; +import { World as WorldConfig } from "@latticexyz/world"; import { homedir } from "os"; import { rmSync } from "fs"; import { deployOptions, runDeploy } from "../runDeploy"; diff --git a/packages/cli/src/commands/trace.ts b/packages/cli/src/commands/trace.ts index 53cc30e5a1..6d7fa8d1ee 100644 --- a/packages/cli/src/commands/trace.ts +++ b/packages/cli/src/commands/trace.ts @@ -12,7 +12,8 @@ import { resourceToHex } from "@latticexyz/common"; import { getExistingContracts } from "../utils/getExistingContracts"; import { createClient, http } from "viem"; import { getChainId } from "viem/actions"; -import { World as WorldConfig, worldToV1 } from "@latticexyz/world/config/v2"; +import { World as WorldConfig } from "@latticexyz/world"; +import { worldToV1 } from "@latticexyz/world/config/v2"; // TODO account for multiple namespaces (https://github.com/latticexyz/mud/issues/994) const systemsTableId = resourceToHex({ diff --git a/packages/cli/src/commands/worldgen.ts b/packages/cli/src/commands/worldgen.ts index 324ad0c10f..a599b813d4 100644 --- a/packages/cli/src/commands/worldgen.ts +++ b/packages/cli/src/commands/worldgen.ts @@ -1,6 +1,6 @@ import type { CommandModule } from "yargs"; import { loadConfig } from "@latticexyz/config/node"; -import { World as WorldConfig } from "@latticexyz/world/config/v2"; +import { World as WorldConfig } from "@latticexyz/world"; import { worldgen } from "@latticexyz/world/node"; import { getSrcDirectory } from "@latticexyz/common/foundry"; import path from "path"; diff --git a/packages/cli/src/runDeploy.ts b/packages/cli/src/runDeploy.ts index 9375330b66..0d9cf1ca88 100644 --- a/packages/cli/src/runDeploy.ts +++ b/packages/cli/src/runDeploy.ts @@ -5,7 +5,8 @@ import { deploy } from "./deploy/deploy"; import { createWalletClient, http, Hex, isHex } from "viem"; import { privateKeyToAccount } from "viem/accounts"; import { loadConfig } from "@latticexyz/config/node"; -import { World as WorldConfig, worldToV1 } from "@latticexyz/world/config/v2"; +import { World as WorldConfig } from "@latticexyz/world"; +import { worldToV1 } from "@latticexyz/world/config/v2"; import { getOutDirectory, getRpcUrl, getSrcDirectory } from "@latticexyz/common/foundry"; import chalk from "chalk"; import { MUDError } from "@latticexyz/common/errors"; diff --git a/packages/world-modules/mud.config.ts b/packages/world-modules/mud.config.ts index ecb008acaa..c0f0c34992 100644 --- a/packages/world-modules/mud.config.ts +++ b/packages/world-modules/mud.config.ts @@ -1,4 +1,4 @@ -import { defineWorld } from "@latticexyz/world/config/v2"; +import { defineWorld } from "@latticexyz/world"; export default defineWorld({ codegen: { diff --git a/packages/world-modules/ts/scripts/worldgen.ts b/packages/world-modules/ts/scripts/worldgen.ts index e16a203f3f..47b895c05b 100644 --- a/packages/world-modules/ts/scripts/worldgen.ts +++ b/packages/world-modules/ts/scripts/worldgen.ts @@ -3,7 +3,7 @@ import path, { basename } from "path"; import { rmSync } from "fs"; import { loadConfig } from "@latticexyz/config/node"; import { getSrcDirectory } from "@latticexyz/common/foundry"; -import { World as WorldConfig } from "@latticexyz/world/config/v2"; +import { World as WorldConfig } from "@latticexyz/world"; import { worldgen } from "@latticexyz/world/node"; // TODO dedupe this and cli's worldgen command diff --git a/templates/phaser/packages/contracts/mud.config.ts b/templates/phaser/packages/contracts/mud.config.ts index 1be4a87791..4a495d0c4e 100644 --- a/templates/phaser/packages/contracts/mud.config.ts +++ b/templates/phaser/packages/contracts/mud.config.ts @@ -1,4 +1,4 @@ -import { defineWorld } from "@latticexyz/world/config/v2"; +import { defineWorld } from "@latticexyz/world"; export default defineWorld({ tables: { diff --git a/templates/react-ecs/packages/contracts/mud.config.ts b/templates/react-ecs/packages/contracts/mud.config.ts index 1be4a87791..4a495d0c4e 100644 --- a/templates/react-ecs/packages/contracts/mud.config.ts +++ b/templates/react-ecs/packages/contracts/mud.config.ts @@ -1,4 +1,4 @@ -import { defineWorld } from "@latticexyz/world/config/v2"; +import { defineWorld } from "@latticexyz/world"; export default defineWorld({ tables: { diff --git a/templates/react/packages/contracts/mud.config.ts b/templates/react/packages/contracts/mud.config.ts index f10a28e3eb..2f11567141 100644 --- a/templates/react/packages/contracts/mud.config.ts +++ b/templates/react/packages/contracts/mud.config.ts @@ -1,4 +1,4 @@ -import { defineWorld } from "@latticexyz/world/config/v2"; +import { defineWorld } from "@latticexyz/world"; export default defineWorld({ tables: { diff --git a/templates/threejs/packages/contracts/mud.config.ts b/templates/threejs/packages/contracts/mud.config.ts index e8b8f855d6..ad59df29ee 100644 --- a/templates/threejs/packages/contracts/mud.config.ts +++ b/templates/threejs/packages/contracts/mud.config.ts @@ -1,4 +1,4 @@ -import { defineWorld } from "@latticexyz/world/config/v2"; +import { defineWorld } from "@latticexyz/world"; export default defineWorld({ tables: { diff --git a/templates/vanilla/packages/contracts/mud.config.ts b/templates/vanilla/packages/contracts/mud.config.ts index 1be4a87791..4a495d0c4e 100644 --- a/templates/vanilla/packages/contracts/mud.config.ts +++ b/templates/vanilla/packages/contracts/mud.config.ts @@ -1,4 +1,4 @@ -import { defineWorld } from "@latticexyz/world/config/v2"; +import { defineWorld } from "@latticexyz/world"; export default defineWorld({ tables: { diff --git a/test/mock-game-contracts/mud.config.ts b/test/mock-game-contracts/mud.config.ts index c56bca8878..064ffbeea7 100644 --- a/test/mock-game-contracts/mud.config.ts +++ b/test/mock-game-contracts/mud.config.ts @@ -1,4 +1,4 @@ -import { defineWorld } from "@latticexyz/world/config/v2"; +import { defineWorld } from "@latticexyz/world"; export default defineWorld({ enums: {