Skip to content

Commit c648f76

Browse files
committed
Introduce prototype of a new Solidity resolver
1 parent 47eae51 commit c648f76

File tree

44 files changed

+2883
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2883
-0
lines changed

pnpm-lock.yaml

+73
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

+108
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export const ERROR_CATEGORIES: {
6666
},
6767
ARGUMENTS: { min: 500, max: 599, websiteTitle: "Arguments related errors" },
6868
BUILTIN_TASKS: { min: 600, max: 699, websiteTitle: "Built-in tasks errors" },
69+
SOLIDITY: { min: 700, max: 799, websiteTitle: "Solidity related errors" },
6970
};
7071

7172
export const ERRORS = {
@@ -473,4 +474,111 @@ Please double check your script's path.`,
473474
Please check Hardhat's output for more details.`,
474475
},
475476
},
477+
SOLIDITY: {
478+
RESOLVING_INCORRECT_FILE_AS_PROJECT_FILE: {
479+
number: 700,
480+
messageTemplate:
481+
"File {file} is being resolved as a project file, but it's not part of the project.",
482+
websiteTitle: "Solidity project file is outside the project",
483+
websiteDescription: `Tried to resolve a file as a project file, but it's not part of the project.`,
484+
},
485+
RESOLVING_NONEXISTENT_PROJECT_FILE: {
486+
number: 701,
487+
messageTemplate:
488+
"File {file} is being resolved as a project file, but it doesn't exist.",
489+
websiteTitle: "Solidity project file doesn't exist",
490+
websiteDescription: `Tried to resolve a file as a project file, but it doesn't exist.`,
491+
},
492+
IMPORTED_FILE_DOESNT_EXIST: {
493+
number: 702,
494+
messageTemplate: 'The import "{importPath} from "{from}" doesn\'t exist.',
495+
websiteTitle: "Imported file doesn't exist",
496+
websiteDescription: `An imported file doesn't exist.`,
497+
},
498+
IMPORTED_FILE_WITH_ICORRECT_CASING: {
499+
number: 703,
500+
messageTemplate:
501+
'The import "{importPath} from "{from}" exists, but its casing is incorrect. The correct casing is "{correctCasing}".',
502+
websiteTitle: "Imported file with incorrect casing",
503+
websiteDescription: `Hardhat enforces that you import your files with the correct casing (as stored in the filesystem).
504+
505+
This error is thrown when you import a file with the wrong casing under a case insensitve filesystem.`,
506+
},
507+
IMPORTED_NPM_DEPENDENCY_NOT_INSTALLED: {
508+
number: 704,
509+
messageTemplate:
510+
'The import "{importPath}" from "{from}" is trying to use an uinstalled npm dependency.',
511+
websiteTitle: "Uninstaleld npm solidity dependency",
512+
websiteDescription: `One of your files is traying to import a dependency using npm, but it hasn't been installed`,
513+
},
514+
IMPORTED_NPM_DEPENDENCY_THAT_USES_EXPORTS: {
515+
number: 705,
516+
messageTemplate:
517+
'The import "{importPath}" from "{from}" is trying to use an npm dependency that uses pacakge#exports, which is not supported by Hardhat.',
518+
websiteTitle:
519+
"Using a npm solidity dependency with pacakge.json#exports is not supported",
520+
websiteDescription: `One of your files is traying to import a dependency using npm, but it uses pacakge.json#exports, which Hardhat doesn't support`,
521+
},
522+
USER_REMAPPING_WITH_NPM_CONTEXT: {
523+
number: 706,
524+
messageTemplate:
525+
'The remapping "{remapping}" has a context starting with "npm/", which is forbidden. Hardhat doesn\'t allow changing the behaviour of npm package\'s imports.',
526+
websiteTitle: "Remapping imports in npm packages is not allowed",
527+
websiteDescription: `This error happened because you are trying to change how the imports within an npm package, which is not allowed.
528+
529+
While Hardhat supports user-defined remappings, it doesn't support remapping the behavior of npm packages to ensure that everything what's imported via npm uses the same npm resolution logic.`,
530+
},
531+
REMAPPING_WITH_INVALID_SYNTAX: {
532+
number: 707,
533+
messageTemplate: `The remapping "{remapping}" is invalid.`,
534+
websiteTitle: "Invalid remapping",
535+
websiteDescription: `You are trying to set a user remapping, but it's syntax is invalid.
536+
537+
Please double check your remmpaings' syntax.`,
538+
},
539+
REMAPPING_TO_UNINSTALLED_PACKAGE: {
540+
number: 708,
541+
messageTemplate: `The remapping "{remapping}" is trying to use the npm package "{package}", which is not installed`,
542+
websiteTitle: "Remapping into an uninstaleld npm package",
543+
websiteDescription: `You are trying to set a user remapping that uses an npm pacakge as target, but it's not installed.
544+
545+
Please make sure to install the package or fix the remapping.`,
546+
},
547+
REMAPPING_TO_PACKAGE_USING_EXPORTS: {
548+
number: 709,
549+
messageTemplate: `The remapping "{remapping}" is using the npm package "{package}", which uses pacakge.json#exports, which is not supported by Hardhat`,
550+
websiteTitle:
551+
"Remapping into an npm package that uses pacakge.json#exports",
552+
websiteDescription: `You are trying to set a user remapping that uses an npm pacakge as target, but it uses pacakge.json#exports, which Hardhat doesn't support.`,
553+
},
554+
REMAPPING_NPM_PACKAGE_AS_MONOREPO: {
555+
number: 710,
556+
messageTemplate: `The remapping "{remapping}" targets the npm pacakge "{pacakge}" as if it were part of this repository, but version "{version}" is installed instead`,
557+
websiteTitle:
558+
"Remapping into a monorepo package but found an npm package instead",
559+
websiteDescription: `You are trying to set a remapping setting a monorepo package as target, but Hardhat found the pacakge to be installed from the npm regristry instead.`,
560+
},
561+
REMAPPING_HARDHAT_PROJECT_AS_MONOREPO_PACKAGE: {
562+
number: 711,
563+
messageTemplate: `The remapping "{remapping}" is trying to set the npm package "{package}" as target, but that's the project is the Hardhat project, so it shouldn't be remapped through npm/, but as internal project remappings.`,
564+
websiteTitle: `Remapping into the project using npm`,
565+
websiteDescription: `You are trying to set a remapping whose target uses the npm/ syntax, but is within your Hardhat project.
566+
567+
Please don't use npm/... as target, but use normal internal project remapping istead.`,
568+
},
569+
REMAPPING_INCORRECT_VERSION: {
570+
number: 712,
571+
messageTemplate: `The remapping "{remapping}" is trying to set the npm package "{package}" version "{expectedVersion}" as target, but found version "{actualVersion}" instead.`,
572+
websiteTitle: `Remapping into incorrect npm package version`,
573+
websiteDescription: `You are trying to set a remapping into an npm package, but the version that you are using is not the currently installed one.
574+
575+
Please change your remapping to match the installed version, or installed the correct one.`,
576+
},
577+
INVALID_NPM_IMPORT: {
578+
number: 713,
579+
messageTemplate: `The import "{imporPath}" in "{from}" is treated as an npm import as it's first directory doesn't exist in your project, but it's syntax is not that of a valid npm import either.`,
580+
websiteTitle: `Invalid npm import`,
581+
websiteDescription: `You are trying to import a file that is not a valid npm import. Please double check that you are using the correct syntax.`,
582+
},
583+
},
476584
} as const;

