Skip to content

Commit

Permalink
refactor: move tablegen to store and worldgen to world, update javasc…
Browse files Browse the repository at this point in the history
…ript build/export setup (#640)

* feat: move tablegen to store and worldgen to world

* chore: sort-package-json

* fix(network): fix store typechain imports

* fix(world): add missing package

* fix(services): skipLibCheck

* fix: fix typechain imports

* fix: attempt tsconfig changes

* build: try different import

* fix: try externalizing solidity parser

* build: try building worldgen script

* build: try to externalize solidity parser more

* build: fix solidity parser

* build(cli): switch from tsup to vite

* build: fix build

* build(cli): make mud.js executable for local use

* test: fix tests

* test: fix types

* refactor: replace typescript rollup plugin with tsc, align versions, clean up

* chore: update vite

* chore: self-review

* refactor(common): move common-codegen to common/codegen

* test(network): fix jest

* build(common): fix output path

* chore: sort package.json

* refactor: remove .js from ts imports

* fix: add missing awaits

* Revert "refactor: remove .js from ts imports"

This reverts commit 77487c0.

* fix(common): bundle execa

* build(cli): fix typo in dev script

---------

Co-authored-by: alvrs <[email protected]>
Co-authored-by: alvarius <[email protected]>
  • Loading branch information
3 people authored Apr 20, 2023
1 parent 43772da commit 60e62eb
Show file tree
Hide file tree
Showing 105 changed files with 2,759 additions and 1,134 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ jobs:
uses: ./.github/actions/setup

- name: Run codegen
run: pnpm codegen
run: pnpm build:codegen

- name: Outdated files, run `pnpm codegen` and commit them
- name: Outdated files, run `pnpm build:codegen` and commit them
uses: ./.github/actions/require-empty-diff

- name: Generate gas reports
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ jobs:
uses: ./.github/actions/setup

- name: Run codegen
run: pnpm codegen
run: pnpm build:codegen

- name: Outdated files, run `pnpm codegen` and commit them
- name: Outdated files, run `pnpm build:codegen` and commit them
uses: ./.github/actions/require-empty-diff

- name: Generate gas reports
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
"url": "https://github.com/latticexyz/mud.git"
},
"scripts": {
"build": "pnpm pnpm recursive run build",
"build": "pnpm recursive run build",
"build:codegen": "pnpm recursive run build:codegen",
"build:docs": "pnpm recursive run docs && pnpm prettier --write '**/*.md' && pnpm run --filter docs build:prepare && pnpm run --filter docs build",
"codegen": "pnpm codegen:tablegen && pnpm codegen:worldgen",
"codegen:tablegen": "pnpm recursive run tablegen",
"codegen:worldgen": "pnpm recursive run worldgen",
"commit": "cz",
"entry:dist": "lerna run prepack",
"entry:src": "lerna run postpack",
Expand Down
1 change: 0 additions & 1 deletion packages/cli/contracts/src/codegen/Types.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity >=0.8.0;

/* Autogenerated file. Do not edit manually. */

enum Enum1 {
E1,
E2,
Expand Down
25 changes: 15 additions & 10 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,38 @@
},
"license": "MIT",
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": "./dist/index.js"
},
"types": "src/index.ts",
"bin": {
"mud": "./dist/mud.js",
"mud2": "./dist/mud2.js"
},
"scripts": {
"build": "tsup",
"build": "pnpm run build:js && chmod +x ./dist/mud.js",
"build:js": "vite build",
"codegen": "tsx ./scripts/codegen.ts",
"dev": "tsup --watch",
"dev": "vite build --watch",
"lint": "eslint . --ext .ts",
"release": "npm publish --access=public",
"test": "tsc --noEmit && pnpm test:contracts",
"test:contracts": "pnpm codegen && forge test"
"test": "pnpm test:typescript && pnpm test:contracts",
"test:contracts": "pnpm codegen && forge test",
"test:typescript": "tsc --noEmit"
},
"dependencies": {
"@ethersproject/abi": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@improbable-eng/grpc-web": "^0.15.0",
"@improbable-eng/grpc-web-node-http-transport": "^0.15.0",
"@latticexyz/common": "workspace:*",
"@latticexyz/config": "workspace:*",
"@latticexyz/schema-type": "workspace:*",
"@latticexyz/services": "workspace:*",
"@latticexyz/solecs": "workspace:*",
"@latticexyz/std-contracts": "workspace:*",
"@latticexyz/store": "workspace:*",
"@latticexyz/world": "workspace:*",
"@solidity-parser/parser": "^0.16.0",
"@typechain/ethers-v5": "^10.2.0",
"chalk": "^5.0.1",
"chokidar": "^3.5.3",
Expand All @@ -50,8 +54,6 @@
"nice-grpc-web": "^2.0.1",
"openurl": "^1.1.1",
"path": "^0.12.7",
"prettier": "^2.8.4",
"prettier-plugin-solidity": "^1.1.2",
"table": "^6.8.1",
"typechain": "^8.1.1",
"typescript": "^4.9.5",
Expand All @@ -64,9 +66,12 @@
"@types/glob": "^7.2.0",
"@types/node": "^17.0.34",
"@types/openurl": "^1.0.0",
"@types/rollup-plugin-peer-deps-external": "^2.2.1",
"@types/yargs": "^17.0.10",
"tsup": "^6.6.3",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-preserve-shebang": "^1.0.1",
"tsx": "^3.12.6",
"vite": "^4.3.0",
"vitest": "^0.29.8"
},
"gitHead": "914a1e0ae4a573d685841ca2ea921435057deb8f"
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/scripts/codegen.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from "path";
import { storeConfig, parseStoreConfig } from "@latticexyz/config";
import { tablegen } from "../src/render-solidity/tablegen.js";
import { tablegen } from "@latticexyz/store";
import { logError } from "../src/utils/errors.js";
import { getSrcDirectory } from "../src/utils/foundry.js";
import { getSrcDirectory } from "@latticexyz/common/foundry";

