Skip to content

Commit

Permalink
fix: cli foundry/hardhat excludes (#4120)
Browse files Browse the repository at this point in the history
* chore: update viem

* fix: fix issue where the Foundry & Hardhat exclude patterns were ignored

* chore: add changeset

* test(cli): exclude

---------

Co-authored-by: jxom <jakemoxey@gmail.com>
Co-authored-by: Alexandre <5808474+allezxandre@users.noreply.github.com>
Co-authored-by: Alexandre Jouandin <alexandre@jouand.in>
  • Loading branch information
4 people authored Jul 8, 2024
1 parent b4033a0 commit 59407bf
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .changeset/five-mice-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wagmi/cli": patch
---

Fixed an issue where the Foundry and Hardhat plugins' `exclude` option was ignored.
11 changes: 11 additions & 0 deletions packages/cli/src/plugins/__fixtures__/foundry/src/Foo.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

contract Foo {
string public bar;

function setFoo(string memory baz) public {
bar = baz;
}
}

10 changes: 10 additions & 0 deletions packages/cli/src/plugins/__fixtures__/hardhat/contracts/Foo.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

contract Foo {
string public bar;

function setFoo(string memory baz) public {
bar = baz;
}
}
15 changes: 10 additions & 5 deletions packages/cli/src/plugins/foundry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ afterEach(() => {

test('forge not installed', async () => {
const dir = f.temp()
await expect(
expect(
foundry({
project: dir,
forge: {
Expand Down Expand Up @@ -44,13 +44,14 @@ test('validates without project', async () => {
const spy = vi.spyOn(process, 'cwd')
spy.mockImplementation(() => dir)

await expect(foundry().validate()).resolves.toBeUndefined()
expect(foundry().validate()).resolves.toBeUndefined()
})

test('contracts', async () => {
await expect(
test('contracts', () => {
expect(
foundry({
project: resolve(__dirname, '__fixtures__/foundry/'),
exclude: ['Foo.sol/**'],
}).contracts(),
).resolves.toMatchInlineSnapshot(`
[
Expand Down Expand Up @@ -102,7 +103,11 @@ test('contracts without project', async () => {
const spy = vi.spyOn(process, 'cwd')
spy.mockImplementation(() => dir)

await expect(foundry().contracts()).resolves.toMatchInlineSnapshot(`
expect(
foundry({
exclude: ['Foo.sol/**'],
}).contracts(),
).resolves.toMatchInlineSnapshot(`
[
{
"abi": [
Expand Down
15 changes: 8 additions & 7 deletions packages/cli/src/plugins/foundry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,14 @@ export function foundry(config: FoundryConfig = {}): FoundryResult {
}
}

async function getArtifactPaths(artifactsDirectory: string) {
const crawler = new fdir()
.withBasePath()
.glob(
...include.map((x) => `${artifactsDirectory}/**/${x}`),
...exclude.map((x) => `!${artifactsDirectory}/**/${x}`),
)
function getArtifactPaths(artifactsDirectory: string) {
const crawler = new fdir().withBasePath().globWithOptions(
include.map((x) => `${artifactsDirectory}/**/${x}`),
{
dot: true,
ignore: exclude.map((x) => `${artifactsDirectory}/**/${x}`),
},
)
return crawler.crawl(artifactsDirectory).withPromise()
}

Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/plugins/hardhat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ afterEach(() => {

test('validate', async () => {
const temp = f.temp()
await expect(
expect(
hardhat({ project: temp }).validate(),
).rejects.toThrowErrorMatchingInlineSnapshot(
'[Error: hardhat must be installed to use Hardhat plugin.]',
Expand All @@ -34,9 +34,10 @@ test('project does not exist', async () => {
})

test('contracts', async () => {
await expect(
expect(
hardhat({
project: resolve(__dirname, '__fixtures__/hardhat/'),
exclude: ['Foo.sol/**'],
}).contracts(),
).resolves.toMatchInlineSnapshot(`
[
Expand Down
15 changes: 8 additions & 7 deletions packages/cli/src/plugins/hardhat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,14 @@ export function hardhat(config: HardhatConfig): HardhatResult {
}
}

async function getArtifactPaths(artifactsDirectory: string) {
const crawler = new fdir()
.withBasePath()
.glob(
...include.map((x) => `${artifactsDirectory}/**/${x}`),
...exclude.map((x) => `!${artifactsDirectory}/**/${x}`),
)
function getArtifactPaths(artifactsDirectory: string) {
const crawler = new fdir().withBasePath().globWithOptions(
include.map((x) => `${artifactsDirectory}/**/${x}`),
{
dot: true,
ignore: exclude.map((x) => `${artifactsDirectory}/**/${x}`),
},
)
return crawler.crawl(artifactsDirectory).withPromise()
}

Expand Down

0 comments on commit 59407bf

Please sign in to comment.