Skip to content

Commit 0b63cae

Browse files
fix: update pre-push hook to allow caret version differences (#9876)
Co-authored-by: randymcmillan <randymcmillan@protonmail.com>
1 parent b7b2eae commit 0b63cae

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

.husky/pre-push

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
#!/bin/sh
2+
set -e
23
# Check if bun version matches package.json
3-
EXPECTED_VERSION=$(grep '"packageManager"' package.json | sed 's/.*"bun@\([^"]*\)".*/\1/')
4-
CURRENT_VERSION=$(bun --version)
5-
if [ "$CURRENT_VERSION" != "$EXPECTED_VERSION" ]; then
6-
echo "Error: Bun version $CURRENT_VERSION does not match expected version $EXPECTED_VERSION from package.json"
7-
exit 1
8-
fi
4+
# keep in sync with packages/script/src/index.ts semver qualifier
5+
bun -e '
6+
import { semver } from "bun";
7+
const pkg = await Bun.file("package.json").json();
8+
const expectedBunVersion = pkg.packageManager?.split("@")[1];
9+
if (!expectedBunVersion) {
10+
throw new Error("packageManager field not found in root package.json");
11+
}
12+
const expectedBunVersionRange = `^${expectedBunVersion}`;
13+
if (!semver.satisfies(process.versions.bun, expectedBunVersionRange)) {
14+
throw new Error(`This script requires bun@${expectedBunVersionRange}, but you are using bun@${process.versions.bun}`);
15+
}
16+
if (process.versions.bun !== expectedBunVersion) {
17+
console.warn(`Warning: Bun version ${process.versions.bun} differs from expected ${expectedBunVersion}`);
18+
}
19+
'
920
bun typecheck

0 commit comments

Comments
 (0)