Skip to content

Commit 8c6f33b

Browse files
committed
AG-46750 Add protection against packageManager field
Squashed commit of the following: commit 3c2ea77 Author: scripthunter7 <d.tota@adguard.com> Date: Tue Sep 30 12:28:41 2025 +0200 Remove packageManager field from package.json and update pre-commit hook to check for its presence
1 parent 84a037f commit 8c6f33b

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

.husky/pre-commit

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,22 @@
44
pnpm test:compile
55
pnpm lint:staged
66
pnpm test
7+
8+
if git diff --cached --name-only | grep -q "package.json"; then
9+
echo "package.json is being committed. Checking if packageManager field is present..."
10+
11+
if pnpm pkg get packageManager > /dev/null 2>&1; then
12+
echo "packageManager field in package.json is present, need to remove it before committing"
13+
14+
PACKAGE_JSON_HASH=$(git hash-object -w package.json)
15+
16+
pnpm pkg delete packageManager
17+
echo "packageManager field removed from package.json"
18+
19+
git add package.json
20+
echo "modified package.json staged for commit"
21+
22+
git cat-file -p "$PACKAGE_JSON_HASH" > package.json
23+
echo "package.json content restored"
24+
fi
25+
fi

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,5 @@
168168
},
169169
"pnpm": {
170170
"neverBuiltDependencies": []
171-
},
172-
"packageManager": "pnpm@10.17.1+sha512.17c560fca4867ae9473a3899ad84a88334914f379be46d455cbf92e5cf4b39d34985d452d2583baf19967fa76cb5c17bc9e245529d0b98745721aa7200ecaf7a"
171+
}
173172
}

0 commit comments

Comments
 (0)