hardhat-deploy 2.0.0-next.67 → 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 CHANGED
@@ -110,3 +110,11 @@ Get started quickly with the [template-ethereum-contracts](https://github.com/wi
110
110
  ## License
111
111
 
112
112
  MIT
113
+
114
+ ## Sponsor
115
+
116
+ If you find this project useful, please consider sponsoring it! Your support helps me continue developing and maintaining this tool.
117
+
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,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=postinstall.d.ts.map
@@ -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,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,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;;;;;;KAMtC,cAAc;;;KAGd,aAAa;;;CAGjB,CAAC;IAEA,IAAI,CAAC;QACH,aAAa,CAAC,UAAU,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,gDAAgD;IAClD,CAAC;AACH,CAAC;AAED,SAAS,cAAc,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;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Q,CAAC,UAAU,CAAC,EAAE,CAAC;wBAC/D,OAAO,CAAC,IAAI,CAAC,qCAAqC,IAAI,+BAA+B,CAAC,CAAC;wBACvF,MAAM;oBACR,CAAC;gBACH,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACX,iCAAiC;gBACnC,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,gDAAgD;IAClD,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,YAAY,OAAiB;QAC3B,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAE9D,KAAK,CAAC;;;;;;;EAOR,WAAW;;;;;;;;;;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,6 +1,6 @@
1
1
  {
2
2
  "name": "hardhat-deploy",
3
- "version": "2.0.0-next.67",
3
+ "version": "2.0.0-next.68",
4
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
5
  "keywords": [
6
6
  "hardhat",
@@ -32,7 +32,8 @@
32
32
  "import": {
33
33
  "types": "./dist/index.d.ts",
34
34
  "default": "./dist/index.js"
35
- }
35
+ },
36
+ "require": "./dist/v1-entry.cjs"
36
37
  },
37
38
  "./helpers": {
38
39
  "import": {
@@ -78,7 +79,8 @@
78
79
  "zod": "^4.3.6"
79
80
  },
80
81
  "scripts": {
81
- "build": "tsc --project tsconfig.json",
82
- "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"
83
85
  }
84
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(() => {});
@@ -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 () {};