@latticexyz/cli 2.2.15-entrykit-539787c27b6d10d00aa9292998c03c222e5afa4d → 2.2.15-entrykit-f3113a2da978f5b4fed35b3756893ea1c883b346

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.
@@ -34,7 +34,7 @@ Missing or invalid environment variables:
34
34
  ${Object.keys(o).join(`
35
35
  `)}
36
36
  `),process.exit(1)}throw e}}var _e=Ts().MUD_PACKAGES;var Ms={command:"set-version",describe:"Set MUD version in all package.json files and optionally backup the previously installed version",builder(e){return e.options({mudVersion:{alias:"v",type:"string",description:"Set MUD to the given version"},tag:{alias:"t",type:"string",description:"Set MUD to the latest version with the given tag from npm"},commit:{alias:"c",type:"string",description:"Set MUD to the version based on a given git commit hash from npm"},link:{alias:"l",type:"string",description:"Relative path to the local MUD root directory to link"}})},async handler(e){try{let o=["mudVersion","link","tag","commit","restore"],t=o.reduce((n,a)=>e[a]?n+1:n,0);if(t===0)throw new Y(`You need to provide one these options: ${o.join(", ")}`);if(t>1)throw new Y(`These options are mutually exclusive: ${o.join(", ")}`);e.link||(e.mudVersion=await Bs(e));let r=Ps("**/package.json").sort().filter(n=>!n.includes("node_modules"));for(let n of r)Os(n,e)}catch(o){ae(o)}finally{process.exit(0)}}};async function Bs(e){e.mudVersion==="canary"&&(e.tag="main");let o;try{console.log(re.blue("Fetching available versions")),o=await(await fetch(`https://registry.npmjs.org/${yt.name}`)).json()}catch{throw new Y("Could not fetch available MUD versions")}if(e.tag){let t=o["dist-tags"][e.tag];if(!t)throw new Y(`Could not find npm version with tag "${e.tag}"`);return console.log(re.green(`Latest version with tag ${e.tag}: ${t}`)),t}if(e.commit){let t=e.commit.substring(0,8),r=Object.keys(o.versions).find(n=>n.includes(t));if(!r)throw new Y(`Could not find npm version based on commit "${e.commit}"`);return console.log(re.green(`Version from commit ${e.commit}: ${r}`)),r}return e.mudVersion}function Os(e,o){let{link:t}=o,{mudVersion:r}=o,n=Rs(e),a=Object.keys(_e),s={};for(let c in n.dependencies)a.includes(c)&&(s[c]=n.dependencies[c]);let i={};for(let c in n.devDependencies)a.includes(c)&&(i[c]=n.devDependencies[c]);for(let c in n.dependencies)a.includes(c)&&(n.dependencies[c]=d(c,"dependencies"));for(let c in n.devDependencies)a.includes(c)&&(n.devDependencies[c]=d(c,"devDependencies"));return Ds(e,JSON.stringify(n,null,2)+`
