@latticexyz/cli 1.31.0 → 1.31.2

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.
@@ -53733,7 +53733,7 @@ ${error.message}`;
53733
53733
  Object.defineProperty(exports2, "__esModule", {
53734
53734
  value: true
53735
53735
  });
53736
- exports2.readFile = readFile;
53736
+ exports2.readFile = readFile2;
53737
53737
  exports2.readFileSync = readFileSync3;
53738
53738
  var _fs = _interopRequireDefault(require("fs"));
53739
53739
  function _interopRequireDefault(obj) {
@@ -53752,7 +53752,7 @@ ${error.message}`;
53752
53752
  });
53753
53753
  });
53754
53754
  }
53755
- async function readFile(filepath, options = {}) {
53755
+ async function readFile2(filepath, options = {}) {
53756
53756
  const throwNotFound = options.throwNotFound === true;
53757
53757
  try {
53758
53758
  const content = await fsReadFileAsync(filepath, "utf8");
@@ -183033,8 +183033,8 @@ ${error.message}`;
183033
183033
  cb(null, x);
183034
183034
  }
183035
183035
  };
183036
- var defaultReadPackage = function defaultReadPackage2(readFile, pkgfile, cb) {
183037
- readFile(pkgfile, function(readFileErr, body) {
183036
+ var defaultReadPackage = function defaultReadPackage2(readFile2, pkgfile, cb) {
183037
+ readFile2(pkgfile, function(readFileErr, body) {
183038
183038
  if (readFileErr)
183039
183039
  cb(readFileErr);
183040
183040
  else {
@@ -183070,7 +183070,7 @@ ${error.message}`;
183070
183070
  opts = normalizeOptions(x, opts);
183071
183071
  var isFile = opts.isFile || defaultIsFile;
183072
183072
  var isDirectory = opts.isDirectory || defaultIsDir;
183073
- var readFile = opts.readFile || fs.readFile;
183073
+ var readFile2 = opts.readFile || fs.readFile;
183074
183074
  var realpath = opts.realpath || defaultRealpath;
183075
183075
  var readPackage = opts.readPackage || defaultReadPackage;
183076
183076
  if (opts.readFile && opts.readPackage) {
@@ -183202,7 +183202,7 @@ ${error.message}`;
183202
183202
  isFile(pkgfile, function(err2, ex) {
183203
183203
  if (!ex)
183204
183204
  return loadpkg(path2.dirname(dir), cb2);
183205
- readPackage(readFile, pkgfile, function(err3, pkgParam) {
183205
+ readPackage(readFile2, pkgfile, function(err3, pkgParam) {
183206
183206
  if (err3)
183207
183207
  cb2(err3);
183208
183208
  var pkg = pkgParam;
@@ -183230,7 +183230,7 @@ ${error.message}`;
183230
183230
  return cb2(err2);
183231
183231
  if (!ex)
183232
183232
  return loadAsFile(path2.join(x2, "index"), fpkg, cb2);
183233
- readPackage(readFile, pkgfile, function(err3, pkgParam) {
183233
+ readPackage(readFile2, pkgfile, function(err3, pkgParam) {
183234
183234
  if (err3)
183235
183235
  return cb2(err3);
183236
183236
  var pkg = pkgParam;
@@ -216206,9 +216206,11 @@ function keccak256(data) {
216206
216206
  }
216207
216207
 
216208
216208
  // src/utils/codegen.ts
216209
+ var import_promises = require("fs/promises");
216209
216210
  var import_ejs = __toESM(require_ejs());
216210
216211
  var import_path = __toESM(require("path"));
216211
216212
  var contractsDir = import_path.default.join(__dirname, "../../src/contracts");
216213
+ var stubLibDeploy = (0, import_promises.readFile)(import_path.default.join(contractsDir, "LibDeploy.sol"));
216212
216214
 
216213
216215
  // src/utils/types.ts
216214
216216
  var import_typechain = __toESM(require_dist());
@@ -18305,7 +18305,7 @@ ${error.message}`;
18305
18305
  Object.defineProperty(exports2, "__esModule", {
18306
18306
  value: true
18307
18307
  });
18308
- exports2.readFile = readFile;
18308
+ exports2.readFile = readFile2;
18309
18309
  exports2.readFileSync = readFileSync2;
18310
18310
  var _fs = _interopRequireDefault(require("fs"));
18311
18311
  function _interopRequireDefault(obj) {
@@ -18324,7 +18324,7 @@ ${error.message}`;
18324
18324
  });
18325
18325
  });
18326
18326
  }
18327
- async function readFile(filepath, options = {}) {
18327
+ async function readFile2(filepath, options = {}) {
18328
18328
  const throwNotFound = options.throwNotFound === true;
18329
18329
  try {
18330
18330
  const content = await fsReadFileAsync(filepath, "utf8");
@@ -147605,8 +147605,8 @@ ${error.message}`;
147605
147605
  cb(null, x);
147606
147606
  }
147607
147607
  };
147608
- var defaultReadPackage = function defaultReadPackage2(readFile, pkgfile, cb) {
147609
- readFile(pkgfile, function(readFileErr, body) {
147608
+ var defaultReadPackage = function defaultReadPackage2(readFile2, pkgfile, cb) {
147609
+ readFile2(pkgfile, function(readFileErr, body) {
147610
147610
  if (readFileErr)
147611
147611
  cb(readFileErr);
147612
147612
  else {
@@ -147642,7 +147642,7 @@ ${error.message}`;
147642
147642
  opts = normalizeOptions(x, opts);
147643
147643
  var isFile = opts.isFile || defaultIsFile;
147644
147644
  var isDirectory = opts.isDirectory || defaultIsDir;
147645
- var readFile = opts.readFile || fs.readFile;
147645
+ var readFile2 = opts.readFile || fs.readFile;
147646
147646
  var realpath = opts.realpath || defaultRealpath;
147647
147647
  var readPackage = opts.readPackage || defaultReadPackage;
147648
147648
  if (opts.readFile && opts.readPackage) {
@@ -147774,7 +147774,7 @@ ${error.message}`;
147774
147774
  isFile(pkgfile, function(err2, ex) {
147775
147775
  if (!ex)
147776
147776
  return loadpkg(path4.dirname(dir), cb2);
147777
- readPackage(readFile, pkgfile, function(err3, pkgParam) {
147777
+ readPackage(readFile2, pkgfile, function(err3, pkgParam) {
147778
147778
  if (err3)
147779
147779
  cb2(err3);
147780
147780
  var pkg = pkgParam;
@@ -147802,7 +147802,7 @@ ${error.message}`;
147802
147802
  return cb2(err2);
147803
147803
  if (!ex)
147804
147804
  return loadAsFile(path4.join(x2, "index"), fpkg, cb2);
147805
- readPackage(readFile, pkgfile, function(err3, pkgParam) {
147805
+ readPackage(readFile2, pkgfile, function(err3, pkgParam) {
147806
147806
  if (err3)
147807
147807
  return cb2(err3);
147808
147808
  var pkg = pkgParam;
@@ -180821,9 +180821,11 @@ function extractIdFromFile(path4) {
180821
180821
  }
180822
180822
 
180823
180823
  // src/utils/codegen.ts
180824
+ var import_promises = require("fs/promises");
180824
180825
  var import_ejs = __toESM(require_ejs());
180825
180826
  var import_path = __toESM(require("path"));
180826
180827
  var contractsDir = import_path.default.join(__dirname, "../../src/contracts");
180828
+ var stubLibDeploy = (0, import_promises.readFile)(import_path.default.join(contractsDir, "LibDeploy.sol"));
180827
180829
 
180828
180830
  // src/utils/types.ts
180829
180831
  var import_typechain = __toESM(require_dist());
@@ -180845,7 +180847,11 @@ function getContractsInDir(dir, exclude) {
180845
180847
  return (0, import_fs2.readdirSync)(dir).filter((item) => item.includes(".sol")).map((item) => item.replace(".sol", "")).filter((item) => !(exclude == null ? void 0 : exclude.includes(item)));
180846
180848
  }
180847
180849
  function copyAbi(inDir, outDir, contract) {
180848
- return (0, import_fs2.copyFileSync)(import_path2.default.join(inDir, contract + ".sol", contract + ".json"), import_path2.default.join(outDir, contract + ".json"));
180850
+ try {
180851
+ return (0, import_fs2.copyFileSync)(import_path2.default.join(inDir, contract + ".sol", contract + ".json"), import_path2.default.join(outDir, contract + ".json"));
180852
+ } catch (e) {
180853
+ console.warn(e);
180854
+ }
180849
180855
  }
180850
180856
  function filterAbi(abiIn = "./out", abiOut = "./abi", exclude = ["Component", "IComponent"]) {
180851
180857
  console.log(`Cleaning output directory (${abiOut}})`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@latticexyz/cli",
3
- "version": "1.31.0",
3
+ "version": "1.31.2",
4
4
  "description": "Command line interface for mud",
5
5
  "main": "dist/index.js",
6
6
  "license": "MIT",
@@ -37,10 +37,10 @@
37
37
  "typescript": "^4.6.4"
38
38
  },
39
39
  "dependencies": {
40
- "@latticexyz/services": "^1.31.0",
41
- "@latticexyz/solecs": "^1.31.0",
42
- "@latticexyz/std-contracts": "^1.31.0",
43
- "@latticexyz/utils": "^1.31.0",
40
+ "@latticexyz/services": "^1.31.2",
41
+ "@latticexyz/solecs": "^1.31.2",
42
+ "@latticexyz/std-contracts": "^1.31.2",
43
+ "@latticexyz/utils": "^1.31.2",
44
44
  "@typechain/ethers-v5": "^10.1.1",
45
45
  "chalk": "^5.0.1",
46
46
  "chokidar": "^3.5.3",
@@ -70,5 +70,5 @@
70
70
  "pkg": {
71
71
  "scripts": "build/**/*.js"
72
72
  },
73
- "gitHead": "a1a0d627e3800039b3b9179a23927aa599bc6e2a"
73
+ "gitHead": "bdcbdd6cb1a056779b73307acce20eccc65ad062"
74
74
  }
@@ -1,6 +1,4 @@
1
1
  import type { Arguments, CommandBuilder } from "yargs";
2
- import ejs from "ejs";
3
- import { readFileSync, writeFileSync } from "fs";
4
2
  import { generateLibDeploy } from "../utils";
5
3
 
6
4
  type Options = {
@@ -18,14 +18,14 @@ function getContractsInDir(dir: string, exclude?: string[]) {
18
18
  }
19
19
 
20
20
  function copyAbi(inDir: string, outDir: string, contract: string) {
21
- return copyFileSync(path.join(inDir, contract + ".sol", contract + ".json"), path.join(outDir, contract + ".json"));
21
+ try {
22
+ return copyFileSync(path.join(inDir, contract + ".sol", contract + ".json"), path.join(outDir, contract + ".json"));
23
+ } catch (e) {
24
+ console.warn(e);
25
+ }
22
26
  }
23
27
 
24
- export function filterAbi(
25
- abiIn = "./out",
26
- abiOut = "./abi",
27
- exclude: string[] = ["Component", "IComponent"]
28
- ) {
28
+ export function filterAbi(abiIn = "./out", abiOut = "./abi", exclude: string[] = ["Component", "IComponent"]) {
29
29
  // Clean our dir
30
30
  console.log(`Cleaning output directory (${abiOut}})`);
31
31
  rmSync(abiOut, { recursive: true, force: true });
@@ -1,12 +1,14 @@
1
- import { readFileSync, writeFileSync } from "fs";
1
+ import { readFile, writeFile } from "fs/promises";
2
2
  import ejs from "ejs";
3
3
  import path from "path";
4
4
 
5
5
  const contractsDir = path.join(__dirname, "../../src/contracts");
6
6
 
7
+ const stubLibDeploy = readFile(path.join(contractsDir, "LibDeploy.sol"));
8
+
7
9
  export async function generateLibDeploy(configPath: string, out: string, systems?: string | string[]) {
8
10
  // Parse config
9
- const config = JSON.parse(readFileSync(configPath, { encoding: "utf8" }));
11
+ const config = JSON.parse(await readFile(configPath, { encoding: "utf8" }));
10
12
 
11
13
  // Filter systems
12
14
  if (systems) {
@@ -20,11 +22,11 @@ export async function generateLibDeploy(configPath: string, out: string, systems
20
22
  console.log("Generating deployment script");
21
23
  const LibDeploy = await ejs.renderFile(path.join(contractsDir, "LibDeploy.ejs"), config, { async: true });
22
24
  const libDeployPath = path.join(out, "LibDeploy.sol");
23
- writeFileSync(libDeployPath, LibDeploy);
25
+ await writeFile(libDeployPath, LibDeploy);
24
26
 
25
27
  return libDeployPath;
26
28
  }
27
29
 
28
30
  export async function resetLibDeploy(out: string) {
29
- writeFileSync(path.join(out, "LibDeploy.sol"), readFileSync(path.join(contractsDir, "LibDeploy.sol")));
31
+ await writeFile(path.join(out, "LibDeploy.sol"), await stubLibDeploy);
30
32
  }
@@ -1,6 +1,5 @@
1
1
  import { constants, Wallet } from "ethers";
2
- import { rmSync } from "fs";
3
- import { generateLibDeploy } from "./codegen";
2
+ import { generateLibDeploy, resetLibDeploy } from "./codegen";
4
3
  import { findLog } from "./findLog";
5
4
  import { generateTypes } from "./types";
6
5
  import { execa } from "execa";
@@ -77,7 +76,7 @@ export async function generateAndDeploy(args: DeployOptions) {
77
76
  } finally {
78
77
  // Remove generated LibDeploy
79
78
  console.log("Cleaning up deployment script");
80
- if (libDeployPath) rmSync(libDeployPath);
79
+ if (libDeployPath) resetLibDeploy(contractsDir);
81
80
  }
82
81
 
83
82
  return { deployedWorldAddress, initialBlockNumber };
package/src/utils/hsr.ts CHANGED
@@ -16,9 +16,19 @@ function extractImports(path: string): string[] {
16
16
  return regexResult;
17
17
  }
18
18
 
19
- function findDependencies(file: string, dependencyGraph: { [file: string]: string[] }): string[] {
19
+ function findDependencies(
20
+ file: string,
21
+ dependencyGraph: { [file: string]: string[] },
22
+ visited: string[] = []
23
+ ): string[] {
20
24
  const dependencies = dependencyGraph[file] ?? [];
21
- const subDependencies = dependencies.flatMap((d) => findDependencies(d, dependencyGraph));
25
+ const subDependencies = dependencies.flatMap((d) => {
26
+ if (visited.includes(d)) {
27
+ console.warn("Circular dependency detected: ", d, dependencyGraph[d]);
28
+ return [];
29
+ }
30
+ return findDependencies(d, dependencyGraph, [...visited, d]);
31
+ });
22
32
  return [...new Set([...dependencies, ...subDependencies])];
23
33
  }
24
34
 
@@ -50,9 +60,9 @@ export function hsr(root: string, replaceSystems: (systems: string[]) => Promise
50
60
  if (event === "change") {
51
61
  // Find all files depending on the changed file
52
62
  const dependencies = findDependencies(changedFile, dependencyGraph);
53
- const changedSystems = [changedFile, ...dependencies]
54
- .filter((f) => systems.has(f))
55
- .map((f) => f.replace(".sol", ""));
63
+ const changedSystems = [
64
+ ...new Set([changedFile, ...dependencies].filter((f) => systems.has(f)).map((f) => f.replace(".sol", ""))),
65
+ ];
56
66
  console.log("Systems to replace", changedSystems);
57
67
  if (changedSystems.length > 0) await replaceSystems(changedSystems);
58
68
  console.log("Watching system file changes...");