Skip to content

Commit f43ef43

Browse files
committed
fix: make replace_first fail on missing patterns and validate lockfiles
- Add EXIT block to awk so replace_first exits with code 2 when the pattern is not found, preventing silent no-ops - Add post-replacement grep validation in restore_twig_npm and restore_twig_bun to catch any remaining PLACEHOLDER values
1 parent 47b4de5 commit f43ef43

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

scripts/update-lockfiles.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ strip_twig() {
2222

2323
replace_first() {
2424
# POSIX-portable first-match replacement (no GNU sed required).
25+
# Exits with code 2 if the pattern is not found.
2526
# Usage: replace_first <file> <literal_old> <literal_new>
2627
local file="$1" old="$2" new="$3"
2728
awk -v o="$old" -v n="$new" -v done=0 \
28-
'{ if (!done && index($0, o)) { sub(o, n); done=1 } print }' \
29+
'{ if (!done && index($0, o)) { sub(o, n); done=1 } print } END { exit(done ? 0 : 2) }' \
2930
"$file" > "${file}.tmp" && mv "${file}.tmp" "$file"
3031
}
3132

@@ -42,6 +43,11 @@ restore_twig_npm() {
4243
replace_first "$lockfile" '"name": "PLACEHOLDER"' "\"name\": \"${twig_name}\""
4344
replace_first "$lockfile" '"version": "PLACEHOLDER"' '"version": "{{ sdk.version }}"'
4445
replace_first "$lockfile" '"license": "PLACEHOLDER"' '"license": "{{ sdk.license }}"'
46+
47+
if grep -q '"PLACEHOLDER"' "$lockfile"; then
48+
echo "ERROR: unresolved PLACEHOLDER values remain in $lockfile" >&2
49+
return 1
50+
fi
4551
}
4652

4753
restore_twig_bun() {
@@ -50,6 +56,11 @@ restore_twig_bun() {
5056
local twig_name="$2"
5157

5258
replace_first "$lockfile" '"name": "PLACEHOLDER"' "\"name\": \"${twig_name}\""
59+
60+
if grep -q '"PLACEHOLDER"' "$lockfile"; then
61+
echo "ERROR: unresolved PLACEHOLDER values remain in $lockfile" >&2
62+
return 1
63+
fi
5364
}
5465

5566
update_npm() {

0 commit comments

Comments
 (0)