hardhat-deploy 2.0.0-next.66 → 2.0.0-next.68
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/README.md +107 -9
- package/dist/postinstall.d.ts +3 -0
- package/dist/postinstall.d.ts.map +1 -0
- package/dist/postinstall.js +130 -0
- package/dist/postinstall.js.map +1 -0
- package/dist/v1-detection.d.ts +12 -0
- package/dist/v1-detection.d.ts.map +1 -0
- package/dist/v1-detection.js +118 -0
- package/dist/v1-detection.js.map +1 -0
- package/dist/v1-entry.cjs +92 -0
- package/package.json +31 -8
- package/src/postinstall.ts +144 -0
- package/src/v1-entry.cjs +92 -0
package/README.md
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
|
-
<
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img alt="Rocketh Logo" src="./public/logo.svg" width="100"/><br/>
|
|
3
|
+
<a href="https://rocketh.dev/hardhat-deploy/">hardhat-deploy</a>
|
|
4
|
+
<hr/>
|
|
5
|
+
|
|
6
|
+
<!-- <a href="https://npmjs.com/package/hardhat-deploy"><img alt="Version" src="https://img.shields.io/npm/v/hardhat-deploy" /></a> -->
|
|
7
|
+
|
|
8
|
+
<a href="https://github.com/wighawag/hardhat-deploy/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/github/license/wighawag/hardhat-deploy" /></a>
|
|
9
|
+
<a href="https://npmjs.com/package/hardhat-deploy"><img src="https://img.shields.io/npm/dw/hardhat-deploy" alt="weekly downloads" /></a>
|
|
10
|
+
<a href="https://npmjs.com/package/hardhat-deploy"><img alt="Dependents" src="https://img.shields.io/librariesio/dependents/npm/hardhat-deploy" /></a>
|
|
11
|
+
|
|
12
|
+
<!-- <a href="https://github.com/wighawag/hardhat-deploy/stargazers"><img alt="Github Stars" src="https://img.shields.io/github/stars/wighawag/hardhat-deploy" /></a> -->
|
|
13
|
+
<!-- <a href="https://npmjs.com/package/hardhat-deploy"><img alt="Node Version" src="https://img.shields.io/node/v/hardhat-deploy"></a> -->
|
|
14
|
+
|
|
15
|
+
<a href="https://github.com/wighawag/hardhat-deploy/issues"><img alt="Issues and PRs" src="https://img.shields.io/github/issues-pr/wighawag/hardhat-deploy" /></a>
|
|
16
|
+
<a href="https://github.com/wighawag/hardhat-deploy/actions"><img alt="Tests Status" src="https://img.shields.io/github/actions/workflow/status/wighawag/hardhat-deploy/test.yml?label=test" /></a>
|
|
17
|
+
<a href="https://github.com/wighawag/hardhat-deploy/commits/main/"><img alt="Commit activity" src="https://img.shields.io/github/commit-activity/w/wighawag/hardhat-deploy" /></a>
|
|
18
|
+
<a href="https://github.com/wighawag/hardhat-deploy/commits/main/"><img alt="Last commit" src="https://img.shields.io/github/last-commit/wighawag/hardhat-deploy" /></a>
|
|
19
|
+
|
|
20
|
+
<!-- <a href="https://npmjs.com/package/hardhat-deploy"><img alt="dependencies status" src="https://img.shields.io/librariesio/release/npm/hardhat-deploy" /></a>-->
|
|
21
|
+
|
|
22
|
+
</div>
|
|
23
|
+
|
|
24
|
+
<h1>hardhat-deploy</h1>
|
|
2
25
|
|
|
3
26
|
_A [Hardhat](https://hardhat.org) Plugin For Replicable Deployments And Easy Testing_
|
|
4
27
|
|
|
@@ -6,17 +29,92 @@ _A [Hardhat](https://hardhat.org) Plugin For Replicable Deployments And Easy Tes
|
|
|
6
29
|
>
|
|
7
30
|
> Documentation for hardhat-deploy v1 can be found on the [v1 branch](https://github.com/wighawag/hardhat-deploy/tree/v1#readme)
|
|
8
31
|
|
|
9
|
-
|
|
32
|
+
## What is hardhat-deploy?
|
|
33
|
+
|
|
34
|
+
**hardhat-deploy** makes it easy for you to deploy your EVM smart contracts across many chains while keeping track of them and replicating the same environment for testing.
|
|
35
|
+
|
|
36
|
+
It adds a mechanism to associate names to addresses, so test and deployment scripts can be reconfigured by simply changing the address a name points to. This results in much clearer tests and deployment scripts — no more `accounts[0]` in your code.
|
|
37
|
+
|
|
38
|
+
## Why hardhat-deploy + rocketh?
|
|
39
|
+
|
|
40
|
+
While Hardhat's official [Ignition](https://hardhat.org/ignition) plugin offers a robust deployment system, it comes with a rigid DSL that limits flexibility. **hardhat-deploy + rocketh** provides:
|
|
41
|
+
|
|
42
|
+
- **Intuitive Deployment Scripts**: Write deployment logic in plain TypeScript without learning a new DSL.
|
|
43
|
+
- **Browser-Compatible Deployments**: Thanks to [rocketh](https://github.com/wighawag/rocketh)'s framework-agnostic design, your deployment scripts can be executed directly in the browser — enabling in-app deployments, testing in web environments, and seamless integration with web frontends.
|
|
44
|
+
- **Hot Contract Replacement (HCR)**: The equivalent of HMR (Hot Module Replacement) for smart contracts. Edit your contracts and see changes live while developing your app or game using proxy patterns with conventions that make it work seamlessly.
|
|
45
|
+
- **Flexible Proxy Patterns**: Declarative proxy deployment with `deployViaProxy` for upgradeable contracts, including support for [OpenZeppelin](https://openzeppelin.com) transparent proxies.
|
|
46
|
+
- **Diamond Support**: Deploy [EIP-2535 Diamonds](https://eips.ethereum.org/EIPS/eip-2535) declaratively — specify the new state and let hardhat-deploy generate the `diamondCut` for you.
|
|
47
|
+
- **Full Control**: Access to all deployment parameters and lifecycle hooks.
|
|
48
|
+
|
|
49
|
+
## Key Features
|
|
50
|
+
|
|
51
|
+
- **Chain configuration export** (via `@rocketh/export`) — listing deployed contracts' addresses and their ABIs (useful for web apps)
|
|
52
|
+
- **Library linking** at the time of deployment
|
|
53
|
+
- **Deterministic deployment** across networks
|
|
54
|
+
- **Support for specific deploy scripts per environment** (L1 vs L2 for example)
|
|
55
|
+
- **Deployment dependency system** — only deploy what is needed
|
|
56
|
+
- **Deployment retrying** (by saving pending tx) — recover confidently from interruptions
|
|
57
|
+
- **Deployments as test fixtures** via Hardhat helpers with caching optimization
|
|
58
|
+
- **Helpers to read and execute transactions** on deployed contracts by name
|
|
59
|
+
- **Save metadata** of deployed contracts for full verification via Sourcify or Etherscan
|
|
60
|
+
- **Contract verification** submission at any time since all necessary info is saved
|
|
61
|
+
- **Support for Hardhat's fork feature** — access deployments even when running through fork
|
|
62
|
+
|
|
63
|
+
## Architecture
|
|
64
|
+
|
|
65
|
+
Version 2 is a full rewrite that has been used in production for several years. It is fully modular, making it much easier to contribute new deployment mechanisms.
|
|
66
|
+
|
|
67
|
+
Under the hood, hardhat-deploy uses [rocketh](https://github.com/wighawag/rocketh), a framework-agnostic system that provides a minimal API to save and load deployments. Everything else is handled by external modules:
|
|
68
|
+
|
|
69
|
+
- **`@rocketh/deploy`** — provides a `deploy` function to deploy contracts
|
|
70
|
+
- **`@rocketh/proxy`** — deploy proxies declaratively like in hardhat-deploy v1
|
|
71
|
+
- **`@rocketh/diamond`** — deploy diamonds declaratively
|
|
72
|
+
- **`@rocketh/read-execute`** — helpers for reading and executing transactions
|
|
73
|
+
- **`@rocketh/viem`** — viem client integration
|
|
74
|
+
|
|
75
|
+
You can also provide your own modules for advanced use cases.
|
|
76
|
+
|
|
77
|
+
## Quick Example
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
import { deployScript, artifacts } from "../rocketh/deploy.js";
|
|
81
|
+
|
|
82
|
+
export default deployScript(
|
|
83
|
+
async ({ deployViaProxy, namedAccounts }) => {
|
|
84
|
+
const { deployer, admin } = namedAccounts;
|
|
85
|
+
|
|
86
|
+
await deployViaProxy(
|
|
87
|
+
"GreetingsRegistry",
|
|
88
|
+
{
|
|
89
|
+
account: deployer,
|
|
90
|
+
artifact: artifacts.GreetingsRegistry,
|
|
91
|
+
args: ["prefix:"],
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
owner: admin,
|
|
95
|
+
},
|
|
96
|
+
);
|
|
97
|
+
},
|
|
98
|
+
{ tags: ["GreetingsRegistry"] },
|
|
99
|
+
);
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Documentation
|
|
103
|
+
|
|
104
|
+
Please find the [full documentation here](https://rocketh.dev/hardhat-deploy/)
|
|
105
|
+
|
|
106
|
+
## Template
|
|
10
107
|
|
|
11
|
-
|
|
108
|
+
Get started quickly with the [template-ethereum-contracts](https://github.com/wighawag/template-ethereum-contracts) template that provides a production-ready setup with hardhat-deploy and rocketh.
|
|
12
109
|
|
|
13
|
-
|
|
110
|
+
## License
|
|
14
111
|
|
|
15
|
-
|
|
16
|
-
But you can provide your own module for advanced use case.
|
|
112
|
+
MIT
|
|
17
113
|
|
|
18
|
-
|
|
114
|
+
## Sponsor
|
|
19
115
|
|
|
20
|
-
|
|
116
|
+
If you find this project useful, please consider sponsoring it! Your support helps me continue developing and maintaining this tool.
|
|
21
117
|
|
|
22
|
-
|
|
118
|
+
<a href="https://github.com/sponsors/wighawag">
|
|
119
|
+
<img src="https://img.shields.io/badge/Sponsor-GitHub-181717?style=for-the-badge&logo=github&logoColor=white" alt="Sponsor on GitHub" />
|
|
120
|
+
</a>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postinstall.d.ts","sourceRoot":"","sources":["../src/postinstall.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Attempt to detect if user is in a v1 environment
|
|
3
|
+
// This script should be lightweight and fail gracefully
|
|
4
|
+
import { existsSync, readFileSync, writeFileSync } from 'fs';
|
|
5
|
+
import { join, dirname } from 'path';
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
import { createRequire } from 'module';
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = dirname(__filename);
|
|
10
|
+
const MIGRATION_URL = 'https://rocketh.dev/hardhat-deploy/documentation/how-to/migration-from-v1';
|
|
11
|
+
const V1_INSTALL_CMD = 'npm install hardhat-deploy@1';
|
|
12
|
+
const MARKER_FILE = '.hardhat-deploy-v2-notice';
|
|
13
|
+
async function checkEnvironment() {
|
|
14
|
+
const projectRoot = process.cwd();
|
|
15
|
+
let v1Detected = false;
|
|
16
|
+
let reasons = [];
|
|
17
|
+
// Check for hardhat version in node_modules
|
|
18
|
+
try {
|
|
19
|
+
const require = createRequire(import.meta.url);
|
|
20
|
+
const hardhatPkgPath = require.resolve('hardhat/package.json', { paths: [projectRoot] });
|
|
21
|
+
const hardhatPkg = JSON.parse(readFileSync(hardhatPkgPath, 'utf-8'));
|
|
22
|
+
const hardhatVersion = hardhatPkg.version;
|
|
23
|
+
if (hardhatVersion.startsWith('2.')) {
|
|
24
|
+
v1Detected = true;
|
|
25
|
+
reasons.push(`hardhat ${hardhatVersion} detected (v2 requires hardhat 3.x)`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
// Hardhat not installed yet - that's fine
|
|
30
|
+
}
|
|
31
|
+
// Check for v1-style config patterns
|
|
32
|
+
try {
|
|
33
|
+
const configFiles = ['hardhat.config.js', 'hardhat.config.ts'];
|
|
34
|
+
for (const configFile of configFiles) {
|
|
35
|
+
const configPath = join(projectRoot, configFile);
|
|
36
|
+
if (existsSync(configPath)) {
|
|
37
|
+
const content = readFileSync(configPath, 'utf-8');
|
|
38
|
+
if (content.includes('namedAccounts')) {
|
|
39
|
+
v1Detected = true;
|
|
40
|
+
reasons.push(`'namedAccounts' found in ${configFile}`);
|
|
41
|
+
}
|
|
42
|
+
if (content.includes("require('hardhat-deploy')") || content.includes('require("hardhat-deploy")')) {
|
|
43
|
+
v1Detected = true;
|
|
44
|
+
reasons.push(`require('hardhat-deploy') found in ${configFile}`);
|
|
45
|
+
}
|
|
46
|
+
if (content.includes('module.exports')) {
|
|
47
|
+
v1Detected = true;
|
|
48
|
+
reasons.push(`CommonJS 'module.exports' found in ${configFile}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
// Config check failed - continue silently
|
|
55
|
+
}
|
|
56
|
+
if (v1Detected) {
|
|
57
|
+
printV1Warning(reasons);
|
|
58
|
+
createMarkerFile(projectRoot, reasons);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
printWelcome();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function createMarkerFile(projectRoot, reasons) {
|
|
65
|
+
const markerPath = join(projectRoot, MARKER_FILE);
|
|
66
|
+
const content = `HARDHAT-DEPLOY V2 - V1 PATTERNS DETECTED
|
|
67
|
+
|
|
68
|
+
This file was created because hardhat-deploy v2 detected v1 patterns in your project.
|
|
69
|
+
You can delete this file after reading.
|
|
70
|
+
|
|
71
|
+
Detected issues:
|
|
72
|
+
${reasons.map((r) => ` - ${r}`).join('\n')}
|
|
73
|
+
|
|
74
|
+
To resolve this, either:
|
|
75
|
+
|
|
76
|
+
1. Install hardhat-deploy v1 instead:
|
|
77
|
+
npm uninstall hardhat-deploy
|
|
78
|
+
${V1_INSTALL_CMD}
|
|
79
|
+
|
|
80
|
+
2. Migrate your project to v2:
|
|
81
|
+
${MIGRATION_URL}
|
|
82
|
+
|
|
83
|
+
For more information, see the migration guide.
|
|
84
|
+
`;
|
|
85
|
+
try {
|
|
86
|
+
writeFileSync(markerPath, content, 'utf-8');
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
// Failed to write marker file - continue anyway
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function printV1Warning(reasons) {
|
|
93
|
+
const reasonsList = reasons.map((r) => ` • ${r}`).join('\n');
|
|
94
|
+
console.log(`
|
|
95
|
+
╔══════════════════════════════════════════════════════════════════════════════╗
|
|
96
|
+
║ ║
|
|
97
|
+
║ ⚠️ HARDHAT-DEPLOY V2 - V1 PATTERNS DETECTED ║
|
|
98
|
+
║ ║
|
|
99
|
+
╚══════════════════════════════════════════════════════════════════════════════╝
|
|
100
|
+
|
|
101
|
+
Your project appears to be using hardhat-deploy v1 patterns:
|
|
102
|
+
|
|
103
|
+
${reasonsList}
|
|
104
|
+
|
|
105
|
+
hardhat-deploy v2 has MAJOR breaking changes and requires hardhat 3.x.
|
|
106
|
+
|
|
107
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
108
|
+
|
|
109
|
+
OPTION 1: Install v1 instead (recommended for existing v1 projects)
|
|
110
|
+
|
|
111
|
+
npm uninstall hardhat-deploy
|
|
112
|
+
${V1_INSTALL_CMD}
|
|
113
|
+
|
|
114
|
+
OPTION 2: Migrate to v2
|
|
115
|
+
|
|
116
|
+
See: ${MIGRATION_URL}
|
|
117
|
+
|
|
118
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
119
|
+
|
|
120
|
+
A marker file '${MARKER_FILE}' has been created in your project root.
|
|
121
|
+
`);
|
|
122
|
+
}
|
|
123
|
+
function printWelcome() {
|
|
124
|
+
console.log(`
|
|
125
|
+
✓ hardhat-deploy v2 installed successfully!
|
|
126
|
+
Documentation: https://rocketh.dev/hardhat-deploy/
|
|
127
|
+
`);
|
|
128
|
+
}
|
|
129
|
+
checkEnvironment().catch(() => { });
|
|
130
|
+
//# sourceMappingURL=postinstall.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postinstall.js","sourceRoot":"","sources":["../src/postinstall.ts"],"names":[],"mappings":";AAEA,mDAAmD;AACnD,wDAAwD;AAExD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEtC,MAAM,aAAa,GAAG,2EAA2E,CAAC;AAClG,MAAM,cAAc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c,CAAC,OAAiB;IACvC,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE9D,OAAO,CAAC,GAAG,CAAC;;;;;;;;;EASZ,WAAW;;;;;;;;;IAST,cAAc;;;;SAIT,aAAa;;;;iBAIL,WAAW;CAC3B,CAAC,CAAC;AACH,CAAC;AAED,SAAS,YAAY;IACnB,OAAO,CAAC,GAAG,CAAC;;;CAGb,CAAC,CAAC;AACH,CAAC;AAED,gBAAgB,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const MIGRATION_URL = "https://rocketh.dev/hardhat-deploy/migration-from-v1";
|
|
2
|
+
export declare const V1_INSTALL_CMD = "npm install hardhat-deploy@1";
|
|
3
|
+
export interface V1DetectionResult {
|
|
4
|
+
isV1Environment: boolean;
|
|
5
|
+
reasons: string[];
|
|
6
|
+
}
|
|
7
|
+
export declare function detectV1Patterns(projectRoot?: string): V1DetectionResult;
|
|
8
|
+
export declare class V1PatternError extends Error {
|
|
9
|
+
constructor(reasons: string[]);
|
|
10
|
+
}
|
|
11
|
+
export declare function throwV1MigrationError(reasons: string[]): never;
|
|
12
|
+
//# sourceMappingURL=v1-detection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v1-detection.d.ts","sourceRoot":"","sources":["../src/v1-detection.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa,yDAAyD,CAAC;AACpF,eAAO,MAAM,cAAc,iCAAiC,CAAC;AAE7D,MAAM,WAAW,iBAAiB;IAChC,eAAe,EAAE,OAAO,CAAC;IACzB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,wBAAgB,gBAAgB,CAAC,WAAW,GAAE,MAAsB,GAAG,iBAAiB,CAevF;AA4FD,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM,EAAE;CA8B9B;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,KAAK,CAE9D"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { existsSync, readFileSync, readdirSync } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
export const MIGRATION_URL = 'https://rocketh.dev/hardhat-deploy/migration-from-v1';
|
|
4
|
+
export const V1_INSTALL_CMD = 'npm install hardhat-deploy@1';
|
|
5
|
+
export function detectV1Patterns(projectRoot = process.cwd()) {
|
|
6
|
+
const reasons = [];
|
|
7
|
+
// Check hardhat.config for v1 patterns
|
|
8
|
+
const configPatterns = checkConfigPatterns(projectRoot);
|
|
9
|
+
reasons.push(...configPatterns);
|
|
10
|
+
// Check deploy scripts for v1 patterns
|
|
11
|
+
const deployPatterns = checkDeployScripts(projectRoot);
|
|
12
|
+
reasons.push(...deployPatterns);
|
|
13
|
+
return {
|
|
14
|
+
isV1Environment: reasons.length > 0,
|
|
15
|
+
reasons,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function checkConfigPatterns(projectRoot) {
|
|
19
|
+
const reasons = [];
|
|
20
|
+
const configFiles = ['hardhat.config.js', 'hardhat.config.ts'];
|
|
21
|
+
for (const configFile of configFiles) {
|
|
22
|
+
const configPath = join(projectRoot, configFile);
|
|
23
|
+
if (existsSync(configPath)) {
|
|
24
|
+
try {
|
|
25
|
+
const content = readFileSync(configPath, 'utf-8');
|
|
26
|
+
if (content.includes('namedAccounts')) {
|
|
27
|
+
reasons.push(`Found 'namedAccounts' in ${configFile} - this is a v1 pattern. In v2, use rocketh/config.ts`);
|
|
28
|
+
}
|
|
29
|
+
if (content.includes("require('hardhat-deploy')") || content.includes('require("hardhat-deploy")')) {
|
|
30
|
+
reasons.push(`Found require('hardhat-deploy') in ${configFile} - v2 uses ESM: import HardhatDeploy from 'hardhat-deploy'`);
|
|
31
|
+
}
|
|
32
|
+
if (content.includes('module.exports')) {
|
|
33
|
+
reasons.push(`Found 'module.exports' in ${configFile} - v2 uses ESM: export default defineConfig({...})`);
|
|
34
|
+
}
|
|
35
|
+
// Check for old solidity config (non-profile based)
|
|
36
|
+
if (content.match(/solidity:\s*['"][0-9]/) || content.match(/solidity:\s*\{\s*version:/)) {
|
|
37
|
+
reasons.push(`Found old-style solidity config in ${configFile} - v2 uses profiles: solidity: { profiles: { default: { version: '...' } } }`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
// Failed to read config - continue
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return reasons;
|
|
46
|
+
}
|
|
47
|
+
function checkDeployScripts(projectRoot) {
|
|
48
|
+
const reasons = [];
|
|
49
|
+
const deployDir = join(projectRoot, 'deploy');
|
|
50
|
+
if (!existsSync(deployDir)) {
|
|
51
|
+
return reasons;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const files = readdirSync(deployDir);
|
|
55
|
+
for (const file of files) {
|
|
56
|
+
if (file.endsWith('.js') || file.endsWith('.ts')) {
|
|
57
|
+
const filePath = join(deployDir, file);
|
|
58
|
+
try {
|
|
59
|
+
const content = readFileSync(filePath, 'utf-8');
|
|
60
|
+
if (content.includes('module.exports') && content.includes('getNamedAccounts')) {
|
|
61
|
+
reasons.push(`Found v1-style deploy script: deploy/${file} - v2 uses: export default deployScript(async ({deploy, namedAccounts}) => {...})`);
|
|
62
|
+
break; // One example is enough
|
|
63
|
+
}
|
|
64
|
+
if (content.includes('deployments.deploy')) {
|
|
65
|
+
reasons.push(`Found 'deployments.deploy()' in deploy/${file} - v2 uses 'deploy()' directly with artifact parameter`);
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
if (content.includes('from:') && !content.includes('account:')) {
|
|
69
|
+
reasons.push(`Found 'from:' parameter in deploy/${file} - v2 uses 'account:' instead`);
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
// Failed to read file - continue
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
// Deploy folder scan failed - continue silently
|
|
81
|
+
}
|
|
82
|
+
return reasons;
|
|
83
|
+
}
|
|
84
|
+
export class V1PatternError extends Error {
|
|
85
|
+
constructor(reasons) {
|
|
86
|
+
const reasonsList = reasons.map((r) => ` • ${r}`).join('\n');
|
|
87
|
+
super(`
|
|
88
|
+
╔══════════════════════════════════════════════════════════════════════════════╗
|
|
89
|
+
║ HARDHAT-DEPLOY V2 - V1 PATTERNS DETECTED ║
|
|
90
|
+
╚══════════════════════════════════════════════════════════════════════════════╝
|
|
91
|
+
|
|
92
|
+
Your project uses hardhat-deploy v1 patterns that are incompatible with v2:
|
|
93
|
+
|
|
94
|
+
${reasonsList}
|
|
95
|
+
|
|
96
|
+
hardhat-deploy v2 has MAJOR breaking changes and requires hardhat 3.x with a
|
|
97
|
+
different configuration structure.
|
|
98
|
+
|
|
99
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
100
|
+
|
|
101
|
+
OPTION 1: Install v1 instead (recommended for existing v1 projects)
|
|
102
|
+
|
|
103
|
+
npm uninstall hardhat-deploy
|
|
104
|
+
${V1_INSTALL_CMD}
|
|
105
|
+
|
|
106
|
+
OPTION 2: Migrate your project to v2
|
|
107
|
+
|
|
108
|
+
Migration guide: ${MIGRATION_URL}
|
|
109
|
+
|
|
110
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
111
|
+
`);
|
|
112
|
+
this.name = 'V1PatternError';
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
export function throwV1MigrationError(reasons) {
|
|
116
|
+
throw new V1PatternError(reasons);
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=v1-detection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v1-detection.js","sourceRoot":"","sources":["../src/v1-detection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,MAAM,CAAC,MAAM,aAAa,GAAG,sDAAsD,CAAC;AACpF,MAAM,CAAC,MAAM,cAAc,GAAG,8BAA8B,CAAC;AAO7D,MAAM,UAAU,gBAAgB,CAAC,cAAsB,OAAO,CAAC,GAAG,EAAE;IAClE,MAAM,OAAO,GAAa,EAAE,CAAC;IAE7B,uCAAuC;IACvC,MAAM,cAAc,GAAG,mBAAmB,CAAC,WAAW,CAAC,CAAC;IACxD,OAAO,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC,CAAC;IAEhC,uCAAuC;IACvC,MAAM,cAAc,GAAG,kBAAkB,CAAC,WAAW,CAAC,CAAC;IACvD,OAAO,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC,CAAC;IAEhC,OAAO;QACL,eAAe,EAAE,OAAO,CAAC,MAAM,GAAG,CAAC;QACnC,OAAO;KACR,CAAC;AACJ,CAAC;AAED,SAAS,mBAAmB,CAAC,WAAmB;IAC9C,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,MAAM,WAAW,GAAG,CAAC,mBAAmB,EAAE,mBAAmB,CAAC,CAAC;IAE/D,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QACrC,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;QACjD,IAAI,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YAC3B,IAAI,CAAC;gBACH,MAAM,OAAO,GAAG,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IAUT,cAAc;;;;qBAIG,aAAa;;;CAGjC,CAAC,CAAC;QACC,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAED,MAAM,UAAU,qBAAqB,CAAC,OAAiB;IACrD,MAAM,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// This file serves as a CommonJS entry point for hardhat v2
|
|
2
|
+
// It detects v1 users and shows them a migration message
|
|
3
|
+
|
|
4
|
+
const MIGRATION_URL = 'https://rocketh.dev/hardhat-deploy/migration-from-v1';
|
|
5
|
+
const V1_INSTALL_CMD = 'npm install hardhat-deploy@1';
|
|
6
|
+
|
|
7
|
+
function getHardhatVersion() {
|
|
8
|
+
try {
|
|
9
|
+
const {execSync} = require('child_process');
|
|
10
|
+
// Run hardhat --version to get the version
|
|
11
|
+
const output = execSync('hardhat --version', {encoding: 'utf-8', stdio: 'pipe'});
|
|
12
|
+
return output.trim();
|
|
13
|
+
} catch (e) {
|
|
14
|
+
console.error(e);
|
|
15
|
+
return 'unknown';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function detectV1Patterns() {
|
|
20
|
+
const fs = require('fs');
|
|
21
|
+
const path = require('path');
|
|
22
|
+
const reasons = [];
|
|
23
|
+
|
|
24
|
+
// Check hardhat.config for v1 patterns
|
|
25
|
+
const configFiles = ['hardhat.config.js', 'hardhat.config.cjs', 'hardhat.config.ts'];
|
|
26
|
+
|
|
27
|
+
for (const configFile of configFiles) {
|
|
28
|
+
const configPath = path.join(process.cwd(), configFile);
|
|
29
|
+
if (fs.existsSync(configPath)) {
|
|
30
|
+
try {
|
|
31
|
+
const content = fs.readFileSync(configPath, 'utf-8');
|
|
32
|
+
|
|
33
|
+
if (content.includes('namedAccounts')) {
|
|
34
|
+
reasons.push(`Found 'namedAccounts' in ${configFile} - this is a v1 pattern`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (content.includes("require('hardhat-deploy')") || content.includes('require("hardhat-deploy")')) {
|
|
38
|
+
reasons.push(
|
|
39
|
+
`Found require('hardhat-deploy') in ${configFile} - v2 uses ESM: import HardhatDeploy from 'hardhat-deploy'`,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (content.includes('module.exports')) {
|
|
44
|
+
reasons.push(`Found 'module.exports' in ${configFile} - v2 uses ESM: export default defineConfig({...})`);
|
|
45
|
+
}
|
|
46
|
+
} catch (e) {
|
|
47
|
+
// Failed to read config - continue
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return reasons;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function throwV1Error() {
|
|
56
|
+
const hardhatVersion = getHardhatVersion();
|
|
57
|
+
const reasons = detectV1Patterns();
|
|
58
|
+
|
|
59
|
+
let reasonsList = '';
|
|
60
|
+
if (reasons.length > 0) {
|
|
61
|
+
reasonsList = '\nYour project uses hardhat-deploy v1 patterns:\n\n' + reasons.map((r) => ` • ${r}`).join('\n');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
throw new Error(`
|
|
65
|
+
╔══════════════════════════════════════════════════════════════════════════════╗
|
|
66
|
+
║ HARDHAT-DEPLOY V2 - INCOMPATIBLE WITH HARDHAT V2 ║
|
|
67
|
+
╚══════════════════════════════════════════════════════════════════════════════╝
|
|
68
|
+
|
|
69
|
+
hardhat-deploy v2 requires hardhat 3.x, but you are using hardhat ${hardhatVersion}.${reasonsList}
|
|
70
|
+
|
|
71
|
+
hardhat-deploy v2 has MAJOR breaking changes and uses ESM modules.
|
|
72
|
+
|
|
73
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
74
|
+
|
|
75
|
+
OPTION 1: Install hardhat-deploy v1 (recommended for hardhat v2 projects)
|
|
76
|
+
|
|
77
|
+
npm uninstall hardhat-deploy
|
|
78
|
+
${V1_INSTALL_CMD}
|
|
79
|
+
|
|
80
|
+
OPTION 2: Upgrade to hardhat 3.x and hardhat-deploy v2
|
|
81
|
+
|
|
82
|
+
Migration guide: ${MIGRATION_URL}
|
|
83
|
+
|
|
84
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
85
|
+
`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Throw error immediately when loaded by hardhat v2
|
|
89
|
+
throwV1Error();
|
|
90
|
+
|
|
91
|
+
// Export a dummy function to satisfy hardhat's plugin loading
|
|
92
|
+
module.exports = function () {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hardhat-deploy",
|
|
3
|
-
"version": "2.0.0-next.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.0.0-next.68",
|
|
4
|
+
"description": "Hardhat plugin for replicable smart contract deployments and easy testing across multiple EVM chains, with support for proxies, diamonds, named accounts, and deployment fixtures",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"hardhat",
|
|
7
|
+
"ethereum",
|
|
8
|
+
"solidity",
|
|
9
|
+
"deployment",
|
|
10
|
+
"test",
|
|
11
|
+
"cli"
|
|
12
|
+
],
|
|
13
|
+
"author": "Ronan Sandford",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"homepage": "https://github.com/wighawag/hardhat-deploy#readme",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/wighawag/hardhat-deploy.git"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/wighawag/hardhat-deploy/issues"
|
|
22
|
+
},
|
|
5
23
|
"publishConfig": {
|
|
6
24
|
"access": "public"
|
|
7
25
|
},
|
|
@@ -14,7 +32,8 @@
|
|
|
14
32
|
"import": {
|
|
15
33
|
"types": "./dist/index.d.ts",
|
|
16
34
|
"default": "./dist/index.js"
|
|
17
|
-
}
|
|
35
|
+
},
|
|
36
|
+
"require": "./dist/v1-entry.cjs"
|
|
18
37
|
},
|
|
19
38
|
"./helpers": {
|
|
20
39
|
"import": {
|
|
@@ -32,19 +51,22 @@
|
|
|
32
51
|
"bin": {
|
|
33
52
|
"hardhat-deploy": "./dist/cli.js"
|
|
34
53
|
},
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": ">=22.0.0"
|
|
56
|
+
},
|
|
35
57
|
"devDependencies": {
|
|
36
58
|
"@changesets/cli": "^2.29.8",
|
|
37
|
-
"@rocketh/node": "0.17.
|
|
59
|
+
"@rocketh/node": "0.17.21",
|
|
38
60
|
"@types/node": "^25.0.10",
|
|
39
61
|
"as-soon": "^0.1.5",
|
|
40
62
|
"hardhat": "3.1.5",
|
|
41
63
|
"rimraf": "^6.1.2",
|
|
42
|
-
"rocketh": "0.17.
|
|
64
|
+
"rocketh": "0.17.18",
|
|
43
65
|
"set-defaults": "^0.0.5",
|
|
44
66
|
"typescript": "^5.9.3"
|
|
45
67
|
},
|
|
46
68
|
"peerDependencies": {
|
|
47
|
-
"@rocketh/node": "^0.17.
|
|
69
|
+
"@rocketh/node": "^0.17.21",
|
|
48
70
|
"hardhat": "^3.1.5"
|
|
49
71
|
},
|
|
50
72
|
"dependencies": {
|
|
@@ -57,7 +79,8 @@
|
|
|
57
79
|
"zod": "^4.3.6"
|
|
58
80
|
},
|
|
59
81
|
"scripts": {
|
|
60
|
-
"build": "tsc --project tsconfig.json",
|
|
61
|
-
"dev": "as-soon -w src pnpm build"
|
|
82
|
+
"build": "tsc --project tsconfig.json && cp src/v1-entry.cjs dist/",
|
|
83
|
+
"dev": "as-soon -w src pnpm build",
|
|
84
|
+
"postinstall": "node ./dist/postinstall.js"
|
|
62
85
|
}
|
|
63
86
|
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Attempt to detect if user is in a v1 environment
|
|
4
|
+
// This script should be lightweight and fail gracefully
|
|
5
|
+
|
|
6
|
+
import { existsSync, readFileSync, writeFileSync } from 'fs';
|
|
7
|
+
import { join, dirname } from 'path';
|
|
8
|
+
import { fileURLToPath } from 'url';
|
|
9
|
+
import { createRequire } from 'module';
|
|
10
|
+
|
|
11
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
12
|
+
const __dirname = dirname(__filename);
|
|
13
|
+
|
|
14
|
+
const MIGRATION_URL = 'https://rocketh.dev/hardhat-deploy/documentation/how-to/migration-from-v1';
|
|
15
|
+
const V1_INSTALL_CMD = 'npm install hardhat-deploy@1';
|
|
16
|
+
const MARKER_FILE = '.hardhat-deploy-v2-notice';
|
|
17
|
+
|
|
18
|
+
async function checkEnvironment() {
|
|
19
|
+
const projectRoot = process.cwd();
|
|
20
|
+
let v1Detected = false;
|
|
21
|
+
let reasons: string[] = [];
|
|
22
|
+
|
|
23
|
+
// Check for hardhat version in node_modules
|
|
24
|
+
try {
|
|
25
|
+
const require = createRequire(import.meta.url);
|
|
26
|
+
const hardhatPkgPath = require.resolve('hardhat/package.json', { paths: [projectRoot] });
|
|
27
|
+
const hardhatPkg = JSON.parse(readFileSync(hardhatPkgPath, 'utf-8'));
|
|
28
|
+
const hardhatVersion = hardhatPkg.version;
|
|
29
|
+
|
|
30
|
+
if (hardhatVersion.startsWith('2.')) {
|
|
31
|
+
v1Detected = true;
|
|
32
|
+
reasons.push(`hardhat ${hardhatVersion} detected (v2 requires hardhat 3.x)`);
|
|
33
|
+
}
|
|
34
|
+
} catch (e) {
|
|
35
|
+
// Hardhat not installed yet - that's fine
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Check for v1-style config patterns
|
|
39
|
+
try {
|
|
40
|
+
const configFiles = ['hardhat.config.js', 'hardhat.config.ts'];
|
|
41
|
+
|
|
42
|
+
for (const configFile of configFiles) {
|
|
43
|
+
const configPath = join(projectRoot, configFile);
|
|
44
|
+
if (existsSync(configPath)) {
|
|
45
|
+
const content = readFileSync(configPath, 'utf-8');
|
|
46
|
+
|
|
47
|
+
if (content.includes('namedAccounts')) {
|
|
48
|
+
v1Detected = true;
|
|
49
|
+
reasons.push(`'namedAccounts' found in ${configFile}`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (content.includes("require('hardhat-deploy')") || content.includes('require("hardhat-deploy")')) {
|
|
53
|
+
v1Detected = true;
|
|
54
|
+
reasons.push(`require('hardhat-deploy') found in ${configFile}`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (content.includes('module.exports')) {
|
|
58
|
+
v1Detected = true;
|
|
59
|
+
reasons.push(`CommonJS 'module.exports' found in ${configFile}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
} catch (e) {
|
|
64
|
+
// Config check failed - continue silently
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (v1Detected) {
|
|
68
|
+
printV1Warning(reasons);
|
|
69
|
+
createMarkerFile(projectRoot, reasons);
|
|
70
|
+
} else {
|
|
71
|
+
printWelcome();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function createMarkerFile(projectRoot: string, reasons: string[]) {
|
|
76
|
+
const markerPath = join(projectRoot, MARKER_FILE);
|
|
77
|
+
const content = `HARDHAT-DEPLOY V2 - V1 PATTERNS DETECTED
|
|
78
|
+
|
|
79
|
+
This file was created because hardhat-deploy v2 detected v1 patterns in your project.
|
|
80
|
+
You can delete this file after reading.
|
|
81
|
+
|
|
82
|
+
Detected issues:
|
|
83
|
+
${reasons.map((r) => ` - ${r}`).join('\n')}
|
|
84
|
+
|
|
85
|
+
To resolve this, either:
|
|
86
|
+
|
|
87
|
+
1. Install hardhat-deploy v1 instead:
|
|
88
|
+
npm uninstall hardhat-deploy
|
|
89
|
+
${V1_INSTALL_CMD}
|
|
90
|
+
|
|
91
|
+
2. Migrate your project to v2:
|
|
92
|
+
${MIGRATION_URL}
|
|
93
|
+
|
|
94
|
+
For more information, see the migration guide.
|
|
95
|
+
`;
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
writeFileSync(markerPath, content, 'utf-8');
|
|
99
|
+
} catch (e) {
|
|
100
|
+
// Failed to write marker file - continue anyway
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function printV1Warning(reasons: string[]) {
|
|
105
|
+
const reasonsList = reasons.map((r) => ` • ${r}`).join('\n');
|
|
106
|
+
|
|
107
|
+
console.log(`
|
|
108
|
+
╔══════════════════════════════════════════════════════════════════════════════╗
|
|
109
|
+
║ ║
|
|
110
|
+
║ ⚠️ HARDHAT-DEPLOY V2 - V1 PATTERNS DETECTED ║
|
|
111
|
+
║ ║
|
|
112
|
+
╚══════════════════════════════════════════════════════════════════════════════╝
|
|
113
|
+
|
|
114
|
+
Your project appears to be using hardhat-deploy v1 patterns:
|
|
115
|
+
|
|
116
|
+
${reasonsList}
|
|
117
|
+
|
|
118
|
+
hardhat-deploy v2 has MAJOR breaking changes and requires hardhat 3.x.
|
|
119
|
+
|
|
120
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
121
|
+
|
|
122
|
+
OPTION 1: Install v1 instead (recommended for existing v1 projects)
|
|
123
|
+
|
|
124
|
+
npm uninstall hardhat-deploy
|
|
125
|
+
${V1_INSTALL_CMD}
|
|
126
|
+
|
|
127
|
+
OPTION 2: Migrate to v2
|
|
128
|
+
|
|
129
|
+
See: ${MIGRATION_URL}
|
|
130
|
+
|
|
131
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
132
|
+
|
|
133
|
+
A marker file '${MARKER_FILE}' has been created in your project root.
|
|
134
|
+
`);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function printWelcome() {
|
|
138
|
+
console.log(`
|
|
139
|
+
✓ hardhat-deploy v2 installed successfully!
|
|
140
|
+
Documentation: https://rocketh.dev/hardhat-deploy/
|
|
141
|
+
`);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
checkEnvironment().catch(() => {});
|
package/src/v1-entry.cjs
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// This file serves as a CommonJS entry point for hardhat v2
|
|
2
|
+
// It detects v1 users and shows them a migration message
|
|
3
|
+
|
|
4
|
+
const MIGRATION_URL = 'https://rocketh.dev/hardhat-deploy/migration-from-v1';
|
|
5
|
+
const V1_INSTALL_CMD = 'npm install hardhat-deploy@1';
|
|
6
|
+
|
|
7
|
+
function getHardhatVersion() {
|
|
8
|
+
try {
|
|
9
|
+
const {execSync} = require('child_process');
|
|
10
|
+
// Run hardhat --version to get the version
|
|
11
|
+
const output = execSync('hardhat --version', {encoding: 'utf-8', stdio: 'pipe'});
|
|
12
|
+
return output.trim();
|
|
13
|
+
} catch (e) {
|
|
14
|
+
console.error(e);
|
|
15
|
+
return 'unknown';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function detectV1Patterns() {
|
|
20
|
+
const fs = require('fs');
|
|
21
|
+
const path = require('path');
|
|
22
|
+
const reasons = [];
|
|
23
|
+
|
|
24
|
+
// Check hardhat.config for v1 patterns
|
|
25
|
+
const configFiles = ['hardhat.config.js', 'hardhat.config.cjs', 'hardhat.config.ts'];
|
|
26
|
+
|
|
27
|
+
for (const configFile of configFiles) {
|
|
28
|
+
const configPath = path.join(process.cwd(), configFile);
|
|
29
|
+
if (fs.existsSync(configPath)) {
|
|
30
|
+
try {
|
|
31
|
+
const content = fs.readFileSync(configPath, 'utf-8');
|
|
32
|
+
|
|
33
|
+
if (content.includes('namedAccounts')) {
|
|
34
|
+
reasons.push(`Found 'namedAccounts' in ${configFile} - this is a v1 pattern`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (content.includes("require('hardhat-deploy')") || content.includes('require("hardhat-deploy")')) {
|
|
38
|
+
reasons.push(
|
|
39
|
+
`Found require('hardhat-deploy') in ${configFile} - v2 uses ESM: import HardhatDeploy from 'hardhat-deploy'`,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (content.includes('module.exports')) {
|
|
44
|
+
reasons.push(`Found 'module.exports' in ${configFile} - v2 uses ESM: export default defineConfig({...})`);
|
|
45
|
+
}
|
|
46
|
+
} catch (e) {
|
|
47
|
+
// Failed to read config - continue
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return reasons;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function throwV1Error() {
|
|
56
|
+
const hardhatVersion = getHardhatVersion();
|
|
57
|
+
const reasons = detectV1Patterns();
|
|
58
|
+
|
|
59
|
+
let reasonsList = '';
|
|
60
|
+
if (reasons.length > 0) {
|
|
61
|
+
reasonsList = '\nYour project uses hardhat-deploy v1 patterns:\n\n' + reasons.map((r) => ` • ${r}`).join('\n');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
throw new Error(`
|
|
65
|
+
╔══════════════════════════════════════════════════════════════════════════════╗
|
|
66
|
+
║ HARDHAT-DEPLOY V2 - INCOMPATIBLE WITH HARDHAT V2 ║
|
|
67
|
+
╚══════════════════════════════════════════════════════════════════════════════╝
|
|
68
|
+
|
|
69
|
+
hardhat-deploy v2 requires hardhat 3.x, but you are using hardhat ${hardhatVersion}.${reasonsList}
|
|
70
|
+
|
|
71
|
+
hardhat-deploy v2 has MAJOR breaking changes and uses ESM modules.
|
|
72
|
+
|
|
73
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
74
|
+
|
|
75
|
+
OPTION 1: Install hardhat-deploy v1 (recommended for hardhat v2 projects)
|
|
76
|
+
|
|
77
|
+
npm uninstall hardhat-deploy
|
|
78
|
+
${V1_INSTALL_CMD}
|
|
79
|
+
|
|
80
|
+
OPTION 2: Upgrade to hardhat 3.x and hardhat-deploy v2
|
|
81
|
+
|
|
82
|
+
Migration guide: ${MIGRATION_URL}
|
|
83
|
+
|
|
84
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
85
|
+
`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Throw error immediately when loaded by hardhat v2
|
|
89
|
+
throwV1Error();
|
|
90
|
+
|
|
91
|
+
// Export a dummy function to satisfy hardhat's plugin loading
|
|
92
|
+
module.exports = function () {};
|