@latticexyz/cli 2.0.0-alpha.2 → 2.0.0-alpha.3

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.
@@ -3651,13 +3651,17 @@ var commandModule9 = {
3651
3651
  description: `Backup fails if a "${BACKUP_FILE}" file is found, unless --force is provided`
3652
3652
  },
3653
3653
  restore: { type: "boolean", description: `Restore the previous MUD versions from "${BACKUP_FILE}"` },
3654
- mudVersion: { alias: "v", type: "string", description: "The MUD version to install" }
3654
+ mudVersion: { alias: "v", type: "string", description: "The MUD version to install" },
3655
+ link: { alias: "l", type: "string", description: "Relative path to the local MUD root directory to link" }
3655
3656
  });
3656
3657
  },
3657
3658
  async handler(options) {
3658
3659
  try {
3659
- if (!options.mudVersion && !options.restore) {
3660
- throw new MUDError3(`Version parameter is required unless --restore is provided.`);
3660
+ if (!options.mudVersion && !options.link && !options.restore) {
3661
+ throw new MUDError3("`--mudVersion` or `--link` is required unless --restore is provided.");
3662
+ }
3663
+ if (options.link && options.mudVersion) {
3664
+ throw new MUDError3("Options `--link` and `--mudVersion` are mutually exclusive");
3661
3665
  }
3662
3666
  options.mudVersion = options.mudVersion === "canary" ? await getCanaryVersion(package_default.name) : options.mudVersion;
3663
3667
  const rootPath = "./package.json";
@@ -3676,9 +3680,13 @@ var commandModule9 = {
3676
3680
  }
3677
3681
  };
3678
3682
  function updatePackageJson(filePath, options) {
3679
- const { backup, restore, force, mudVersion } = options;
3683
+ const { restore, force, link } = options;
3684
+ let { backup, mudVersion } = options;
3680
3685
  const backupFilePath = path6.join(path6.dirname(filePath), BACKUP_FILE);
3681
- if (backup && !force && existsSync(backupFilePath)) {
3686
+ const backupFileExists = existsSync(backupFilePath);
3687
+ if (link && !backupFileExists)
3688
+ backup = true;
3689
+ if (backup && !force && backupFileExists) {
3682
3690
  throw new MUDError3(
3683
3691
  `A backup file already exists at ${backupFilePath}.
3684
3692
  Use --force to overwrite it or --restore to restore it.`
@@ -3707,12 +3715,12 @@ Use --force to overwrite it or --restore to restore it.`
3707
3715
  }
3708
3716
  for (const key in packageJson.dependencies) {
3709
3717
  if (key.startsWith(MUD_PREFIX)) {
3710
- packageJson.dependencies[key] = restore && backupJson ? backupJson.dependencies[key] : mudVersion || packageJson.dependencies[key];
3718
+ packageJson.dependencies[key] = resolveMudVersion(key, "dependencies");
3711
3719
  }
3712
3720
  }
3713
3721
  for (const key in packageJson.devDependencies) {
3714
3722
  if (key.startsWith(MUD_PREFIX)) {
3715
- packageJson.devDependencies[key] = restore && backupJson ? backupJson.devDependencies[key] : mudVersion || packageJson.devDependencies[key];
3723
+ packageJson.devDependencies[key] = resolveMudVersion(key, "devDependencies");
3716
3724
  }
3717
3725
  }
3718
3726
  writeFileSync3(filePath, JSON.stringify(packageJson, null, 2) + "\n");
@@ -3724,6 +3732,15 @@ Use --force to overwrite it or --restore to restore it.`
3724
3732
  console.log(chalk4.green(`Cleaned up ${backupFilePath}`));
3725
3733
  }
3726
3734
  return packageJson;
3735
+ function resolveMudVersion(key, type) {
3736
+ if (restore && backupJson)
3737
+ return backupJson[type][key];
3738
+ if (link)
3739
+ mudVersion = resolveLinkPath(filePath, link, key);
3740
+ if (!mudVersion)
3741
+ return packageJson[type][key];
3742
+ return mudVersion;
3743
+ }
3727
3744
  }
3728
3745
  function readPackageJson(path7) {
3729
3746
  try {
@@ -3751,6 +3768,12 @@ function logComparison(prev, curr) {
3751
3768
  }
3752
3769
  }
3753
3770
  }
3771
+ function resolveLinkPath(packageJsonPath, mudLinkPath, pkg) {
3772
+ const pkgName = pkg.replace(MUD_PREFIX, "");
3773
+ const packageJsonToRootPath = path6.relative(path6.dirname(packageJsonPath), process.cwd());
3774
+ const linkPath = path6.join(packageJsonToRootPath, mudLinkPath, "packages", pkgName);
3775
+ return "link:" + linkPath;
3776
+ }
3754
3777
  var set_version_default = commandModule9;
3755
3778
 
3756
3779
  // src/commands/test-v2.ts
package/dist/mud.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  commands
4
- } from "./chunk-ZSZDPSLH.js";
4
+ } from "./chunk-KJTPZOUH.js";
5
5
  import {
6
6
  logError
7
7
  } from "./chunk-YL4GJLLL.js";
package/dist/mud2.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  commands
4
- } from "./chunk-ZSZDPSLH.js";
4
+ } from "./chunk-KJTPZOUH.js";
5
5
  import {
6
6
  logError
7
7
  } from "./chunk-YL4GJLLL.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@latticexyz/cli",
