Skip to content

Commit ccd31e4

Browse files
authored
fix: include build script in contract hash calculation (#4399)
- generated: compute hash from both src and build-contract-types.sh - contracts: write combined hash to .contracts-hash file - prevents stale npm artifacts when build script changes (e.g., adding/removing contracts)
1 parent 1ebec39 commit ccd31e4

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

packages/contracts/scripts/build-contract-types.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ done
2929

3030
# Generate contract hash for this artifact build
3131
echo "Generating contract hash..."
32-
CONTRACTS_HASH=$(git rev-parse HEAD:./src 2>/dev/null || echo "")
32+
SRC_HASH=$(git rev-parse HEAD:./src 2>/dev/null || echo "")
33+
BUILD_SCRIPT_HASH=$(git rev-parse HEAD:./scripts/build-contract-types.sh 2>/dev/null || echo "")
3334

34-
if [ -n "$CONTRACTS_HASH" ]; then
35+
if [ -n "$SRC_HASH" ] && [ -n "$BUILD_SCRIPT_HASH" ]; then
36+
CONTRACTS_HASH="$SRC_HASH:$BUILD_SCRIPT_HASH"
3537
echo "$CONTRACTS_HASH" > "$PARENT_DIR/generated/dev/.contracts-hash"
3638
echo "Contract hash: $CONTRACTS_HASH"
3739
else

packages/generated/scripts/prepare.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,22 @@ function generatedFilesExist() {
3939

4040
// Get git hash of contracts directory
4141
function getContractsHash() {
42-
if (!existsSync(resolve(contractsDir, 'src'))) return null;
42+
if (!existsSync(contractsDir)) return null;
4343

4444
try {
45-
return execSync('git rev-parse HEAD:./src', {
45+
const srcHash = execSync('git rev-parse HEAD:./src', {
4646
cwd: contractsDir,
4747
encoding: 'utf8',
4848
stdio: 'pipe'
4949
}).trim();
50+
51+
const buildScriptHash = execSync('git rev-parse HEAD:./scripts/build-contract-types.sh', {
52+
cwd: contractsDir,
53+
encoding: 'utf8',
54+
stdio: 'pipe'
55+
}).trim();
56+
57+
return `${srcHash}:${buildScriptHash}`;
5058
} catch (error) {
5159
return null; // Not in git repo or other error
5260
}

0 commit comments

Comments
 (0)