Skip to content

Commit d821a0a

Browse files
committed
Fix userSourceName generation from relative paths on artifact cleanup
1 parent d22f9dd commit d821a0a

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

.changeset/fast-turkeys-applaud.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@nomicfoundation/hardhat-utils": patch
3+
"hardhat": patch
4+
---
5+
6+
Fix npm artifact cleanup on windows ([#7459](https://github.com/NomicFoundation/hardhat/issues/7459))

v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/build-system.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,9 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
827827
const parsed = parseRootPath(rootFilePath);
828828
return isNpmParsedRootPath(parsed)
829829
? parsed.npmPath
830-
: path.relative(this.#options.projectRoot, parsed.fsPath);
830+
: toForwardSlash(
831+
path.relative(this.#options.projectRoot, parsed.fsPath),
832+
);
831833
});
832834

833835
const userSourceNamesSet = new Set(userSourceNames);
@@ -836,7 +838,9 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
836838
artifactsDirectory,
837839
(d) => d.endsWith(".sol"),
838840
)) {
839-
const relativePath = path.relative(artifactsDirectory, file);
841+
const relativePath = toForwardSlash(
842+
path.relative(artifactsDirectory, file),
843+
);
840844

841845
if (!userSourceNamesSet.has(relativePath)) {
842846
await remove(file);
@@ -1126,3 +1130,7 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
11261130
}
11271131
}
11281132
}
1133+
1134+
function toForwardSlash(str: string): string {
1135+
return str.split(/[\\\/]/).join(path.posix.sep);
1136+
}

0 commit comments

Comments
 (0)