forge-pack 0.1.0 → 0.2.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/README.md +88 -0
- package/dist/cli.d.mts +1 -0
- package/dist/{cli.js → cli.mjs} +1 -2
- package/dist/{index.js → index.mjs} +1 -1
- package/package.json +20 -10
- package/dist/cli-Dc4X1WbF.d.ts +0 -1
- package/dist/index.d.ts +0 -68
- /package/dist/{index-ECFAYGrl.d.ts → index.d.mts} +0 -0
- /package/dist/{pack-A6vKuf56.js → pack-Be_7Cz7w.mjs} +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# forge-pack
|
|
2
|
+
|
|
3
|
+
Generate self-contained Solidity deployer libraries from [Forge](https://book.getfoundry.sh/) build artifacts.
|
|
4
|
+
|
|
5
|
+
`forge-pack` reads your compiled contract JSON, resolves library dependencies, and outputs a single `.sol` file containing a deployer library with `deploy()`, `deploy2()` (CREATE2), and `initcode()` functions — ready to use in scripts or tests.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
The package does not require installation, you can directly use `npx`/`pnpx` to run it:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npx forge-pack@latest <contract-name>
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## CLI Usage
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
forge-pack <ContractName> [options]
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Options
|
|
22
|
+
|
|
23
|
+
| Flag | Description | Default |
|
|
24
|
+
| ------------------ | ------------------------------------------ | ------------- |
|
|
25
|
+
| `--out <dir>` | Forge output directory | `./out` |
|
|
26
|
+
| `--output <dir>` | Where to write the deployer `.sol` file | `./deployers` |
|
|
27
|
+
| `--build` | Run `forge build` before reading artifacts | `false` |
|
|
28
|
+
| `--pragma <range>` | Solidity pragma for generated file | `>=0.8.0` |
|
|
29
|
+
| `-h, --help` | Show help message | — |
|
|
30
|
+
|
|
31
|
+
### Example
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# Generate a deployer for MyToken
|
|
35
|
+
forge-pack MyToken
|
|
36
|
+
|
|
37
|
+
# Build first, then generate with a specific pragma
|
|
38
|
+
forge-pack MyToken --build --pragma "^0.8.20"
|
|
39
|
+
|
|
40
|
+
# Use a custom output directory
|
|
41
|
+
forge-pack MyToken --output src/deployers
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
This produces a file like `deployers/MyTokenDeployer.sol`:
|
|
45
|
+
|
|
46
|
+
```solidity
|
|
47
|
+
// SPDX-License-Identifier: UNLICENSED
|
|
48
|
+
pragma solidity >=0.8.0;
|
|
49
|
+
|
|
50
|
+
library MyTokenDeployer {
|
|
51
|
+
function deploy(string memory name, string memory symbol) internal returns (address deployed) { ... }
|
|
52
|
+
function deploy2(bytes32 salt, string memory name, string memory symbol) internal returns (address deployed) { ... }
|
|
53
|
+
function initcode(string memory name, string memory symbol) internal pure returns (bytes memory) { ... }
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Constructor parameters are automatically extracted from the ABI. Struct types used in constructor arguments get their definitions included in the generated file.
|
|
58
|
+
|
|
59
|
+
## Library Dependencies
|
|
60
|
+
|
|
61
|
+
If your contract links against external libraries, `forge-pack` resolves them recursively in topological order and generates inline deployment helpers. The deployer handles deploying libraries before the main contract, so the output remains self-contained.
|
|
62
|
+
|
|
63
|
+
## Programmatic API
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import { findArtifact, parseArtifact, generateDeployer, resolveLibraries } from "forge-pack";
|
|
67
|
+
|
|
68
|
+
const artifactPath = findArtifact("MyToken", "./out");
|
|
69
|
+
const parsed = parseArtifact(artifactPath, "MyToken");
|
|
70
|
+
|
|
71
|
+
const libraries = resolveLibraries(parsed.linkReferences, "./out");
|
|
72
|
+
const solidity = generateDeployer(parsed, { pragma: ">=0.8.0", libraries });
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Exports
|
|
76
|
+
|
|
77
|
+
**Functions:**
|
|
78
|
+
|
|
79
|
+
- `findArtifact(contractName, outDir, options?)` — Locate a contract artifact in the Forge output directory
|
|
80
|
+
- `parseArtifact(artifactPath, contractName)` — Parse a Forge artifact JSON into a structured object
|
|
81
|
+
- `resolveLibraries(linkReferences, outDir)` — Recursively resolve library dependencies in deploy order
|
|
82
|
+
- `generateDeployer(parsed, options?)` — Generate Solidity deployer library source code
|
|
83
|
+
|
|
84
|
+
**Types:** `ParsedArtifact`, `LinkReference`, `LinkReferences`, `AbiParam`, `AbiEntry`, `FindArtifactOptions`, `ResolvedLibrary`, `GenerateDeployerOptions`
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
|
|
88
|
+
MIT
|
package/dist/cli.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/{cli.js → cli.mjs}
RENAMED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { i as resolveLibraries, n as generateDeployer, r as parseArtifact, t as findArtifact } from "./pack-A6vKuf56.js";
|
|
1
|
+
import { i as resolveLibraries, n as generateDeployer, r as parseArtifact, t as findArtifact } from "./pack-Be_7Cz7w.mjs";
|
|
3
2
|
import { parseArgs } from "node:util";
|
|
4
3
|
import { execSync } from "node:child_process";
|
|
5
4
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { i as resolveLibraries, n as generateDeployer, r as parseArtifact, t as findArtifact } from "./pack-
|
|
1
|
+
import { i as resolveLibraries, n as generateDeployer, r as parseArtifact, t as findArtifact } from "./pack-Be_7Cz7w.mjs";
|
|
2
2
|
|
|
3
3
|
export { findArtifact, generateDeployer, parseArtifact, resolveLibraries };
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "forge-pack",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Generate self-contained Solidity deployer files from Forge build artifacts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
|
-
"forge-pack": "./dist/cli.
|
|
7
|
+
"forge-pack": "./dist/cli.mjs"
|
|
8
8
|
},
|
|
9
|
-
"main": "./dist/index.
|
|
10
|
-
"types": "./dist/index.d.
|
|
9
|
+
"main": "./dist/index.mjs",
|
|
10
|
+
"types": "./dist/index.d.mts",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
-
"import": "./dist/index.
|
|
14
|
-
"types": "./dist/index.d.
|
|
13
|
+
"import": "./dist/index.mjs",
|
|
14
|
+
"types": "./dist/index.d.mts"
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
@@ -24,10 +24,17 @@
|
|
|
24
24
|
"deployer",
|
|
25
25
|
"bytecode"
|
|
26
26
|
],
|
|
27
|
-
"
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/akshatmittal/forge-pack.git"
|
|
30
|
+
},
|
|
31
|
+
"author": "Akshat Mittal <hi@akshatmittal.com>",
|
|
28
32
|
"license": "MIT",
|
|
29
33
|
"devDependencies": {
|
|
30
|
-
"
|
|
34
|
+
"@changesets/changelog-github": "^0.5.2",
|
|
35
|
+
"@changesets/cli": "^2.29.8",
|
|
36
|
+
"@changesets/config": "^3.1.2",
|
|
37
|
+
"tsdown": "^0.20.3",
|
|
31
38
|
"typescript": "^5.8.3",
|
|
32
39
|
"@types/node": "^24.10.13"
|
|
33
40
|
},
|
|
@@ -35,7 +42,10 @@
|
|
|
35
42
|
"access": "public"
|
|
36
43
|
},
|
|
37
44
|
"scripts": {
|
|
38
|
-
"build": "tsdown
|
|
39
|
-
"dev": "tsdown --watch"
|
|
45
|
+
"build": "tsdown",
|
|
46
|
+
"dev": "tsdown --watch",
|
|
47
|
+
"changeset": "changeset",
|
|
48
|
+
"version": "changeset version",
|
|
49
|
+
"release": "changeset publish"
|
|
40
50
|
}
|
|
41
51
|
}
|
package/dist/cli-Dc4X1WbF.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/index.d.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
//#region src/pack.d.ts
|
|
2
|
-
interface LinkReference {
|
|
3
|
-
start: number;
|
|
4
|
-
length: number;
|
|
5
|
-
}
|
|
6
|
-
interface LinkReferences {
|
|
7
|
-
[file: string]: {
|
|
8
|
-
[lib: string]: LinkReference[];
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
interface AbiParam {
|
|
12
|
-
name: string;
|
|
13
|
-
type: string;
|
|
14
|
-
internalType?: string;
|
|
15
|
-
components?: AbiParam[];
|
|
16
|
-
indexed?: boolean;
|
|
17
|
-
}
|
|
18
|
-
interface AbiEntry {
|
|
19
|
-
type: string;
|
|
20
|
-
name?: string;
|
|
21
|
-
inputs?: AbiParam[];
|
|
22
|
-
outputs?: AbiParam[];
|
|
23
|
-
stateMutability?: string;
|
|
24
|
-
}
|
|
25
|
-
interface ParsedArtifact {
|
|
26
|
-
contractName: string;
|
|
27
|
-
abi: AbiEntry[];
|
|
28
|
-
bytecode: string;
|
|
29
|
-
linkReferences: LinkReferences;
|
|
30
|
-
sourcePath?: string;
|
|
31
|
-
solcVersion?: string;
|
|
32
|
-
optimizerRuns?: number;
|
|
33
|
-
viaIR?: boolean;
|
|
34
|
-
evmVersion?: string;
|
|
35
|
-
}
|
|
36
|
-
interface FindArtifactOptions {
|
|
37
|
-
solcVersion?: string;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* A library dependency resolved from linkReferences, with its own parsed
|
|
41
|
-
* artifact and the param name used in generated code.
|
|
42
|
-
*/
|
|
43
|
-
interface ResolvedLibrary {
|
|
44
|
-
/** Parameter-style name, e.g. "mathLib" */
|
|
45
|
-
paramName: string;
|
|
46
|
-
/** Source file declaring the library, e.g. "src/libs/MathLib.sol" */
|
|
47
|
-
file: string;
|
|
48
|
-
/** Library contract name, e.g. "MathLib" */
|
|
49
|
-
lib: string;
|
|
50
|
-
/** Parsed artifact for this library */
|
|
51
|
-
artifact: ParsedArtifact;
|
|
52
|
-
/** Param names of libraries this library depends on (its own linkReferences) */
|
|
53
|
-
deps: string[];
|
|
54
|
-
}
|
|
55
|
-
declare function findArtifact(contractName: string, outDir: string, options?: FindArtifactOptions): string;
|
|
56
|
-
declare function parseArtifact(artifactPath: string, contractName: string): ParsedArtifact;
|
|
57
|
-
/**
|
|
58
|
-
* Recursively resolve all library dependencies for a contract's linkReferences.
|
|
59
|
-
* Returns libraries in topological order (deploy-order: leaves first).
|
|
60
|
-
*/
|
|
61
|
-
declare function resolveLibraries(linkRefs: LinkReferences, outDir: string): ResolvedLibrary[];
|
|
62
|
-
interface GenerateDeployerOptions {
|
|
63
|
-
pragma?: string;
|
|
64
|
-
libraries?: ResolvedLibrary[];
|
|
65
|
-
}
|
|
66
|
-
declare function generateDeployer(parsed: ParsedArtifact, pragmaOrOpts?: string | GenerateDeployerOptions): string;
|
|
67
|
-
//#endregion
|
|
68
|
-
export { type AbiEntry, type AbiParam, type FindArtifactOptions, type GenerateDeployerOptions, type LinkReference, type LinkReferences, type ParsedArtifact, type ResolvedLibrary, findArtifact, generateDeployer, parseArtifact, resolveLibraries };
|
|
File without changes
|
|
File without changes
|