Skip to content

Commit

Permalink
Remove forked files from solhint to prevent errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Connolly committed Dec 11, 2023
1 parent f306aa2 commit 800a2cc
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ cache
coverage
typechain
dist
forks
forks
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ artifacts
cache
coverage*
gasReporterOutput.json

3 changes: 3 additions & 0 deletions .solhintignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
node_modules
contracts/passport
contracts/seaport
forks
8 changes: 4 additions & 4 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const config: HardhatUserConfig = {
optimizer: {
enabled: true,
runs: 200,
}
},
},
},
{
Expand All @@ -41,10 +41,10 @@ const config: HardhatUserConfig = {
optimizer: {
enabled: true,
runs: 200,
}
},
},
}
]
},
],
},
paths: {
tests: "./test",
Expand Down
95 changes: 46 additions & 49 deletions scripts/build.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,50 @@

import fs from 'fs';
import replace from 'replace-in-file';
import forks from '../forks/forks.json';
import main from '../package.json';

forks.forEach(fork => {
const dest = `contracts/${fork.name}`;
fs.rmSync(dest, { recursive: true, force: true });
fs.cpSync(`forks/${fork.contracts}`, dest, {
recursive: true,
filter: (src: string, dest: string) => {
const matches = fork.ignore.filter(ig => src.includes(`forks/${fork.contracts}/${ig}`));
// only include if there are no matches
return matches.length == 0;
}
});

const rmTemplate = `DO NOT MODIFY THESE CONTRACTS DIRECTLY. This folder has been automatically extracted from ${fork.upstream} via a submodule in this repository's forks directory. See the upstream repository for full context.`

fs.writeFileSync(`${dest}/README.md`, rmTemplate);

if (fork.dependencies) {
const pkg = JSON.parse(fs.readFileSync(`forks/${fork.name}/package.json`));
fork.dependencies.forEach(dep => {
const depVersion = pkg.dependencies[dep] ? pkg.dependencies[dep] : pkg.devDependencies[dep];

const mainDepVersion = (main.dependencies as any)[dep];
// What happens if the version clashes!
if (mainDepVersion && depVersion != mainDepVersion) {
// Create a custom name e.g. @openzeppelin/contracts/seaport
const customDepName = `${dep}/${fork.name}`;
(main.dependencies as any)[customDepName] = `npm:${dep}@${depVersion}`;
// Now replace all of the references to the dependency
// inside the fork's copied contracts folder
// e.g. '@openzeppelin/contracts/x/y.sol --> @openzeppelin/contracts/seaport/x/y.sol
replace.sync({
from: dep,
to: customDepName,
files: [`${dest}/**/*.sol`]
});
} else {
// No clash in the dependencies, just add it
(main.dependencies as any)[dep] = depVersion;
}
import fs from "fs";
import replace from "replace-in-file";
import forks from "../forks/forks.json";
import main from "../package.json";

forks.forEach((fork) => {
const dest = `contracts/${fork.name}`;
fs.rmSync(dest, { recursive: true, force: true });
fs.cpSync(`forks/${fork.contracts}`, dest, {
recursive: true,
filter: (src: string, dest: string) => {
const matches = fork.ignore.filter((ig) => src.includes(`forks/${fork.contracts}/${ig}`));
// only include if there are no matches
return matches.length === 0;
},
});

const rmTemplate = `DO NOT MODIFY THESE CONTRACTS DIRECTLY. This folder has been automatically extracted from ${fork.upstream} via a submodule in this repository's forks directory. See the upstream repository for full context.`;

fs.writeFileSync(`${dest}/README.md`, rmTemplate);

if (fork.dependencies) {
const pkg = JSON.parse(fs.readFileSync(`forks/${fork.name}/package.json`));
fork.dependencies.forEach((dep) => {
const depVersion = pkg.dependencies[dep] ? pkg.dependencies[dep] : pkg.devDependencies[dep];

const mainDepVersion = (main.dependencies as any)[dep];
// What happens if the version clashes!
if (mainDepVersion && depVersion !== mainDepVersion) {
// Create a custom name e.g. @openzeppelin/contracts/seaport
const customDepName = `${dep}/${fork.name}`;
(main.dependencies as any)[customDepName] = `npm:${dep}@${depVersion}`;
// Now replace all of the references to the dependency
// inside the fork's copied contracts folder
// e.g. '@openzeppelin/contracts/x/y.sol --> @openzeppelin/contracts/seaport/x/y.sol
replace.sync({
from: dep,
to: customDepName,
files: [`${dest}/**/*.sol`],
});

}
} else {
// No clash in the dependencies, just add it
(main.dependencies as any)[dep] = depVersion;
}
});
}
});

// Update our main package.json
fs.writeFileSync('package.json', JSON.stringify(main, null, 2), 'utf8');

fs.writeFileSync("package.json", JSON.stringify(main, null, 2), "utf8");

0 comments on commit 800a2cc

Please sign in to comment.