v-next/resolver/.eslintrc.cjs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const { createConfig } = require("../../config-v-next/eslint.cjs");
2+
3+
module.exports = createConfig(__filename, ["src/index.ts"]);

v-next/resolver/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Node modules
2+
/node_modules
3+
4+
# Compilation output
5+
/dist

v-next/resolver/.prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/node_modules
2+
/dist
3+
CHANGELOG.md

v-next/resolver/LICENSE

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Nomic Foundation
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

v-next/resolver/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Template package
2+
3+
This is a template package with a base configuration that should be shared by other packages.
4+
5+
It sets up the following things:
6+
7+
- Typescript
8+
- eslint
9+
- prettier
10+
- npm scripts
11+
- package.json' export field

v-next/resolver/package.json

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"name": "@nomicfoundation/resolver",
3+
"version": "3.0.0",
4+
"description": "Hardhat's v3 resolver",
5+
"homepage": "https://github.com/nomicfoundation/hardhat/tree/v-next/v-next/template-package",
6+
"repository": "github:nomicfoundation/hardhat",
7+
"author": "Nomic Foundation",
8+
"license": "MIT",
9+
"type": "module",
10+
"types": "dist/src/index.d.ts",
11+
"exports": {
12+
".": "./dist/src/index.js"
13+
},
14+
"keywords": [
15+
"ethereum",
16+
"smart-contracts",
17+
"hardhat"
18+
],
19+
"scripts": {
20+
"lint": "pnpm prettier --check && pnpm eslint",
21+
"lint:fix": "pnpm prettier --write && pnpm eslint --fix",
22+
"eslint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
23+
"prettier": "prettier \"**/*.{ts,js,md,json}\"",
24+
"test": "node --import tsx/esm --test --test-reporter=@ignored/hardhat-vnext-node-test-reporter \"test/*.ts\" \"test/!(fixture-projects|helpers)/**/*.ts\"",
25+
"test:only": "node --import tsx/esm --test --test-only --test-reporter=@ignored/hardhat-vnext-node-test-reporter \"test/*.ts\" \"test/!(fixture-projects|helpers)/**/*.ts\"",
26+
"pretest": "pnpm build",
27+
"build": "tsc --build .",
28+
"prepublishOnly": "pnpm build",
29+
"clean": "rimraf dist"
30+
},
31+
"files": [
32+
"dist/src/",
33+
"src/",
34+
"CHANGELOG.md",
35+
"LICENSE",
36+
"README.md"
37+
],
38+
"devDependencies": {
39+
"@eslint-community/eslint-plugin-eslint-comments": "^4.3.0",
40+
"@nomicfoundation/eslint-plugin-hardhat-internal-rules": "workspace:^",
41+
"@nomicfoundation/eslint-plugin-slow-imports": "workspace:^",
42+
"@ignored/hardhat-vnext-node-test-reporter": "workspace:^3.0.0-next.2",
43+
"@nomicfoundation/hardhat-test-utils": "workspace:^",
44+
"@types/node": "^20.14.9",
45+
"@typescript-eslint/eslint-plugin": "^7.7.1",
46+
"@typescript-eslint/parser": "^7.7.1",
47+
"c8": "^9.1.0",
48+
"eslint": "8.57.0",
49+
"eslint-config-prettier": "9.1.0",
50+
"eslint-import-resolver-typescript": "^3.6.1",
51+
"eslint-plugin-import": "2.29.1",
52+
"eslint-plugin-no-only-tests": "3.1.0",
53+
"expect-type": "^0.19.0",
54+
"nyc": "^15.1.0",
55+
"prettier": "3.2.5",
56+
"rimraf": "^5.0.5",
57+
"tsx": "^4.11.0",
58+
"typescript": "~5.5.0",
59+
"typescript-eslint": "7.7.1"
60+
},
61+
"dependencies": {
62+
"@ignored/hardhat-vnext-errors": "workspace:^3.0.0-next.2",
63+
"@ignored/hardhat-vnext-utils": "workspace:^3.0.0-next.2"
64+
}
65+
}

0 commit comments

Comments
 (0)