3
- "version": "2.0.0-alpha.2+3be1cb4d",
3
+ "version": "2.0.0-alpha.3+5fff6670",
4
4
  "description": "Command line interface for mud",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -39,13 +39,13 @@
39
39
  "@ethersproject/providers": "^5.7.2",
40
40
  "@improbable-eng/grpc-web": "^0.15.0",
41
41
  "@improbable-eng/grpc-web-node-http-transport": "^0.15.0",
42
- "@latticexyz/config": "2.0.0-alpha.2+3be1cb4d",
43
- "@latticexyz/schema-type": "2.0.0-alpha.2+3be1cb4d",
44
- "@latticexyz/services": "2.0.0-alpha.2+3be1cb4d",
45
- "@latticexyz/solecs": "2.0.0-alpha.2+3be1cb4d",
46
- "@latticexyz/std-contracts": "2.0.0-alpha.2+3be1cb4d",
47
- "@latticexyz/store": "2.0.0-alpha.2+3be1cb4d",
48
- "@latticexyz/world": "2.0.0-alpha.2+3be1cb4d",
42
+ "@latticexyz/config": "2.0.0-alpha.3+5fff6670",
43
+ "@latticexyz/schema-type": "2.0.0-alpha.3+5fff6670",
44
+ "@latticexyz/services": "2.0.0-alpha.3+5fff6670",
45
+ "@latticexyz/solecs": "2.0.0-alpha.3+5fff6670",
46
+ "@latticexyz/std-contracts": "2.0.0-alpha.3+5fff6670",
47
+ "@latticexyz/store": "2.0.0-alpha.3+5fff6670",
48
+ "@latticexyz/world": "2.0.0-alpha.3+5fff6670",
49
49
  "@solidity-parser/parser": "^0.16.0",
50
50
  "@typechain/ethers-v5": "^10.2.0",
51
51
  "chalk": "^5.0.1",
@@ -69,5 +69,5 @@
69
69
  "zod": "^3.21.4",
70
70
  "zod-validation-error": "^1.3.0"
71
71
  },
72
- "gitHead": "3be1cb4d811f002e7f7b12cd9f4d4eef8aaf28eb"
72
+ "gitHead": "5fff6670e3dc3887a0af75355737e6874717ee25"
73
73
  }
@@ -11,6 +11,7 @@ type Options = {
11
11
  force?: boolean;
12
12
  restore?: boolean;
13
13
  mudVersion?: string;
14
+ link?: string;
14
15
  };
15
16
 
16
17
  const BACKUP_FILE = ".mudbackup";
@@ -30,13 +31,19 @@ const commandModule: CommandModule<Options, Options> = {
30
31
  },
31
32
  restore: { type: "boolean", description: `Restore the previous MUD versions from "${BACKUP_FILE}"` },
32
33
  mudVersion: { alias: "v", type: "string", description: "The MUD version to install" },