37
- `),console.log(`Updating ${e}`),bt(s,n.dependencies),bt(i,n.devDependencies),n;function d(c,p){return t&&(r=Is(e,t,c)),r||n[p][c]}}function Rs(e){try{let o=ks(e,"utf8");return JSON.parse(o)}catch{throw new Y("Could not read JSON at "+e)}}function bt(e,o){for(let t in e)e[t]!==o[t]&&console.log(`${t}: ${re.red(e[t])} -> ${re.green(o[t])}`)}function Is(e,o,t){let r=Ue.relative(Ue.dirname(e),process.cwd());return"link:"+Ue.join(r,o,_e[t].localPath)}var ht=Ms;import{anvil as Hs,forge as Ws,getRpcUrl as js}from"@latticexyz/common/foundry";import $s from"chalk";var Ls={...R,port:{type:"number",description:"Port to run internal node for fork testing on",default:4242},worldAddress:{type:"string",description:"Address of an existing world contract. If provided, deployment is skipped and the RPC provided in the foundry.toml is used for fork testing."},forgeOptions:{type:"string",description:"Options to pass to forge test"}},Es={command:"test",describe:"Run tests in MUD contracts",builder(e){return e.options(Ls)},async handler(e){if(!e.worldAddress){let n=["--block-base-fee-per-gas","0","--port",String(e.port)];Hs(n)}let o=e.worldAddress?await js(e.profile):`http://127.0.0.1:${e.port}`,t=e.worldAddress??(await G({...e,saveDeployment:!1,rpc:o})).address;console.log($s.blue("World address",t));let r=e.forgeOptions?.replaceAll("\\","").split(" ")??[];try{await Ws(["test","--fork-url",o,...r],{profile:e.profile,env:{WORLD_ADDRESS:t}}),process.exit(0)}catch(n){console.error(n),process.exit(1)}}},wt=Es;import Fs from"node:path";import xt from"node:fs";import{loadConfig as zs,resolveConfigPath as Ns}from"@latticexyz/config/node";import{MUDError as Ct}from"@latticexyz/common/errors";import{cast as _s,getRpcUrl as Us}from"@latticexyz/common/foundry";import Vs from"@latticexyz/world/mud.config";import{createClient as Ks,http as Js}from"viem";import{getChainId as qs,readContract as Gs}from"viem/actions";import{resolveSystems as Ys}from"@latticexyz/world/node";import{getAction as At}from"viem/utils";var Qs=Vs.namespaces.world.tables.Systems.tableId;function Zs(e,o){if(!xt.existsSync(e))throw new Ct(`Missing expected worlds.json file at "${e}"`);let t=JSON.parse(xt.readFileSync(e,"utf-8"));if(!t[o])throw new Ct(`Missing chain ID ${o} in "${e}"`);return t[o].address}var Xs={command:"trace",describe:"Display the trace of a transaction",builder(e){return e.options({tx:{type:"string",required:!0,description:"Transaction hash to replay"},worldAddress:{type:"string",description:"World contract address. Defaults to the value from worlds.json, based on rpc's chainId"},configPath:{type:"string",description:"Path to the MUD config file"},profile:{type:"string",description:"The foundry profile to use"},rpc:{type:"string",description:"json rpc endpoint. Defaults to foundry's configured eth_rpc_url"}})},async handler(e){let o=await Ns(e.configPath),t=Fs.dirname(o),r=e.profile??process.env.FOUNDRY_PROFILE,n=e.rpc??await Us(r),a=await zs(o),s=Ks({transport:Js(n)}),i=await At(s,qs,"getChainId")({}),d=e.worldAddress??Zs(a.deploy.worldsFile,i),c=await Ys({rootDir:t,config:a}),p=await Promise.all(c.map(async g=>({label:g.label,address:await At(s,Gs,"readContract")({abi:k,address:d,functionName:"getField",args:[Qs,[g.systemId],0]})}))),f=await _s(["run","--label",`${d}:World`,...p.map(({label:g,address:b})=>["--label",`${b}:${g}`]).flat(),`${e.tx}`]);console.log(f),process.exit(0)}},vt=Xs;import{anvil as ei,getScriptDirectory as oi,getSrcDirectory as ti}from"@latticexyz/common/foundry";import j from"chalk";import ri from"chokidar";import{loadConfig as ni,resolveConfigPath as ai}from"@latticexyz/config/node";import si from"path";import{homedir as ii}from"os";import{rmSync as ci}from"fs";import{BehaviorSubject as di,debounceTime as li,exhaustMap as mi,filter as pi}from"rxjs";import{isDefined as fi}from"@latticexyz/common/utils";var ui={rpc:R.rpc,configPath:R.configPath,alwaysRunPostDeploy:R.alwaysRunPostDeploy,forgeScriptOptions:R.forgeScriptOptions,worldAddress:R.worldAddress},yi={command:"dev-contracts",describe:"Start a development server for MUD contracts",builder(e){return e.options(ui)},async handler(e){let o=e.rpc,t=e.configPath??await ai(e.configPath),r=await ti(),n=await oi(),a=await ni(t);if(!e.rpc){console.log(j.gray("Cleaning devnode cache"));let c=ii();ci(si.join(c,".foundry","anvil","tmp"),{recursive:!0,force:!0}),ei(["--block-time","1","--block-base-fee-per-gas","0"]),o="http://127.0.0.1:8545"}let s=new di(Date.now());ri.watch([t,r,n],{ignoreInitial:!0}).on("all",async(c,p)=>{p.includes(t)&&(console.log(j.blue("Config changed, queuing deploy\u2026")),s.next(Date.now())),(p.includes(r)||p.includes(n))&&(p.includes(a.codegen.outputDirectory)||(console.log(j.blue("Contracts changed, queuing deploy\u2026")),s.next(Date.now())))});let i=e.worldAddress;s.pipe(li(200),mi(async c=>{i&&console.log(j.blue("Rebuilding and upgrading world\u2026"));try{let p=await G({...e,configPath:t,rpc:o,rpcBatch:!1,skipBuild:!1,printConfig:!1,profile:void 0,saveDeployment:!0,deployerAddress:void 0,worldAddress:i,salt:"0x",kms:void 0});return i=p.address,c<s.value?s.next(s.value):console.log(j.gray(`
37
+ `),console.log(`Updating ${e}`),bt(s,n.dependencies),bt(i,n.devDependencies),n;function d(c,p){return t&&(r=Is(e,t,c)),r||n[p][c]}}function Rs(e){try{let o=ks(e,"utf8");return JSON.parse(o)}catch{throw new Y("Could not read JSON at "+e)}}function bt(e,o){for(let t in e)e[t]!==o[t]&&console.log(`${t}: ${re.red(e[t])} -> ${re.green(o[t])}`)}function Is(e,o,t){let r=Ue.relative(Ue.dirname(e),process.cwd());return"link:"+Ue.join(r,o,_e[t].localPath)}var ht=Ms;import{anvil as Hs,forge as Ws,getRpcUrl as js}from"@latticexyz/common/foundry";import $s from"chalk";var Ls={...R,port:{type:"number",description:"Port to run internal node for fork testing on",default:4242},worldAddress:{type:"string",description:"Address of an existing world contract. If provided, deployment is skipped and the RPC provided in the foundry.toml is used for fork testing."},forgeOptions:{type:"string",description:"Options to pass to forge test"}},Es={command:"test",describe:"Run tests in MUD contracts",builder(e){return e.options(Ls)},async handler(e){if(!e.worldAddress){let n=["--block-base-fee-per-gas","0","--port",String(e.port)];Hs(n)}let o=e.worldAddress?await js(e.profile):`http://127.0.0.1:${e.port}`,t=e.worldAddress??(await G({...e,saveDeployment:!1,rpc:o})).address;console.log($s.blue("World address",t));let r=e.forgeOptions?.replaceAll("\\","").split(" ")??[];try{await Ws(["test","--fork-url",o,...r],{profile:e.profile,env:{WORLD_ADDRESS:t}}),process.exit(0)}catch(n){console.error(n),process.exit(1)}}},wt=Es;import Fs from"node:path";import xt from"node:fs";import{loadConfig as zs,resolveConfigPath as Ns}from"@latticexyz/config/node";import{MUDError as Ct}from"@latticexyz/common/errors";import{cast as _s,getRpcUrl as Us}from"@latticexyz/common/foundry";import Vs from"@latticexyz/world/mud.config";import{createClient as Ks,http as Js}from"viem";import{getChainId as qs,readContract as Gs}from"viem/actions";import{resolveSystems as Ys}from"@latticexyz/world/node";import{getAction as At}from"viem/utils";var Qs=Vs.namespaces.world.tables.Systems.tableId;function Zs(e,o){if(!xt.existsSync(e))throw new Ct(`Missing expected worlds.json file at "${e}"`);let t=JSON.parse(xt.readFileSync(e,"utf-8"));if(!t[o])throw new Ct(`Missing chain ID ${o} in "${e}"`);return t[o].address}var Xs={command:"trace",describe:"Display the trace of a transaction",builder(e){return e.options({tx:{type:"string",required:!0,description:"Transaction hash to replay"},worldAddress:{type:"string",description:"World contract address. Defaults to the value from worlds.json, based on rpc's chainId"},configPath:{type:"string",description:"Path to the MUD config file"},profile:{type:"string",description:"The foundry profile to use"},rpc:{type:"string",description:"json rpc endpoint. Defaults to foundry's configured eth_rpc_url"}})},async handler(e){let o=await Ns(e.configPath),t=Fs.dirname(o),r=e.profile??process.env.FOUNDRY_PROFILE,n=e.rpc??await Us(r),a=await zs(o),s=Ks({transport:Js(n)}),i=await At(s,qs,"getChainId")({}),d=e.worldAddress??Zs(a.deploy.worldsFile,i),c=await Ys({rootDir:t,config:a}),p=await Promise.all(c.map(async g=>({label:g.label,address:await At(s,Gs,"readContract")({abi:k,address:d,functionName:"getField",args:[Qs,[g.systemId],0]})}))),f=await _s(["run","--label",`${d}:World`,...p.map(({label:g,address:b})=>["--label",`${b}:${g}`]).flat(),`${e.tx}`]);console.log(f),process.exit(0)}},vt=Xs;import{anvil as ei,getScriptDirectory as oi,getSrcDirectory as ti}from"@latticexyz/common/foundry";import j from"chalk";import ri from"chokidar";import{loadConfig as ni,resolveConfigPath as ai}from"@latticexyz/config/node";import si from"path";import{homedir as ii}from"os";import{rmSync as ci}from"fs";import{BehaviorSubject as di,debounceTime as li,exhaustMap as mi,filter as pi}from"rxjs";import{isDefined as fi}from"@latticexyz/common/utils";var ui={rpc:R.rpc,configPath:R.configPath,alwaysRunPostDeploy:R.alwaysRunPostDeploy,forgeScriptOptions:R.forgeScriptOptions,worldAddress:R.worldAddress,smartAccount:R.smartAccount},yi={command:"dev-contracts",describe:"Start a development server for MUD contracts",builder(e){return e.options(ui)},async handler(e){let o=e.rpc,t=e.configPath??await ai(e.configPath),r=await ti(),n=await oi(),a=await ni(t);if(!e.rpc){console.log(j.gray("Cleaning devnode cache"));let c=ii();ci(si.join(c,".foundry","anvil","tmp"),{recursive:!0,force:!0}),ei(["--block-time","1","--block-base-fee-per-gas","0"]),o="http://127.0.0.1:8545"}let s=new di(Date.now());ri.watch([t,r,n],{ignoreInitial:!0}).on("all",async(c,p)=>{p.includes(t)&&(console.log(j.blue("Config changed, queuing deploy\u2026")),s.next(Date.now())),(p.includes(r)||p.includes(n))&&(p.includes(a.codegen.outputDirectory)||(console.log(j.blue("Contracts changed, queuing deploy\u2026")),s.next(Date.now())))});let i=e.worldAddress;s.pipe(li(200),mi(async c=>{i&&console.log(j.blue("Rebuilding and upgrading world\u2026"));try{let p=await G({...e,configPath:t,rpc:o,rpcBatch:!1,skipBuild:!1,printConfig:!1,profile:void 0,saveDeployment:!0,deployerAddress:void 0,worldAddress:i,salt:"0x",kms:void 0});return i=p.address,c<s.value?s.next(s.value):console.log(j.gray(`
38
38
  Waiting for file changes\u2026
39
39
  `)),p}catch(p){console.error(j.bgRed(j.whiteBright(`
40
40
  Error while attempting deploy
@@ -51,4 +51,4 @@ Waiting for file changes\u2026
51
51
  `),{overwrite:n});let x=E.join(y.sourceDirectory,"remote");n&&await Te.rm(x,{recursive:!0,force:!0});for(let h of g.filter(C=>C.abi.length)){let C=`I${h.label}`,l=E.join(x,"namespaces",h.namespaceLabel,`${C}.sol`);H("writing system interface",C,"to",l);let u=Bt({name:C,systemId:h.systemId,abi:h.abi});await Ge(E.join(e,l),await Ot(u),{overwrite:n})}let A=g.flatMap(h=>h.worldAbi);if(A.length){let h="IWorldSystems",C=E.join(x,`${h}.sol`);H("writing world systems interface to",C);let l=Bt({name:h,abi:A});await Ge(E.join(e,C),await Ot(l),{overwrite:n})}return{config:y}}async function Yi(e){return Te.access(e).then(()=>!0,()=>!1)}async function Ge(e,o,t={}){if(!t.overwrite&&await Yi(e))throw new ne(e);await Te.mkdir(E.dirname(e),{recursive:!0}),await Te.writeFile(e,o)}import ec from"node:path";var oc={worldAddress:{type:"string",required:!0,desc:"Remote world address"},profile:{type:"string",desc:"The foundry profile to use"},rpc:{type:"string",desc:"The RPC URL to use. Defaults to the RPC url from the local foundry.toml"},rpcBatch:{type:"boolean",desc:"Enable batch processing of RPC requests in viem client (defaults to batch size of 100 and wait of 1s)"},replace:{type:"boolean",desc:"Replace existing files and directories with data from remote world."}},tc={command:"pull",describe:"Pull mud.config.ts and interfaces from an existing world.",builder(e){return e.options(oc)},async handler(e){let o=e.profile??process.env.FOUNDRY_PROFILE,t=e.rpc??await Qi(o),r=Zi({transport:Xi(t,{batch:e.rpcBatch?{batchSize:100,wait:1e3}:void 0})});console.log(ke.bgBlue(ke.whiteBright(`
52
52
  Pulling MUD config from world at ${e.worldAddress}
53
53
  `)));let n=process.cwd();try{let{config:a}=await Ht({rootDir:n,client:r,worldAddress:e.worldAddress,replace:e.replace});await F({rootDir:n,config:a,foundryProfile:o})}catch(a){if(a instanceof ne){console.log(),console.log(ke.bgRed(ke.whiteBright(" Error "))),console.log(` Attempted to write file at "${ec.relative(n,a.filename)}", but it already exists.`),console.log(),console.log(" To overwrite files, use `--replace` when running this command."),console.log();return}throw a}}},Wt=tc;var ph=[Ye,ft,Qe,rc,Ze,Xe,ut,ht,wt,vt,St,nc,Pt,Wt];export{ph as commands};
54
- //# sourceMappingURL=commands-A4PSM3JH.js.map
54
+ //# sourceMappingURL=commands-NPM3ZTRX.js.map