@latticexyz/cli 2.0.0-alpha.93 → 2.0.0-foundry-js-c7b0289b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/dist/chunk-22IIKR4S.js +4 -0
  2. package/dist/chunk-22IIKR4S.js.map +1 -0
  3. package/dist/commands-UYAATBY6.js +27 -0
  4. package/dist/commands-UYAATBY6.js.map +1 -0
  5. package/dist/errors-XGN6V2Y3.js +2 -0
  6. package/dist/errors-XGN6V2Y3.js.map +1 -0
  7. package/dist/index.js +1 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/mud.js +2 -8340
  10. package/dist/mud.js.map +1 -0
  11. package/package.json +54 -46
  12. package/src/commands/deploy.ts +26 -0
  13. package/src/commands/dev-contracts.ts +114 -0
  14. package/src/commands/devnode.ts +7 -2
  15. package/src/commands/faucet.ts +1 -1
  16. package/src/commands/index.ts +19 -14
  17. package/src/commands/set-version.ts +103 -81
  18. package/src/commands/tablegen.ts +7 -5
  19. package/src/commands/test.ts +65 -0
  20. package/src/commands/trace.ts +118 -0
  21. package/src/commands/worldgen.ts +29 -28
  22. package/src/common.ts +1 -0
  23. package/src/debug.ts +3 -0
  24. package/src/deploy/assertNamespaceOwner.ts +42 -0
  25. package/src/deploy/common.ts +76 -0
  26. package/src/deploy/configToTables.ts +68 -0
  27. package/src/deploy/create2/README.md +9 -0
  28. package/src/deploy/create2/deployment.json +7 -0
  29. package/src/deploy/debug.ts +3 -0
  30. package/src/deploy/deploy.ts +108 -0
  31. package/src/deploy/deployWorld.ts +33 -0
  32. package/src/deploy/ensureContract.ts +61 -0
  33. package/src/deploy/ensureContractsDeployed.ts +25 -0
  34. package/src/deploy/ensureDeployer.ts +36 -0
  35. package/src/deploy/ensureFunctions.ts +86 -0
  36. package/src/deploy/ensureModules.ts +73 -0
  37. package/src/deploy/ensureSystems.ts +162 -0
  38. package/src/deploy/ensureTables.ts +65 -0
  39. package/src/deploy/ensureWorldFactory.ts +47 -0
  40. package/src/deploy/getFunctions.ts +58 -0
  41. package/src/deploy/getResourceAccess.ts +51 -0
  42. package/src/deploy/getResourceIds.ts +31 -0
  43. package/src/deploy/getSystems.ts +48 -0
  44. package/src/deploy/getTableValue.ts +30 -0
  45. package/src/deploy/getTables.ts +59 -0
  46. package/src/deploy/getWorldDeploy.ts +39 -0
  47. package/src/deploy/logsToWorldDeploy.ts +49 -0
  48. package/src/deploy/resolveConfig.ts +151 -0
  49. package/src/deploy/resourceLabel.ts +3 -0
  50. package/src/index.ts +1 -1
  51. package/src/modules.d.ts +11 -0
  52. package/src/mud.ts +38 -23
  53. package/src/mudPackages.ts +24 -0
  54. package/src/runDeploy.ts +128 -0
  55. package/src/utils/errors.ts +1 -1
  56. package/src/utils/getExistingContracts.ts +12 -0
  57. package/src/utils/modules/constants.ts +26 -0
  58. package/src/utils/printMUD.ts +14 -0
  59. package/src/utils/utils/getContractData.ts +32 -0
  60. package/src/utils/utils/postDeploy.ts +25 -0
  61. package/dist/chunk-6V563IAZ.js +0 -283
  62. package/dist/chunk-FPG73MVN.js +0 -71
  63. package/dist/chunk-L4YLJHLJ.js +0 -30
  64. package/dist/chunk-P5YXGXRI.js +0 -3842
  65. package/dist/chunk-SKNB74MT.js +0 -726
  66. package/dist/chunk-VQTZJIFF.js +0 -353
  67. package/dist/chunk-WZFXLDPK.js +0 -761
  68. package/dist/chunk-YL4GJLLL.js +0 -26139
  69. package/dist/index.d.ts +0 -2
  70. package/dist/mud.d.ts +0 -1
  71. package/dist/mud2.d.ts +0 -1
  72. package/dist/mud2.js +0 -25
  73. package/dist/render-solidity/index.d.ts +0 -171
  74. package/dist/render-solidity/index.js +0 -49
  75. package/dist/render-ts/index.d.ts +0 -26
  76. package/dist/render-ts/index.js +0 -14
  77. package/dist/utils/deprecated/index.d.ts +0 -76
  78. package/dist/utils/deprecated/index.js +0 -36
  79. package/dist/utils/index.d.ts +0 -88
  80. package/dist/utils/index.js +0 -39
  81. package/src/commands/deploy-v2.ts +0 -112
  82. package/src/commands/deprecated/bulkupload.ts +0 -50
  83. package/src/commands/deprecated/call-system.ts +0 -70
  84. package/src/commands/deprecated/codegen-libdeploy.ts +0 -29
  85. package/src/commands/deprecated/deploy-contracts.ts +0 -120
  86. package/src/commands/deprecated/index.ts +0 -22
  87. package/src/commands/deprecated/system-types.ts +0 -29
  88. package/src/commands/deprecated/test.ts +0 -53
  89. package/src/commands/deprecated/trace.ts +0 -81
  90. package/src/commands/deprecated/types.ts +0 -33
  91. package/src/commands/gas-report.ts +0 -219
  92. package/src/commands/test-v2.ts +0 -71
  93. package/src/commands/tsgen.ts +0 -33
  94. package/src/contracts/BulkUpload.sol +0 -174
  95. package/src/contracts/Deploy.sol +0 -23
  96. package/src/contracts/LibDeploy.ejs +0 -121
  97. package/src/contracts/LibDeploy.sol +0 -23
  98. package/src/contracts/LibDeployStub.sol +0 -23
  99. package/src/mud2.ts +0 -29
  100. package/src/render-solidity/common.ts +0 -138
  101. package/src/render-solidity/field.ts +0 -160
  102. package/src/render-solidity/index.ts +0 -10
  103. package/src/render-solidity/record.ts +0 -158
  104. package/src/render-solidity/renderSystemInterface.ts +0 -31
  105. package/src/render-solidity/renderTable.ts +0 -164
  106. package/src/render-solidity/renderTableIndex.ts +0 -15
  107. package/src/render-solidity/renderTypeHelpers.ts +0 -99
  108. package/src/render-solidity/renderTypes.ts +0 -19
  109. package/src/render-solidity/renderTypesFromConfig.ts +0 -13
  110. package/src/render-solidity/renderWorld.ts +0 -24
  111. package/src/render-solidity/tableOptions.ts +0 -107
  112. package/src/render-solidity/tablegen.ts +0 -35
  113. package/src/render-solidity/types.ts +0 -111
  114. package/src/render-solidity/userType.ts +0 -131
  115. package/src/render-solidity/worldgen.ts +0 -59
  116. package/src/render-ts/index.ts +0 -5
  117. package/src/render-ts/recsV1TableOptions.ts +0 -39
  118. package/src/render-ts/renderRecsV1Tables.ts +0 -31
  119. package/src/render-ts/schemaTypesToRecsTypeStrings.ts +0 -202
  120. package/src/render-ts/tsgen.ts +0 -12
  121. package/src/render-ts/types.ts +0 -13
  122. package/src/utils/contractToInterface.ts +0 -132
  123. package/src/utils/deploy-v2.ts +0 -518
  124. package/src/utils/deprecated/build.ts +0 -55
  125. package/src/utils/deprecated/codegen.ts +0 -42
  126. package/src/utils/deprecated/constants.ts +0 -2
  127. package/src/utils/deprecated/deploy.ts +0 -111
  128. package/src/utils/deprecated/exec.ts +0 -18
  129. package/src/utils/deprecated/findLog.ts +0 -8
  130. package/src/utils/deprecated/hsr.ts +0 -71
  131. package/src/utils/deprecated/ids.ts +0 -14
  132. package/src/utils/deprecated/index.ts +0 -8
  133. package/src/utils/deprecated/typegen.ts +0 -133
  134. package/src/utils/execLog.ts +0 -22
  135. package/src/utils/format.ts +0 -39
  136. package/src/utils/formatAndWrite.ts +0 -21
  137. package/src/utils/foundry.ts +0 -103
  138. package/src/utils/getChainId.ts +0 -10
  139. package/src/utils/index.ts +0 -5
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/mud.ts"],"sourcesContent":["#!/usr/bin/env node\n\n// Load .env file into process.env\nimport * as dotenv from \"dotenv\";\ndotenv.config();\n\nasync function run() {\n // Import everything else async so they can pick up env vars in .env\n const { default: yargs } = await import(\"yargs\");\n const { default: chalk } = await import(\"chalk\");\n const { hideBin } = await import(\"yargs/helpers\");\n const { logError } = await import(\"./utils/errors\");\n const { commands } = await import(\"./commands\");\n\n yargs(hideBin(process.argv))\n // Explicit name to display in help (by default it's the entry file, which may not be \"mud\" for e.g. ts-node)\n .scriptName(\"mud\")\n // Use the commands directory to scaffold\n // command array overload isn't typed, see https://github.com/yargs/yargs/blob/main/docs/advanced.md#esm-hierarchy\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n .command(commands as any)\n // Enable strict mode.\n .strict()\n // Custom error handler\n .fail((msg, err) => {\n console.error(chalk.red(msg));\n if (msg.includes(\"Missing required argument\")) {\n console.log(\n chalk.yellow(`Run 'pnpm mud ${process.argv[2]} --help' for a list of available and required arguments.`)\n );\n }\n console.log(\"\");\n // Even though `.fail` type says we should get an `Error`, this can sometimes be undefined\n if (err != null) {\n logError(err);\n console.log(\"\");\n }\n\n process.exit(1);\n })\n // Useful aliases.\n .alias({ h: \"help\" }).argv;\n}\n\nrun();\n"],"mappings":";AAGA,UAAYA,MAAY,SACjB,SAAO,EAEd,eAAeC,GAAM,CAEnB,GAAM,CAAE,QAASC,CAAM,EAAI,KAAM,QAAO,OAAO,EACzC,CAAE,QAASC,CAAM,EAAI,KAAM,QAAO,OAAO,EACzC,CAAE,QAAAC,CAAQ,EAAI,KAAM,QAAO,eAAe,EAC1C,CAAE,SAAAC,CAAS,EAAI,KAAM,QAAO,sBAAgB,EAC5C,CAAE,SAAAC,CAAS,EAAI,KAAM,QAAO,wBAAY,EAE9CJ,EAAME,EAAQ,QAAQ,IAAI,CAAC,EAExB,WAAW,KAAK,EAIhB,QAAQE,CAAe,EAEvB,OAAO,EAEP,KAAK,CAACC,EAAKC,IAAQ,CAClB,QAAQ,MAAML,EAAM,IAAII,CAAG,CAAC,EACxBA,EAAI,SAAS,2BAA2B,GAC1C,QAAQ,IACNJ,EAAM,OAAO,iBAAiB,QAAQ,KAAK,CAAC,2DAA2D,CACzG,EAEF,QAAQ,IAAI,EAAE,EAEVK,GAAO,OACTH,EAASG,CAAG,EACZ,QAAQ,IAAI,EAAE,GAGhB,QAAQ,KAAK,CAAC,CAChB,CAAC,EAEA,MAAM,CAAE,EAAG,MAAO,CAAC,EAAE,IAC1B,CAEAP,EAAI","names":["dotenv","run","yargs","chalk","hideBin","logError","commands","msg","err"]}
package/package.json CHANGED
@@ -1,74 +1,82 @@
1
1
  {
2
2
  "name": "@latticexyz/cli",
3
- "version": "2.0.0-alpha.93+16190e69",
3
+ "version": "2.0.0-foundry-js-c7b0289b",
4
4
  "description": "Command line interface for mud",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "type": "module",
8
- "license": "MIT",
9
- "bin": {
10
- "mud": "./dist/mud.js",
11
- "mud2": "./dist/mud2.js"
12
- },
13
5
  "repository": {
14
6
  "type": "git",
15
7
  "url": "https://github.com/latticexyz/mud.git",
16
8
  "directory": "packages/cli"
17
9
  },
18
- "scripts": {
19
- "prepare": "pnpm build",
20
- "codegen": "tsx ./scripts/codegen.ts",
21
- "lint": "eslint . --ext .ts",
22
- "dev": "tsup --watch",
23
- "build": "tsup",
24
- "test": "tsc --noEmit && pnpm test:contracts",
25
- "test:contracts": "pnpm codegen && forge test",
26
- "release": "npm publish --access=public"
10
+ "license": "MIT",
11
+ "type": "module",
12
+ "exports": {
13
+ ".": "./dist/index.js"
27
14
  },
28
- "devDependencies": {
29
- "@types/ejs": "^3.1.1",
30
- "@types/glob": "^7.2.0",
31
- "@types/node": "^17.0.34",
32
- "@types/openurl": "^1.0.0",
33
- "@types/yargs": "^17.0.10",
34
- "tsup": "^6.6.3",
35
- "tsx": "^3.12.6",
36
- "vitest": "^0.29.8"
15
+ "types": "src/index.ts",
16
+ "bin": {
17
+ "mud": "./dist/mud.js"
37
18
  },
38
19
  "dependencies": {
39
20
  "@ethersproject/abi": "^5.7.0",
40
21
  "@ethersproject/providers": "^5.7.2",
41
22
  "@improbable-eng/grpc-web": "^0.15.0",
42
23
  "@improbable-eng/grpc-web-node-http-transport": "^0.15.0",
43
- "@latticexyz/config": "2.0.0-alpha.93+16190e69",
44
- "@latticexyz/schema-type": "2.0.0-alpha.93+16190e69",
45
- "@latticexyz/services": "2.0.0-alpha.93+16190e69",
46
- "@latticexyz/solecs": "2.0.0-alpha.93+16190e69",
47
- "@latticexyz/std-contracts": "2.0.0-alpha.93+16190e69",
48
- "@latticexyz/store": "2.0.0-alpha.93+16190e69",
49
- "@latticexyz/world": "2.0.0-alpha.93+16190e69",
50
- "@solidity-parser/parser": "^0.16.0",
51
- "@typechain/ethers-v5": "^10.2.0",
52
24
  "chalk": "^5.0.1",
53
25
  "chokidar": "^3.5.3",
26
+ "debug": "^4.3.4",
54
27
  "dotenv": "^16.0.3",
55
- "ds-test": "https://github.com/dapphub/ds-test.git#c9ce3f25bde29fc5eb9901842bf02850dfd2d084",
56
28
  "ejs": "^3.1.8",
57
29
  "ethers": "^5.7.2",
58
30
  "execa": "^7.0.0",
59
- "forge-std": "https://github.com/foundry-rs/forge-std.git#b4f121555729b3afb3c5ffccb62ff4b6e2818fd3",
60
31
  "glob": "^8.0.3",
61
32
  "nice-grpc-web": "^2.0.1",
62
33
  "openurl": "^1.1.1",
34
+ "p-retry": "^5.1.2",
63
35
  "path": "^0.12.7",
64
- "prettier": "^2.8.4",
65
- "prettier-plugin-solidity": "^1.1.2",
66
- "table": "^6.8.1",
67
- "typechain": "^8.1.1",
68
- "typescript": "^4.9.5",
36
+ "rxjs": "7.5.5",
37
+ "throttle-debounce": "^5.0.0",
38
+ "typescript": "5.1.6",
39
+ "viem": "1.14.0",
69
40
  "yargs": "^17.7.1",
70
41
  "zod": "^3.21.4",
71
- "zod-validation-error": "^1.3.0"
42
+ "zod-validation-error": "^1.3.0",
43
+ "@latticexyz/abi-ts": "2.0.0-foundry-js-c7b0289b",
44
+ "@latticexyz/common": "2.0.0-foundry-js-c7b0289b",
45
+ "@latticexyz/config": "2.0.0-foundry-js-c7b0289b",
46
+ "@latticexyz/gas-report": "2.0.0-foundry-js-c7b0289b",
47
+ "@latticexyz/protocol-parser": "2.0.0-foundry-js-c7b0289b",
48
+ "@latticexyz/schema-type": "2.0.0-foundry-js-c7b0289b",
49
+ "@latticexyz/services": "2.0.0-foundry-js-c7b0289b",
50
+ "@latticexyz/store": "2.0.0-foundry-js-c7b0289b",
51
+ "@latticexyz/utils": "2.0.0-foundry-js-c7b0289b",
52
+ "@latticexyz/world": "2.0.0-foundry-js-c7b0289b",
53
+ "@latticexyz/world-modules": "2.0.0-foundry-js-c7b0289b"
72
54
  },
73
- "gitHead": "16190e69dfc58c20b3cbaf7628bb1dc1da9ed441"
74
- }
55
+ "devDependencies": {
56
+ "@types/debug": "^4.1.7",
57
+ "@types/ejs": "^3.1.1",
58
+ "@types/glob": "^7.2.0",
59
+ "@types/node": "^18.15.11",
60
+ "@types/openurl": "^1.0.0",
61
+ "@types/throttle-debounce": "^5.0.0",
62
+ "@types/yargs": "^17.0.10",
63
+ "ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0",
64
+ "forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1",
65
+ "tsup": "^6.7.0",
66
+ "tsx": "^3.12.6",
67
+ "vitest": "0.31.4"
68
+ },
69
+ "gitHead": "914a1e0ae4a573d685841ca2ea921435057deb8f",
70
+ "scripts": {
71
+ "build": "pnpm run build:js && pnpm run build:test-tables",
72
+ "build:js": "tsup && chmod +x ./dist/mud.js",
73
+ "build:test-tables": "tsx ./scripts/generate-test-tables.ts",
74
+ "clean": "pnpm run clean:js && pnpm run clean:test-tables",
75
+ "clean:js": "rimraf dist",
76
+ "clean:test-tables": "rimraf src/codegen",
77
+ "dev": "tsup --watch",
78
+ "lint": "eslint . --ext .ts",
79
+ "test": "tsc --noEmit && forge test",
80
+ "test:ci": "pnpm run test"
81
+ }
82
+ }
@@ -0,0 +1,26 @@
1
+ import type { CommandModule } from "yargs";
2
+ import { logError } from "../utils/errors";
3
+ import { DeployOptions, deployOptions, runDeploy } from "../runDeploy";
4
+
5
+ const commandModule: CommandModule<typeof deployOptions, DeployOptions> = {
6
+ command: "deploy",
7
+
8
+ describe: "Deploy MUD contracts",
9
+
10
+ builder(yargs) {
11
+ return yargs.options(deployOptions);
12
+ },
13
+
14
+ async handler(opts) {
15
+ // Wrap in try/catch, because yargs seems to swallow errors
16
+ try {
17
+ await runDeploy(opts);
18
+ } catch (error: any) {
19
+ logError(error);
20
+ process.exit(1);
21
+ }
22
+ process.exit(0);
23
+ },
24
+ };
25
+
26
+ export default commandModule;
@@ -0,0 +1,114 @@
1
+ import type { CommandModule, InferredOptionTypes } from "yargs";
2
+ import { anvil, getScriptDirectory, getSrcDirectory } from "@latticexyz/common/foundry";
3
+ import chalk from "chalk";
4
+ import chokidar from "chokidar";
5
+ import { loadConfig, resolveConfigPath } from "@latticexyz/config/node";
6
+ import { StoreConfig } from "@latticexyz/store";
7
+ import path from "path";
8
+ import { WorldConfig } from "@latticexyz/world";
9
+ import { homedir } from "os";
10
+ import { rmSync } from "fs";
11
+ import { deployOptions, runDeploy } from "../runDeploy";
12
+ import { BehaviorSubject, debounceTime, exhaustMap, filter } from "rxjs";
13
+ import { Address } from "viem";
14
+ import { isDefined } from "@latticexyz/common/utils";
15
+
16
+ const devOptions = {
17
+ rpc: deployOptions.rpc,
18
+ configPath: deployOptions.configPath,
19
+ alwaysRunPostDeploy: deployOptions.alwaysRunPostDeploy,
20
+ worldAddress: deployOptions.worldAddress,
21
+ };
22
+
23
+ const commandModule: CommandModule<typeof devOptions, InferredOptionTypes<typeof devOptions>> = {
24
+ command: "dev-contracts",
25
+
26
+ describe: "Start a development server for MUD contracts",
27
+
28
+ builder(yargs) {
29
+ return yargs.options(devOptions);
30
+ },
31
+
32
+ async handler(opts) {
33
+ let rpc = opts.rpc;
34
+ const configPath = opts.configPath ?? (await resolveConfigPath(opts.configPath));
35
+ const srcDir = await getSrcDirectory();
36
+ const scriptDir = await getScriptDirectory();
37
+ const initialConfig = (await loadConfig(configPath)) as StoreConfig & WorldConfig;
38
+
39
+ // Start an anvil instance in the background if no RPC url is provided
40
+ if (!opts.rpc) {
41
+ // Clean anvil cache as 1s block times can fill up the disk
42
+ // - https://github.com/foundry-rs/foundry/issues/3623
43
+ // - https://github.com/foundry-rs/foundry/issues/4989
44
+ // - https://github.com/foundry-rs/foundry/issues/3699
45
+ // - https://github.com/foundry-rs/foundry/issues/3512
46
+ console.log(chalk.gray("Cleaning devnode cache"));
47
+ const userHomeDir = homedir();
48
+ rmSync(path.join(userHomeDir, ".foundry", "anvil", "tmp"), { recursive: true, force: true });
49
+
50
+ const anvilArgs = ["--block-time", "1", "--block-base-fee-per-gas", "0"];
51
+ anvil(anvilArgs);
52
+ rpc = "http://127.0.0.1:8545";
53
+ }
54
+
55
+ // Watch for changes
56
+ const lastChange$ = new BehaviorSubject<number>(Date.now());
57
+ chokidar.watch([configPath, srcDir, scriptDir], { ignoreInitial: true }).on("all", async (_, updatePath) => {
58
+ if (updatePath.includes(configPath)) {
59
+ console.log(chalk.blue("Config changed, queuing deploy…"));
60
+ lastChange$.next(Date.now());
61
+ }
62
+ if (updatePath.includes(srcDir) || updatePath.includes(scriptDir)) {
63
+ // Ignore changes to codegen files to avoid an infinite loop
64
+ if (!updatePath.includes(initialConfig.codegenDirectory)) {
65
+ console.log(chalk.blue("Contracts changed, queuing deploy…"));
66
+ lastChange$.next(Date.now());
67
+ }
68
+ }
69
+ });
70
+
71
+ let worldAddress = opts.worldAddress as Address | undefined;
72
+
73
+ const deploys$ = lastChange$.pipe(
74
+ // debounce so that a large batch of file changes only triggers a deploy after it settles down, rather than the first change it sees (and then redeploying immediately after)
75
+ debounceTime(200),
76
+ exhaustMap(async (lastChange) => {
77
+ if (worldAddress) {
78
+ console.log(chalk.blue("Rebuilding and upgrading world…"));
79
+ }
80
+
81
+ try {
82
+ const deploy = await runDeploy({
83
+ ...opts,
84
+ configPath,
85
+ rpc,
86
+ skipBuild: false,
87
+ printConfig: false,
88
+ profile: undefined,
89
+ saveDeployment: true,
90
+ worldAddress,
91
+ srcDir,
92
+ });
93
+ worldAddress = deploy.address;
94
+ // if there were changes while we were deploying, trigger it again
95
+ if (lastChange < lastChange$.value) {
96
+ lastChange$.next(lastChange$.value);
97
+ } else {
98
+ console.log(chalk.gray("\nWaiting for file changes…\n"));
99
+ }
100
+ return deploy;
101
+ } catch (error) {
102
+ console.error(chalk.bgRed(chalk.whiteBright("\n Error while attempting deploy \n")));
103
+ console.error(error);
104
+ console.log(chalk.gray("\nWaiting for file changes…\n"));
105
+ }
106
+ }),
107
+ filter(isDefined)
108
+ );
109
+
110
+ deploys$.subscribe();
111
+ },
112
+ };
113
+
114
+ export default commandModule;
@@ -2,7 +2,7 @@ import { rmSync } from "fs";
2
2
  import { homedir } from "os";
3
3
  import path from "path";
4
4
  import type { CommandModule } from "yargs";
5
- import { execLog } from "../utils/deprecated/index.js";
5
+ import { execa } from "execa";
6
6
 
7
7
  type Options = {
8
8
  blocktime: number;
@@ -23,7 +23,12 @@ const commandModule: CommandModule<Options, Options> = {
23
23
  console.log("Clearing devnode history");
24
24
  const userHomeDir = homedir();
25
25
  rmSync(path.join(userHomeDir, ".foundry", "anvil", "tmp"), { recursive: true, force: true });
26
- const child = execLog("anvil", ["-b", String(blocktime), "--block-base-fee-per-gas", "0"]);
26
+
27
+ const anvilArgs = ["-b", String(blocktime), "--block-base-fee-per-gas", "0"];
28
+ console.log(`Running: anvil ${anvilArgs.join(" ")}`);
29
+ const child = execa("anvil", anvilArgs, {
30
+ stdio: ["inherit", "inherit", "inherit"],
31
+ });
27
32
 
28
33
  process.on("SIGINT", () => {
29
34
  console.log("\ngracefully shutting down from SIGINT (Crtl-C)");
@@ -1,5 +1,5 @@
1
1
  import type { CommandModule } from "yargs";
2
- import { FaucetServiceDefinition } from "@latticexyz/services/protobuf/ts/faucet/faucet.js";
2
+ import { FaucetServiceDefinition } from "@latticexyz/services/faucet";
3
3
  import { createChannel, createClient } from "nice-grpc-web";
4
4
  import chalk from "chalk";
5
5
  import { NodeHttpTransport } from "@improbable-eng/grpc-web-node-http-transport";
@@ -1,26 +1,31 @@
1
1
  import { CommandModule } from "yargs";
2
2
 
3
- import devnode from "./devnode.js";
4
- import faucet from "./faucet.js";
5
- import gasReport from "./gas-report.js";
6
- import hello from "./hello.js";
7
- import tablegen from "./tablegen.js";
8
- import tsgen from "./tsgen.js";
9
- import deployV2 from "./deploy-v2.js";
10
- import worldgen from "./worldgen.js";
11
- import setVersion from "./set-version.js";
12
- import testV2 from "./test-v2.js";
3
+ import gasReport from "@latticexyz/gas-report";
4
+ import abiTs from "@latticexyz/abi-ts";
5
+
6
+ import devnode from "./devnode";
7
+ import faucet from "./faucet";
8
+ import hello from "./hello";
9
+ import tablegen from "./tablegen";
10
+ import deploy from "./deploy";
11
+ import worldgen from "./worldgen";
12
+ import setVersion from "./set-version";
13
+ import test from "./test";
14
+ import trace from "./trace";
15
+ import devContracts from "./dev-contracts";
13
16
 
14
17
  // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Each command has different options
15
18
  export const commands: CommandModule<any, any>[] = [
16
- deployV2,
19
+ deploy,
17
20
  devnode,
18
21
  faucet,
19
- gasReport,
22
+ gasReport as CommandModule,
20
23
  hello,
21
24
  tablegen,
22
- tsgen,
23
25
  worldgen,
24
26
  setVersion,
25
- testV2,
27
+ test,
28
+ trace,
29
+ devContracts,
30
+ abiTs,
26
31
  ];
@@ -1,58 +1,68 @@
1
1
  import chalk from "chalk";
2
- import { existsSync, readFileSync, rmSync, writeFileSync } from "fs";
2
+ import { readFileSync, writeFileSync } from "fs";
3
3
  import path from "path";
4
4
  import type { CommandModule } from "yargs";
5
- import { MUDError } from "@latticexyz/config";
6
- import { logError } from "../utils/errors.js";
5
+ import { MUDError } from "@latticexyz/common/errors";
6
+ import { logError } from "../utils/errors";
7
7
  import localPackageJson from "../../package.json" assert { type: "json" };
8
+ import glob from "glob";
9
+ import { mudPackages } from "../mudPackages";
8
10
 
9
11
  type Options = {
10
12
  backup?: boolean;
11
13
  force?: boolean;
12
14
  restore?: boolean;
13
15
  mudVersion?: string;
16
+ tag?: string;
17
+ commit?: string;
18
+ link?: string;
14
19
  };
15
20
 
16
- const BACKUP_FILE = ".mudbackup";
17
- const MUD_PREFIX = "@latticexyz";
18
-
19
21
  const commandModule: CommandModule<Options, Options> = {
20
22
  command: "set-version",
21
23
 
22
- describe: "Install a custom MUD version and optionally backup the previously installed version",
24
+ describe: "Set MUD version in all package.json files and optionally backup the previously installed version",
23
25
 
24
26
  builder(yargs) {
25
27
  return yargs.options({
26
- backup: { type: "boolean", description: `Back up the current MUD versions to "${BACKUP_FILE}"` },
27
- force: {
28
- type: "boolean",
29
- description: `Backup fails if a "${BACKUP_FILE}" file is found, unless --force is provided`,
28
+ mudVersion: { alias: "v", type: "string", description: "Set MUD to the given version" },
29
+ tag: {
30
+ alias: "t",
31
+ type: "string",
32
+ description: "Set MUD to the latest version with the given tag from npm",
33
+ },
34
+ commit: {
35
+ alias: "c",
36
+ type: "string",
37
+ description: "Set MUD to the version based on a given git commit hash from npm",
30
38
  },
31
- restore: { type: "boolean", description: `Restore the previous MUD versions from "${BACKUP_FILE}"` },
32
- mudVersion: { alias: "v", type: "string", description: "The MUD version to install" },
39
+ link: { alias: "l", type: "string", description: "Relative path to the local MUD root directory to link" },
33
40
  });
34
41
  },
35
42
 
36
43
  async handler(options) {
37
44
  try {
38
- if (!options.mudVersion && !options.restore) {
39
- throw new MUDError(`Version parameter is required unless --restore is provided.`);
45
+ const mutuallyExclusiveOptions = ["mudVersion", "link", "tag", "commit", "restore"];
46
+ const numMutuallyExclusiveOptions = mutuallyExclusiveOptions.reduce(
47
+ (acc, opt) => (options[opt] ? acc + 1 : acc),
48
+ 0
49
+ );
50
+
51
+ if (numMutuallyExclusiveOptions === 0) {
52
+ throw new MUDError(`You need to provide one these options: ${mutuallyExclusiveOptions.join(", ")}`);
40
53
  }
41
54
 
42
- // Resolve the `canary` version number if needed
43
- options.mudVersion =
44
- options.mudVersion === "canary" ? await getCanaryVersion(localPackageJson.name) : options.mudVersion;
55
+ if (numMutuallyExclusiveOptions > 1) {
56
+ throw new MUDError(`These options are mutually exclusive: ${mutuallyExclusiveOptions.join(", ")}`);
57
+ }
45
58
 
46
- // Read the current package.json
47
- const rootPath = "./package.json";
48
- const { workspaces } = updatePackageJson(rootPath, options);
59
+ // Resolve the version number from available options like `tag` or `commit`
60
+ options.mudVersion = await resolveVersion(options);
49
61
 
50
- // Load the package.json of each workspace
51
- if (workspaces) {
52
- for (const workspace of workspaces) {
53
- const filePath = path.join(workspace, "/package.json");
54
- updatePackageJson(filePath, options);
55
- }
62
+ // Update all package.json below the current working directory (except in node_modules)
63
+ const packageJsons = glob.sync("**/package.json").filter((p) => !p.includes("node_modules"));
64
+ for (const packageJson of packageJsons) {
65
+ updatePackageJson(packageJson, options);
56
66
  }
57
67
  } catch (e) {
58
68
  logError(e);
@@ -62,60 +72,76 @@ const commandModule: CommandModule<Options, Options> = {
62
72
  },
63
73
  };
64
74
 
65
- function updatePackageJson(filePath: string, options: Options): { workspaces?: string[] } {
66
- const { backup, restore, force, mudVersion } = options;
67
- const backupFilePath = path.join(path.dirname(filePath), BACKUP_FILE);
68
-
69
- // If `backup` is true and force not set, check if a backup file already exists and throw an error if it does
70
- if (backup && !force && existsSync(backupFilePath)) {
71
- throw new MUDError(
72
- `A backup file already exists at ${backupFilePath}.\nUse --force to overwrite it or --restore to restore it.`
73
- );
75
+ async function resolveVersion(options: Options) {
76
+ // Backwards compatibility to previous behavior of this script where passing "canary" as the version resolved to the latest commit on main
77
+ if (options.mudVersion === "canary") options.tag = "main";
78
+
79
+ let npmResult;
80
+ try {
81
+ console.log(chalk.blue(`Fetching available versions`));
82
+ npmResult = await (await fetch(`https://registry.npmjs.org/${localPackageJson.name}`)).json();
83
+ } catch (e) {
84
+ throw new MUDError(`Could not fetch available MUD versions`);
74
85
  }
75
86
 
76
- const packageJson = readPackageJson(filePath);
87
+ if (options.tag) {
88
+ const version = npmResult["dist-tags"][options.tag];
89
+ if (!version) {
90
+ throw new MUDError(`Could not find npm version with tag "${options.tag}"`);
91
+ }
92
+ console.log(chalk.green(`Latest version with tag ${options.tag}: ${version}`));
93
+ return version;
94
+ }
95
+
96
+ if (options.commit) {
97
+ // Find a version with this commit hash
98
+ const commit = options.commit.substring(0, 8); // changesets uses the first 8 characters of the commit hash as version for prereleases/snapshot releases
99
+ const version = Object.keys(npmResult["versions"]).find((v) => (v as string).includes(commit));
100
+ if (!version) {
101
+ throw new MUDError(`Could not find npm version based on commit "${options.commit}"`);
102
+ }
103
+ console.log(chalk.green(`Version from commit ${options.commit}: ${version}`));
104
+ return version;
105
+ }
106
+
107
+ // If neither a tag nor a commit option is given, return the `mudVersion`
108
+ return options.mudVersion;
109
+ }
77
110
 
78
- // Load .mudbackup if `restore` is true
79
- const backupJson = restore ? readPackageJson(backupFilePath) : undefined;
111
+ function updatePackageJson(filePath: string, options: Options): { workspaces?: string[] } {
112
+ const { link } = options;
113
+ let { mudVersion } = options;
114
+
115
+ const packageJson = readPackageJson(filePath);
116
+ const mudPackageNames = Object.keys(mudPackages);
80
117
 
81
118
  // Find all MUD dependencies
82
119
  const mudDependencies: Record<string, string> = {};
83
- for (const key in packageJson.dependencies) {
84
- if (key.startsWith(MUD_PREFIX)) {
85
- mudDependencies[key] = packageJson.dependencies[key];
120
+ for (const packageName in packageJson.dependencies) {
121
+ if (mudPackageNames.includes(packageName)) {
122
+ mudDependencies[packageName] = packageJson.dependencies[packageName];
86
123
  }
87
124
  }
88
125
 
89
126
  // Find all MUD devDependencies
90
127
  const mudDevDependencies: Record<string, string> = {};
91
- for (const key in packageJson.devDependencies) {
92
- if (key.startsWith(MUD_PREFIX)) {
93
- mudDevDependencies[key] = packageJson.devDependencies[key];
128
+ for (const packageName in packageJson.devDependencies) {
129
+ if (mudPackageNames.includes(packageName)) {
130
+ mudDevDependencies[packageName] = packageJson.devDependencies[packageName];
94
131
  }
95
132
  }
96
133
 
97
- // Back up the current dependencies if `backup` is true
98
- if (backup) {
99
- writeFileSync(
100
- backupFilePath,
101
- JSON.stringify({ dependencies: mudDependencies, devDependencies: mudDevDependencies }, null, 2)
102
- );
103
- console.log(chalk.green(`Backed up MUD dependencies from ${filePath} to ${backupFilePath}`));
104
- }
105
-
106
134
  // Update the dependencies
107
- for (const key in packageJson.dependencies) {
108
- if (key.startsWith(MUD_PREFIX)) {
109
- packageJson.dependencies[key] =
110
- restore && backupJson ? backupJson.dependencies[key] : mudVersion || packageJson.dependencies[key];
135
+ for (const packageName in packageJson.dependencies) {
136
+ if (mudPackageNames.includes(packageName)) {
137
+ packageJson.dependencies[packageName] = resolveMudVersion(packageName, "dependencies");
111
138
  }
112
139
  }
113
140
 
114
141
  // Update the devDependencies
115
- for (const key in packageJson.devDependencies) {
116
- if (key.startsWith(MUD_PREFIX)) {
117
- packageJson.devDependencies[key] =
118
- restore && backupJson ? backupJson.devDependencies[key] : mudVersion || packageJson.devDependencies[key];
142
+ for (const packageName in packageJson.devDependencies) {
143
+ if (mudPackageNames.includes(packageName)) {
144
+ packageJson.devDependencies[packageName] = resolveMudVersion(packageName, "devDependencies");
119
145
  }
120
146
  }
121
147
 
@@ -126,14 +152,13 @@ function updatePackageJson(filePath: string, options: Options): { workspaces?: s
126
152
  logComparison(mudDependencies, packageJson.dependencies);
127
153
  logComparison(mudDevDependencies, packageJson.devDependencies);
128
154
 
129
- // Remove the backup file if `restore` is true and `backup` is false
130
- // because the old backup file is no longer needed
131
- if (restore && !backup) {
132
- rmSync(backupFilePath);
133
- console.log(chalk.green(`Cleaned up ${backupFilePath}`));
134
- }
135
-
136
155
  return packageJson;
156
+
157
+ function resolveMudVersion(key: string, type: "dependencies" | "devDependencies") {
158
+ if (link) mudVersion = resolveLinkPath(filePath, link, key);
159
+ if (!mudVersion) return packageJson[type][key];
160
+ return mudVersion;
161
+ }
137
162
  }
138
163
 
139
164
  function readPackageJson(path: string): {
@@ -149,18 +174,6 @@ function readPackageJson(path: string): {
149
174
  }
150
175
  }
151
176
 
152
- async function getCanaryVersion(pkg: string) {
153
- try {
154
- console.log(chalk.blue("fetching MUD canary version..."));
155
- const result = await (await fetch(`https://registry.npmjs.org/${pkg}`)).json();
156
- const canary = result["dist-tags"].canary;
157
- console.log(chalk.green("MUD canary version:", canary));
158
- return canary;
159
- } catch (e) {
160
- throw new MUDError(`Could not fetch canary version of ${pkg}`);
161
- }
162
- }
163
-
164
177
  function logComparison(prev: Record<string, string>, curr: Record<string, string>) {
165
178
  for (const key in prev) {
166
179
  if (prev[key] !== curr[key]) {
@@ -169,4 +182,13 @@ function logComparison(prev: Record<string, string>, curr: Record<string, string
169
182
  }
170
183
  }
171
184
 
185
+ /**
186
+ * Returns path of the package to link, given a path to a local MUD clone and a package
187
+ */
188
+ function resolveLinkPath(packageJsonPath: string, mudLinkPath: string, packageName: string) {
189
+ const packageJsonToRootPath = path.relative(path.dirname(packageJsonPath), process.cwd());
190
+ const linkPath = path.join(packageJsonToRootPath, mudLinkPath, mudPackages[packageName].localPath);
191
+ return "link:" + linkPath;
192
+ }
193
+
172
194
  export default commandModule;
@@ -1,8 +1,9 @@
1
1
  import path from "path";
2
2
  import type { CommandModule } from "yargs";
3
- import { loadStoreConfig } from "@latticexyz/config";
4
- import { tablegen } from "../render-solidity/tablegen.js";
5
- import { getSrcDirectory } from "../utils/index.js";
3
+ import { loadConfig } from "@latticexyz/config/node";
4
+ import { StoreConfig } from "@latticexyz/store";
5
+ import { tablegen } from "@latticexyz/store/codegen";
6
+ import { getRemappings, getSrcDirectory } from "@latticexyz/common/foundry";
6
7
 
7
8
  type Options = {
8
9
  configPath?: string;
@@ -20,10 +21,11 @@ const commandModule: CommandModule<Options, Options> = {
20
21
  },
21
22
 
22
23
  async handler({ configPath }) {
23
- const config = await loadStoreConfig(configPath);
24
+ const config = (await loadConfig(configPath)) as StoreConfig;
24
25
  const srcDir = await getSrcDirectory();
26
+ const remappings = await getRemappings();
25
27
 
26
- await tablegen(config, path.join(srcDir, config.codegenDirectory));
28
+ await tablegen(config, path.join(srcDir, config.codegenDirectory), remappings);
27
29
 
28
30
  process.exit(0);
29
31
  },