mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-17 03:10:38 +09:00
fix: harden worktree dependency hydration
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
parent
8ae4c0e765
commit
c19208010a
2 changed files with 60 additions and 28 deletions
|
|
@ -335,6 +335,18 @@ disable_seeded_routines() {
|
||||||
|
|
||||||
disable_seeded_routines
|
disable_seeded_routines
|
||||||
|
|
||||||
|
list_base_node_modules_paths() {
|
||||||
|
cd "$base_cwd" &&
|
||||||
|
find . \
|
||||||
|
-mindepth 1 \
|
||||||
|
-maxdepth 4 \
|
||||||
|
-type d \
|
||||||
|
-name node_modules \
|
||||||
|
! -path './.git/*' \
|
||||||
|
! -path './.paperclip/*' \
|
||||||
|
| sed 's#^\./##'
|
||||||
|
}
|
||||||
|
|
||||||
if [[ -f "$worktree_cwd/package.json" && -f "$worktree_cwd/pnpm-lock.yaml" ]]; then
|
if [[ -f "$worktree_cwd/package.json" && -f "$worktree_cwd/pnpm-lock.yaml" ]]; then
|
||||||
needs_install=0
|
needs_install=0
|
||||||
|
|
||||||
|
|
@ -342,32 +354,56 @@ if [[ -f "$worktree_cwd/package.json" && -f "$worktree_cwd/pnpm-lock.yaml" ]]; t
|
||||||
[[ -n "$relative_path" ]] || continue
|
[[ -n "$relative_path" ]] || continue
|
||||||
target_path="$worktree_cwd/$relative_path"
|
target_path="$worktree_cwd/$relative_path"
|
||||||
|
|
||||||
if [[ -L "$target_path" ]]; then
|
if [[ -L "$target_path" || ! -e "$target_path" ]]; then
|
||||||
rm "$target_path"
|
|
||||||
needs_install=1
|
needs_install=1
|
||||||
continue
|
break
|
||||||
fi
|
fi
|
||||||
|
done < <(list_base_node_modules_paths)
|
||||||
if [[ ! -e "$target_path" ]]; then
|
|
||||||
needs_install=1
|
|
||||||
fi
|
|
||||||
done < <(
|
|
||||||
cd "$base_cwd" &&
|
|
||||||
find . \
|
|
||||||
-mindepth 1 \
|
|
||||||
-maxdepth 3 \
|
|
||||||
-type d \
|
|
||||||
-name node_modules \
|
|
||||||
! -path './.git/*' \
|
|
||||||
! -path './.paperclip/*' \
|
|
||||||
| sed 's#^\./##'
|
|
||||||
)
|
|
||||||
|
|
||||||
if [[ "$needs_install" -eq 1 ]]; then
|
if [[ "$needs_install" -eq 1 ]]; then
|
||||||
|
backup_suffix=".paperclip-backup-$BASHPID"
|
||||||
|
moved_symlink_paths=()
|
||||||
|
|
||||||
|
while IFS= read -r relative_path; do
|
||||||
|
[[ -n "$relative_path" ]] || continue
|
||||||
|
target_path="$worktree_cwd/$relative_path"
|
||||||
|
if [[ -L "$target_path" ]]; then
|
||||||
|
backup_path="${target_path}${backup_suffix}"
|
||||||
|
rm -rf "$backup_path"
|
||||||
|
mv "$target_path" "$backup_path"
|
||||||
|
moved_symlink_paths+=("$relative_path")
|
||||||
|
fi
|
||||||
|
done < <(list_base_node_modules_paths)
|
||||||
|
|
||||||
|
restore_moved_symlinks() {
|
||||||
|
local relative_path target_path backup_path
|
||||||
|
for relative_path in "${moved_symlink_paths[@]}"; do
|
||||||
|
target_path="$worktree_cwd/$relative_path"
|
||||||
|
backup_path="${target_path}${backup_suffix}"
|
||||||
|
[[ -L "$backup_path" ]] || continue
|
||||||
|
rm -rf "$target_path"
|
||||||
|
mv "$backup_path" "$target_path"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup_moved_symlinks() {
|
||||||
|
local relative_path target_path backup_path
|
||||||
|
for relative_path in "${moved_symlink_paths[@]}"; do
|
||||||
|
target_path="$worktree_cwd/$relative_path"
|
||||||
|
backup_path="${target_path}${backup_suffix}"
|
||||||
|
[[ -L "$backup_path" ]] && rm "$backup_path"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
(
|
(
|
||||||
cd "$worktree_cwd"
|
cd "$worktree_cwd"
|
||||||
pnpm install --frozen-lockfile
|
pnpm install --frozen-lockfile
|
||||||
)
|
) || {
|
||||||
|
restore_moved_symlinks
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup_moved_symlinks
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
@ -384,13 +420,5 @@ while IFS= read -r relative_path; do
|
||||||
mkdir -p "$(dirname "$target_path")"
|
mkdir -p "$(dirname "$target_path")"
|
||||||
ln -s "$source_path" "$target_path"
|
ln -s "$source_path" "$target_path"
|
||||||
done < <(
|
done < <(
|
||||||
cd "$base_cwd" &&
|
list_base_node_modules_paths
|
||||||
find . \
|
|
||||||
-mindepth 1 \
|
|
||||||
-maxdepth 3 \
|
|
||||||
-type d \
|
|
||||||
-name node_modules \
|
|
||||||
! -path './.git/*' \
|
|
||||||
! -path './.paperclip/*' \
|
|
||||||
| sed 's#^\./##'
|
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -779,6 +779,8 @@ function enrichWakeContextSnapshot(input: {
|
||||||
contextSnapshot[WAKE_COMMENT_IDS_KEY] = wakeCommentIds;
|
contextSnapshot[WAKE_COMMENT_IDS_KEY] = wakeCommentIds;
|
||||||
contextSnapshot.commentId = latestCommentId;
|
contextSnapshot.commentId = latestCommentId;
|
||||||
contextSnapshot.wakeCommentId = latestCommentId;
|
contextSnapshot.wakeCommentId = latestCommentId;
|
||||||
|
// Once comment ids are normalized into the snapshot, rebuild the structured
|
||||||
|
// wake payload from those ids later instead of carrying forward stale data.
|
||||||
delete contextSnapshot[PAPERCLIP_WAKE_PAYLOAD_KEY];
|
delete contextSnapshot[PAPERCLIP_WAKE_PAYLOAD_KEY];
|
||||||
} else if (!readNonEmptyString(contextSnapshot["wakeCommentId"]) && wakeCommentId) {
|
} else if (!readNonEmptyString(contextSnapshot["wakeCommentId"]) && wakeCommentId) {
|
||||||
contextSnapshot.wakeCommentId = wakeCommentId;
|
contextSnapshot.wakeCommentId = wakeCommentId;
|
||||||
|
|
@ -814,6 +816,8 @@ export function mergeCoalescedContextSnapshot(
|
||||||
merged[WAKE_COMMENT_IDS_KEY] = mergedCommentIds;
|
merged[WAKE_COMMENT_IDS_KEY] = mergedCommentIds;
|
||||||
merged.commentId = latestCommentId;
|
merged.commentId = latestCommentId;
|
||||||
merged.wakeCommentId = latestCommentId;
|
merged.wakeCommentId = latestCommentId;
|
||||||
|
// The merged context should carry canonical comment ids; the next wake will
|
||||||
|
// regenerate any structured payload from those ids.
|
||||||
delete merged[PAPERCLIP_WAKE_PAYLOAD_KEY];
|
delete merged[PAPERCLIP_WAKE_PAYLOAD_KEY];
|
||||||
}
|
}
|
||||||
return merged;
|
return merged;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue