Skip to content

Commit 93061e3

Browse files
committed
Throw if trying to resolve an npm root with incorrect casing
1 parent 9355597 commit 93061e3

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

v-next/hardhat-errors/src/descriptors.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,12 @@ Please try renaming the directory.`,
11221122
websiteTitle: "Resolution of non-existent npm file",
11231123
websiteDescription: `You are tying to resolve an npm file that doesn't exist within its package.`,
11241124
},
1125+
RESOLVE_WRONG_CASING_NPM_FILE: {
1126+
number: 1224,
1127+
messageTemplate: `You are tying to resolve the npm file "{module}", its casing is incorrect.`,
1128+
websiteTitle: "Resolution of npm file with incorrect casing",
1129+
websiteDescription: `You are tying to resolve an npm file whose casing is incorrect.`,
1130+
},
11251131
DOWNLOAD_FAILED: {
11261132
number: 1225,
11271133
messageTemplate:

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

+10-6
Original file line numberDiff line numberDiff line change
@@ -306,21 +306,25 @@ export class ResolverImplementation implements Resolver {
306306
);
307307
}
308308

309-
// Just like with the project files, we are more forgiving with the casing
310-
// here, as this is not used for imports.
309+
if (resolvedSubpath !== trueCaseFsPath) {
310+
throw new HardhatError(
311+
HardhatError.ERRORS.SOLIDITY.RESOLVE_WRONG_CASING_NPM_FILE,
312+
{ module: npmModule },
313+
);
314+
}
311315

312316
const sourceName = sourceNamePathJoin(
313317
npmPackageToRootSourceName(npmPackage.name, npmPackage.version),
318+
// We use the subpath (pre-resolution) to create source names
314319
fsPathToSourceNamePath(subpath),
315320
);
316321

317-
const resolvedWithTheRightCasing =
318-
this.#resolvedFileBySourceName.get(sourceName);
322+
const resolved = this.#resolvedFileBySourceName.get(sourceName);
319323

320-
if (resolvedWithTheRightCasing !== undefined) {
324+
if (resolved !== undefined) {
321325
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions
322326
-- If it was, it's a ProjectResolvedFile */
323-
return resolvedWithTheRightCasing as NpmPackageResolvedFile;
327+
return resolved as NpmPackageResolvedFile;
324328
}
325329

326330
const fsPath = path.join(npmPackage.rootFsPath, trueCaseFsPath);

0 commit comments

Comments
 (0)