Skip to content

Commit

Permalink
Merge pull request #4647 from NomicFoundation/esm-support-hardhat-viem
Browse files Browse the repository at this point in the history
Exclude artifacts/package.json from artifacts in getArtifactPaths
  • Loading branch information
schaable authored Dec 5, 2023
2 parents efbcce6 + b475fc4 commit 309dc21
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-moose-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"hardhat": patch
---

Modified the artifacts cleanup logic to avoid removing a `package.json` file under the artifacts directory
29 changes: 13 additions & 16 deletions packages/hardhat-core/src/internal/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,8 @@ export class Artifacts implements IArtifacts {
return cached;
}

const buildInfosDir = path.join(this._artifactsPath, BUILD_INFO_DIR_NAME);

const paths = await getAllFilesMatching(
this._artifactsPath,
(f) =>
f.endsWith(".json") &&
!f.startsWith(buildInfosDir) &&
!f.endsWith(".dbg.json")
const paths = await getAllFilesMatching(this._artifactsPath, (f) =>
this._isArtifactPath(f)
);

const result = paths.sort();
Expand Down Expand Up @@ -563,14 +557,8 @@ export class Artifacts implements IArtifacts {
return cached;
}

const buildInfosDir = path.join(this._artifactsPath, BUILD_INFO_DIR_NAME);

const paths = getAllFilesMatchingSync(
this._artifactsPath,
(f) =>
f.endsWith(".json") &&
!f.startsWith(buildInfosDir) &&
!f.endsWith(".dbg.json")
const paths = getAllFilesMatchingSync(this._artifactsPath, (f) =>
this._isArtifactPath(f)
);

const result = paths.sort();
Expand Down Expand Up @@ -934,6 +922,15 @@ Please replace "${contractName}" for the correct contract name wherever you are

return undefined;
}

private _isArtifactPath(file: string) {
return (
file.endsWith(".json") &&
file !== path.join(this._artifactsPath, "package.json") &&
!file.startsWith(path.join(this._artifactsPath, BUILD_INFO_DIR_NAME)) &&
!file.endsWith(".dbg.json")
);
}
}

/**
Expand Down

0 comments on commit 309dc21

Please sign in to comment.