diff --git a/CHANGELOG.md b/CHANGELOG.md index eb236c1..d9e86a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 0.3.1 + +### Fixed + +- Foundry: after `forge build --build-info`, an edit and a plain `forge build`, the newer build info holds no compiler input and building again does not change that. slotdiff said "Build again"; it now says to run `forge build --build-info --force` or set `build_info = true`. +- The `bin` path is `dist/bin.js`: npm 11 warned that it removed `./dist/bin.js` on publish (0.3.0 still installs its `slotdiff` command). + ## 0.3.0 ### Fixed diff --git a/package.json b/package.json index f18bf96..a61de9f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "slotdiff", - "version": "0.3.0", + "version": "0.3.1", "description": "Storage layout diff for upgradeable Solidity contracts: compare a local build or a live deployment against another", "license": "MIT", "author": "Rohit Solia (https://github.com/rokso)", @@ -16,7 +16,7 @@ "main": "./dist/index.js", "types": "./dist/index.d.ts", "bin": { - "slotdiff": "./dist/bin.js" + "slotdiff": "dist/bin.js" }, "exports": { ".": { diff --git a/src/build-info.ts b/src/build-info.ts index d879f82..624a5ad 100644 --- a/src/build-info.ts +++ b/src/build-info.ts @@ -172,9 +172,15 @@ export async function findBuildInfo( if (fresh.length === 0) { throw new Error( - stale.length > 0 - ? `Every build info holding ${contract} is older than the sources on disk. Build again.` - : `${contract} is no longer on disk (moved or deleted). Build again.`, + stale.length === 0 + ? `${contract} is no longer on disk (moved or deleted). Build again.` + : withoutInput + ? // Forge then skips the unchanged files, so building again keeps the input out. + `Every build info holding ${contract} with its compiler input is older than the ` + + "sources on disk; newer build info holds no compiler input (built without " + + "`--build-info`). Run `forge build --build-info --force`, or set " + + "`build_info = true` in foundry.toml so every build keeps it." + : `Every build info holding ${contract} is older than the sources on disk. Build again.`, ); } diff --git a/test/build-info.test.ts b/test/build-info.test.ts index 34976bf..124243d 100644 --- a/test/build-info.test.ts +++ b/test/build-info.test.ts @@ -126,6 +126,16 @@ describe("findBuildInfo", () => { await expect(findBuildInfo(root, "src/Vault.sol:Vault")).rejects.toThrow(/older than the/); }); + // forge 1.8.3: `forge build --build-info`, an edit, then a plain `forge build`. + // Building again, even with --build-info, skips the unchanged files: only --force helps. + it("says how to get out of a stale build when newer builds hold no compiler input", async () => { + await put("out/build-info/a.json", foundry({ "src/Vault.sol": "old", "src/Base.sol": BASE })); + await put("out/build-info/b.json", { id: "b", source_id_to_path: { 0: "src/Vault.sol" } }); + await expect(findBuildInfo(root, "src/Vault.sol:Vault")).rejects.toThrow( + /newer build info holds no compiler input.*`forge build --build-info --force`/, + ); + }); + it("says a build of a moved or deleted target is gone", async () => { await put("out/build-info/a.json", foundry({ "src/Gone.sol": "x", "src/Base.sol": BASE })); await expect(findBuildInfo(root, "src/Gone.sol:Gone")).rejects.toThrow(/no longer on disk/); diff --git a/test/package.test.ts b/test/package.test.ts new file mode 100644 index 0000000..663506c --- /dev/null +++ b/test/package.test.ts @@ -0,0 +1,14 @@ +/** + * The published manifest, as npm reads it on publish. + */ +import { describe, it, expect } from "vitest"; +import { readFile } from "node:fs/promises"; + +describe("package.json", () => { + // npm 11 drops a bin path written as "./dist/bin.js" on publish ("script name + // ... was invalid and removed"), which would ship a package without the CLI. + it("names the CLI's file without a leading ./", async () => { + const pkg = JSON.parse(await readFile(new URL("../package.json", import.meta.url), "utf8")); + expect(pkg.bin).toEqual({ slotdiff: "dist/bin.js" }); + }); +});