Skip to content

Commit

Permalink
Fix merge package.json files (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
rin-st authored Dec 25, 2024
1 parent 8c4e925 commit aed3345
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/tame-donuts-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-eth": patch
---

cli: fix merge package.json files for extensions with both solidity-frameworks
28 changes: 23 additions & 5 deletions src/tasks/copy-template-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ const copyBaseFiles = async (basePath: string, targetDir: string, { dev: isDev }
}
};

const isUnselectedSolidityFrameworkFile = ({
path,
solidityFramework,
}: {
path: string;
solidityFramework: SolidityFramework | null;
}) => {
const unselectedSolidityFrameworks = [SOLIDITY_FRAMEWORKS.FOUNDRY, SOLIDITY_FRAMEWORKS.HARDHAT].filter(
sf => sf !== solidityFramework,
);
return unselectedSolidityFrameworks.map(sf => new RegExp(`${sf}`)).some(sfregex => sfregex.test(path));
};

const copyExtensionFiles = async (
{ dev: isDev, solidityFramework }: Options,
extensionPath: string,
Expand Down Expand Up @@ -101,11 +114,7 @@ const copyExtensionFiles = async (
const isTemplate = isTemplateRegex.test(path);
const isPackageJson = isPackageJsonRegex.test(path);

const unselectedSolidityFrameworks = [SOLIDITY_FRAMEWORKS.FOUNDRY, SOLIDITY_FRAMEWORKS.HARDHAT].filter(
sf => sf !== solidityFramework,
);
const isUnselectedSolidityFrameworksRegexes = unselectedSolidityFrameworks.map(sf => new RegExp(`${sf}$`));
const isUnselectedSolidityFramework = isUnselectedSolidityFrameworksRegexes.some(sfregex => sfregex.test(path));
const isUnselectedSolidityFramework = isUnselectedSolidityFrameworkFile({ path, solidityFramework });

const shouldSkip = isArgs || isTemplate || isPackageJson || isUnselectedSolidityFramework;

Expand All @@ -116,6 +125,15 @@ const copyExtensionFiles = async (
// copy each package's package.json
const extensionPackages = fs.readdirSync(extensionPackagesPath);
extensionPackages.forEach(packageName => {
const isUnselectedSolidityFramework = isUnselectedSolidityFrameworkFile({
path: path.join(targetDir, "packages", packageName, "package.json"),
solidityFramework,
});

if (isUnselectedSolidityFramework) {
return;
}

mergePackageJson(
path.join(targetDir, "packages", packageName, "package.json"),
path.join(extensionPath, "packages", packageName, "package.json"),
Expand Down

0 comments on commit aed3345

Please sign in to comment.