// This config is used only for tests
const config = storeConfig({
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/deploy-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { loadStoreConfig, loadWorldConfig } from "@latticexyz/config";
import { MUDError } from "@latticexyz/config";
import { deploy } from "../utils/deploy-v2.js";
import { logError } from "../utils/errors.js";
import { forge, getRpcUrl, getSrcDirectory } from "../utils/foundry.js";
import { forge, getRpcUrl, getSrcDirectory } from "@latticexyz/common/foundry";
import { mkdirSync, writeFileSync } from "fs";
import { getChainId } from "../utils/getChainId.js";

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/deprecated/call-system.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getTestDirectory } from "@latticexyz/common/foundry";
import { defaultAbiCoder as abi } from "ethers/lib/utils.js";
import path from "path";
import type { CommandModule } from "yargs";
import { execLog } from "../../utils/deprecated/index.js";
import { getTestDirectory } from "../../utils/foundry.js";

type Options = {
rpc?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/deprecated/deploy-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { CommandModule } from "yargs";
import { DeployOptions, generateAndDeploy, hsr } from "../../utils/deprecated/index.js";
import openurl from "openurl";
import chalk from "chalk";
import { getSrcDirectory } from "../../utils/foundry.js";
import { getSrcDirectory } from "@latticexyz/common/foundry";

type Options = DeployOptions & {
watch?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/deprecated/test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { CommandModule } from "yargs";
import { execLog, generateLibDeploy, resetLibDeploy } from "../../utils/deprecated/index.js";
import { getTestDirectory } from "../../utils/foundry.js";
import { getTestDirectory } from "@latticexyz/common/foundry";

type Options = {
forgeOpts?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/deprecated/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { readFileSync } from "fs";
import { Contract } from "ethers";
import { JsonRpcProvider } from "@ethersproject/providers";
import WorldAbi from "@latticexyz/solecs/abi/World.json" assert { type: "json" };
import { getSrcDirectory } from "../../utils/foundry.js";
import { getSrcDirectory } from "@latticexyz/common/foundry";
import path from "path";
import { componentsDir, systemsDir } from "../../utils/deprecated/constants.js";

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/tablegen.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from "path";
import type { CommandModule } from "yargs";
import { loadStoreConfig } from "@latticexyz/config";
import { tablegen } from "../render-solidity/tablegen.js";
import { getSrcDirectory } from "../utils/index.js";
import { tablegen } from "@latticexyz/store";
import { getSrcDirectory } from "@latticexyz/common/foundry";

type Options = {
configPath?: string;
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/commands/test-v2.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { CommandModule } from "yargs";
import { deployHandler, DeployOptions } from "./deploy-v2.js";
import { yDeployOptions } from "./deploy-v2.js";
import { anvil, forge, getRpcUrl, getTestDirectory } from "../utils/foundry.js";
import { anvil, forge, getRpcUrl } from "@latticexyz/common/foundry";
import chalk from "chalk";
import { rmSync, writeFileSync } from "fs";
import path from "path";

type Options = DeployOptions & { port?: number; worldAddress?: string; forgeOptions?: string };

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/worldgen.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { CommandModule } from "yargs";
import { loadStoreConfig, loadWorldConfig } from "@latticexyz/config";
import { getSrcDirectory } from "../utils/foundry.js";
import { worldgen } from "@latticexyz/world";
import { getSrcDirectory } from "@latticexyz/common/foundry";
import glob from "glob";
import path, { basename } from "path";
import { worldgen } from "../render-solidity/worldgen.js";
import { rmSync } from "fs";

type Options = {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export {};
export * from "./render-ts";
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ declare module "protobufjs/minimal" {
export const Writer: any;
export type Writer = any;
}
declare module "rollup-plugin-preserve-shebang";
10 changes: 0 additions & 10 deletions packages/cli/src/render-solidity/index.ts

This file was deleted.

19 changes: 0 additions & 19 deletions packages/cli/src/render-solidity/renderTypes.ts

This file was deleted.

116 changes: 0 additions & 116 deletions packages/cli/src/render-solidity/types.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/cli/src/render-ts/recsV1TableOptions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { StoreConfig } from "@latticexyz/config";
import { resolveAbiOrUserType } from "../render-solidity/userType.js";
import { resolveAbiOrUserType } from "@latticexyz/common/codegen";
import { schemaTypesToRecsTypeStrings } from "./schemaTypesToRecsTypeStrings.js";
import { RecsV1TableOptions } from "./types.js";

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/render-ts/tsgen.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from "path";
import { StoreConfig } from "@latticexyz/config";
import { formatAndWriteTypescript } from "@latticexyz/common/codegen";
import { getRecsV1TableOptions } from "../render-ts/recsV1TableOptions.js";
import { renderRecsV1Tables } from "../render-ts/renderRecsV1Tables.js";
import { formatAndWriteTypescript } from "../utils/formatAndWrite.js";

export async function tsgen(config: StoreConfig, outDirectory: string) {
const fullOutputPath = path.join(outDirectory, `contractComponents.ts`);
Expand Down
Loading

0 comments on commit 60e62eb

Please sign in to comment.