Repository navigation
fix(termui): address #3384 — create-termui-app no-overwrite - #3387
tmdeveloper007 wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughThe CLI now inspects an existing project directory before generation. It rejects directories with entries other than ChangesProject directory inspection
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 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: 3
🤖 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 `@packages/create-termui-app/src/index.ts`:
- Line 7: Replace the undeclared fs namespace usage in the directory-reading
logic with the imported readdirSync binding, calling readdirSync(projectDir)
while preserving the existing behavior.
- Around line 129-130: Replace the direct console.log calls in the
non-empty-directory branch with the approved CLI output mechanism, and render
the error symbol through caps.unicode with an ASCII fallback instead of
hard-coding ✖. Ensure the updated output remains equivalent and complies with
the package-wide console and Unicode handling conventions.
- Around line 133-135: Update the directory inspection flow around readdirSync
to abort generation when inspection fails instead of continuing to write. Ensure
the subsequent writeFileSync calls cannot overwrite existing files, including
check/write races, by using exclusive or atomic file creation semantics.
🪄 Autofix (Beta)
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: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: cd51f20e-f319-48c8-a5c6-dc71b4fe30b8
📒 Files selected for processing (1)
packages/create-termui-app/src/index.ts
| import { dirname, resolve, join } from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import { mkdirSync, writeFileSync, existsSync, readFileSync } from 'node:fs'; | ||
| import { mkdirSync, writeFileSync, existsSync, readFileSync, readdirSync } from 'node:fs'; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win
Use the imported readdirSync binding.
Line 7 imports readdirSync, but Line 126 uses an undeclared fs namespace. This causes the TypeScript build to fail. Call readdirSync(projectDir), or import the namespace explicitly.
Proposed fix
- const entries = fs.readdirSync(projectDir);
+ const entries = readdirSync(projectDir);Also applies to: 126-126
🤖 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/create-termui-app/src/index.ts` at line 7, Replace the undeclared fs
namespace usage in the directory-reading logic with the imported readdirSync
binding, calling readdirSync(projectDir) while preserving the existing behavior.
| console.log(`\n ✖ Directory "${projectName}" is not empty. Refusing to overwrite.\n`); | ||
| console.log(` Remove the directory or choose a different name.\n`); |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Use the approved output and Unicode capability handling.
The new branch calls console.log and hard-codes ✖. Use the permitted CLI output mechanism and render the symbol with caps.unicode plus an ASCII fallback.
As per coding guidelines, packages/**/src/**/*.{ts,tsx} must not contain console.log, and packages/**/*.{ts,tsx} must use caps.unicode for non-ASCII characters with an ASCII fallback.
🤖 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/create-termui-app/src/index.ts` around lines 129 - 130, Replace the
direct console.log calls in the non-empty-directory branch with the approved CLI
output mechanism, and render the error symbol through caps.unicode with an ASCII
fallback instead of hard-coding ✖. Ensure the updated output remains equivalent
and complies with the package-wide console and Unicode handling conventions.
Source: Coding guidelines
| } catch { | ||
| // readdirSync failed — let the write calls fail naturally | ||
| } |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Fail closed when directory inspection fails.
This catch block continues to generation after readdirSync fails. writeFileSync on Line 148 uses overwrite mode by default, so an existing directory that cannot be read can still have files overwritten. A check/write race has the same result. Abort on inspection failure and enforce exclusive or atomic file creation.
🤖 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/create-termui-app/src/index.ts` around lines 133 - 135, Update the
directory inspection flow around readdirSync to abort generation when inspection
fails instead of continuing to write. Ensure the subsequent writeFileSync calls
cannot overwrite existing files, including check/write races, by using exclusive
or atomic file creation semantics.
|
Blocking — already on main (non-empty-dir guard, merged #3633), and this PR would not compile anyway: it calls |
|
Closing this one. It is part of a large automated-PR batch and is not mergeable: either already fixed on |
📄 Description
Fix for Karanjot786/TermUI #3384.
create-termui-app — refuses to scaffold into non-empty directories, preventing accidental overwrites.
🔗 Related Issues
🧩 Type of Change
✅ Checklist