34
+ link: { alias: "l", type: "string", description: "Relative path to the local MUD root directory to link" },
33
35
  });
34
36
  },
35
37
 
36
38
  async handler(options) {
37
39
  try {
38
- if (!options.mudVersion && !options.restore) {
39
- throw new MUDError(`Version parameter is required unless --restore is provided.`);
40
+ if (!options.mudVersion && !options.link && !options.restore) {
41
+ throw new MUDError("`--mudVersion` or `--link` is required unless --restore is provided.");
42
+ }
43
+
44
+ // `link` and `mudVersion` are mutually exclusive
45
+ if (options.link && options.mudVersion) {
46
+ throw new MUDError("Options `--link` and `--mudVersion` are mutually exclusive");
40
47
  }
41
48
 
42
49
  // Resolve the `canary` version number if needed
@@ -63,11 +70,17 @@ const commandModule: CommandModule<Options, Options> = {
63
70
  };
64
71
 
65
72
  function updatePackageJson(filePath: string, options: Options): { workspaces?: string[] } {
66
- const { backup, restore, force, mudVersion } = options;
73
+ const { restore, force, link } = options;
74
+ let { backup, mudVersion } = options;
75
+
67
76
  const backupFilePath = path.join(path.dirname(filePath), BACKUP_FILE);
77
+ const backupFileExists = existsSync(backupFilePath);
78
+
79
+ // Create a backup file for previous MUD versions by default if linking to local MUD
80
+ if (link && !backupFileExists) backup = true;
68
81
 
69
82
  // 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)) {
83
+ if (backup && !force && backupFileExists) {
71
84
  throw new MUDError(
72
85
  `A backup file already exists at ${backupFilePath}.\nUse --force to overwrite it or --restore to restore it.`
73
86
  );
@@ -106,16 +119,14 @@ function updatePackageJson(filePath: string, options: Options): { workspaces?: s
106
119
  // Update the dependencies
107
120
  for (const key in packageJson.dependencies) {
108
121
  if (key.startsWith(MUD_PREFIX)) {
109
- packageJson.dependencies[key] =
110
- restore && backupJson ? backupJson.dependencies[key] : mudVersion || packageJson.dependencies[key];
122
+ packageJson.dependencies[key] = resolveMudVersion(key, "dependencies");
111
123
  }
112
124
  }
113
125
 
114
126
  // Update the devDependencies
115
127
  for (const key in packageJson.devDependencies) {
116
128
  if (key.startsWith(MUD_PREFIX)) {
117
- packageJson.devDependencies[key] =
118
- restore && backupJson ? backupJson.devDependencies[key] : mudVersion || packageJson.devDependencies[key];
129
+ packageJson.devDependencies[key] = resolveMudVersion(key, "devDependencies");
119
130
  }
120
131
  }
121
132
 
@@ -134,6 +145,13 @@ function updatePackageJson(filePath: string, options: Options): { workspaces?: s
134
145
  }
135
146
 
136
147
  return packageJson;
148
+
149
+ function resolveMudVersion(key: string, type: "dependencies" | "devDependencies") {
150
+ if (restore && backupJson) return backupJson[type][key];
151
+ if (link) mudVersion = resolveLinkPath(filePath, link, key);
152
+ if (!mudVersion) return packageJson[type][key];
153
+ return mudVersion;
154
+ }
137
155
  }
138
156
 
139
157
  function readPackageJson(path: string): {
@@ -169,4 +187,14 @@ function logComparison(prev: Record<string, string>, curr: Record<string, string
169
187
  }
170
188
  }
171
189
 
190
+ /**
191
+ * Returns path of the package to link, given a path to a local MUD clone and a package
192
+ */
193
+ function resolveLinkPath(packageJsonPath: string, mudLinkPath: string, pkg: string) {
194
+ const pkgName = pkg.replace(MUD_PREFIX, "");
195
+ const packageJsonToRootPath = path.relative(path.dirname(packageJsonPath), process.cwd());
196
+ const linkPath = path.join(packageJsonToRootPath, mudLinkPath, "packages", pkgName);
197
+ return "link:" + linkPath;
198
+ }
199
+
172
200
  export default commandModule;