Skip to content

Commit

Permalink
refactor: enhance artifact processing by adding file existence check
Browse files Browse the repository at this point in the history
  • Loading branch information
ljankovic-txfusion committed Jan 22, 2025
1 parent 16a6671 commit 783f779
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions solidity/generate-artifact-exports.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,38 @@ const srcOutputDir = join(__dirname, 'core-utils/zksync/artifacts');
// Ensure output directory exists
await fsPromises.mkdir(srcOutputDir, { recursive: true });

/**
* @dev Processes a single artifact file
*/
async function processArtifactFile(file) {
const fileName = `${basename(file, '.json')}`;
const outputFile = join(srcOutputDir, `${fileName}.json`);

// Check if file already exists
const fileExists = await fsPromises
.access(outputFile)
.then(() => true)
.catch(() => false);

if (fileExists) {
// File already exists, skipping...
// NOTE: Hardhat compiler produces duplicate artifacts when
// shared interfaces/libraries are used across different contracts
// This is expected behavior and we only need one copy of each artifact
return;
}

const fileContent = await fsPromises.readFile(file, { encoding: 'utf-8' });
await fsPromises.writeFile(outputFile, fileContent);
}

/**
* @dev Reads each artifact file and writes it to srcOutputDir concurrently
*/
await Promise.all(
zksyncArtifacts.map(async (file) => {
try {
const fileContent = await fsPromises.readFile(file, {
encoding: 'utf-8',
});
const fileName = `${basename(file, '.json')}`;
const outputFile = join(srcOutputDir, `${fileName}.json`);

await fsPromises.writeFile(outputFile, fileContent);
await processArtifactFile(file);
} catch (error) {
console.error(`Error processing file ${file}:`, error);
}
Expand Down

0 comments on commit 783f779

Please sign in to comment.