hardhat 2.9.8-dev.0 → 2.10.0
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/internal/cli/cli.js +37 -7
- package/internal/cli/cli.js.map +1 -1
- package/internal/cli/hardhat-vscode-installation.d.ts +8 -0
- package/internal/cli/hardhat-vscode-installation.d.ts.map +1 -0
- package/internal/cli/hardhat-vscode-installation.js +41 -0
- package/internal/cli/hardhat-vscode-installation.js.map +1 -0
- package/internal/cli/project-creation.d.ts +0 -1
- package/internal/cli/project-creation.d.ts.map +1 -1
- package/internal/cli/project-creation.js +87 -179
- package/internal/cli/project-creation.js.map +1 -1
- package/internal/cli/prompt.d.ts +14 -0
- package/internal/cli/prompt.d.ts.map +1 -0
- package/internal/cli/prompt.js +120 -0
- package/internal/cli/prompt.js.map +1 -0
- package/internal/cli/types.d.ts +4 -0
- package/internal/cli/types.d.ts.map +1 -0
- package/internal/cli/types.js +3 -0
- package/internal/cli/types.js.map +1 -0
- package/internal/core/config/config-loading.js +1 -1
- package/internal/core/errors-list.js +4 -4
- package/internal/core/errors-list.js.map +1 -1
- package/internal/core/jsonrpc/types/input/blockTag.d.ts +3 -3
- package/internal/core/jsonrpc/types/input/blockTag.d.ts.map +1 -1
- package/internal/core/providers/construction.d.ts.map +1 -1
- package/internal/core/providers/construction.js +0 -4
- package/internal/core/providers/construction.js.map +1 -1
- package/internal/core/providers/gas-providers.d.ts +0 -15
- package/internal/core/providers/gas-providers.d.ts.map +1 -1
- package/internal/core/providers/gas-providers.js +1 -33
- package/internal/core/providers/gas-providers.js.map +1 -1
- package/internal/hardhat-network/provider/modules/logger.js +1 -1
- package/internal/hardhat-network/provider/modules/logger.js.map +1 -1
- package/internal/hardhat-network/provider/node.js +1 -1
- package/internal/hardhat-network/provider/node.js.map +1 -1
- package/internal/hardhat-network/stack-traces/solidity-errors.js +1 -1
- package/internal/hardhat-network/stack-traces/solidity-errors.js.map +1 -1
- package/internal/util/global-dir.d.ts +5 -0
- package/internal/util/global-dir.d.ts.map +1 -1
- package/internal/util/global-dir.js +17 -1
- package/internal/util/global-dir.js.map +1 -1
- package/internal/util/keys-derivation.d.ts.map +1 -1
- package/internal/util/keys-derivation.js +3 -1
- package/internal/util/keys-derivation.js.map +1 -1
- package/package.json +18 -9
- package/recommended-gitignore.txt +2 -0
- package/sample-projects/{basic → javascript}/LICENSE.md +1 -1
- package/sample-projects/javascript/README.md +13 -0
- package/sample-projects/javascript/contracts/Lock.sol +34 -0
- package/sample-projects/javascript/hardhat.config.js +6 -0
- package/sample-projects/javascript/scripts/deploy.js +29 -0
- package/sample-projects/javascript/test/Lock.js +126 -0
- package/sample-projects/typescript/LICENSE.md +11 -0
- package/sample-projects/typescript/README.md +13 -0
- package/sample-projects/typescript/contracts/Lock.sol +34 -0
- package/sample-projects/typescript/hardhat.config.ts +8 -0
- package/sample-projects/typescript/scripts/deploy.ts +23 -0
- package/sample-projects/typescript/test/Lock.ts +124 -0
- package/sample-projects/typescript/tsconfig.json +10 -0
- package/src/internal/cli/cli.ts +55 -7
- package/src/internal/cli/hardhat-vscode-installation.ts +43 -0
- package/src/internal/cli/project-creation.ts +124 -290
- package/src/internal/cli/prompt.ts +143 -0
- package/src/internal/cli/types.ts +3 -0
- package/src/internal/core/config/config-loading.ts +1 -1
- package/src/internal/core/errors-list.ts +4 -4
- package/src/internal/core/providers/construction.ts +0 -9
- package/src/internal/core/providers/gas-providers.ts +0 -39
- package/src/internal/hardhat-network/provider/modules/logger.ts +1 -1
- package/src/internal/hardhat-network/provider/node.ts +1 -1
- package/src/internal/hardhat-network/stack-traces/solidity-errors.ts +1 -1
- package/src/internal/util/global-dir.ts +19 -0
- package/src/internal/util/keys-derivation.ts +3 -1
- package/src/types/artifacts.ts +7 -0
- package/types/artifacts.d.ts +6 -0
- package/types/artifacts.d.ts.map +1 -1
- package/sample-projects/advanced/.env.example +0 -3
- package/sample-projects/advanced/.eslintignore +0 -4
- package/sample-projects/advanced/.eslintrc.js +0 -22
- package/sample-projects/advanced/.prettierignore +0 -5
- package/sample-projects/advanced/.prettierrc +0 -1
- package/sample-projects/advanced/.solhint.json +0 -7
- package/sample-projects/advanced/.solhintignore +0 -1
- package/sample-projects/advanced/README.md +0 -42
- package/sample-projects/advanced/hardhat.config.js +0 -40
- package/sample-projects/advanced/npmignore +0 -3
- package/sample-projects/advanced/scripts/deploy.js +0 -30
- package/sample-projects/advanced-ts/.eslintrc.js +0 -24
- package/sample-projects/advanced-ts/README.md +0 -46
- package/sample-projects/advanced-ts/hardhat.config.ts +0 -43
- package/sample-projects/advanced-ts/npmignore +0 -3
- package/sample-projects/advanced-ts/scripts/deploy.ts +0 -30
- package/sample-projects/advanced-ts/test/index.ts +0 -19
- package/sample-projects/advanced-ts/tsconfig.json +0 -12
- package/sample-projects/basic/README.md +0 -15
- package/sample-projects/basic/contracts/Greeter.sol +0 -22
- package/sample-projects/basic/hardhat.config.js +0 -21
- package/sample-projects/basic/scripts/sample-script.js +0 -32
- package/sample-projects/basic/test/sample-test.js +0 -19
package/internal/cli/cli.js
CHANGED
|
@@ -29,6 +29,8 @@ const analytics_1 = require("./analytics");
|
|
|
29
29
|
const ArgumentsParser_1 = require("./ArgumentsParser");
|
|
30
30
|
const emoji_1 = require("./emoji");
|
|
31
31
|
const project_creation_1 = require("./project-creation");
|
|
32
|
+
const prompt_1 = require("./prompt");
|
|
33
|
+
const hardhat_vscode_installation_1 = require("./hardhat-vscode-installation");
|
|
32
34
|
const log = (0, debug_1.default)("hardhat:core:cli");
|
|
33
35
|
(0, antlr_prototype_pollution_workaround_1.applyWorkaround)();
|
|
34
36
|
const ANALYTICS_SLOW_TASK_THRESHOLD = 300;
|
|
@@ -45,6 +47,31 @@ Please, make sure you are using a supported version of Node.js.
|
|
|
45
47
|
To learn more about which versions of Node.js are supported go to https://hardhat.org/nodejs-versions`));
|
|
46
48
|
}
|
|
47
49
|
}
|
|
50
|
+
async function suggestInstallingHardhatVscode() {
|
|
51
|
+
const alreadyPrompted = (0, global_dir_1.hasPromptedForHHVSCode)();
|
|
52
|
+
if (alreadyPrompted) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const isInstalled = (0, hardhat_vscode_installation_1.isHardhatVSCodeInstalled)();
|
|
56
|
+
(0, global_dir_1.writePromptedForHHVSCode)();
|
|
57
|
+
if (isInstalled !== hardhat_vscode_installation_1.InstallationState.EXTENSION_NOT_INSTALLED) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const installationConsent = await (0, prompt_1.confirmHHVSCodeInstallation)();
|
|
61
|
+
if (installationConsent === true) {
|
|
62
|
+
console.log("Installing Hardhat for Visual Studio Code...");
|
|
63
|
+
const installed = (0, hardhat_vscode_installation_1.installHardhatVSCode)();
|
|
64
|
+
if (installed) {
|
|
65
|
+
console.log("Hardhat for Visual Studio Code was successfully installed");
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
console.log("Hardhat for Visual Studio Code couldn't be installed. To learn more about it, go to https://hardhat.org/hardhat-vscode");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
console.log("To learn more about Hardhat for Visual Studio Code, go to https://hardhat.org/hardhat-vscode");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
48
75
|
async function main() {
|
|
49
76
|
// We first accept this argument anywhere, so we know if the user wants
|
|
50
77
|
// stack traces before really parsing the arguments.
|
|
@@ -70,12 +97,9 @@ async function main() {
|
|
|
70
97
|
}
|
|
71
98
|
if (hardhatArguments.config === undefined && !(0, project_structure_1.isCwdInsideProject)()) {
|
|
72
99
|
if (process.stdout.isTTY === true ||
|
|
73
|
-
process.env.
|
|
74
|
-
undefined ||
|
|
75
|
-
process.env.HARDHAT_CREATE_ADVANCED_SAMPLE_PROJECT_WITH_DEFAULTS !==
|
|
100
|
+
process.env.HARDHAT_CREATE_JAVASCRIPT_PROJECT_WITH_DEFAULTS !==
|
|
76
101
|
undefined ||
|
|
77
|
-
process.env
|
|
78
|
-
.HARDHAT_CREATE_ADVANCED_TYPESCRIPT_SAMPLE_PROJECT_WITH_DEFAULTS !==
|
|
102
|
+
process.env.HARDHAT_CREATE_TYPESCRIPT_PROJECT_WITH_DEFAULTS !==
|
|
79
103
|
undefined) {
|
|
80
104
|
await (0, project_creation_1.createProject)();
|
|
81
105
|
return;
|
|
@@ -108,7 +132,7 @@ async function main() {
|
|
|
108
132
|
!isHelpCommand &&
|
|
109
133
|
!(0, ci_detection_1.isRunningOnCiServer)() &&
|
|
110
134
|
process.stdout.isTTY === true) {
|
|
111
|
-
telemetryConsent = await (0,
|
|
135
|
+
telemetryConsent = await (0, prompt_1.confirmTelemetryConsent)();
|
|
112
136
|
if (telemetryConsent !== undefined) {
|
|
113
137
|
(0, global_dir_1.writeTelemetryConsent)(telemetryConsent);
|
|
114
138
|
}
|
|
@@ -153,6 +177,12 @@ async function main() {
|
|
|
153
177
|
else {
|
|
154
178
|
abortAnalytics();
|
|
155
179
|
}
|
|
180
|
+
// VSCode extension prompt for installation
|
|
181
|
+
if (taskName === "test" &&
|
|
182
|
+
!(0, ci_detection_1.isRunningOnCiServer)() &&
|
|
183
|
+
process.stdout.isTTY === true) {
|
|
184
|
+
await suggestInstallingHardhatVscode();
|
|
185
|
+
}
|
|
156
186
|
log(`Killing Hardhat after successfully running task ${taskName}`);
|
|
157
187
|
}
|
|
158
188
|
catch (error) {
|
|
@@ -185,7 +215,7 @@ async function main() {
|
|
|
185
215
|
}
|
|
186
216
|
else {
|
|
187
217
|
if (!isHardhatError) {
|
|
188
|
-
console.error(`If you think this is a bug in Hardhat, please report it here: https://hardhat.org/
|
|
218
|
+
console.error(`If you think this is a bug in Hardhat, please report it here: https://hardhat.org/report-bug`);
|
|
189
219
|
}
|
|
190
220
|
if (errors_1.HardhatError.isHardhatError(error)) {
|
|
191
221
|
const link = `https://hardhat.org/${(0, errors_list_1.getErrorCode)(error.errorDescriptor)}`;
|
package/internal/cli/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/internal/cli/cli.ts"],"names":[],"mappings":";;;;;;AACA,kDAA0B;AAC1B,kDAA0B;AAC1B,oDAA4B;AAC5B,uCAAqC;AAErC,+DAAyE;AAEzE,4CAA4C;AAC5C,wCAA4C;AAC5C,kEAAmE;AACnE,2CAAkE;AAClE,qDAA2D;AAC3D,2DAA2E;AAC3E,gEAAsE;AACtE,kEAA0E;AAC1E,iEAA+D;AAC/D,qEAA0D;AAC1D,mEAA+E;AAC/E,iDAA8C;AAC9C,uDAA2D;AAC3D,
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/internal/cli/cli.ts"],"names":[],"mappings":";;;;;;AACA,kDAA0B;AAC1B,kDAA0B;AAC1B,oDAA4B;AAC5B,uCAAqC;AAErC,+DAAyE;AAEzE,4CAA4C;AAC5C,wCAA4C;AAC5C,kEAAmE;AACnE,2CAAkE;AAClE,qDAA2D;AAC3D,2DAA2E;AAC3E,gEAAsE;AACtE,kEAA0E;AAC1E,iEAA+D;AAC/D,qEAA0D;AAC1D,mEAA+E;AAC/E,iDAA8C;AAC9C,uDAA2D;AAC3D,mDAK4B;AAC5B,qDAAkE;AAElE,uGAA+E;AAC/E,2CAAwC;AACxC,uDAAoD;AACpD,mCAAsC;AACtC,yDAAmD;AACnD,qCAAgF;AAChF,+EAIuC;AAEvC,MAAM,GAAG,GAAG,IAAA,eAAK,EAAC,kBAAkB,CAAC,CAAC;AAEtC,IAAA,sDAAe,GAAE,CAAC;AAElB,MAAM,6BAA6B,GAAG,GAAG,CAAC;AAE1C,KAAK,UAAU,mBAAmB,CAAC,WAAwB;IACzD,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;AACnC,CAAC;AAED,SAAS,yCAAyC,CAAC,WAAwB;IACzE,MAAM,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC;IAC7C,IAAI,CAAC,gBAA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AAC;SAC/C;QAED,IAAI,eAAe,EAAE;YACnB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;SACtB;aAAM;YACL,IAAI,CAAC,cAAc,EAAE;gBACnB,OAAO,CAAC,KAAK,CACX,8FAA8F,CAC/F,CAAC;aACH;YAED,IAAI,qBAAY,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE;gBACtC,MAAM,IAAI,GAAG,uBAAuB,IAAA,0BAAY,EAC9C,KAAK,CAAC,eAAe,CACtB,EAAE,CAAC;gBAEJ,OAAO,CAAC,KAAK,CACX,uBAAuB,IAAI,WAAW,wBAAY,2BAA2B,CAC9E,CAAC;aACH;iBAAM;gBACL,OAAO,CAAC,KAAK,CACX,qBAAqB,wBAAY,2BAA2B,CAC7D,CAAC;aACH;SACF;QAED,MAAM,mBAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC3B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;AACH,CAAC;AAED,IAAI,EAAE;KACH,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;KAC1C,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACf,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare enum InstallationState {
|
|
2
|
+
VSCODE_FAILED_OR_NOT_INSTALLED = 0,
|
|
3
|
+
EXTENSION_INSTALLED = 1,
|
|
4
|
+
EXTENSION_NOT_INSTALLED = 2
|
|
5
|
+
}
|
|
6
|
+
export declare function isHardhatVSCodeInstalled(): InstallationState;
|
|
7
|
+
export declare function installHardhatVSCode(): boolean;
|
|
8
|
+
//# sourceMappingURL=hardhat-vscode-installation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hardhat-vscode-installation.d.ts","sourceRoot":"","sources":["../../src/internal/cli/hardhat-vscode-installation.ts"],"names":[],"mappings":"AAEA,oBAAY,iBAAiB;IAC3B,8BAA8B,IAAA;IAC9B,mBAAmB,IAAA;IACnB,uBAAuB,IAAA;CACxB;AAID,wBAAgB,wBAAwB,IAAI,iBAAiB,CAgB5D;AAED,wBAAgB,oBAAoB,IAAI,OAAO,CAc9C"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.installHardhatVSCode = exports.isHardhatVSCodeInstalled = exports.InstallationState = void 0;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
var InstallationState;
|
|
6
|
+
(function (InstallationState) {
|
|
7
|
+
InstallationState[InstallationState["VSCODE_FAILED_OR_NOT_INSTALLED"] = 0] = "VSCODE_FAILED_OR_NOT_INSTALLED";
|
|
8
|
+
InstallationState[InstallationState["EXTENSION_INSTALLED"] = 1] = "EXTENSION_INSTALLED";
|
|
9
|
+
InstallationState[InstallationState["EXTENSION_NOT_INSTALLED"] = 2] = "EXTENSION_NOT_INSTALLED";
|
|
10
|
+
})(InstallationState = exports.InstallationState || (exports.InstallationState = {}));
|
|
11
|
+
const HARDHAT_VSCODE_ID = "NomicFoundation.hardhat-solidity";
|
|
12
|
+
function isHardhatVSCodeInstalled() {
|
|
13
|
+
try {
|
|
14
|
+
const { stdout, status } = (0, child_process_1.spawnSync)("code", ["--list-extensions"], {
|
|
15
|
+
encoding: "utf8",
|
|
16
|
+
});
|
|
17
|
+
if (status !== 0) {
|
|
18
|
+
return InstallationState.VSCODE_FAILED_OR_NOT_INSTALLED;
|
|
19
|
+
}
|
|
20
|
+
return stdout.includes(HARDHAT_VSCODE_ID)
|
|
21
|
+
? InstallationState.EXTENSION_INSTALLED
|
|
22
|
+
: InstallationState.EXTENSION_NOT_INSTALLED;
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
return InstallationState.VSCODE_FAILED_OR_NOT_INSTALLED;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.isHardhatVSCodeInstalled = isHardhatVSCodeInstalled;
|
|
29
|
+
function installHardhatVSCode() {
|
|
30
|
+
try {
|
|
31
|
+
const { status } = (0, child_process_1.spawnSync)("code", ["--install-extension", HARDHAT_VSCODE_ID], {
|
|
32
|
+
encoding: "utf8",
|
|
33
|
+
});
|
|
34
|
+
return status === 0;
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.installHardhatVSCode = installHardhatVSCode;
|
|
41
|
+
//# sourceMappingURL=hardhat-vscode-installation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hardhat-vscode-installation.js","sourceRoot":"","sources":["../../src/internal/cli/hardhat-vscode-installation.ts"],"names":[],"mappings":";;;AAAA,iDAA0C;AAE1C,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IAC3B,6GAA8B,CAAA;IAC9B,uFAAmB,CAAA;IACnB,+FAAuB,CAAA;AACzB,CAAC,EAJW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAI5B;AAED,MAAM,iBAAiB,GAAG,kCAAkC,CAAC;AAE7D,SAAgB,wBAAwB;IACtC,IAAI;QACF,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,yBAAS,EAAC,MAAM,EAAE,CAAC,mBAAmB,CAAC,EAAE;YAClE,QAAQ,EAAE,MAAM;SACjB,CAAC,CAAC;QAEH,IAAI,MAAM,KAAK,CAAC,EAAE;YAChB,OAAO,iBAAiB,CAAC,8BAA8B,CAAC;SACzD;QAED,OAAO,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC;YACvC,CAAC,CAAC,iBAAiB,CAAC,mBAAmB;YACvC,CAAC,CAAC,iBAAiB,CAAC,uBAAuB,CAAC;KAC/C;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,iBAAiB,CAAC,8BAA8B,CAAC;KACzD;AACH,CAAC;AAhBD,4DAgBC;AAED,SAAgB,oBAAoB;IAClC,IAAI;QACF,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,yBAAS,EAC1B,MAAM,EACN,CAAC,qBAAqB,EAAE,iBAAiB,CAAC,EAC1C;YACE,QAAQ,EAAE,MAAM;SACjB,CACF,CAAC;QAEF,OAAO,MAAM,KAAK,CAAC,CAAC;KACrB;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAdD,oDAcC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-creation.d.ts","sourceRoot":"","sources":["../../src/internal/cli/project-creation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"project-creation.d.ts","sourceRoot":"","sources":["../../src/internal/cli/project-creation.ts"],"names":[],"mappings":"AA+PA,wBAAsB,aAAa,kBAuIlC"}
|
|
@@ -22,54 +22,56 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.
|
|
25
|
+
exports.createProject = void 0;
|
|
26
26
|
const chalk_1 = __importDefault(require("chalk"));
|
|
27
27
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
28
28
|
const os_1 = __importDefault(require("os"));
|
|
29
29
|
const path_1 = __importDefault(require("path"));
|
|
30
30
|
const constants_1 = require("../constants");
|
|
31
|
-
const default_config_1 = require("../core/config/default-config");
|
|
32
31
|
const errors_1 = require("../core/errors");
|
|
33
32
|
const errors_list_1 = require("../core/errors-list");
|
|
34
33
|
const project_structure_1 = require("../core/project-structure");
|
|
35
34
|
const global_dir_1 = require("../util/global-dir");
|
|
36
35
|
const lang_1 = require("../util/lang");
|
|
37
36
|
const packageInfo_1 = require("../util/packageInfo");
|
|
37
|
+
const strings_1 = require("../util/strings");
|
|
38
|
+
const prompt_1 = require("./prompt");
|
|
38
39
|
const emoji_1 = require("./emoji");
|
|
39
40
|
var Action;
|
|
40
41
|
(function (Action) {
|
|
41
|
-
Action["
|
|
42
|
-
Action["
|
|
43
|
-
Action["CREATE_ADVANCED_TYPESCRIPT_SAMPLE_PROJECT_ACTION"] = "Create an advanced sample project that uses TypeScript";
|
|
42
|
+
Action["CREATE_JAVASCRIPT_PROJECT_ACTION"] = "Create a JavaScript project";
|
|
43
|
+
Action["CREATE_TYPESCRIPT_PROJECT_ACTION"] = "Create a TypeScript project";
|
|
44
44
|
Action["CREATE_EMPTY_HARDHAT_CONFIG_ACTION"] = "Create an empty hardhat.config.js";
|
|
45
45
|
Action["QUIT_ACTION"] = "Quit";
|
|
46
46
|
})(Action || (Action = {}));
|
|
47
47
|
const HARDHAT_PACKAGE_NAME = "hardhat";
|
|
48
|
-
const
|
|
49
|
-
"@
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
const PROJECT_DEPENDENCIES = {
|
|
49
|
+
"@nomicfoundation/hardhat-toolbox": "^1.0.1",
|
|
50
|
+
};
|
|
51
|
+
const PEER_DEPENDENCIES = {
|
|
52
|
+
hardhat: "^2.9.9",
|
|
53
|
+
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
|
|
54
|
+
"@nomicfoundation/hardhat-chai-matchers": "^1.0.0",
|
|
52
55
|
"@nomiclabs/hardhat-ethers": "^2.0.0",
|
|
53
|
-
|
|
56
|
+
"@nomiclabs/hardhat-etherscan": "^3.0.0",
|
|
57
|
+
chai: "^4.2.0",
|
|
58
|
+
ethers: "^5.4.7",
|
|
59
|
+
"hardhat-gas-reporter": "^1.0.8",
|
|
60
|
+
"solidity-coverage": "^0.7.21",
|
|
61
|
+
"@typechain/hardhat": "^6.1.2",
|
|
62
|
+
typechain: "^8.1.0",
|
|
63
|
+
"@typechain/ethers-v5": "^10.1.0",
|
|
64
|
+
"@ethersproject/abi": "^5.4.7",
|
|
65
|
+
"@ethersproject/providers": "^5.4.7",
|
|
54
66
|
};
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
67
|
+
const TYPESCRIPT_DEPENDENCIES = {};
|
|
68
|
+
const TYPESCRIPT_PEER_DEPENDENCIES = {
|
|
69
|
+
"@types/chai": "^4.2.0",
|
|
70
|
+
"@types/mocha": "^9.1.0",
|
|
71
|
+
"@types/node": ">=12.0.0",
|
|
72
|
+
"ts-node": ">=8.0.0",
|
|
73
|
+
typescript: ">=4.5.0",
|
|
61
74
|
};
|
|
62
|
-
const TELEMETRY_CONSENT_TIMEOUT = 10000;
|
|
63
|
-
async function removeProjectDirIfPresent(projectRoot, dirName) {
|
|
64
|
-
const dirPath = path_1.default.join(projectRoot, dirName);
|
|
65
|
-
if (await fs_extra_1.default.pathExists(dirPath)) {
|
|
66
|
-
await fs_extra_1.default.remove(dirPath);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
async function removeTempFilesIfPresent(projectRoot) {
|
|
70
|
-
await removeProjectDirIfPresent(projectRoot, "cache");
|
|
71
|
-
await removeProjectDirIfPresent(projectRoot, "artifacts");
|
|
72
|
-
}
|
|
73
75
|
// generated with the "colossal" font
|
|
74
76
|
function printAsciiLogo() {
|
|
75
77
|
console.log(chalk_1.default.blue("888 888 888 888 888"));
|
|
@@ -86,56 +88,26 @@ async function printWelcomeMessage() {
|
|
|
86
88
|
const packageJson = await (0, packageInfo_1.getPackageJson)();
|
|
87
89
|
console.log(chalk_1.default.cyan(`${(0, emoji_1.emoji)("👷 ")}Welcome to ${constants_1.HARDHAT_NAME} v${packageJson.version}${(0, emoji_1.emoji)(" 👷")}\n`));
|
|
88
90
|
}
|
|
89
|
-
async function checkForDuplicates(projectRoot, projectType) {
|
|
90
|
-
const { intersection, union } = await Promise.resolve().then(() => __importStar(require("lodash")));
|
|
91
|
-
const packageRoot = (0, packageInfo_1.getPackageRoot)();
|
|
92
|
-
const srcPath = path_1.default.join(packageRoot, "sample-projects");
|
|
93
|
-
const destFiles = fs_extra_1.default.readdirSync(projectRoot);
|
|
94
|
-
let srcFiles = fs_extra_1.default.readdirSync(path_1.default.join(srcPath, "basic"));
|
|
95
|
-
switch (projectType) {
|
|
96
|
-
case Action.CREATE_ADVANCED_SAMPLE_PROJECT_ACTION:
|
|
97
|
-
srcFiles = union(srcFiles, fs_extra_1.default.readdirSync(path_1.default.join(srcPath, "advanced")));
|
|
98
|
-
break;
|
|
99
|
-
case Action.CREATE_ADVANCED_TYPESCRIPT_SAMPLE_PROJECT_ACTION:
|
|
100
|
-
srcFiles = union(srcFiles, fs_extra_1.default.readdirSync(path_1.default.join(srcPath, "advanced")), fs_extra_1.default.readdirSync(path_1.default.join(srcPath, "advanced-ts")));
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
const duplicates = intersection(srcFiles, destFiles);
|
|
104
|
-
if (duplicates.length > 0) {
|
|
105
|
-
throw new errors_1.HardhatError(errors_list_1.ERRORS.GENERAL.CONFLICTING_FILES, {
|
|
106
|
-
dest: projectRoot,
|
|
107
|
-
conflicts: duplicates.map((n) => ` ${n}`).join(os_1.default.EOL),
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
91
|
async function copySampleProject(projectRoot, projectType) {
|
|
112
92
|
const packageRoot = (0, packageInfo_1.getPackageRoot)();
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
// on top of the advanced ones.
|
|
117
|
-
await checkForDuplicates(projectRoot, projectType);
|
|
93
|
+
const sampleProjectName = projectType === Action.CREATE_JAVASCRIPT_PROJECT_ACTION
|
|
94
|
+
? "javascript"
|
|
95
|
+
: "typescript";
|
|
118
96
|
await fs_extra_1.default.ensureDir(projectRoot);
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
97
|
+
const sampleProjectPath = path_1.default.join(packageRoot, "sample-projects", sampleProjectName);
|
|
98
|
+
const sampleProjectRootFiles = fs_extra_1.default.readdirSync(sampleProjectPath);
|
|
99
|
+
const existingFiles = sampleProjectRootFiles
|
|
100
|
+
.map((f) => path_1.default.join(projectRoot, f))
|
|
101
|
+
.filter((f) => fs_extra_1.default.pathExistsSync(f))
|
|
102
|
+
.map((f) => path_1.default.relative(process.cwd(), f));
|
|
103
|
+
if (existingFiles.length > 0) {
|
|
104
|
+
const errorMsg = `We couldn't initialize the sample project because ${(0, strings_1.pluralize)(existingFiles.length, "this file already exists", "these files already exist")}: ${existingFiles.join(", ")}
|
|
105
|
+
|
|
106
|
+
Please delete or move them and try again.`;
|
|
107
|
+
console.log(chalk_1.default.red(errorMsg));
|
|
108
|
+
process.exit(1);
|
|
125
109
|
}
|
|
126
|
-
|
|
127
|
-
await fs_extra_1.default.copy(path_1.default.join(packageRoot, "sample-projects", "advanced-ts"), projectRoot);
|
|
128
|
-
for (const jsFile of [
|
|
129
|
-
"hardhat.config.js",
|
|
130
|
-
path_1.default.join("scripts", "deploy.js"),
|
|
131
|
-
path_1.default.join("test", "sample-test.js"),
|
|
132
|
-
]) {
|
|
133
|
-
await fs_extra_1.default.remove(jsFile);
|
|
134
|
-
}
|
|
135
|
-
await fs_extra_1.default.move(path_1.default.join(projectRoot, "npmignore"), path_1.default.join(projectRoot, ".npmignore"), { overwrite: true });
|
|
136
|
-
}
|
|
137
|
-
// This is just in case we have been using the sample project for dev/testing
|
|
138
|
-
await removeTempFilesIfPresent(projectRoot);
|
|
110
|
+
await fs_extra_1.default.copy(path_1.default.join(packageRoot, "sample-projects", sampleProjectName), projectRoot);
|
|
139
111
|
await fs_extra_1.default.remove(path_1.default.join(projectRoot, "LICENSE.md"));
|
|
140
112
|
}
|
|
141
113
|
async function addGitIgnore(projectRoot) {
|
|
@@ -154,26 +126,18 @@ async function printRecommendedDepsInstallationInstructions(projectType) {
|
|
|
154
126
|
console.log(` ${cmd.join(" ")}`);
|
|
155
127
|
}
|
|
156
128
|
async function writeEmptyHardhatConfig() {
|
|
157
|
-
return fs_extra_1.default.writeFile("hardhat.config.js", `/**
|
|
158
|
-
* @type import('hardhat/config').HardhatUserConfig
|
|
159
|
-
*/
|
|
129
|
+
return fs_extra_1.default.writeFile("hardhat.config.js", `/** @type import('hardhat/config').HardhatUserConfig */
|
|
160
130
|
module.exports = {
|
|
161
|
-
solidity: "
|
|
131
|
+
solidity: "0.8.9",
|
|
162
132
|
};
|
|
163
133
|
`, "utf-8");
|
|
164
134
|
}
|
|
165
135
|
async function getAction() {
|
|
166
|
-
if (process.env.
|
|
167
|
-
return Action.
|
|
168
|
-
}
|
|
169
|
-
else if (process.env.HARDHAT_CREATE_ADVANCED_SAMPLE_PROJECT_WITH_DEFAULTS !==
|
|
170
|
-
undefined) {
|
|
171
|
-
return Action.CREATE_ADVANCED_SAMPLE_PROJECT_ACTION;
|
|
136
|
+
if (process.env.HARDHAT_CREATE_JAVASCRIPT_PROJECT_WITH_DEFAULTS !== undefined) {
|
|
137
|
+
return Action.CREATE_JAVASCRIPT_PROJECT_ACTION;
|
|
172
138
|
}
|
|
173
|
-
else if (process.env
|
|
174
|
-
.
|
|
175
|
-
undefined) {
|
|
176
|
-
return Action.CREATE_ADVANCED_TYPESCRIPT_SAMPLE_PROJECT_ACTION;
|
|
139
|
+
else if (process.env.HARDHAT_CREATE_TYPESCRIPT_PROJECT_WITH_DEFAULTS !== undefined) {
|
|
140
|
+
return Action.CREATE_TYPESCRIPT_PROJECT_ACTION;
|
|
177
141
|
}
|
|
178
142
|
const { default: enquirer } = await Promise.resolve().then(() => __importStar(require("enquirer")));
|
|
179
143
|
try {
|
|
@@ -210,8 +174,13 @@ async function createPackageJson() {
|
|
|
210
174
|
name: "hardhat-project",
|
|
211
175
|
}, { spaces: 2 });
|
|
212
176
|
}
|
|
177
|
+
function showStarOnGitHubMessage() {
|
|
178
|
+
console.log(chalk_1.default.cyan("Give Hardhat a star on Github if you're enjoying it!") +
|
|
179
|
+
(0, emoji_1.emoji)(" 💞✨"));
|
|
180
|
+
console.log();
|
|
181
|
+
console.log(chalk_1.default.cyan(" https://github.com/NomicFoundation/hardhat"));
|
|
182
|
+
}
|
|
213
183
|
async function createProject() {
|
|
214
|
-
const { default: enquirer } = await Promise.resolve().then(() => __importStar(require("enquirer")));
|
|
215
184
|
printAsciiLogo();
|
|
216
185
|
await printWelcomeMessage();
|
|
217
186
|
const action = await getAction();
|
|
@@ -234,16 +203,13 @@ async function createProject() {
|
|
|
234
203
|
console.log(cmd.join(" "));
|
|
235
204
|
console.log("");
|
|
236
205
|
}
|
|
206
|
+
console.log();
|
|
207
|
+
showStarOnGitHubMessage();
|
|
237
208
|
return;
|
|
238
209
|
}
|
|
239
210
|
let responses;
|
|
240
|
-
const useDefaultPromptResponses = process.env.
|
|
241
|
-
undefined
|
|
242
|
-
process.env.HARDHAT_CREATE_ADVANCED_SAMPLE_PROJECT_WITH_DEFAULTS !==
|
|
243
|
-
undefined ||
|
|
244
|
-
process.env
|
|
245
|
-
.HARDHAT_CREATE_ADVANCED_TYPESCRIPT_SAMPLE_PROJECT_WITH_DEFAULTS !==
|
|
246
|
-
undefined;
|
|
211
|
+
const useDefaultPromptResponses = process.env.HARDHAT_CREATE_JAVASCRIPT_PROJECT_WITH_DEFAULTS !== undefined ||
|
|
212
|
+
process.env.HARDHAT_CREATE_TYPESCRIPT_PROJECT_WITH_DEFAULTS !== undefined;
|
|
247
213
|
if (useDefaultPromptResponses) {
|
|
248
214
|
responses = {
|
|
249
215
|
projectRoot: process.cwd(),
|
|
@@ -252,15 +218,7 @@ async function createProject() {
|
|
|
252
218
|
}
|
|
253
219
|
else {
|
|
254
220
|
try {
|
|
255
|
-
responses = await
|
|
256
|
-
{
|
|
257
|
-
name: "projectRoot",
|
|
258
|
-
type: "input",
|
|
259
|
-
initial: process.cwd(),
|
|
260
|
-
message: "Hardhat project root:",
|
|
261
|
-
},
|
|
262
|
-
createConfirmationPrompt("shouldAddGitIgnore", "Do you want to add a .gitignore?"),
|
|
263
|
-
]);
|
|
221
|
+
responses = await (0, prompt_1.confirmProjectCreation)();
|
|
264
222
|
}
|
|
265
223
|
catch (e) {
|
|
266
224
|
if (e === "") {
|
|
@@ -271,20 +229,19 @@ async function createProject() {
|
|
|
271
229
|
}
|
|
272
230
|
}
|
|
273
231
|
const { projectRoot, shouldAddGitIgnore } = responses;
|
|
274
|
-
await copySampleProject(projectRoot, action);
|
|
275
232
|
if (shouldAddGitIgnore) {
|
|
276
233
|
await addGitIgnore(projectRoot);
|
|
277
234
|
}
|
|
278
235
|
if ((0, global_dir_1.hasConsentedTelemetry)() === undefined) {
|
|
279
|
-
const telemetryConsent = await confirmTelemetryConsent();
|
|
236
|
+
const telemetryConsent = await (0, prompt_1.confirmTelemetryConsent)();
|
|
280
237
|
if (telemetryConsent !== undefined) {
|
|
281
238
|
(0, global_dir_1.writeTelemetryConsent)(telemetryConsent);
|
|
282
239
|
}
|
|
283
240
|
}
|
|
241
|
+
await copySampleProject(projectRoot, action);
|
|
284
242
|
let shouldShowInstallationInstructions = true;
|
|
285
243
|
if (await canInstallRecommendedDeps()) {
|
|
286
|
-
const dependencies = await getDependencies(action
|
|
287
|
-
because we already returned from this function if it isn't valid. */);
|
|
244
|
+
const dependencies = await getDependencies(action);
|
|
288
245
|
const recommendedDeps = Object.keys(dependencies);
|
|
289
246
|
const dependenciesToInstall = (0, lang_1.fromEntries)(Object.entries(dependencies).filter(([name]) => !isInstalled(name)));
|
|
290
247
|
const installedRecommendedDeps = recommendedDeps.filter(isInstalled);
|
|
@@ -294,7 +251,7 @@ async function createProject() {
|
|
|
294
251
|
}
|
|
295
252
|
else if (installedExceptHardhat.length === 0) {
|
|
296
253
|
const shouldInstall = useDefaultPromptResponses ||
|
|
297
|
-
(await confirmRecommendedDepsInstallation(dependenciesToInstall));
|
|
254
|
+
(await (0, prompt_1.confirmRecommendedDepsInstallation)(dependenciesToInstall, await isYarnProject()));
|
|
298
255
|
if (shouldInstall) {
|
|
299
256
|
const installed = await installRecommendedDependencies(dependenciesToInstall);
|
|
300
257
|
if (!installed) {
|
|
@@ -309,38 +266,12 @@ async function createProject() {
|
|
|
309
266
|
await printRecommendedDepsInstallationInstructions(action);
|
|
310
267
|
}
|
|
311
268
|
console.log(`\n${(0, emoji_1.emoji)("✨ ")}${chalk_1.default.cyan("Project created")}${(0, emoji_1.emoji)(" ✨")}`);
|
|
312
|
-
console.log(
|
|
269
|
+
console.log();
|
|
270
|
+
console.log("See the README.md file for some example tasks you can run");
|
|
271
|
+
console.log();
|
|
272
|
+
showStarOnGitHubMessage();
|
|
313
273
|
}
|
|
314
274
|
exports.createProject = createProject;
|
|
315
|
-
function createConfirmationPrompt(name, message) {
|
|
316
|
-
return {
|
|
317
|
-
type: "confirm",
|
|
318
|
-
name,
|
|
319
|
-
message,
|
|
320
|
-
initial: "y",
|
|
321
|
-
default: "(Y/n)",
|
|
322
|
-
isTrue(input) {
|
|
323
|
-
if (typeof input === "string") {
|
|
324
|
-
return input.toLowerCase() === "y";
|
|
325
|
-
}
|
|
326
|
-
return input;
|
|
327
|
-
},
|
|
328
|
-
isFalse(input) {
|
|
329
|
-
if (typeof input === "string") {
|
|
330
|
-
return input.toLowerCase() === "n";
|
|
331
|
-
}
|
|
332
|
-
return input;
|
|
333
|
-
},
|
|
334
|
-
format() {
|
|
335
|
-
const that = this;
|
|
336
|
-
const value = that.value === true ? "y" : "n";
|
|
337
|
-
if (that.state.submitted === true) {
|
|
338
|
-
return that.styles.submitted(value);
|
|
339
|
-
}
|
|
340
|
-
return value;
|
|
341
|
-
},
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
275
|
async function canInstallRecommendedDeps() {
|
|
345
276
|
return ((await fs_extra_1.default.pathExists("package.json")) &&
|
|
346
277
|
// TODO: Figure out why this doesn't work on Win
|
|
@@ -355,6 +286,16 @@ function isInstalled(dep) {
|
|
|
355
286
|
async function isYarnProject() {
|
|
356
287
|
return fs_extra_1.default.pathExists("yarn.lock");
|
|
357
288
|
}
|
|
289
|
+
async function doesNpmAutoInstallPeerDependencies() {
|
|
290
|
+
const { execSync } = require("child_process");
|
|
291
|
+
try {
|
|
292
|
+
const version = execSync("npm --version").toString();
|
|
293
|
+
return parseInt(version.split(".")[0], 10) >= 7;
|
|
294
|
+
}
|
|
295
|
+
catch (_) {
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
358
299
|
async function installRecommendedDependencies(dependencies) {
|
|
359
300
|
console.log("");
|
|
360
301
|
// The reason we don't quote the dependencies here is because they are going
|
|
@@ -363,49 +304,11 @@ async function installRecommendedDependencies(dependencies) {
|
|
|
363
304
|
const installCmd = await getRecommendedDependenciesInstallationCommand(dependencies, false);
|
|
364
305
|
return installDependencies(installCmd[0], installCmd.slice(1));
|
|
365
306
|
}
|
|
366
|
-
async function confirmRecommendedDepsInstallation(depsToInstall) {
|
|
367
|
-
const { default: enquirer } = await Promise.resolve().then(() => __importStar(require("enquirer")));
|
|
368
|
-
let responses;
|
|
369
|
-
const packageManager = (await isYarnProject()) ? "yarn" : "npm";
|
|
370
|
-
try {
|
|
371
|
-
responses = await enquirer.prompt([
|
|
372
|
-
createConfirmationPrompt("shouldInstallPlugin", `Do you want to install this sample project's dependencies with ${packageManager} (${Object.keys(depsToInstall).join(" ")})?`),
|
|
373
|
-
]);
|
|
374
|
-
}
|
|
375
|
-
catch (e) {
|
|
376
|
-
if (e === "") {
|
|
377
|
-
return false;
|
|
378
|
-
}
|
|
379
|
-
// eslint-disable-next-line @nomiclabs/hardhat-internal-rules/only-hardhat-error
|
|
380
|
-
throw e;
|
|
381
|
-
}
|
|
382
|
-
return responses.shouldInstallPlugin;
|
|
383
|
-
}
|
|
384
|
-
async function confirmTelemetryConsent() {
|
|
385
|
-
const enquirer = require("enquirer");
|
|
386
|
-
const prompt = new enquirer.prompts.Confirm({
|
|
387
|
-
name: "telemetryConsent",
|
|
388
|
-
type: "confirm",
|
|
389
|
-
initial: true,
|
|
390
|
-
message: "Help us improve Hardhat with anonymous crash reports & basic usage data?",
|
|
391
|
-
});
|
|
392
|
-
let timeout;
|
|
393
|
-
const timeoutPromise = new Promise((resolve) => {
|
|
394
|
-
timeout = setTimeout(resolve, TELEMETRY_CONSENT_TIMEOUT);
|
|
395
|
-
});
|
|
396
|
-
const result = await Promise.race([prompt.run(), timeoutPromise]);
|
|
397
|
-
clearTimeout(timeout);
|
|
398
|
-
if (result === undefined) {
|
|
399
|
-
await prompt.cancel();
|
|
400
|
-
}
|
|
401
|
-
return result;
|
|
402
|
-
}
|
|
403
|
-
exports.confirmTelemetryConsent = confirmTelemetryConsent;
|
|
404
307
|
async function installDependencies(packageManager, args) {
|
|
405
308
|
const { spawn } = await Promise.resolve().then(() => __importStar(require("child_process")));
|
|
406
309
|
console.log(`${packageManager} ${args.join(" ")}`);
|
|
407
310
|
const childProcess = spawn(packageManager, args, {
|
|
408
|
-
stdio: "inherit",
|
|
311
|
+
stdio: "inherit",
|
|
409
312
|
});
|
|
410
313
|
return new Promise((resolve, reject) => {
|
|
411
314
|
childProcess.once("close", (status) => {
|
|
@@ -430,6 +333,11 @@ async function getRecommendedDependenciesInstallationCommand(dependencies, quote
|
|
|
430
333
|
return ["npm", "install", "--save-dev", ...deps];
|
|
431
334
|
}
|
|
432
335
|
async function getDependencies(projectType) {
|
|
433
|
-
|
|
336
|
+
const shouldInstallPeerDependencies = (await isYarnProject()) || !(await doesNpmAutoInstallPeerDependencies());
|
|
337
|
+
const shouldInstallTypescriptDependencies = projectType === Action.CREATE_TYPESCRIPT_PROJECT_ACTION;
|
|
338
|
+
const shouldInstallTypescriptPeerDependencies = shouldInstallTypescriptDependencies && shouldInstallPeerDependencies;
|
|
339
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({ [HARDHAT_PACKAGE_NAME]: `^${(await (0, packageInfo_1.getPackageJson)()).version}` }, PROJECT_DEPENDENCIES), (shouldInstallPeerDependencies ? PEER_DEPENDENCIES : {})), (shouldInstallTypescriptDependencies ? TYPESCRIPT_DEPENDENCIES : {})), (shouldInstallTypescriptPeerDependencies
|
|
340
|
+
? TYPESCRIPT_PEER_DEPENDENCIES
|
|
341
|
+
: {}));
|
|
434
342
|
}
|
|
435
343
|
//# sourceMappingURL=project-creation.js.map
|