From e2a66aefc49ee5378ecb2e3adccb816d263e4392 Mon Sep 17 00:00:00 2001 From: dk1a Date: Sat, 8 Apr 2023 16:00:52 +0300 Subject: [PATCH 1/2] feat(config): separate config from cli --- packages/cli/contracts/src/codegen/Tables.sol | 4 +- packages/cli/package.json | 12 +- packages/cli/scripts/codegen.ts | 2 +- packages/cli/src/commands/deploy-v2.ts | 6 +- packages/cli/src/commands/set-version.ts | 5 +- packages/cli/src/commands/tablegen.ts | 2 +- packages/cli/src/commands/tsgen.ts | 2 +- packages/cli/src/commands/worldgen.ts | 3 +- packages/cli/src/config/index.ts | 24 ---- packages/cli/src/index.ts | 16 +-- .../render-solidity/renderTypesFromConfig.ts | 2 +- .../cli/src/render-solidity/tableOptions.ts | 2 +- packages/cli/src/render-solidity/tablegen.ts | 2 +- packages/cli/src/render-solidity/userType.ts | 3 +- packages/cli/src/render-solidity/worldgen.ts | 2 +- .../cli/src/render-ts/recsV1TableOptions.ts | 2 +- packages/cli/src/render-ts/tsgen.ts | 2 +- packages/cli/src/utils/contractToInterface.ts | 2 +- packages/cli/src/utils/deploy-v2.ts | 4 +- packages/cli/src/utils/errors.ts | 26 +---- packages/cli/tsconfig.json | 10 +- packages/config/package.json | 11 +- .../config => config/src}/commonSchemas.ts | 0 .../src}/dynamicResolution.ts | 2 +- packages/config/src/errors.ts | 25 ++++ packages/config/src/index.ts | 27 ++++- .../src/config => config/src}/loadConfig.ts | 2 +- .../src/store}/loadStoreConfig.ts | 4 +- .../src/store}/parseStoreConfig.test-d.ts | 0 .../src/store}/parseStoreConfig.ts | 6 +- .../src/utils => config/src}/typeUtils.ts | 0 .../src/config => config/src}/validation.ts | 0 .../src/config => config/src}/world/index.ts | 0 .../src}/world/loadWorldConfig.test-d.ts | 0 .../src}/world/loadWorldConfig.ts | 2 +- .../src}/world/parseWorldConfig.ts | 0 .../src}/world/resolveWorldConfig.ts | 2 +- .../config => config/src}/world/userTypes.ts | 0 packages/config/tsconfig.json | 1 - packages/config/vite.config.ts | 1 + packages/store/mud.config.mts | 2 +- packages/store/package.json | 1 + packages/world/mud.config.mts | 2 +- packages/world/package.json | 1 + yarn.lock | 108 ++++++++++++------ 45 files changed, 182 insertions(+), 148 deletions(-) delete mode 100644 packages/cli/src/config/index.ts rename packages/{cli/src/config => config/src}/commonSchemas.ts (100%) rename packages/{cli/src/config => config/src}/dynamicResolution.ts (96%) create mode 100644 packages/config/src/errors.ts rename packages/{cli/src/config => config/src}/loadConfig.ts (95%) rename packages/{cli/src/config => config/src/store}/loadStoreConfig.ts (80%) rename packages/{cli/src/config => config/src/store}/parseStoreConfig.test-d.ts (100%) rename packages/{cli/src/config => config/src/store}/parseStoreConfig.ts (98%) rename packages/{cli/src/utils => config/src}/typeUtils.ts (100%) rename packages/{cli/src/config => config/src}/validation.ts (100%) rename packages/{cli/src/config => config/src}/world/index.ts (100%) rename packages/{cli/src/config => config/src}/world/loadWorldConfig.test-d.ts (100%) rename packages/{cli/src/config => config/src}/world/loadWorldConfig.ts (94%) rename packages/{cli/src/config => config/src}/world/parseWorldConfig.ts (100%) rename packages/{cli/src/config => config/src}/world/resolveWorldConfig.ts (98%) rename packages/{cli/src/config => config/src}/world/userTypes.ts (100%) diff --git a/packages/cli/contracts/src/codegen/Tables.sol b/packages/cli/contracts/src/codegen/Tables.sol index c2f6bee77e..737c017f43 100644 --- a/packages/cli/contracts/src/codegen/Tables.sol +++ b/packages/cli/contracts/src/codegen/Tables.sol @@ -3,6 +3,6 @@ pragma solidity >=0.8.0; /* Autogenerated file. Do not edit manually. */ -import { Statics, StaticsTableId, StaticsData } from "./tables/Statics.sol"; -import { Dynamics, DynamicsTableId, DynamicsData } from "./tables/Dynamics.sol"; +import { Statics, StaticsData, StaticsTableId } from "./tables/Statics.sol"; +import { Dynamics, DynamicsData, DynamicsTableId } from "./tables/Dynamics.sol"; import { Singleton, SingletonTableId } from "./tables/Singleton.sol"; diff --git a/packages/cli/package.json b/packages/cli/package.json index 1161348be7..1d420694e9 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -17,12 +17,12 @@ }, "scripts": { "prepare": "yarn build", - "codegen": "ts-node --esm --files ./scripts/codegen.ts", + "codegen": "tsx ./scripts/codegen.ts", "lint": "eslint . --ext .ts", "dev": "tsup --watch", "build": "tsup", "link": "yarn link", - "test": "vitest typecheck --run && yarn test:contracts", + "test": "tsc --noEmit && yarn test:contracts", "test:contracts": "yarn codegen && forge test", "release": "npm publish --access=public" }, @@ -33,13 +33,14 @@ "@types/node": "^17.0.34", "@types/openurl": "^1.0.0", "@types/yargs": "^17.0.10", - "esbuild": "^0.15.16", "tsup": "^6.6.3", + "tsx": "^3.12.6", "vitest": "^0.29.8" }, "dependencies": { "@improbable-eng/grpc-web": "^0.15.0", "@improbable-eng/grpc-web-node-http-transport": "^0.15.0", + "@latticexyz/config": "^1.41.0", "@latticexyz/schema-type": "^1.41.0", "@latticexyz/services": "^1.41.0", "@latticexyz/solecs": "^1.41.0", @@ -51,10 +52,8 @@ "dotenv": "^16.0.3", "ds-test": "https://github.com/dapphub/ds-test.git#c9ce3f25bde29fc5eb9901842bf02850dfd2d084", "ejs": "^3.1.8", - "esbuild": "^0.17.14", "ethers": "^5.7.2", "execa": "^7.0.0", - "find-up": "^6.3.0", "forge-std": "https://github.com/foundry-rs/forge-std.git#b4f121555729b3afb3c5ffccb62ff4b6e2818fd3", "glob": "^8.0.3", "nice-grpc-web": "^2.0.1", @@ -63,12 +62,11 @@ "prettier": "^2.8.4", "prettier-plugin-solidity": "^1.1.2", "table": "^6.8.1", - "ts-node": "^10.9.1", "typechain": "^8.1.1", "typescript": "^4.9.5", "yargs": "^17.7.1", "zod": "^3.21.4", - "zod-validation-error": "^1.0.1" + "zod-validation-error": "^1.3.0" }, "gitHead": "914a1e0ae4a573d685841ca2ea921435057deb8f" } diff --git a/packages/cli/scripts/codegen.ts b/packages/cli/scripts/codegen.ts index 3c8f953c4f..9e12b4bc79 100644 --- a/packages/cli/scripts/codegen.ts +++ b/packages/cli/scripts/codegen.ts @@ -1,5 +1,5 @@ import path from "path"; -import { storeConfig, parseStoreConfig } from "../src/config/index.js"; +import { storeConfig, parseStoreConfig } from "@latticexyz/config"; import { tablegen } from "../src/render-solidity/tablegen.js"; import { logError } from "../src/utils/errors.js"; import { getSrcDirectory } from "../src/utils/foundry.js"; diff --git a/packages/cli/src/commands/deploy-v2.ts b/packages/cli/src/commands/deploy-v2.ts index 57d7dec604..b1bc4c4d8d 100644 --- a/packages/cli/src/commands/deploy-v2.ts +++ b/packages/cli/src/commands/deploy-v2.ts @@ -2,12 +2,12 @@ import chalk from "chalk"; import glob from "glob"; import path, { basename } from "path"; import type { CommandModule, Options } from "yargs"; -import { loadWorldConfig } from "../config/world/index.js"; +import { loadStoreConfig, loadWorldConfig } from "@latticexyz/config"; +import { MUDError } from "@latticexyz/config"; import { deploy } from "../utils/deploy-v2.js"; -import { logError, MUDError } from "../utils/errors.js"; +import { logError } from "../utils/errors.js"; import { forge, getRpcUrl, getSrcDirectory } from "../utils/foundry.js"; import { mkdirSync, writeFileSync } from "fs"; -import { loadStoreConfig } from "../config/loadStoreConfig.js"; import { getChainId } from "../utils/getChainId.js"; export type DeployOptions = { diff --git a/packages/cli/src/commands/set-version.ts b/packages/cli/src/commands/set-version.ts index 775e727624..98aeeccbd6 100644 --- a/packages/cli/src/commands/set-version.ts +++ b/packages/cli/src/commands/set-version.ts @@ -2,8 +2,9 @@ import chalk from "chalk"; import { existsSync, readFileSync, rmSync, writeFileSync } from "fs"; import path from "path"; import type { CommandModule } from "yargs"; -import { logError, MUDError } from "../utils/errors.js"; -import localPackageJson from "../../package.json"; +import { MUDError } from "@latticexyz/config"; +import { logError } from "../utils/errors.js"; +import localPackageJson from "../../package.json" assert { type: "json" }; type Options = { backup?: boolean; diff --git a/packages/cli/src/commands/tablegen.ts b/packages/cli/src/commands/tablegen.ts index 9e7bdac792..ca09adea35 100644 --- a/packages/cli/src/commands/tablegen.ts +++ b/packages/cli/src/commands/tablegen.ts @@ -1,6 +1,6 @@ import path from "path"; import type { CommandModule } from "yargs"; -import { loadStoreConfig } from "../config/loadStoreConfig.js"; +import { loadStoreConfig } from "@latticexyz/config"; import { tablegen } from "../render-solidity/tablegen.js"; import { getSrcDirectory } from "../utils/index.js"; diff --git a/packages/cli/src/commands/tsgen.ts b/packages/cli/src/commands/tsgen.ts index 9d69444c91..69fcaf2e86 100644 --- a/packages/cli/src/commands/tsgen.ts +++ b/packages/cli/src/commands/tsgen.ts @@ -1,5 +1,5 @@ import type { CommandModule } from "yargs"; -import { loadStoreConfig } from "../config/loadStoreConfig.js"; +import { loadStoreConfig } from "@latticexyz/config"; import { tsgen } from "../render-ts/tsgen.js"; type Options = { diff --git a/packages/cli/src/commands/worldgen.ts b/packages/cli/src/commands/worldgen.ts index 158ff42c69..dc02e5865a 100644 --- a/packages/cli/src/commands/worldgen.ts +++ b/packages/cli/src/commands/worldgen.ts @@ -1,6 +1,5 @@ import type { CommandModule } from "yargs"; -import { loadStoreConfig } from "../config/loadStoreConfig.js"; -import { loadWorldConfig } from "../config/index.js"; +import { loadStoreConfig, loadWorldConfig } from "@latticexyz/config"; import { getSrcDirectory } from "../utils/foundry.js"; import glob from "glob"; import path, { basename } from "path"; diff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.ts deleted file mode 100644 index c72545dfd5..0000000000 --- a/packages/cli/src/config/index.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { ExtractUserTypes, StringForUnion } from "../utils/typeUtils.js"; -import { StoreUserConfig, StoreConfig } from "./parseStoreConfig.js"; -import { WorldUserConfig, ResolvedWorldConfig } from "./world/index.js"; - -export type MUDUserConfig< - EnumNames extends StringForUnion = StringForUnion, - StaticUserTypes extends ExtractUserTypes = ExtractUserTypes -> = StoreUserConfig & WorldUserConfig; -export type MUDConfig = StoreConfig & ResolvedWorldConfig; - -export function mudConfig< - EnumNames extends StringForUnion = never, - StaticUserTypes extends ExtractUserTypes = ExtractUserTypes ->(config: MUDUserConfig) { - return config; -} - -export * from "./commonSchemas.js"; -export * from "./loadConfig.js"; -export * from "./loadStoreConfig.js"; -export * from "./parseStoreConfig.js"; -export * from "./world/index.js"; -export * from "./validation.js"; -export * from "./dynamicResolution.js"; diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index 26f8b11cfe..cb0ff5c3b5 100755 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -1,15 +1 @@ -export { loadStoreConfig } from "./config/loadStoreConfig.js"; -export { parseStoreConfig } from "./config/parseStoreConfig.js"; -export { loadWorldConfig, resolveWorldConfig, parseWorldConfig } from "./config/world/index.js"; -export { resolveTableId } from "./config/dynamicResolution.js"; - -export type { - StoreUserConfig, - StoreConfig, - WorldUserConfig, - ResolvedWorldConfig, - MUDUserConfig, - MUDConfig, -} from "./config/index.js"; - -export { storeConfig, mudConfig } from "./config/index.js"; +export {}; diff --git a/packages/cli/src/render-solidity/renderTypesFromConfig.ts b/packages/cli/src/render-solidity/renderTypesFromConfig.ts index 77f95cce6d..aec8e2bce2 100644 --- a/packages/cli/src/render-solidity/renderTypesFromConfig.ts +++ b/packages/cli/src/render-solidity/renderTypesFromConfig.ts @@ -1,4 +1,4 @@ -import { StoreConfig } from "../config/parseStoreConfig.js"; +import { StoreConfig } from "@latticexyz/config"; import { renderTypes } from "./renderTypes.js"; export function renderTypesFromConfig(config: StoreConfig) { diff --git a/packages/cli/src/render-solidity/tableOptions.ts b/packages/cli/src/render-solidity/tableOptions.ts index eaea9e05e5..667812ceb8 100644 --- a/packages/cli/src/render-solidity/tableOptions.ts +++ b/packages/cli/src/render-solidity/tableOptions.ts @@ -1,6 +1,6 @@ import path from "path"; import { SchemaTypeArrayToElement } from "@latticexyz/schema-type"; -import { StoreConfig } from "../config/parseStoreConfig.js"; +import { StoreConfig } from "@latticexyz/config"; import { ImportDatum, RenderTableDynamicField, diff --git a/packages/cli/src/render-solidity/tablegen.ts b/packages/cli/src/render-solidity/tablegen.ts index 073a104bb3..09baf2f7b5 100644 --- a/packages/cli/src/render-solidity/tablegen.ts +++ b/packages/cli/src/render-solidity/tablegen.ts @@ -1,5 +1,5 @@ import path from "path"; -import { StoreConfig } from "../config/index.js"; +import { StoreConfig } from "@latticexyz/config"; import { getTableOptions } from "./tableOptions.js"; import { renderTable } from "./renderTable.js"; import { renderTypesFromConfig } from "./renderTypesFromConfig.js"; diff --git a/packages/cli/src/render-solidity/userType.ts b/packages/cli/src/render-solidity/userType.ts index 51f39d5d92..35c41f0cfe 100644 --- a/packages/cli/src/render-solidity/userType.ts +++ b/packages/cli/src/render-solidity/userType.ts @@ -1,7 +1,6 @@ import { AbiTypeToSchemaType, getStaticByteLength, SchemaType, SchemaTypeToAbiType } from "@latticexyz/schema-type"; -import { StoreConfig } from "../config/index.js"; +import { StoreConfig, parseStaticArray } from "@latticexyz/config"; import { ImportDatum, RenderTableType } from "./types.js"; -import { parseStaticArray } from "../config/validation.js"; export type UserTypeInfo = ReturnType; diff --git a/packages/cli/src/render-solidity/worldgen.ts b/packages/cli/src/render-solidity/worldgen.ts index d58766c6f5..1e6f02fc34 100644 --- a/packages/cli/src/render-solidity/worldgen.ts +++ b/packages/cli/src/render-solidity/worldgen.ts @@ -1,6 +1,6 @@ import { readFileSync } from "fs"; import path from "path"; -import { MUDConfig } from "../config/index.js"; +import { MUDConfig } from "@latticexyz/config"; import { contractToInterface } from "../utils/contractToInterface.js"; import { formatAndWriteSolidity } from "../utils/formatAndWrite.js"; import { renderSystemInterface } from "./renderSystemInterface.js"; diff --git a/packages/cli/src/render-ts/recsV1TableOptions.ts b/packages/cli/src/render-ts/recsV1TableOptions.ts index 7b74d7193f..4fb5fad912 100644 --- a/packages/cli/src/render-ts/recsV1TableOptions.ts +++ b/packages/cli/src/render-ts/recsV1TableOptions.ts @@ -1,4 +1,4 @@ -import { StoreConfig } from "../config/parseStoreConfig.js"; +import { StoreConfig } from "@latticexyz/config"; import { resolveAbiOrUserType } from "../render-solidity/userType.js"; import { schemaTypesToRecsTypeStrings } from "./schemaTypesToRecsTypeStrings.js"; import { RecsV1TableOptions } from "./types.js"; diff --git a/packages/cli/src/render-ts/tsgen.ts b/packages/cli/src/render-ts/tsgen.ts index fb7bffcfe2..791969851b 100644 --- a/packages/cli/src/render-ts/tsgen.ts +++ b/packages/cli/src/render-ts/tsgen.ts @@ -1,5 +1,5 @@ import path from "path"; -import { StoreConfig } from "../config/index.js"; +import { StoreConfig } from "@latticexyz/config"; import { getRecsV1TableOptions } from "../render-ts/recsV1TableOptions.js"; import { renderRecsV1Tables } from "../render-ts/renderRecsV1Tables.js"; import { formatAndWriteTypescript } from "../utils/formatAndWrite.js"; diff --git a/packages/cli/src/utils/contractToInterface.ts b/packages/cli/src/utils/contractToInterface.ts index 1c24dcaef2..462a8b807f 100644 --- a/packages/cli/src/utils/contractToInterface.ts +++ b/packages/cli/src/utils/contractToInterface.ts @@ -1,7 +1,7 @@ import { parse, visit } from "@solidity-parser/parser"; import { TypeName, VariableDeclaration } from "@solidity-parser/parser/dist/src/ast-types.js"; +import { MUDError } from "@latticexyz/config"; import { RenderSystemInterfaceFunction } from "../render-solidity/types.js"; -import { MUDError } from "./errors.js"; /** * Parse the contract data to get the functions necessary to generate an interface, diff --git a/packages/cli/src/utils/deploy-v2.ts b/packages/cli/src/utils/deploy-v2.ts index d3e48d7ee3..4891dd3591 100644 --- a/packages/cli/src/utils/deploy-v2.ts +++ b/packages/cli/src/utils/deploy-v2.ts @@ -1,7 +1,7 @@ import { existsSync, readFileSync } from "fs"; import path from "path"; -import { MUDConfig, resolveWithContext } from "../config/index.js"; -import { MUDError } from "./errors.js"; +import { MUDConfig, resolveWithContext } from "@latticexyz/config"; +import { MUDError } from "@latticexyz/config"; import { getOutDirectory, getScriptDirectory, cast, forge } from "./foundry.js"; import { BigNumber, ContractInterface, ethers } from "ethers"; import { IBaseWorld } from "@latticexyz/world/types/ethers-contracts/IBaseWorld.js"; diff --git a/packages/cli/src/utils/errors.ts b/packages/cli/src/utils/errors.ts index ce114b8c21..89dcb6496c 100644 --- a/packages/cli/src/utils/errors.ts +++ b/packages/cli/src/utils/errors.ts @@ -1,28 +1,8 @@ import chalk from "chalk"; -import { z, ZodError, ZodIssueCode } from "zod"; +import { ZodError } from "zod"; import { fromZodError, ValidationError } from "zod-validation-error"; - -// Wrapper with preset styles, only requires a `prefix` -export function fromZodErrorCustom(error: ZodError, prefix: string) { - return fromZodError(error, { - prefix: chalk.red(prefix), - prefixSeparator: "\n- ", - issueSeparator: "\n- ", - }); -} - -export class NotInsideProjectError extends Error { - name = "NotInsideProjectError"; - message = "You are not inside a MUD project"; -} - -export class MUDError extends Error { - name = "MUDError"; -} - -export function UnrecognizedSystemErrorFactory(path: string[], systemName: string) { - return new z.ZodError([{ code: ZodIssueCode.custom, path: path, message: `Unrecognized system: "${systemName}"` }]); -} +import { NotInsideProjectError } from "@latticexyz/config"; +import { MUDError } from "@latticexyz/config"; export function logError(error: unknown) { if (error instanceof ValidationError) { diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json index 5fb5b0f673..89099cad5b 100644 --- a/packages/cli/tsconfig.json +++ b/packages/cli/tsconfig.json @@ -3,9 +3,12 @@ /* Visit https://aka.ms/tsconfig.json to read more about this file */ "target": "es2021", "module": "esnext", - "moduleResolution": "nodenext", + "moduleResolution": "node", "resolveJsonModule": true, - "outDir": "./dist", + "declaration": true, + "sourceMap": true, + "rootDir": ".", + "outDir": "dist", "importHelpers": false, "isolatedModules": true, "allowSyntheticDefaultImports": true, @@ -13,5 +16,6 @@ "forceConsistentCasingInFileNames": true, "strict": true, "skipLibCheck": true - } + }, + "include": ["src", "scripts", "modules.d.ts"] } diff --git a/packages/config/package.json b/packages/config/package.json index 25062e4ef5..9fa573f2dc 100644 --- a/packages/config/package.json +++ b/packages/config/package.json @@ -14,7 +14,7 @@ }, "scripts": { "prepare": "yarn build", - "test": "echo 'TODO tests'", + "test": "vitest typecheck --run", "build": "vite build", "link": "yarn link", "release": "npm publish --access=public" @@ -26,5 +26,14 @@ "vite": "^4.2.1", "vitest": "^0.29.8" }, + "dependencies": { + "@latticexyz/schema-type": "^1.41.0", + "chalk": "^5.2.0", + "esbuild": "^0.17.15", + "ethers": "^6.3.0", + "find-up": "^6.3.0", + "zod": "^3.21.4", + "zod-validation-error": "^1.3.0" + }, "gitHead": "914a1e0ae4a573d685841ca2ea921435057deb8f" } diff --git a/packages/cli/src/config/commonSchemas.ts b/packages/config/src/commonSchemas.ts similarity index 100% rename from packages/cli/src/config/commonSchemas.ts rename to packages/config/src/commonSchemas.ts diff --git a/packages/cli/src/config/dynamicResolution.ts b/packages/config/src/dynamicResolution.ts similarity index 96% rename from packages/cli/src/config/dynamicResolution.ts rename to packages/config/src/dynamicResolution.ts index 6799c36488..7dd088114b 100644 --- a/packages/cli/src/config/dynamicResolution.ts +++ b/packages/config/src/dynamicResolution.ts @@ -1,4 +1,4 @@ -import { MUDError } from "../utils/errors.js"; +import { MUDError } from "./errors.js"; import { ValueWithType } from "./world/userTypes.js"; export enum DynamicResolutionType { diff --git a/packages/config/src/errors.ts b/packages/config/src/errors.ts new file mode 100644 index 0000000000..d79b92ac90 --- /dev/null +++ b/packages/config/src/errors.ts @@ -0,0 +1,25 @@ +import chalk from "chalk"; +import { z, ZodError, ZodIssueCode } from "zod"; +import { fromZodError } from "zod-validation-error"; + +export class MUDError extends Error { + name = "MUDError"; +} + +// Wrapper with preset styles, only requires a `prefix` +export function fromZodErrorCustom(error: ZodError, prefix: string) { + return fromZodError(error, { + prefix: chalk.red(prefix), + prefixSeparator: "\n- ", + issueSeparator: "\n- ", + }); +} + +export class NotInsideProjectError extends Error { + name = "NotInsideProjectError"; + message = "You are not inside a MUD project"; +} + +export function UnrecognizedSystemErrorFactory(path: string[], systemName: string) { + return new z.ZodError([{ code: ZodIssueCode.custom, path: path, message: `Unrecognized system: "${systemName}"` }]); +} diff --git a/packages/config/src/index.ts b/packages/config/src/index.ts index 40ee001760..49b8c91a2f 100644 --- a/packages/config/src/index.ts +++ b/packages/config/src/index.ts @@ -1,2 +1,25 @@ -// TODO stub -export {}; +import { ExtractUserTypes, StringForUnion } from "./typeUtils.js"; +import { StoreUserConfig, StoreConfig } from "./store/parseStoreConfig.js"; +import { WorldUserConfig, ResolvedWorldConfig } from "./world/index.js"; + +export type MUDUserConfig< + EnumNames extends StringForUnion = StringForUnion, + StaticUserTypes extends ExtractUserTypes = ExtractUserTypes +> = StoreUserConfig & WorldUserConfig; +export type MUDConfig = StoreConfig & ResolvedWorldConfig; + +export function mudConfig< + EnumNames extends StringForUnion = never, + StaticUserTypes extends ExtractUserTypes = ExtractUserTypes +>(config: MUDUserConfig) { + return config; +} + +export * from "./commonSchemas.js"; +export * from "./loadConfig.js"; +export * from "./store/loadStoreConfig.js"; +export * from "./store/parseStoreConfig.js"; +export * from "./world/index.js"; +export * from "./validation.js"; +export * from "./dynamicResolution.js"; +export * from "./errors.js"; diff --git a/packages/cli/src/config/loadConfig.ts b/packages/config/src/loadConfig.ts similarity index 95% rename from packages/cli/src/config/loadConfig.ts rename to packages/config/src/loadConfig.ts index 56b21f8b88..ab063509eb 100644 --- a/packages/cli/src/config/loadConfig.ts +++ b/packages/config/src/loadConfig.ts @@ -1,6 +1,6 @@ import { findUp } from "find-up"; import path from "path"; -import { NotInsideProjectError } from "../utils/errors.js"; +import { NotInsideProjectError } from "./errors.js"; import esbuild from "esbuild"; import { rmSync } from "fs"; diff --git a/packages/cli/src/config/loadStoreConfig.ts b/packages/config/src/store/loadStoreConfig.ts similarity index 80% rename from packages/cli/src/config/loadStoreConfig.ts rename to packages/config/src/store/loadStoreConfig.ts index c649cdc24b..32dd7fb5a6 100644 --- a/packages/cli/src/config/loadStoreConfig.ts +++ b/packages/config/src/store/loadStoreConfig.ts @@ -1,6 +1,6 @@ import { ZodError } from "zod"; -import { fromZodErrorCustom } from "../utils/errors.js"; -import { loadConfig } from "./loadConfig.js"; +import { fromZodErrorCustom } from "../errors.js"; +import { loadConfig } from "../loadConfig.js"; import { parseStoreConfig } from "./parseStoreConfig.js"; export async function loadStoreConfig(configPath?: string) { diff --git a/packages/cli/src/config/parseStoreConfig.test-d.ts b/packages/config/src/store/parseStoreConfig.test-d.ts similarity index 100% rename from packages/cli/src/config/parseStoreConfig.test-d.ts rename to packages/config/src/store/parseStoreConfig.test-d.ts diff --git a/packages/cli/src/config/parseStoreConfig.ts b/packages/config/src/store/parseStoreConfig.ts similarity index 98% rename from packages/cli/src/config/parseStoreConfig.ts rename to packages/config/src/store/parseStoreConfig.ts index 2b66fc7109..35756a4af4 100644 --- a/packages/cli/src/config/parseStoreConfig.ts +++ b/packages/config/src/store/parseStoreConfig.ts @@ -1,8 +1,8 @@ import { AbiType, AbiTypes, StaticAbiType, StaticAbiTypes } from "@latticexyz/schema-type"; import { RefinementCtx, z, ZodIssueCode } from "zod"; -import { AsDependent, ExtractUserTypes, RequireKeys, StaticArray, StringForUnion } from "../utils/typeUtils.js"; -import { zObjectName, zSelector, zUserEnum, zValueName } from "./commonSchemas.js"; -import { getDuplicates, parseStaticArray } from "./validation.js"; +import { AsDependent, ExtractUserTypes, RequireKeys, StaticArray, StringForUnion } from "../typeUtils.js"; +import { zObjectName, zSelector, zUserEnum, zValueName } from "../commonSchemas.js"; +import { getDuplicates, parseStaticArray } from "../validation.js"; const zTableName = zObjectName; const zKeyName = zValueName; diff --git a/packages/cli/src/utils/typeUtils.ts b/packages/config/src/typeUtils.ts similarity index 100% rename from packages/cli/src/utils/typeUtils.ts rename to packages/config/src/typeUtils.ts diff --git a/packages/cli/src/config/validation.ts b/packages/config/src/validation.ts similarity index 100% rename from packages/cli/src/config/validation.ts rename to packages/config/src/validation.ts diff --git a/packages/cli/src/config/world/index.ts b/packages/config/src/world/index.ts similarity index 100% rename from packages/cli/src/config/world/index.ts rename to packages/config/src/world/index.ts diff --git a/packages/cli/src/config/world/loadWorldConfig.test-d.ts b/packages/config/src/world/loadWorldConfig.test-d.ts similarity index 100% rename from packages/cli/src/config/world/loadWorldConfig.test-d.ts rename to packages/config/src/world/loadWorldConfig.test-d.ts diff --git a/packages/cli/src/config/world/loadWorldConfig.ts b/packages/config/src/world/loadWorldConfig.ts similarity index 94% rename from packages/cli/src/config/world/loadWorldConfig.ts rename to packages/config/src/world/loadWorldConfig.ts index 7a9eea34bf..8270947253 100644 --- a/packages/cli/src/config/world/loadWorldConfig.ts +++ b/packages/config/src/world/loadWorldConfig.ts @@ -1,5 +1,5 @@ import { ZodError } from "zod"; -import { fromZodErrorCustom } from "../../utils/errors.js"; +import { fromZodErrorCustom } from "../errors.js"; import { loadConfig } from "../loadConfig.js"; import { zWorldConfig } from "./parseWorldConfig.js"; import { resolveWorldConfig } from "./resolveWorldConfig.js"; diff --git a/packages/cli/src/config/world/parseWorldConfig.ts b/packages/config/src/world/parseWorldConfig.ts similarity index 100% rename from packages/cli/src/config/world/parseWorldConfig.ts rename to packages/config/src/world/parseWorldConfig.ts diff --git a/packages/cli/src/config/world/resolveWorldConfig.ts b/packages/config/src/world/resolveWorldConfig.ts similarity index 98% rename from packages/cli/src/config/world/resolveWorldConfig.ts rename to packages/config/src/world/resolveWorldConfig.ts index 05338ee598..1012ff3575 100644 --- a/packages/cli/src/config/world/resolveWorldConfig.ts +++ b/packages/config/src/world/resolveWorldConfig.ts @@ -1,4 +1,4 @@ -import { UnrecognizedSystemErrorFactory } from "../../utils/errors.js"; +import { UnrecognizedSystemErrorFactory } from "../errors.js"; import { ParsedWorldConfig } from "./parseWorldConfig.js"; import { SystemUserConfig } from "./userTypes.js"; diff --git a/packages/cli/src/config/world/userTypes.ts b/packages/config/src/world/userTypes.ts similarity index 100% rename from packages/cli/src/config/world/userTypes.ts rename to packages/config/src/world/userTypes.ts diff --git a/packages/config/tsconfig.json b/packages/config/tsconfig.json index d384194a73..cdf8d8d2f1 100644 --- a/packages/config/tsconfig.json +++ b/packages/config/tsconfig.json @@ -4,7 +4,6 @@ "target": "es2021", "module": "esnext", "moduleResolution": "node", - "types": [], "declaration": true, "sourceMap": true, "rootDir": "./src", diff --git a/packages/config/vite.config.ts b/packages/config/vite.config.ts index 6487b6b042..218ab2caf1 100644 --- a/packages/config/vite.config.ts +++ b/packages/config/vite.config.ts @@ -7,6 +7,7 @@ import peerDepsExternal from "rollup-plugin-peer-deps-external"; */ export default defineConfig({ build: { + ssr: true, lib: { entry: "src/index.ts", formats: ["cjs", "es"], diff --git a/packages/store/mud.config.mts b/packages/store/mud.config.mts index d7ade50c13..1347576fd8 100644 --- a/packages/store/mud.config.mts +++ b/packages/store/mud.config.mts @@ -1,4 +1,4 @@ -import { storeConfig } from "@latticexyz/cli"; +import { storeConfig } from "@latticexyz/config"; export default storeConfig({ storeImportPath: "../../", diff --git a/packages/store/package.json b/packages/store/package.json index 6b6333de47..e07f184721 100644 --- a/packages/store/package.json +++ b/packages/store/package.json @@ -31,6 +31,7 @@ }, "devDependencies": { "@latticexyz/cli": "^1.41.0", + "@latticexyz/config": "^1.41.0", "@latticexyz/schema-type": "^1.41.0", "@typechain/ethers-v5": "^9.0.0", "@types/ejs": "^3.1.1", diff --git a/packages/world/mud.config.mts b/packages/world/mud.config.mts index 3241e2ec29..649f23a2c0 100644 --- a/packages/world/mud.config.mts +++ b/packages/world/mud.config.mts @@ -1,4 +1,4 @@ -import { mudConfig } from "@latticexyz/cli"; +import { mudConfig } from "@latticexyz/config"; export default mudConfig({ worldImportPath: "../", diff --git a/packages/world/package.json b/packages/world/package.json index 6ef0a091a1..85ff90ef16 100644 --- a/packages/world/package.json +++ b/packages/world/package.json @@ -31,6 +31,7 @@ }, "devDependencies": { "@latticexyz/cli": "^1.41.0", + "@latticexyz/config": "^1.41.0", "@latticexyz/schema-type": "^1.41.0", "@latticexyz/store": "^1.41.0", "@typechain/ethers-v5": "^9.0.0", diff --git a/yarn.lock b/yarn.lock index 160bb94bff..c3c2784d76 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,6 +2,11 @@ # yarn lockfile v1 +"@adraffy/ens-normalize@1.9.0": + version "1.9.0" + resolved "https://registry.yarnpkg.com/@adraffy/ens-normalize/-/ens-normalize-1.9.0.tgz#223572538f6bea336750039bb43a4016dcc8182d" + integrity sha512-iowxq3U30sghZotgl4s/oJRci6WPBfNO5YYgk2cIOMCHr3LeGPcsZjCEr+33Q4N+oV3OABDAtA+pyvWjbvBifQ== + "@ampproject/remapping@^2.1.0": version "2.2.0" resolved "https://registry.yarnpkg.com/@ampproject/remapping/-/remapping-2.2.0.tgz#56c133824780de3174aed5ab6834f3026790154d" @@ -2408,6 +2413,11 @@ resolved "https://registry.yarnpkg.com/@noble/secp256k1/-/secp256k1-1.6.3.tgz#7eed12d9f4404b416999d0c87686836c4c5c9b94" integrity sha512-T04e4iTurVy7I8Sw4+c5OSN9/RkPlo1uKxAomtxQNLq8j1uPAqnsqG1bqvY3Jv7c13gyr6dui0zmh/I3+f/JaQ== +"@noble/secp256k1@1.7.1": + version "1.7.1" + resolved "https://registry.yarnpkg.com/@noble/secp256k1/-/secp256k1-1.7.1.tgz#b251c70f824ce3ca7f8dc3df08d58f005cc0507c" + integrity sha512-hOUk6AyBFmqVrv7k5WAw/LpszxVbj9gGN4JRkIX52fdFAj1UA61KXmZDvqVEm+pOyec3+fIeZB02LYa/pWOArw== + "@nodelib/fs.scandir@2.1.5": version "2.1.5" resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5" @@ -4506,6 +4516,11 @@ aes-js@3.0.0: resolved "https://registry.yarnpkg.com/aes-js/-/aes-js-3.0.0.tgz#e21df10ad6c2053295bcbb8dab40b09dbea87e4d" integrity sha512-H7wUZRn8WpTq9jocdxQ2c8x2sKo9ZVmzfRE13GiNJXfp7NcKYEdvl3vspKjXox6RIG2VtaRe4JFvxG4rqp2Zuw== +aes-js@4.0.0-beta.3: + version "4.0.0-beta.3" + resolved "https://registry.yarnpkg.com/aes-js/-/aes-js-4.0.0-beta.3.tgz#da2253f0ff03a0b3a9e445c8cbdf78e7fda7d48c" + integrity sha512-/xJX0/VTPcbc5xQE2VUP91y1xN8q/rDfhEzLm+vLc3hYvb5+qHCnpJRuFcrKn63zumK/sCwYYzhG8HP78JYSTA== + agent-base@6, agent-base@^6.0.2: version "6.0.2" resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-6.0.2.tgz#49fff58577cfee3f37176feab4c22e00f86d7f77" @@ -7386,35 +7401,7 @@ esbuild@^0.16.14: "@esbuild/win32-ia32" "0.16.17" "@esbuild/win32-x64" "0.16.17" -esbuild@^0.17.14, esbuild@~0.17.6: - version "0.17.14" - resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.17.14.tgz#d61a22de751a3133f3c6c7f9c1c3e231e91a3245" - integrity sha512-vOO5XhmVj/1XQR9NQ1UPq6qvMYL7QFJU57J5fKBKBKxp17uDt5PgxFDb4A2nEiXhr1qQs4x0F5+66hVVw4ruNw== - optionalDependencies: - "@esbuild/android-arm" "0.17.14" - "@esbuild/android-arm64" "0.17.14" - "@esbuild/android-x64" "0.17.14" - "@esbuild/darwin-arm64" "0.17.14" - "@esbuild/darwin-x64" "0.17.14" - "@esbuild/freebsd-arm64" "0.17.14" - "@esbuild/freebsd-x64" "0.17.14" - "@esbuild/linux-arm" "0.17.14" - "@esbuild/linux-arm64" "0.17.14" - "@esbuild/linux-ia32" "0.17.14" - "@esbuild/linux-loong64" "0.17.14" - "@esbuild/linux-mips64el" "0.17.14" - "@esbuild/linux-ppc64" "0.17.14" - "@esbuild/linux-riscv64" "0.17.14" - "@esbuild/linux-s390x" "0.17.14" - "@esbuild/linux-x64" "0.17.14" - "@esbuild/netbsd-x64" "0.17.14" - "@esbuild/openbsd-x64" "0.17.14" - "@esbuild/sunos-x64" "0.17.14" - "@esbuild/win32-arm64" "0.17.14" - "@esbuild/win32-ia32" "0.17.14" - "@esbuild/win32-x64" "0.17.14" - -esbuild@^0.17.5: +esbuild@^0.17.15, esbuild@^0.17.5: version "0.17.15" resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.17.15.tgz#209ebc87cb671ffb79574db93494b10ffaf43cbc" integrity sha512-LBUV2VsUIc/iD9ME75qhT4aJj0r75abCVS0jakhFzOtR7TQsqQA5w0tZ+KTKnwl3kXE0MhskNdHDh/I5aCR1Zw== @@ -7470,6 +7457,34 @@ esbuild@^0.17.6: "@esbuild/win32-ia32" "0.17.8" "@esbuild/win32-x64" "0.17.8" +esbuild@~0.17.6: + version "0.17.14" + resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.17.14.tgz#d61a22de751a3133f3c6c7f9c1c3e231e91a3245" + integrity sha512-vOO5XhmVj/1XQR9NQ1UPq6qvMYL7QFJU57J5fKBKBKxp17uDt5PgxFDb4A2nEiXhr1qQs4x0F5+66hVVw4ruNw== + optionalDependencies: + "@esbuild/android-arm" "0.17.14" + "@esbuild/android-arm64" "0.17.14" + "@esbuild/android-x64" "0.17.14" + "@esbuild/darwin-arm64" "0.17.14" + "@esbuild/darwin-x64" "0.17.14" + "@esbuild/freebsd-arm64" "0.17.14" + "@esbuild/freebsd-x64" "0.17.14" + "@esbuild/linux-arm" "0.17.14" + "@esbuild/linux-arm64" "0.17.14" + "@esbuild/linux-ia32" "0.17.14" + "@esbuild/linux-loong64" "0.17.14" + "@esbuild/linux-mips64el" "0.17.14" + "@esbuild/linux-ppc64" "0.17.14" + "@esbuild/linux-riscv64" "0.17.14" + "@esbuild/linux-s390x" "0.17.14" + "@esbuild/linux-x64" "0.17.14" + "@esbuild/netbsd-x64" "0.17.14" + "@esbuild/openbsd-x64" "0.17.14" + "@esbuild/sunos-x64" "0.17.14" + "@esbuild/win32-arm64" "0.17.14" + "@esbuild/win32-ia32" "0.17.14" + "@esbuild/win32-x64" "0.17.14" + escalade@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.1.tgz#d8cfdc7000965c5a0174b4a82eaa5c0552742e40" @@ -7918,6 +7933,18 @@ ethers@^5.7.2: "@ethersproject/web" "5.7.1" "@ethersproject/wordlists" "5.7.0" +ethers@^6.3.0: + version "6.3.0" + resolved "https://registry.yarnpkg.com/ethers/-/ethers-6.3.0.tgz#c61efaafa2bd9a4d9f0c799d932ef3b5cd4bd37d" + integrity sha512-CKFYvTne1YT4S1glTiu7TgGsj0t6c6GAD7evrIk8zbeUb6nK8dcUPAiAWM8uDX/1NmRTvLM9+1Vnn49hwKtEzw== + dependencies: + "@adraffy/ens-normalize" "1.9.0" + "@noble/hashes" "1.1.2" + "@noble/secp256k1" "1.7.1" + aes-js "4.0.0-beta.3" + tslib "2.4.0" + ws "8.5.0" + ethjs-unit@0.1.6: version "0.1.6" resolved "https://registry.yarnpkg.com/ethjs-unit/-/ethjs-unit-0.1.6.tgz#c665921e476e87bce2a9d588a6fe0405b2c41699" @@ -16014,16 +16041,16 @@ tsconfig-paths@^4.1.2: minimist "^1.2.6" strip-bom "^3.0.0" +tslib@2.4.0, tslib@^2.1.0, tslib@^2.3.1, tslib@^2.4.0: + version "2.4.0" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.0.tgz#7cecaa7f073ce680a05847aa77be941098f36dc3" + integrity sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ== + tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3: version "1.14.1" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== -tslib@^2.1.0, tslib@^2.3.1, tslib@^2.4.0: - version "2.4.0" - resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.0.tgz#7cecaa7f073ce680a05847aa77be941098f36dc3" - integrity sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ== - tslib@^2.3.0, tslib@^2.5.0: version "2.5.0" resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.0.tgz#42bfed86f5787aeb41d031866c8f402429e0fddf" @@ -17005,6 +17032,11 @@ ws@7.4.6: resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.6.tgz#5654ca8ecdeee47c33a9a4bf6d28e2be2980377c" integrity sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A== +ws@8.5.0: + version "8.5.0" + resolved "https://registry.yarnpkg.com/ws/-/ws-8.5.0.tgz#bfb4be96600757fe5382de12c670dab984a1ed4f" + integrity sha512-BWX0SWVgLPzYwF8lTzEy1egjhS4S4OEAHfsO8o65WOVsrnSRGaSiUaa9e0ggGlkMTtBlmOpEXiie9RUcBO86qg== + ws@^7.4.6: version "7.5.9" resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.9.tgz#54fa7db29f4c7cec68b1ddd3a89de099942bb591" @@ -17198,10 +17230,10 @@ yocto-queue@^1.0.0: resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-1.0.0.tgz#7f816433fb2cbc511ec8bf7d263c3b58a1a3c251" integrity sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g== -zod-validation-error@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/zod-validation-error/-/zod-validation-error-1.0.1.tgz#fc8758b667ecdb8121439458c7ab05d0be469b19" - integrity sha512-QRk2AtHLJg8sCZAbEjXSs7E0n4/mSdX5caoh6eOUvDSdcIQz03i0xoNN1Qx6UZT+ADVHRK6+ZXRtldzW6nnltA== +zod-validation-error@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/zod-validation-error/-/zod-validation-error-1.3.0.tgz#6a37e8b1896e45362a4e4cf9506eca203fad3c6e" + integrity sha512-4WoQnuWnj06kwKR4A+cykRxFmy+CTvwMQO5ogTXLiVx1AuvYYmMjixh7sbkSsQTr1Fvtss6d5kVz8PGeMPUQjQ== zod@^3.21.4: version "3.21.4" From 0cb3dce1db02a7ab2b670e896b6da6bf0e8b9903 Mon Sep 17 00:00:00 2001 From: dk1a Date: Sat, 8 Apr 2023 16:26:11 +0300 Subject: [PATCH 2/2] fix(std-client): fix config import --- packages/std-client/package.json | 4 +++- packages/std-client/scripts/codegen.mts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/std-client/package.json b/packages/std-client/package.json index 60deb0d65f..76d9956f9f 100644 --- a/packages/std-client/package.json +++ b/packages/std-client/package.json @@ -22,6 +22,7 @@ "release": "npm publish --access=public" }, "devDependencies": { + "@latticexyz/config": "^1.41.0", "@latticexyz/network": "^1.41.0", "@latticexyz/recs": "^1.41.0", "@latticexyz/solecs": "^1.41.0", @@ -71,5 +72,6 @@ "rxjs": "^7.5.5", "viem": "^0.2.0" }, - "gitHead": "914a1e0ae4a573d685841ca2ea921435057deb8f" + "gitHead": "914a1e0ae4a573d685841ca2ea921435057deb8f", + "dependencies": {} } diff --git a/packages/std-client/scripts/codegen.mts b/packages/std-client/scripts/codegen.mts index 1f03f3b387..805e0f2224 100644 --- a/packages/std-client/scripts/codegen.mts +++ b/packages/std-client/scripts/codegen.mts @@ -1,4 +1,4 @@ -import { parseStoreConfig } from "@latticexyz/cli"; +import { parseStoreConfig } from "@latticexyz/config"; import { tsgen } from "@latticexyz/cli/dist/render-ts"; import storeMudConfig from "@latticexyz/store/mud.config.mjs";