From aed334510cb7d384ef60d0cc0debcb1d64ab4c4f Mon Sep 17 00:00:00 2001 From: Rinat Date: Wed, 25 Dec 2024 13:26:21 +0100 Subject: [PATCH] Fix merge package.json files (#181) --- .changeset/tame-donuts-thank.md | 5 +++++ src/tasks/copy-template-files.ts | 28 +++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 .changeset/tame-donuts-thank.md diff --git a/.changeset/tame-donuts-thank.md b/.changeset/tame-donuts-thank.md new file mode 100644 index 000000000..460671a13 --- /dev/null +++ b/.changeset/tame-donuts-thank.md @@ -0,0 +1,5 @@ +--- +"create-eth": patch +--- + +cli: fix merge package.json files for extensions with both solidity-frameworks diff --git a/src/tasks/copy-template-files.ts b/src/tasks/copy-template-files.ts index a6a868b7e..d6036d38f 100644 --- a/src/tasks/copy-template-files.ts +++ b/src/tasks/copy-template-files.ts @@ -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, @@ -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; @@ -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"),