diff --git a/.gitignore b/.gitignore index 8f407a9..429d407 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ -/dist - # Logs logs *.log diff --git a/dist/src/index.d.ts b/dist/src/index.d.ts new file mode 100644 index 0000000..29d85df --- /dev/null +++ b/dist/src/index.d.ts @@ -0,0 +1,2 @@ +import "./type-extensions"; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/src/index.d.ts.map b/dist/src/index.d.ts.map new file mode 100644 index 0000000..8df216e --- /dev/null +++ b/dist/src/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AASA,OAAO,mBAAmB,CAAC"} \ No newline at end of file diff --git a/dist/src/index.js b/dist/src/index.js new file mode 100644 index 0000000..e5b04cd --- /dev/null +++ b/dist/src/index.js @@ -0,0 +1,71 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const config_1 = require("hardhat/config"); +const task_names_1 = require("hardhat/builtin-tasks/task-names"); +const plugins_1 = require("hardhat/plugins"); +const errors_1 = require("hardhat/internal/core/errors"); +const path_1 = __importDefault(require("path")); +const debug_1 = __importDefault(require("debug")); +const fs_extra_1 = __importDefault(require("fs-extra")); +require("./type-extensions"); +(0, config_1.extendConfig)((config, userConfig) => { + const compilerPath = userConfig.solidityx?.compilerPath; + let newPath; + if (compilerPath === undefined) { + throw new plugins_1.HardhatPluginError("SolidityX compiler path not found in hardhat.config.js"); + } + if (path_1.default.isAbsolute(compilerPath)) { + newPath = compilerPath; + } + else { + newPath = path_1.default.normalize(path_1.default.join(config.paths.root, compilerPath)); + } + // Check if the customCompilerPath exists + if (!fs_extra_1.default.existsSync(newPath)) { + console.log('\x1b[1m\x1b[31m%s\x1b[0m%s', 'Error:', ' Path not found: ' + newPath); + process.exit(); + } + // Check if the customCompilerPath is a file + if (!fs_extra_1.default.statSync(newPath).isFile()) { + console.log('\x1b[1m\x1b[31m%s\x1b[0m%s', 'Error:', ' Path is not an executable file: ' + newPath); + process.exit(); + } + config.solidityx = { + compilerPath: newPath, + }; +}); +const log = (0, debug_1.default)("hardhat:core:tasks:compile"); +(0, config_1.internalTask)(task_names_1.TASK_COMPILE_SOLIDITY_GET_SOLC_BUILD).setAction(async ({ quiet, solcVersion }, hre, runSuper) => { + const customCompilerPath = hre.config.solidityx.compilerPath; + const resolvedPath = path_1.default.resolve(customCompilerPath); + try { + fs_extra_1.default.accessSync(resolvedPath, fs_extra_1.default.constants.X_OK); + } + catch { + console.log('\x1b[1m\x1b[31m%s\x1b[0m%s', '\nError: ', 'Executable not found or lacks permission.'); + console.log('\x1b[1m\x1b[32m%s\x1b[0m%s', 'Tip: ', 'If the file exists, grant execute permission using: \'chmod +x ' + resolvedPath + '\'\n'); + process.exit(); + } + const compiler = { + version: 'Solx', + longVersion: 'Solidity X', + compilerPath: resolvedPath, + isSolcJs: false + }; + if (compiler !== undefined) { + return compiler; + } + log("Native solc binary doesn't work, using solcjs instead. Try running npx hardhat clean --global"); + const wasmCompiler = { + version: 'Solx', + longVersion: 'Solidity X', + compilerPath: resolvedPath, + isSolcJs: true + }; + (0, errors_1.assertHardhatInvariant)(wasmCompiler !== undefined, `WASM build of solc ${solcVersion} isn't working`); + return wasmCompiler; +}); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/src/index.js.map b/dist/src/index.js.map new file mode 100644 index 0000000..fc770fd --- /dev/null +++ b/dist/src/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;AAAA,2CAAkE;AAClE,iEAAwH;AAExH,6CAAqD;AAErD,yDAAsE;AACtE,gDAAwB;AACxB,kDAA0B;AAC1B,wDAA+B;AAC/B,6BAA2B;AAE3B,IAAA,qBAAY,EACV,CAAC,MAAqB,EAAE,UAAuC,EAAE,EAAE;IACjE,MAAM,YAAY,GAAG,UAAU,CAAC,SAAS,EAAE,YAAY,CAAC;IACxD,IAAI,OAAe,CAAC;IACpB,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAC/B,MAAM,IAAI,4BAAkB,CAAC,wDAAwD,CAAC,CAAC;IACzF,CAAC;IACD,IAAI,cAAI,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;QAClC,OAAO,GAAG,YAAY,CAAC;IACzB,CAAC;SAAM,CAAC;QACN,OAAO,GAAG,cAAI,CAAC,SAAS,CAAC,cAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC;IACvE,CAAC;IAED,yCAAyC;IACzC,IAAI,CAAC,kBAAO,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QACjC,OAAO,CAAC,GAAG,CAAC,4BAA4B,EAAE,QAAQ,EAAE,mBAAmB,GAAG,OAAO,CAAC,CAAC;QACnF,OAAO,CAAC,IAAI,EAAE,CAAA;IAChB,CAAC;IAED,4CAA4C;IAC5C,IAAI,CAAC,kBAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;QACxC,OAAO,CAAC,GAAG,CAAC,4BAA4B,EAAE,QAAQ,EAAE,mCAAmC,GAAG,OAAO,CAAC,CAAC;QACnG,OAAO,CAAC,IAAI,EAAE,CAAA;IAChB,CAAC;IAED,MAAM,CAAC,SAAS,GAAG;QACjB,YAAY,EAAE,OAAO;KACtB,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,MAAM,GAAG,GAAG,IAAA,eAAK,EAAC,4BAA4B,CAAC,CAAC;AAEhD,IAAA,qBAAY,EAAC,iDAAoC,CAAC,CAAC,SAAS,CAC1D,KAAK,EACH,EAAE,KAAK,EAAE,WAAW,EAA2C,EAC/D,GAAG,EACH,QAAQ,EACY,EAAE;IACtB,MAAM,kBAAkB,GAAG,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC;IAC7D,MAAM,YAAY,GAAG,cAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAEtD,IAAI,CAAC;QACH,kBAAO,CAAC,UAAU,CAAC,YAAY,EAAE,kBAAO,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC3D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,CAAC,GAAG,CAAC,4BAA4B,EAAE,WAAW,EAAE,2CAA2C,CAAC,CAAC;QACpG,OAAO,CAAC,GAAG,CAAC,4BAA4B,EAAE,OAAO,EAAE,iEAAiE,GAAG,YAAY,GAAE,MAAM,CAAC,CAAC;QAC7I,OAAO,CAAC,IAAI,EAAE,CAAA;IAChB,CAAC;IAED,MAAM,QAAQ,GAAG;QACf,OAAO,EAAE,MAAM;QACf,WAAW,EAAE,YAAY;QACzB,YAAY,EAAE,YAAY;QAC1B,QAAQ,EAAE,KAAK;KAChB,CAAC;IAEF,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,GAAG,CACD,+FAA+F,CAChG,CAAC;IAEF,MAAM,YAAY,GAAG;QACnB,OAAO,EAAE,MAAM;QACf,WAAW,EAAE,YAAY;QACzB,YAAY,EAAE,YAAY;QAC1B,QAAQ,EAAE,IAAI;KACf,CAAC;IAEF,IAAA,+BAAsB,EACpB,YAAY,KAAK,SAAS,EAC1B,sBAAsB,WAAW,gBAAgB,CAClD,CAAC;IAEF,OAAO,YAAY,CAAC;AACtB,CAAC,CACF,CAAC"} \ No newline at end of file diff --git a/dist/src/type-extensions.d.ts b/dist/src/type-extensions.d.ts new file mode 100644 index 0000000..4ab4e38 --- /dev/null +++ b/dist/src/type-extensions.d.ts @@ -0,0 +1,15 @@ +import "hardhat/types/runtime"; +import "hardhat/types/config"; +declare module "hardhat/types/config" { + interface HardhatUserConfig { + solidityx: { + [compilerPath: string]: string; + }; + } + interface HardhatConfig { + solidityx: { + [compilerPath: string]: string; + }; + } +} +//# sourceMappingURL=type-extensions.d.ts.map \ No newline at end of file diff --git a/dist/src/type-extensions.d.ts.map b/dist/src/type-extensions.d.ts.map new file mode 100644 index 0000000..f4d9e8d --- /dev/null +++ b/dist/src/type-extensions.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"type-extensions.d.ts","sourceRoot":"","sources":["../../src/type-extensions.ts"],"names":[],"mappings":"AACA,OAAO,uBAAuB,CAAC;AAC/B,OAAO,sBAAsB,CAAC;AAE9B,OAAO,QAAQ,sBAAsB,CAAC;IACpC,UAAU,iBAAiB;QACzB,SAAS,EAAE;YACT,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAAC;SAChC,CAAC;KACH;IACD,UAAU,aAAa;QACrB,SAAS,EAAE;YACT,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAAC;SAChC,CAAC;KACH;CACF"} \ No newline at end of file diff --git a/dist/src/type-extensions.js b/dist/src/type-extensions.js new file mode 100644 index 0000000..c200f89 --- /dev/null +++ b/dist/src/type-extensions.js @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +/* eslint-disable @typescript-eslint/no-explicit-any */ +require("hardhat/types/runtime"); +require("hardhat/types/config"); +//# sourceMappingURL=type-extensions.js.map \ No newline at end of file diff --git a/dist/src/type-extensions.js.map b/dist/src/type-extensions.js.map new file mode 100644 index 0000000..8e65339 --- /dev/null +++ b/dist/src/type-extensions.js.map @@ -0,0 +1 @@ +{"version":3,"file":"type-extensions.js","sourceRoot":"","sources":["../../src/type-extensions.ts"],"names":[],"mappings":";;AAAA,uDAAuD;AACvD,iCAA+B;AAC/B,gCAA8B"} \ No newline at end of file diff --git a/dist/test/fixture-projects/hardhat-project/hardhat.config.d.ts b/dist/test/fixture-projects/hardhat-project/hardhat.config.d.ts new file mode 100644 index 0000000..1f51f3e --- /dev/null +++ b/dist/test/fixture-projects/hardhat-project/hardhat.config.d.ts @@ -0,0 +1,5 @@ +import { HardhatUserConfig } from "hardhat/types"; +import "../../../src/index"; +declare const config: HardhatUserConfig; +export default config; +//# sourceMappingURL=hardhat.config.d.ts.map \ No newline at end of file diff --git a/dist/test/fixture-projects/hardhat-project/hardhat.config.d.ts.map b/dist/test/fixture-projects/hardhat-project/hardhat.config.d.ts.map new file mode 100644 index 0000000..eac1265 --- /dev/null +++ b/dist/test/fixture-projects/hardhat-project/hardhat.config.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"hardhat.config.d.ts","sourceRoot":"","sources":["../../../../test/fixture-projects/hardhat-project/hardhat.config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElD,OAAO,oBAAoB,CAAC;AAE5B,QAAA,MAAM,MAAM,EAAE,iBAOb,CAAC;AAEF,eAAe,MAAM,CAAC"} \ No newline at end of file diff --git a/dist/test/fixture-projects/hardhat-project/hardhat.config.js b/dist/test/fixture-projects/hardhat-project/hardhat.config.js new file mode 100644 index 0000000..cf0fbf4 --- /dev/null +++ b/dist/test/fixture-projects/hardhat-project/hardhat.config.js @@ -0,0 +1,12 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +require("../../../src/index"); +const config = { + solidity: "0.7.3", + defaultNetwork: "hardhat", + solidityx: { + compilerPath: "/Users/ruialbuquerque/Projects/CRYPTO/QUAI/hardhat-quai-plugin/test/fixture-projects/hardhat-project/asd", + }, +}; +exports.default = config; +//# sourceMappingURL=hardhat.config.js.map \ No newline at end of file diff --git a/dist/test/fixture-projects/hardhat-project/hardhat.config.js.map b/dist/test/fixture-projects/hardhat-project/hardhat.config.js.map new file mode 100644 index 0000000..5febab4 --- /dev/null +++ b/dist/test/fixture-projects/hardhat-project/hardhat.config.js.map @@ -0,0 +1 @@ +{"version":3,"file":"hardhat.config.js","sourceRoot":"","sources":["../../../../test/fixture-projects/hardhat-project/hardhat.config.ts"],"names":[],"mappings":";;AAGA,8BAA4B;AAE5B,MAAM,MAAM,GAAsB;IAChC,QAAQ,EAAE,OAAO;IACjB,cAAc,EAAE,SAAS;IACzB,SAAS,EAAE;QACT,YAAY,EACV,0GAA0G;KAC7G;CACF,CAAC;AAEF,kBAAe,MAAM,CAAC"} \ No newline at end of file diff --git a/dist/test/helpers.d.ts b/dist/test/helpers.d.ts new file mode 100644 index 0000000..4fc7310 --- /dev/null +++ b/dist/test/helpers.d.ts @@ -0,0 +1,8 @@ +import { HardhatRuntimeEnvironment } from "hardhat/types"; +declare module "mocha" { + interface Context { + hre: HardhatRuntimeEnvironment; + } +} +export declare function useEnvironment(fixtureProjectName: string): void; +//# sourceMappingURL=helpers.d.ts.map \ No newline at end of file diff --git a/dist/test/helpers.d.ts.map b/dist/test/helpers.d.ts.map new file mode 100644 index 0000000..ecde553 --- /dev/null +++ b/dist/test/helpers.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../test/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAG1D,OAAO,QAAQ,OAAO,CAAC;IACrB,UAAU,OAAO;QACf,GAAG,EAAE,yBAAyB,CAAC;KAChC;CACF;AAED,wBAAgB,cAAc,CAAC,kBAAkB,EAAE,MAAM,QAUxD"} \ No newline at end of file diff --git a/dist/test/helpers.js b/dist/test/helpers.js new file mode 100644 index 0000000..7a4306e --- /dev/null +++ b/dist/test/helpers.js @@ -0,0 +1,19 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.useEnvironment = void 0; +const plugins_testing_1 = require("hardhat/plugins-testing"); +const path_1 = __importDefault(require("path")); +function useEnvironment(fixtureProjectName) { + beforeEach("Loading hardhat environment", function () { + process.chdir(path_1.default.join(__dirname, "fixture-projects", fixtureProjectName)); + this.hre = require("hardhat"); + }); + afterEach("Resetting hardhat", function () { + (0, plugins_testing_1.resetHardhatContext)(); + }); +} +exports.useEnvironment = useEnvironment; +//# sourceMappingURL=helpers.js.map \ No newline at end of file diff --git a/dist/test/helpers.js.map b/dist/test/helpers.js.map new file mode 100644 index 0000000..f108815 --- /dev/null +++ b/dist/test/helpers.js.map @@ -0,0 +1 @@ +{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../test/helpers.ts"],"names":[],"mappings":";;;;;;AAAA,6DAA8D;AAE9D,gDAAwB;AAQxB,SAAgB,cAAc,CAAC,kBAA0B;IACvD,UAAU,CAAC,6BAA6B,EAAE;QACxC,OAAO,CAAC,KAAK,CAAC,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CAAC;QAE5E,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,mBAAmB,EAAE;QAC7B,IAAA,qCAAmB,GAAE,CAAC;IACxB,CAAC,CAAC,CAAC;AACL,CAAC;AAVD,wCAUC"} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 9b8dc6f..3863af3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ }, "devDependencies": { "@types/chai": "^4.1.7", + "@types/debug": "^4.1.12", "@types/fs-extra": "^5.0.4", "@types/mocha": "^5.2.6", "@types/node": "^8.10.38", @@ -1701,6 +1702,15 @@ "integrity": "sha512-of+ICnbqjmFCiixUnqRulbylyXQrPqIGf/B3Jax1wIF3DvSheysQxAWvqHhZiW3IQrycvokcLcFQlveGp+vyNg==", "dev": true }, + "node_modules/@types/debug": { + "version": "4.1.12", + "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.12.tgz", + "integrity": "sha512-vIChWdVG3LG1SMxEvI/AK+FWJthlrqlTu7fbrlywTkkaONwk/UAGaULXRlf8vkzFBLVm0zkMdCquhL5aOjhXPQ==", + "dev": true, + "dependencies": { + "@types/ms": "*" + } + }, "node_modules/@types/fs-extra": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-5.1.0.tgz", @@ -1727,6 +1737,12 @@ "integrity": "sha512-NYrtPht0wGzhwe9+/idPaBB+TqkY9AhTvOLMkThm0IoEfLaiVQZwBwyJ5puCkO3AUCWrmcoePjp2mbFocKy4SQ==", "dev": true }, + "node_modules/@types/ms": { + "version": "0.7.34", + "resolved": "https://registry.npmjs.org/@types/ms/-/ms-0.7.34.tgz", + "integrity": "sha512-nG96G3Wp6acyAgJqGasjODb+acrI7KltPiRxzHPXnP3NgI28bpQDRv53olbqGXbfcgF5aiiHmO3xpwEpS5Ld9g==", + "dev": true + }, "node_modules/@types/node": { "version": "8.10.66", "resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.66.tgz", @@ -2456,6 +2472,18 @@ "fsevents": "~2.3.2" } }, + "node_modules/chokidar/node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/ci-info": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-2.0.0.tgz", @@ -2873,82 +2901,6 @@ "url": "https://opencollective.com/eslint" } }, - "node_modules/eslint/node_modules/find-up": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", - "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", - "dependencies": { - "locate-path": "^6.0.0", - "path-exists": "^4.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/eslint/node_modules/glob-parent": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", - "integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==", - "dependencies": { - "is-glob": "^4.0.3" - }, - "engines": { - "node": ">=10.13.0" - } - }, - "node_modules/eslint/node_modules/locate-path": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", - "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", - "dependencies": { - "p-locate": "^5.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/eslint/node_modules/p-limit": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", - "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", - "dependencies": { - "yocto-queue": "^0.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/eslint/node_modules/p-locate": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", - "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", - "dependencies": { - "p-limit": "^3.0.2" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/eslint/node_modules/path-exists": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", - "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", - "engines": { - "node": ">=8" - } - }, "node_modules/espree": { "version": "9.6.1", "resolved": "https://registry.npmjs.org/espree/-/espree-9.6.1.tgz", @@ -3182,6 +3134,17 @@ "node": ">=8.6.0" } }, + "node_modules/fast-glob/node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", @@ -3223,15 +3186,18 @@ } }, "node_modules/find-up": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", - "integrity": "sha512-NWzkk0jSJtTt08+FBFMvXoeZnOJD+jTtsRmBYbAIzJdX6l7dLgR7CTubCM5/eDdPUBvLCeVasP1brfVR/9/EZQ==", - "dev": true, + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", + "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", "dependencies": { - "locate-path": "^2.0.0" + "locate-path": "^6.0.0", + "path-exists": "^4.0.0" }, "engines": { - "node": ">=4" + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/flat": { @@ -3374,14 +3340,14 @@ } }, "node_modules/glob-parent": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", - "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", + "integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==", "dependencies": { - "is-glob": "^4.0.1" + "is-glob": "^4.0.3" }, "engines": { - "node": ">= 6" + "node": ">=10.13.0" } }, "node_modules/globals": { @@ -3525,15 +3491,6 @@ "node": ">=4" } }, - "node_modules/hardhat/node_modules/chalk/node_modules/escape-string-regexp": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", - "dev": true, - "engines": { - "node": ">=0.8.0" - } - }, "node_modules/hardhat/node_modules/color-convert": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", @@ -3549,6 +3506,27 @@ "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", "dev": true }, + "node_modules/hardhat/node_modules/escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", + "dev": true, + "engines": { + "node": ">=0.8.0" + } + }, + "node_modules/hardhat/node_modules/find-up": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", + "integrity": "sha512-NWzkk0jSJtTt08+FBFMvXoeZnOJD+jTtsRmBYbAIzJdX6l7dLgR7CTubCM5/eDdPUBvLCeVasP1brfVR/9/EZQ==", + "dev": true, + "dependencies": { + "locate-path": "^2.0.0" + }, + "engines": { + "node": ">=4" + } + }, "node_modules/hardhat/node_modules/fs-extra": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz", @@ -3563,6 +3541,15 @@ "node": ">=6 <7 || >=8" } }, + "node_modules/hardhat/node_modules/has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", + "dev": true, + "engines": { + "node": ">=4" + } + }, "node_modules/hardhat/node_modules/jsonfile": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", @@ -3572,6 +3559,52 @@ "graceful-fs": "^4.1.6" } }, + "node_modules/hardhat/node_modules/locate-path": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz", + "integrity": "sha512-NCI2kiDkyR7VeEKm27Kda/iQHyKJe1Bu0FlTbYp3CqJu+9IFe9bLyAjMxf5ZDDbEg+iMPzB5zYyUTSm8wVTKmA==", + "dev": true, + "dependencies": { + "p-locate": "^2.0.0", + "path-exists": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/hardhat/node_modules/p-limit": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz", + "integrity": "sha512-vvcXsLAJ9Dr5rQOPk7toZQZJApBl2K4J6dANSsEuh6QI41JYcsS/qhTGa9ErIUUgK3WNQoJYvylxvjqmiqEA9Q==", + "dev": true, + "dependencies": { + "p-try": "^1.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/hardhat/node_modules/p-locate": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-2.0.0.tgz", + "integrity": "sha512-nQja7m7gSKuewoVRen45CtVfODR3crN3goVQ0DDZ9N3yHxgpkuBhZqsaiotSQRrADUrne346peY7kT3TSACykg==", + "dev": true, + "dependencies": { + "p-limit": "^1.1.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/hardhat/node_modules/path-exists": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", + "integrity": "sha512-bpC7GYwiDYQ4wYLe+FA8lhRjhQCMcQGuSgGGqDkg/QerRWw9CmGRT0iSOVRSZJ29NMLZgIzqaljJ63oaL4NIJQ==", + "dev": true, + "engines": { + "node": ">=4" + } + }, "node_modules/hardhat/node_modules/semver": { "version": "6.3.1", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", @@ -3593,15 +3626,6 @@ "node": ">=4" } }, - "node_modules/hardhat/node_modules/supports-color/node_modules/has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", - "dev": true, - "engines": { - "node": ">=4" - } - }, "node_modules/hardhat/node_modules/universalify": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", @@ -4066,16 +4090,17 @@ } }, "node_modules/locate-path": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz", - "integrity": "sha512-NCI2kiDkyR7VeEKm27Kda/iQHyKJe1Bu0FlTbYp3CqJu+9IFe9bLyAjMxf5ZDDbEg+iMPzB5zYyUTSm8wVTKmA==", - "dev": true, + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", + "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", "dependencies": { - "p-locate": "^2.0.0", - "path-exists": "^3.0.0" + "p-locate": "^5.0.0" }, "engines": { - "node": ">=4" + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/lodash": { @@ -4288,37 +4313,6 @@ "balanced-match": "^1.0.0" } }, - "node_modules/mocha/node_modules/find-up": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", - "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", - "dev": true, - "dependencies": { - "locate-path": "^6.0.0", - "path-exists": "^4.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/mocha/node_modules/locate-path": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", - "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", - "dev": true, - "dependencies": { - "p-locate": "^5.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/mocha/node_modules/minimatch": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.0.1.tgz", @@ -4337,45 +4331,6 @@ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", "dev": true }, - "node_modules/mocha/node_modules/p-limit": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", - "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", - "dev": true, - "dependencies": { - "yocto-queue": "^0.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/mocha/node_modules/p-locate": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", - "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", - "dev": true, - "dependencies": { - "p-limit": "^3.0.2" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/mocha/node_modules/path-exists": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", - "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", - "dev": true, - "engines": { - "node": ">=8" - } - }, "node_modules/mocha/node_modules/supports-color": { "version": "8.1.1", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", @@ -4494,27 +4449,31 @@ } }, "node_modules/p-limit": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz", - "integrity": "sha512-vvcXsLAJ9Dr5rQOPk7toZQZJApBl2K4J6dANSsEuh6QI41JYcsS/qhTGa9ErIUUgK3WNQoJYvylxvjqmiqEA9Q==", - "dev": true, + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", + "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", "dependencies": { - "p-try": "^1.0.0" + "yocto-queue": "^0.1.0" }, "engines": { - "node": ">=4" + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/p-locate": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-2.0.0.tgz", - "integrity": "sha512-nQja7m7gSKuewoVRen45CtVfODR3crN3goVQ0DDZ9N3yHxgpkuBhZqsaiotSQRrADUrne346peY7kT3TSACykg==", - "dev": true, + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", + "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", "dependencies": { - "p-limit": "^1.1.0" + "p-limit": "^3.0.2" }, "engines": { - "node": ">=4" + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/p-map": { @@ -4553,12 +4512,11 @@ } }, "node_modules/path-exists": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", - "integrity": "sha512-bpC7GYwiDYQ4wYLe+FA8lhRjhQCMcQGuSgGGqDkg/QerRWw9CmGRT0iSOVRSZJ29NMLZgIzqaljJ63oaL4NIJQ==", - "dev": true, + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", "engines": { - "node": ">=4" + "node": ">=8" } }, "node_modules/path-is-absolute": { diff --git a/package.json b/package.json index 6883b40..337d196 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ ], "devDependencies": { "@types/chai": "^4.1.7", + "@types/debug": "^4.1.12", "@types/fs-extra": "^5.0.4", "@types/mocha": "^5.2.6", "@types/node": "^8.10.38", diff --git a/src/index.ts b/src/index.ts index 7dc54ac..3c3c937 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,11 @@ -import { internalTask, extendConfig } from "hardhat/config"; -import { TASK_COMPILE_SOLIDITY_RUN_SOLC } from "hardhat/builtin-tasks/task-names"; +import { internalTask, extendConfig, task } from "hardhat/config"; +import { TASK_COMPILE_SOLIDITY_RUN_SOLC, TASK_COMPILE_SOLIDITY_GET_SOLC_BUILD } from "hardhat/builtin-tasks/task-names"; +import { SolcBuild } from "hardhat/types/builtin-tasks/compile"; import { HardhatPluginError } from "hardhat/plugins"; import { HardhatConfig, HardhatUserConfig, CompilerInput } from "hardhat/types"; +import { assertHardhatInvariant } from "hardhat/internal/core/errors"; import path from "path"; +import debug from "debug"; import fsExtra from "fs-extra"; import "./type-extensions"; @@ -11,30 +14,78 @@ extendConfig( const compilerPath = userConfig.solidityx?.compilerPath; let newPath: string; if (compilerPath === undefined) { - throw new HardhatPluginError("SolidityX compiler path should be setted"); + throw new HardhatPluginError("SolidityX compiler path not found in hardhat.config.js"); } if (path.isAbsolute(compilerPath)) { newPath = compilerPath; } else { newPath = path.normalize(path.join(config.paths.root, compilerPath)); } + + // Check if the customCompilerPath exists if (!fsExtra.existsSync(newPath)) { - throw new HardhatPluginError("SolidityX compiler not found in path"); + console.log('\x1b[1m\x1b[31m%s\x1b[0m%s', 'Error:', ' Path not found: ' + newPath); + process.exit() + } + + // Check if the customCompilerPath is a file + if (!fsExtra.statSync(newPath).isFile()) { + console.log('\x1b[1m\x1b[31m%s\x1b[0m%s', 'Error:', ' Path is not an executable file: ' + newPath); + process.exit() } + config.solidityx = { compilerPath: newPath, }; } ); -internalTask(TASK_COMPILE_SOLIDITY_RUN_SOLC).setAction( +const log = debug("hardhat:core:tasks:compile"); + +internalTask(TASK_COMPILE_SOLIDITY_GET_SOLC_BUILD).setAction( async ( - { input, solcPath }: { input: CompilerInput; solcPath: string }, + { quiet, solcVersion }: { quiet: boolean; solcVersion: string }, hre, runSuper - ): Promise => { - solcPath = hre.config.solidityx.compilerPath; - fsExtra.chmodSync(solcPath, "0755"); - return runSuper({ input, solcPath }); + ): Promise => { + const customCompilerPath = hre.config.solidityx.compilerPath; + const resolvedPath = path.resolve(customCompilerPath); + + try { + fsExtra.accessSync(resolvedPath, fsExtra.constants.X_OK); + } catch { + console.log('\x1b[1m\x1b[31m%s\x1b[0m%s', '\nError: ', 'Executable not found or lacks permission.'); + console.log('\x1b[1m\x1b[32m%s\x1b[0m%s', 'Tip: ', 'If the file exists, grant execute permission using: \'chmod +x ' + resolvedPath +'\'\n'); + process.exit() + } + + const compiler = { + version: 'Solx', + longVersion: 'Solidity X', + compilerPath: resolvedPath, + isSolcJs: false + }; + + if (compiler !== undefined) { + return compiler; + } + + log( + "Native solc binary doesn't work, using solcjs instead. Try running npx hardhat clean --global" + ); + + const wasmCompiler = { + version: 'Solx', + longVersion: 'Solidity X', + compilerPath: resolvedPath, + isSolcJs: true + }; + + assertHardhatInvariant( + wasmCompiler !== undefined, + `WASM build of solc ${solcVersion} isn't working` + ); + + return wasmCompiler; } -); +); \ No newline at end of file