@bgd-labs/toolbox 0.0.24 → 0.0.25

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.
package/dist/node.mjs CHANGED
@@ -28465,7 +28465,7 @@ var hyperRPCSupportedNetworks = [
28465
28465
  ];
28466
28466
 
28467
28467
  // src/operations/diffCode.ts
28468
- import { createPatch, createTwoFilesPatch } from "diff";
28468
+ import { createPatch, createTwoFilesPatch, diffChars } from "diff";
28469
28469
  import { format } from "prettier/standalone";
28470
28470
  import solidityPlugin from "prettier-plugin-solidity/standalone";
28471
28471
  var prettierOptions = { parser: "solidity-parse", plugins: [solidityPlugin] };
@@ -28490,7 +28490,25 @@ async function diffCode(before, after) {
28490
28490
  ])
28491
28491
  );
28492
28492
  for (const [name, path, source] of contractsBefore) {
28493
- const indexAfter = contractsAfter.findIndex(([_name]) => _name === name);
28493
+ const matchingIndexes = contractsAfter.reduce((acc, val, i) => {
28494
+ if (val[0] === name) acc.push(i);
28495
+ return acc;
28496
+ }, []);
28497
+ let indexAfter = -1;
28498
+ if (matchingIndexes.length === 1) {
28499
+ indexAfter = matchingIndexes[0];
28500
+ } else if (matchingIndexes.length > 1) {
28501
+ let maxSimilarity = -1;
28502
+ for (const idx of matchingIndexes) {
28503
+ const afterSource = contractsAfter[idx][2];
28504
+ const diff = diffChars(source, afterSource);
28505
+ const similarity = diff.reduce((acc, part) => acc + (part.added || part.removed ? 0 : part.count || part.value.length), 0);
28506
+ if (similarity > maxSimilarity) {
28507
+ maxSimilarity = similarity;
28508
+ indexAfter = idx;
28509
+ }
28510
+ }
28511
+ }
28494
28512
  if (indexAfter === -1) {
28495
28513
  changes[name] = createPatch(path, source, "");
28496
28514
  } else {