hardhat 2.18.3 → 2.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/builtin-tasks/compile.js +13 -8
- package/builtin-tasks/compile.js.map +1 -1
- package/builtin-tasks/vars.d.ts +2 -0
- package/builtin-tasks/vars.d.ts.map +1 -0
- package/builtin-tasks/vars.js +41 -0
- package/builtin-tasks/vars.js.map +1 -0
- package/internal/cli/bootstrap.js +0 -0
- package/internal/cli/cli.js +4 -0
- package/internal/cli/cli.js.map +1 -1
- package/internal/cli/project-creation.js +6 -6
- package/internal/cli/vars.d.ts +2 -0
- package/internal/cli/vars.d.ts.map +1 -0
- package/internal/cli/vars.js +216 -0
- package/internal/cli/vars.js.map +1 -0
- package/internal/context.d.ts +4 -0
- package/internal/context.d.ts.map +1 -1
- package/internal/context.js +3 -0
- package/internal/context.js.map +1 -1
- package/internal/core/config/config-env.d.ts +34 -0
- package/internal/core/config/config-env.d.ts.map +1 -1
- package/internal/core/config/config-env.js +47 -1
- package/internal/core/config/config-env.js.map +1 -1
- package/internal/core/config/config-loading.d.ts +1 -0
- package/internal/core/config/config-loading.d.ts.map +1 -1
- package/internal/core/config/config-loading.js +8 -4
- package/internal/core/config/config-loading.js.map +1 -1
- package/internal/core/errors-list.d.ts +30 -0
- package/internal/core/errors-list.d.ts.map +1 -1
- package/internal/core/errors-list.js +36 -1
- package/internal/core/errors-list.js.map +1 -1
- package/internal/core/providers/gas-providers.d.ts.map +1 -1
- package/internal/core/providers/gas-providers.js +15 -1
- package/internal/core/providers/gas-providers.js.map +1 -1
- package/internal/core/tasks/builtin-tasks.d.ts +1 -0
- package/internal/core/tasks/builtin-tasks.d.ts.map +1 -1
- package/internal/core/tasks/builtin-tasks.js +1 -0
- package/internal/core/tasks/builtin-tasks.js.map +1 -1
- package/internal/core/vars/vars-manager-setup.d.ts +22 -0
- package/internal/core/vars/vars-manager-setup.d.ts.map +1 -0
- package/internal/core/vars/vars-manager-setup.js +95 -0
- package/internal/core/vars/vars-manager-setup.js.map +1 -0
- package/internal/core/vars/vars-manager.d.ts +21 -0
- package/internal/core/vars/vars-manager.d.ts.map +1 -0
- package/internal/core/vars/vars-manager.js +110 -0
- package/internal/core/vars/vars-manager.js.map +1 -0
- package/internal/hardhat-network/stack-traces/constants.d.ts +1 -1
- package/internal/hardhat-network/stack-traces/constants.js +1 -1
- package/internal/solidity/compiler/downloader.d.ts +2 -2
- package/internal/solidity/compiler/downloader.d.ts.map +1 -1
- package/internal/solidity/compiler/downloader.js +11 -1
- package/internal/solidity/compiler/downloader.js.map +1 -1
- package/internal/solidity/compiler/solc-info.d.ts.map +1 -1
- package/internal/solidity/compiler/solc-info.js +1 -0
- package/internal/solidity/compiler/solc-info.js.map +1 -1
- package/internal/util/global-dir.d.ts +1 -0
- package/internal/util/global-dir.d.ts.map +1 -1
- package/internal/util/global-dir.js +5 -1
- package/internal/util/global-dir.js.map +1 -1
- package/package.json +18 -19
- package/recommended-gitignore.txt +9 -6
- package/src/builtin-tasks/compile.ts +37 -36
- package/src/builtin-tasks/vars.ts +54 -0
- package/src/internal/cli/cli.ts +5 -1
- package/src/internal/cli/project-creation.ts +6 -6
- package/src/internal/cli/vars.ts +301 -0
- package/src/internal/context.ts +8 -0
- package/src/internal/core/config/config-env.ts +54 -0
- package/src/internal/core/config/config-loading.ts +16 -5
- package/src/internal/core/errors-list.ts +39 -1
- package/src/internal/core/providers/gas-providers.ts +20 -1
- package/src/internal/core/tasks/builtin-tasks.ts +1 -0
- package/src/internal/core/vars/vars-manager-setup.ts +124 -0
- package/src/internal/core/vars/vars-manager.ts +152 -0
- package/src/internal/hardhat-network/stack-traces/constants.ts +1 -1
- package/src/internal/solidity/compiler/downloader.ts +24 -2
- package/src/internal/solidity/compiler/solc-info.ts +1 -0
- package/src/internal/util/global-dir.ts +4 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import debug from "debug";
|
|
2
|
+
import { VarsManager } from "./vars-manager";
|
|
3
|
+
|
|
4
|
+
const log = debug("hardhat:core:vars:varsManagerSetup");
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* This class is ONLY used when collecting the required and optional vars that have to be filled by the user
|
|
8
|
+
*/
|
|
9
|
+
export class VarsManagerSetup extends VarsManager {
|
|
10
|
+
private readonly _getVarsAlreadySet: Set<string>;
|
|
11
|
+
private readonly _hasVarsAlreadySet: Set<string>;
|
|
12
|
+
private readonly _getVarsWithDefaultValueAlreadySet: Set<string>;
|
|
13
|
+
|
|
14
|
+
private readonly _getVarsToSet: Set<string>;
|
|
15
|
+
private readonly _hasVarsToSet: Set<string>;
|
|
16
|
+
private readonly _getVarsWithDefaultValueToSet: Set<string>;
|
|
17
|
+
|
|
18
|
+
constructor(varsFilePath: string) {
|
|
19
|
+
log("Creating a new instance of VarsManagerSetup");
|
|
20
|
+
|
|
21
|
+
super(varsFilePath);
|
|
22
|
+
|
|
23
|
+
this._getVarsAlreadySet = new Set();
|
|
24
|
+
this._hasVarsAlreadySet = new Set();
|
|
25
|
+
this._getVarsWithDefaultValueAlreadySet = new Set();
|
|
26
|
+
|
|
27
|
+
this._getVarsToSet = new Set();
|
|
28
|
+
this._hasVarsToSet = new Set();
|
|
29
|
+
this._getVarsWithDefaultValueToSet = new Set();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Checks if the key exists, and updates sets accordingly.
|
|
33
|
+
// Ignore the parameter 'includeEnvs' defined in the parent class because during setup env vars are ignored.
|
|
34
|
+
public has(key: string): boolean {
|
|
35
|
+
log(`function 'has' called with key '${key}'`);
|
|
36
|
+
|
|
37
|
+
const hasKey = super.has(key);
|
|
38
|
+
|
|
39
|
+
if (hasKey) {
|
|
40
|
+
this._hasVarsAlreadySet.add(key);
|
|
41
|
+
} else {
|
|
42
|
+
this._hasVarsToSet.add(key);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return hasKey;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Gets the value for the provided key, and updates sets accordingly.
|
|
49
|
+
// Ignore the parameter 'includeEnvs' defined in the parent class because during setup env vars are ignored.
|
|
50
|
+
public get(key: string, defaultValue?: string): string {
|
|
51
|
+
log(`function 'get' called with key '${key}'`);
|
|
52
|
+
|
|
53
|
+
const varAlreadySet = super.has(key);
|
|
54
|
+
|
|
55
|
+
if (varAlreadySet) {
|
|
56
|
+
if (defaultValue !== undefined) {
|
|
57
|
+
this._getVarsWithDefaultValueAlreadySet.add(key);
|
|
58
|
+
} else {
|
|
59
|
+
this._getVarsAlreadySet.add(key);
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
if (defaultValue !== undefined) {
|
|
63
|
+
this._getVarsWithDefaultValueToSet.add(key);
|
|
64
|
+
} else {
|
|
65
|
+
this._getVarsToSet.add(key);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Do not return undefined to avoid throwing an error
|
|
70
|
+
return super.get(key, defaultValue) ?? "";
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public getRequiredVarsAlreadySet(): string[] {
|
|
74
|
+
return this._getRequired(this._getVarsAlreadySet, this._hasVarsAlreadySet);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public getOptionalVarsAlreadySet(): string[] {
|
|
78
|
+
return this._getOptionals(
|
|
79
|
+
this._getVarsAlreadySet,
|
|
80
|
+
this._hasVarsAlreadySet,
|
|
81
|
+
this._getVarsWithDefaultValueAlreadySet
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public getRequiredVarsToSet(): string[] {
|
|
86
|
+
return this._getRequired(this._getVarsToSet, this._hasVarsToSet);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public getOptionalVarsToSet(): string[] {
|
|
90
|
+
return this._getOptionals(
|
|
91
|
+
this._getVarsToSet,
|
|
92
|
+
this._hasVarsToSet,
|
|
93
|
+
this._getVarsWithDefaultValueToSet
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// How to calculate required and optional variables:
|
|
98
|
+
//
|
|
99
|
+
// G = get function
|
|
100
|
+
// H = has function
|
|
101
|
+
// GD = get function with default value
|
|
102
|
+
//
|
|
103
|
+
// optional variables = H + (GD - G)
|
|
104
|
+
// required variables = G - H
|
|
105
|
+
private _getRequired(getVars: Set<string>, hasVars: Set<string>): string[] {
|
|
106
|
+
return Array.from(getVars).filter((k) => !hasVars.has(k));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private _getOptionals(
|
|
110
|
+
getVars: Set<string>,
|
|
111
|
+
hasVars: Set<string>,
|
|
112
|
+
getVarsWithDefault: Set<string>
|
|
113
|
+
): string[] {
|
|
114
|
+
const result = new Set(hasVars);
|
|
115
|
+
|
|
116
|
+
for (const k of getVarsWithDefault) {
|
|
117
|
+
if (!getVars.has(k)) {
|
|
118
|
+
result.add(k);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return Array.from(result);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import debug from "debug";
|
|
3
|
+
import { HardhatError } from "../errors";
|
|
4
|
+
import { ERRORS } from "../errors-list";
|
|
5
|
+
|
|
6
|
+
interface Var {
|
|
7
|
+
value: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface VarsFile {
|
|
11
|
+
_format: string; // Version of the json vars file
|
|
12
|
+
vars: Record<string, Var>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const log = debug("hardhat:core:vars:varsManager");
|
|
16
|
+
|
|
17
|
+
export class VarsManager {
|
|
18
|
+
private readonly _VERSION = "hh-vars-1";
|
|
19
|
+
private readonly _ENV_VAR_PREFIX = "HARDHAT_VAR_";
|
|
20
|
+
private readonly _storageCache: VarsFile;
|
|
21
|
+
private readonly _envCache: Record<string, string>;
|
|
22
|
+
|
|
23
|
+
constructor(private readonly _varsFilePath: string) {
|
|
24
|
+
log("Creating a new instance of VarsManager");
|
|
25
|
+
|
|
26
|
+
this._initializeVarsFile();
|
|
27
|
+
this._storageCache = fs.readJSONSync(this._varsFilePath);
|
|
28
|
+
|
|
29
|
+
this._envCache = {};
|
|
30
|
+
this._loadVarsFromEnv();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public getStoragePath(): string {
|
|
34
|
+
return this._varsFilePath;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public set(key: string, value: string) {
|
|
38
|
+
this.validateKey(key);
|
|
39
|
+
|
|
40
|
+
if (value === "") {
|
|
41
|
+
throw new HardhatError(ERRORS.VARS.INVALID_EMPTY_VALUE);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const vars = this._storageCache.vars;
|
|
45
|
+
|
|
46
|
+
vars[key] = { value };
|
|
47
|
+
this._writeStoredVars(vars);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public has(key: string, includeEnvs: boolean = false): boolean {
|
|
51
|
+
if (includeEnvs && key in this._envCache) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return key in this._storageCache.vars;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public get(
|
|
59
|
+
key: string,
|
|
60
|
+
defaultValue?: string,
|
|
61
|
+
includeEnvs: boolean = false
|
|
62
|
+
): string | undefined {
|
|
63
|
+
if (includeEnvs && key in this._envCache) {
|
|
64
|
+
return this._envCache[key];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return this._storageCache.vars[key]?.value ?? defaultValue;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public getEnvVars(): string[] {
|
|
71
|
+
return Object.keys(this._envCache).map(
|
|
72
|
+
(k) => `${this._ENV_VAR_PREFIX}${k}`
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public list(): string[] {
|
|
77
|
+
return Object.keys(this._storageCache.vars);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public delete(key: string): boolean {
|
|
81
|
+
const vars = this._storageCache.vars;
|
|
82
|
+
|
|
83
|
+
if (vars[key] === undefined) return false;
|
|
84
|
+
|
|
85
|
+
delete vars[key];
|
|
86
|
+
this._writeStoredVars(vars);
|
|
87
|
+
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public validateKey(key: string) {
|
|
92
|
+
const KEY_REGEX = /^[a-zA-Z_]+[a-zA-Z0-9_]*$/;
|
|
93
|
+
|
|
94
|
+
if (!KEY_REGEX.test(key)) {
|
|
95
|
+
throw new HardhatError(ERRORS.VARS.INVALID_CONFIG_VAR_NAME, {
|
|
96
|
+
value: key,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
private _initializeVarsFile() {
|
|
102
|
+
if (!fs.pathExistsSync(this._varsFilePath)) {
|
|
103
|
+
// Initialize the vars file if it does not exist
|
|
104
|
+
log(
|
|
105
|
+
`Vars file do not exist. Creating a new one at '${this._varsFilePath}' with version '${this._VERSION}'`
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
fs.writeJSONSync(this._varsFilePath, this._getVarsFileStructure(), {
|
|
109
|
+
spaces: 2,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
private _getVarsFileStructure(): VarsFile {
|
|
115
|
+
return {
|
|
116
|
+
_format: this._VERSION,
|
|
117
|
+
vars: {},
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
private _loadVarsFromEnv() {
|
|
122
|
+
log("Loading ENV variables if any");
|
|
123
|
+
|
|
124
|
+
for (const key in process.env) {
|
|
125
|
+
if (key.startsWith(this._ENV_VAR_PREFIX)) {
|
|
126
|
+
const envVar = process.env[key];
|
|
127
|
+
|
|
128
|
+
if (
|
|
129
|
+
envVar === undefined ||
|
|
130
|
+
envVar.replace(/[\s\t]/g, "").length === 0
|
|
131
|
+
) {
|
|
132
|
+
throw new HardhatError(ERRORS.ARGUMENTS.INVALID_ENV_VAR_VALUE, {
|
|
133
|
+
varName: key,
|
|
134
|
+
value: envVar!,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const envKey = key.replace(this._ENV_VAR_PREFIX, "");
|
|
139
|
+
this.validateKey(envKey);
|
|
140
|
+
|
|
141
|
+
// Store only in cache, not in a file, as the vars are sourced from environment variables
|
|
142
|
+
this._envCache[envKey] = envVar;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
private _writeStoredVars(vars: Record<string, Var>) {
|
|
148
|
+
// ENV variables are not stored in the file
|
|
149
|
+
this._storageCache.vars = vars;
|
|
150
|
+
fs.writeJSONSync(this._varsFilePath, this._storageCache, { spaces: 2 });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const SUPPORTED_SOLIDITY_VERSION_RANGE = "<=0.8.
|
|
1
|
+
export const SUPPORTED_SOLIDITY_VERSION_RANGE = "<=0.8.22";
|
|
2
2
|
export const FIRST_SOLC_VERSION_SUPPORTED = "0.5.1";
|
|
@@ -60,7 +60,11 @@ export interface ICompilerDownloader {
|
|
|
60
60
|
* Downloads the compiler for a given version, which can later be obtained
|
|
61
61
|
* with getCompiler.
|
|
62
62
|
*/
|
|
63
|
-
downloadCompiler(
|
|
63
|
+
downloadCompiler(
|
|
64
|
+
version: string,
|
|
65
|
+
downloadStartedCb: (isCompilerDownloaded: boolean) => Promise<any>,
|
|
66
|
+
downloadEndedCb: (isCompilerDownloaded: boolean) => Promise<any>
|
|
67
|
+
): Promise<void>;
|
|
64
68
|
|
|
65
69
|
/**
|
|
66
70
|
* Returns the compiler, which MUST be downloaded before calling this function.
|
|
@@ -146,8 +150,24 @@ export class CompilerDownloader implements ICompilerDownloader {
|
|
|
146
150
|
return fsExtra.pathExists(downloadPath);
|
|
147
151
|
}
|
|
148
152
|
|
|
149
|
-
public async downloadCompiler(
|
|
153
|
+
public async downloadCompiler(
|
|
154
|
+
version: string,
|
|
155
|
+
downloadStartedCb: (isCompilerDownloaded: boolean) => Promise<any>,
|
|
156
|
+
downloadEndedCb: (isCompilerDownloaded: boolean) => Promise<any>
|
|
157
|
+
): Promise<void> {
|
|
158
|
+
// Since only one process at a time can acquire the mutex, we avoid the risk of downloading the same compiler multiple times.
|
|
159
|
+
// This is because the mutex blocks access until a compiler has been fully downloaded, preventing any new process
|
|
160
|
+
// from checking whether that version of the compiler exists. Without mutex it might incorrectly
|
|
161
|
+
// return false, indicating that the compiler isn't present, even though it is currently being downloaded.
|
|
150
162
|
await this._mutex.use(async () => {
|
|
163
|
+
const isCompilerDownloaded = await this.isCompilerDownloaded(version);
|
|
164
|
+
|
|
165
|
+
if (isCompilerDownloaded === true) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
await downloadStartedCb(isCompilerDownloaded);
|
|
170
|
+
|
|
151
171
|
let build = await this._getCompilerBuild(version);
|
|
152
172
|
|
|
153
173
|
if (build === undefined && (await this._shouldDownloadCompilerList())) {
|
|
@@ -189,6 +209,8 @@ export class CompilerDownloader implements ICompilerDownloader {
|
|
|
189
209
|
}
|
|
190
210
|
|
|
191
211
|
await this._postProcessCompilerDownload(build, downloadPath);
|
|
212
|
+
|
|
213
|
+
await downloadEndedCb(isCompilerDownloaded);
|
|
192
214
|
});
|
|
193
215
|
}
|
|
194
216
|
|