Skip to content

Commit 309dc21

Browse files
authored
Merge pull request #4647 from NomicFoundation/esm-support-hardhat-viem
Exclude artifacts/package.json from artifacts in getArtifactPaths
2 parents efbcce6 + b475fc4 commit 309dc21

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

.changeset/dry-moose-draw.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"hardhat": patch
3+
---
4+
5+
Modified the artifacts cleanup logic to avoid removing a `package.json` file under the artifacts directory

packages/hardhat-core/src/internal/artifacts.ts

+13-16
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,8 @@ export class Artifacts implements IArtifacts {
154154
return cached;
155155
}
156156

157-
const buildInfosDir = path.join(this._artifactsPath, BUILD_INFO_DIR_NAME);
158-
159-
const paths = await getAllFilesMatching(
160-
this._artifactsPath,
161-
(f) =>
162-
f.endsWith(".json") &&
163-
!f.startsWith(buildInfosDir) &&
164-
!f.endsWith(".dbg.json")
157+
const paths = await getAllFilesMatching(this._artifactsPath, (f) =>
158+
this._isArtifactPath(f)
165159
);
166160

167161
const result = paths.sort();
@@ -563,14 +557,8 @@ export class Artifacts implements IArtifacts {
563557
return cached;
564558
}
565559

566-
const buildInfosDir = path.join(this._artifactsPath, BUILD_INFO_DIR_NAME);
567-
568-
const paths = getAllFilesMatchingSync(
569-
this._artifactsPath,
570-
(f) =>
571-
f.endsWith(".json") &&
572-
!f.startsWith(buildInfosDir) &&
573-
!f.endsWith(".dbg.json")
560+
const paths = getAllFilesMatchingSync(this._artifactsPath, (f) =>
561+
this._isArtifactPath(f)
574562
);
575563

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

935923
return undefined;
936924
}
925+
926+
private _isArtifactPath(file: string) {
927+
return (
928+
file.endsWith(".json") &&
929+
file !== path.join(this._artifactsPath, "package.json") &&
930+
!file.startsWith(path.join(this._artifactsPath, BUILD_INFO_DIR_NAME)) &&
931+
!file.endsWith(".dbg.json")
932+
);
933+
}
937934
}
938935

939936
/**

0 commit comments

Comments
 (0)