Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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)",
Expand All @@ -16,7 +16,7 @@
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"bin": {
"slotdiff": "./dist/bin.js"
"slotdiff": "dist/bin.js"
},
"exports": {
".": {
Expand Down
12 changes: 9 additions & 3 deletions src/build-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
);
}

Expand Down
10 changes: 10 additions & 0 deletions test/build-info.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
Expand Down
14 changes: 14 additions & 0 deletions test/package.test.ts
Original file line number Diff line number Diff line change
@@ -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" });
});
});
Loading