Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cli): refactor findLibraries to accept an array of paths #3321

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5acb239
Initial attempt to support deploying libraries needed for modules
vdrg Oct 18, 2024
06262d0
Remove console.log
vdrg Oct 18, 2024
19d2bbb
minor changes
vdrg Oct 18, 2024
4569426
Refactor to do the module library search inside resolveConfig
vdrg Oct 21, 2024
680b333
PR feedback
vdrg Oct 21, 2024
e8659c2
Add pupet modules to e2e mud config
vdrg Oct 21, 2024
ce3cea0
Update e2e worlds.json
vdrg Oct 21, 2024
08ff3f6
Add erc20 module to e2e tests, local e2e tests working
vdrg Oct 21, 2024
78b1c21
Update worlds.json
vdrg Oct 21, 2024
b00e6d3
Add erc20 module dev dependency to store-sync, as it needs to be reso…
vdrg Oct 21, 2024
a809793
Remove modules to better understand e2e failures
vdrg Oct 22, 2024
6e2369d
Add e2e module test package
vdrg Oct 22, 2024
c912cef
Remove erc20 module from store-sync deps
vdrg Oct 22, 2024
1545b94
Add missing dep to module-test
vdrg Oct 22, 2024
348287a
Change anvil port so it doesn't conflict with contracts package tests
vdrg Oct 22, 2024
19011d7
Add back missing dep to e2e contracts package
vdrg Oct 22, 2024
7c781b9
Move puppet modules test to main test directory, and turn it into a p…
vdrg Oct 22, 2024
a6dde7c
Revert change to worlds.json
vdrg Oct 22, 2024
f7f05c0
Remove puppet module test from changeset
vdrg Oct 22, 2024
d9ff221
Split changeset in two (one for cli and one for token modules)
vdrg Oct 22, 2024
9b7233d
Refactor findLibraries to accept an array of paths
vdrg Oct 22, 2024
e2bcd67
Return Library[] from findLibraries
vdrg Oct 22, 2024
ebe292a
Revert change in getContractData
vdrg Oct 22, 2024
5d4f83f
Only deduplicate output dirs if input is an array
vdrg Oct 22, 2024
48591d0
Create dull-spiders-hear.md
vdrg Oct 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dull-spiders-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/cli": patch
---

Refactored findLibraries to accept an array of paths.
38 changes: 29 additions & 9 deletions packages/cli/src/deploy/findLibraries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@ import { readFileSync } from "fs";
import { globSync } from "glob";
import { orderByDependencies } from "./orderByDependencies";
import { LinkReferences } from "../utils/findPlaceholders";
import { Library } from "./common";
import { getContractData } from "../utils/getContractData";
import { createPrepareDeploy } from "./createPrepareDeploy";
import path from "path";

export function findLibraries(forgeOutDir: string): readonly {
readonly path: string;
readonly name: string;
}[] {
const artifacts = globSync(`${forgeOutDir}/**/*.json`, { ignore: "**/*.abi.json" })
.sort()
.map((path) => JSON.parse(readFileSync(path, "utf8")));
export function findLibraries(forgeOutDirs: string | string[]): Library[] {
const dirs = Array.isArray(forgeOutDirs) ? [...new Set(forgeOutDirs)] : [forgeOutDirs];

const libraries = artifacts.flatMap((artifact) => {
// Deduplicate output directories and get all the artifacts
const artifactsWithDirs = dirs.flatMap((dir) => {
const files = globSync(`${dir}/**/*.json`, { ignore: "/**/*.abi.json" }).sort();
return files.map((filePath) => ({
forgeOutDir: dir,
artifact: JSON.parse(readFileSync(filePath, "utf8")),
}));
});

const libraries = artifactsWithDirs.flatMap(({ artifact, forgeOutDir }) => {
if (!artifact.metadata) return [];

const contractPath = Object.keys(artifact.metadata.settings.compilationTarget)[0];
Expand All @@ -24,13 +32,25 @@ export function findLibraries(forgeOutDir: string): readonly {
name: libraryName,
dependentPath: contractPath,
dependentName: contractName,
forgeOutDir,
})),
);
});

return orderByDependencies(
const orderedByDeps = orderByDependencies(
libraries,
(lib) => `${lib.path}:${lib.name}`,
(lib) => [`${lib.dependentPath}:${lib.dependentName}`],
);

return orderedByDeps.map((library) => {
const contractData = getContractData(path.basename(library.path), library.name, library.forgeOutDir);
return {
path: library.path,
name: library.name,
abi: contractData.abi,
prepareDeploy: createPrepareDeploy(contractData.bytecode, contractData.placeholders),
deployedBytecodeSize: contractData.deployedBytecodeSize,
};
});
}
14 changes: 1 addition & 13 deletions packages/cli/src/deploy/resolveConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,7 @@ export async function resolveConfig({
return [moduleOutDir];
});

const libraries = [forgeOutDir, ...moduleOutDirs].flatMap((outDir) =>
findLibraries(outDir).map((library): Library => {
// foundry/solc flattens artifacts, so we just use the path basename
const contractData = getContractData(path.basename(library.path), library.name, outDir);
return {
path: library.path,
name: library.name,
abi: contractData.abi,
prepareDeploy: createPrepareDeploy(contractData.bytecode, contractData.placeholders),
deployedBytecodeSize: contractData.deployedBytecodeSize,
};
}),
);
const libraries = findLibraries([forgeOutDir, ...moduleOutDirs]);

const baseSystemContractData = getContractData("System.sol", "System", forgeOutDir);
const baseSystemFunctions = baseSystemContractData.abi
Expand Down
Loading