Skip to content

Commit

Permalink
fix: merge package.json files
Browse files Browse the repository at this point in the history
  • Loading branch information
rin-st committed Dec 24, 2024
1 parent 7e32370 commit 5e42ce9
Showing 1 changed file with 23 additions and 5 deletions.
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 5e42ce9

Please sign in to comment.