Skip to content

fix(termui): address #3384 — create-termui-app no-overwrite - #3387

Closed
tmdeveloper007 wants to merge 1 commit into
Karanjot786:mainfrom
tmdeveloper007:termui-mavis-fix-3384-create-app-no-overwrite
Closed

tmdeveloper007 wants to merge 1 commit into
Karanjot786:mainfrom
tmdeveloper007:termui-mavis-fix-3384-create-app-no-overwrite

Conversation

@tmdeveloper007

@tmdeveloper007 tmdeveloper007 commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

📄 Description

Fix for Karanjot786/TermUI #3384.

create-termui-app — refuses to scaffold into non-empty directories, preventing accidental overwrites.

🔗 Related Issues

🧩 Type of Change

  • Bug fix

✅ Checklist

  • Code follows project style guidelines
  • Tests added/updated if applicable
  • Documentation updated if applicable
  • Changes don't introduce new warnings

@github-actions github-actions Bot added the type:bug +10 pts. Bug fix. label Aug 3, 2026
@coderabbitai

coderabbitai Bot commented Aug 3, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The CLI now inspects an existing project directory before generation. It rejects directories with entries other than .git and continues when inspection fails. The implementation currently references fs.readdirSync without importing fs.

Changes

Project directory inspection

Layer / File(s) Summary
Directory inspection and generation guard
packages/create-termui-app/src/index.ts
The CLI adds readdirSync, checks existing directory entries, rejects non-.git contents, and catches inspection failures. The current call uses fs.readdirSync although only readdirSync is imported.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: karanjot786, kajalpa302005

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description covers the fix, linked issue, and bug-fix type, but it omits the package, GSSoC, and required checklist sections. Add the required package, GSSoC participation, profile, and repository checklist sections from the template.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies a fix for issue #3384 and the create-termui-app no-overwrite behavior.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6c7584e and cd30142.

📒 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';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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.

Comment on lines +129 to +130
console.log(`\n ✖ Directory "${projectName}" is not empty. Refusing to overwrite.\n`);
console.log(` Remove the directory or choose a different name.\n`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 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

Comment on lines +133 to +135
} catch {
// readdirSync failed — let the write calls fail naturally
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ 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.

@Karanjot786

Copy link
Copy Markdown
Owner

Blocking — already on main (non-empty-dir guard, merged #3633), and this PR would not compile anyway: it calls fs.readdirSync(...) but only named imports from node:fs exist (no fs namespace import). Superseded.

@Karanjot786 Karanjot786 added the quality:needs-work Needs changes before merge. label Aug 19, 2026
@Karanjot786

Copy link
Copy Markdown
Owner

Closing this one. It is part of a large automated-PR batch and is not mergeable: either already fixed on main by a prior merged PR, a no-op/defensive change for a non-bug, or has a defect noted in the review above. If you have a genuine, locally-verified fix (bun run build + bun vitest run green), please open a single focused PR.

@Karanjot786 Karanjot786 added the gssoc:invalid PR violates GSSoC rules. 0 points. label Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:invalid PR violates GSSoC rules. 0 points. quality:needs-work Needs changes before merge. type:bug +10 pts. Bug fix.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] create-termui-app overwrites files in an existing project directory

2 participants