Add warning at delete contents for Linux users on @fedify/init - #992
Add warning at delete contents for Linux users on @fedify/init#992lego37yoon wants to merge 4 commits into
@fedify/init#992Conversation
✅ Deploy Preview for fedify-json-schema canceled.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesProject directory cleanup
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant FedifyInit
participant ActionPlanner
participant CommandExecutor
FedifyInit->>ActionPlanner: Select cleanup mode by operating system
ActionPlanner->>FedifyInit: Request mode-specific confirmation
FedifyInit->>CommandExecutor: Execute trash or permanent-delete command
CommandExecutor-->>FedifyInit: Return success or mode-specific failure
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@changes.d/init/permanent-delete.md`:
- Around line 1-2: Correct the release-note grammar in
changes.d/init/permanent-delete.md lines 1-2 and CHANGES.md lines 178-179 by
changing “before delete” to “before deleting” and referring to the existing
contents.
In `@packages/init/src/ask/dir.ts`:
- Around line 123-127: Update the command builder around
getPowershellTrashCommand to escape apostrophes in dir by doubling them before
interpolation into the PowerShell single-quoted literal. Preserve existing path
behavior and add a Windows test covering a directory path containing an
apostrophe.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 593d4915-bb1e-4486-9907-cc88fd8527b3
📒 Files selected for processing (3)
CHANGES.mdchanges.d/init/permanent-delete.mdpackages/init/src/ask/dir.ts
| command: (dir: string) => [ | ||
| "powershell", | ||
| "-Command", | ||
| getPowershellTrashCommand(dir), | ||
| ], |
There was a problem hiding this comment.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "Files matching dir.ts:"
fd -a 'dir\.ts$' . || true
file="$(fd 'dir\.ts$' . | grep 'packages/init/src/ask/dir.ts' | head -n 1 || true)"
echo "Target file: $file"
if [ -n "$file" ]; then
wc -l "$file"
sed -n '1,180p' "$file" | cat -n
fi
echo
echo "Search PowerShell command construction:"
rg -n "getPowershellTrashCommand|powershell|DeleteDirectory|Trash|trash" packages/init/src -S || true
echo
echo "Search dir input paths/usages in init ask flow:"
rg -n "command:\s*\(dir: string\) => \[|getPowershellTrashCommand|selectDirectory|ask.*dir|dir" packages/init/src -S || trueRepository: fedify-dev/fedify
Length of output: 40650
🌐 Web query:
PowerShell single-quoted string escaping single quote doubled two single quotes
💡 Result:
To include a single quotation mark within a PowerShell single-quoted string, you must use two consecutive single quotation marks ('') [1][2]. This effectively escapes the quote by "doubling" it, which tells the PowerShell parser to treat the pair as a single literal quote character [3][4]. For example, to represent the word don't in a single-quoted string, you would write: 'don''t' Because single-quoted strings are treated as verbatim literals, other common escape methods—such as the backtick character (`)—do not function as escape sequences inside them [1][5][3]. The backtick is treated as a literal character when placed within single quotes [1][6]. If you require complex quoting or find doubling single quotes difficult to manage, you can alternatively use a here-string (@'... '@), which preserves the content literally without requiring special escaping for single quotes [2][4].
Citations:
- 1: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-7.6
- 2: https://ss64.com/ps/syntax-esc.html
- 3: https://www.red-gate.com/simple-talk/sysadmin/powershell/when-to-quote-in-powershell/
- 4: https://stackoverflow.com/questions/22525381/escaping-single-quote-sign-in-powershell
- 5: https://stackoverflow.com/questions/11231410/can-i-use-a-single-quote-in-a-powershell-string
- 6: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-7.5
Escape dir in the PowerShell trash command.
getPowershellTrashCommand() inserts dir into a PowerShell single-quoted literal, so a name like C:\O'Brien terminates the string. In PowerShell single quotes, escape an apostrophe by doubling it (''). Add a Windows test with an apostrophe-containing directory path.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/init/src/ask/dir.ts` around lines 123 - 127, Update the command
builder around getPowershellTrashCommand to escape apostrophes in dir by
doubling them before interpolation into the PowerShell single-quoted literal.
Preserve existing path behavior and add a Windows test covering a directory path
containing an apostrophe.
Summary
@fedify/initproject initialization asks users to use non-empty directory, and confirm to move existing contents to Trash. However, its behavior actually permanently delete all of existing contents without back up for Linux or UNIX-like system users.This pull request notices users who are using Linux or UNIX-like systems that this action deletes existing data permanently. Furthermore, refactored messages and action structure in
dir.tsfile to easily add conditions or supported systems.Fixes #989
Test Plan
mise run check-each initmise run test-each init