@@ -7,6 +7,8 @@ import { groupBy } from "@latticexyz/common/utils";
7
7
import { findLibraries } from "./findLibraries" ;
8
8
import { createPrepareDeploy } from "./createPrepareDeploy" ;
9
9
import { World } from "@latticexyz/world" ;
10
+ import { findUp } from "find-up" ;
11
+ import { createRequire } from "node:module" ;
10
12
11
13
// TODO: replace this with a manifest/combined config output
12
14
@@ -22,18 +24,34 @@ export async function resolveConfig({
22
24
readonly systems : readonly System [ ] ;
23
25
readonly libraries : readonly Library [ ] ;
24
26
} > {
25
- const libraries = findLibraries ( forgeOutDir ) . map ( ( library ) : Library => {
26
- // foundry/solc flattens artifacts, so we just use the path basename
27
- const contractData = getContractData ( path . basename ( library . path ) , library . name , forgeOutDir ) ;
28
- return {
29
- path : library . path ,
30
- name : library . name ,
31
- abi : contractData . abi ,
32
- prepareDeploy : createPrepareDeploy ( contractData . bytecode , contractData . placeholders ) ,
33
- deployedBytecodeSize : contractData . deployedBytecodeSize ,
34
- } ;
27
+ const requirePath = await findUp ( "package.json" ) ;
28
+ if ( ! requirePath ) throw new Error ( "Could not find package.json to import relative to." ) ;
29
+ const require = createRequire ( requirePath ) ;
30
+
31
+ const moduleOutDirs = config . modules . flatMap ( ( mod ) => {
32
+ if ( mod . artifactPath == undefined ) {
33
+ return [ ] ;
34
+ }
35
+
36
+ // Navigate up two dirs to get the contract output directory
37
+ const moduleOutDir = path . join ( require . resolve ( mod . artifactPath ) , "../../" ) ;
38
+ return [ moduleOutDir ] ;
35
39
} ) ;
36
40
41
+ const libraries = [ forgeOutDir , ...moduleOutDirs ] . flatMap ( ( outDir ) =>
42
+ findLibraries ( outDir ) . map ( ( library ) : Library => {
43
+ // foundry/solc flattens artifacts, so we just use the path basename
44
+ const contractData = getContractData ( path . basename ( library . path ) , library . name , outDir ) ;
45
+ return {
46
+ path : library . path ,
47
+ name : library . name ,
48
+ abi : contractData . abi ,
49
+ prepareDeploy : createPrepareDeploy ( contractData . bytecode , contractData . placeholders ) ,
50
+ deployedBytecodeSize : contractData . deployedBytecodeSize ,
51
+ } ;
52
+ } ) ,
53
+ ) ;
54
+
37
55
const baseSystemContractData = getContractData ( "System.sol" , "System" , forgeOutDir ) ;
38
56
const baseSystemFunctions = baseSystemContractData . abi
39
57
. filter ( ( item ) : item is typeof item & { type : "function" } => item . type === "function" )
0 commit comments