Skip to content

fix(init): refuse to overwrite files when scaffolding into the current directory - #3985

Merged
kwakayama merged 6 commits into
mainfrom
fix/dx-init-cwd-overwrite
Aug 22, 2026
Merged

kwakayama merged 6 commits into
mainfrom
fix/dx-init-cwd-overwrite

Conversation

@kojiwakayama

@kojiwakayama kojiwakayama commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Without a project name, veryfront init scaffolds into the working directory (the documented non-interactive default: piped stdin, CI, --template with no name). createProject only checked for conflicts when a name was given, so an existing package.json (with the author's scripts), README.md, or any other file the template ships was silently replaced — no --force, exit 0, "✓ Project ready".
  • The current-directory path now refuses when any file the scaffold would write already exists, naming every conflicting file and pointing at --force:
    Directory already contains README.md, package.json. Use --force to overwrite.
    
  • .gitignore is merged rather than replaced, so it is never a conflict. An empty directory, or one holding unrelated files, scaffolds exactly as before. --force keeps overwriting.
  • docs/api-reference/veryfront/scaffold.md line pins regenerated with CI's pinned Deno 2.7.7 (only that file changed).

Found by the vf-dx-dogfood edge-case pass against published veryfront@0.1.1251.

Test plan

  • RED: 2 new createProject conflict tests + 1 initCommand test failed on main (no rejection); the empty-dir and --force tests passed on main and still pass (behaviour preserved)
  • GREEN: cli/commands/init/, cli/shared/project-creation.test.ts, cli/app/operations/project-creation.test.ts (15 files, 177 steps) pass
  • Pass 2 from a sandbox outside the repo: non-empty cwd → refusal, exit 1, files byte-identical; --force → overwritten; empty cwd → scaffolded
  • deno lint, deno fmt --check, lint:anti-slop, lint:sanitizer-baseline, lint:test-typecheck, docs:api-reference:check clean

Update

  • Merged origin/main. fix(init): exit non-zero when the target directory already exists #3983 landed a describe("initCommand target directory") block in the same
    place this branch adds describe("initCommand into the current directory"). Both are kept: they
    cover different paths through initCommand (a named target directory, and the current directory).
  • --force help copy now reads "Overwrite existing files and directories". The flag no longer only
    overwrites a directory, so the old line described half of it.
  • Added one test. scaffoldWritePaths is a hand-maintained mirror of the writes in createProject,
    and every other test names only one or two files, so a write added without a matching mirror entry
    would narrow the guard with the suite still green. The new test scaffolds with the deno runtime and
    an integration (the widest write set: template files, package.json, deno.json, .env,
    .env.example), runs again over that directory, and requires every created path back in the
    refusal. Dropping deno.json or the env files from the mirror turns it red and leaves the other
    four green.

…t directory

Without a project name, `veryfront init` scaffolds into the working directory
(the non-interactive default: piped stdin, CI, `--template` with no name).
`createProject` only checked for conflicts when a name was given, so an
existing `package.json`, `README.md`, or any other file the template ships
was silently replaced, with no `--force` and a "Project ready" banner.

The current-directory path now refuses when any file the scaffold would write
already exists, naming every conflicting file and pointing at `--force`.
`.gitignore` is merged rather than replaced and so is never a conflict; an
empty directory, or one holding unrelated files, scaffolds as before.

Regression tests cover the refusal, the message, the empty and unrelated-file
cases, `--force`, and the CLI path through `initCommand`. The API reference
pins for `cli/shared/project-creation.ts` are regenerated with CI's Deno.
@coderabbitai

coderabbitai Bot commented Aug 22, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@kwakayama, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 17 minutes

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

Wait for the limit to reset, then comment @coderabbitai review or push new commits to the PR.

An organization admin can change what happens after included review limits in Billing.

How do review limits work?

CodeRabbit enforces per-developer PR review limits within each organization.

For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 81146bcb-96fa-417b-ab28-aafd019c6424

📥 Commits

Reviewing files that changed from the base of the PR and between 988edca and e67f7b9.

📒 Files selected for processing (6)
  • cli/commands/init/command-help.ts
  • cli/commands/init/init-command.test.ts
  • cli/commands/init/types.ts
  • cli/shared/project-creation.test.ts
  • cli/shared/project-creation.ts
  • docs/api-reference/veryfront/scaffold.md

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.

@github-actions

Copy link
Copy Markdown

📦 Client bundle boundary

Entrypoint Modules Source size Server leaks
src/index.client.ts 327 1961 KiB ✅ 0

A server module in a client graph aborts hydration in the browser. New leaks fail CI; known leaks are tracked in scripts/lint/client-bundle-baseline.json to burn down.

@kojiwakayama
kojiwakayama added this pull request to the merge queue Aug 22, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Aug 22, 2026
main added the named-directory refusal test from #3983 in the same place this
branch adds the current-directory refusal test. Both describes are kept: they
cover different paths through initCommand.
`--force` now also overwrites files the scaffold would write into the current
directory, so "Overwrite existing directory" no longer describes the whole
flag. The help line and the InitOptions doc comment both say files and
directories.
`scaffoldWritePaths` is a hand-maintained mirror of the writes in
`createProject`. A new write added without a matching entry silently narrows
the guard, and every existing test still passes because they each name one or
two files.

The new test scaffolds with the deno runtime and an integration, which is the
widest write set (template files, package.json, deno.json, .env, .env.example),
then runs again over that directory and requires every created path back in the
refusal. Dropping deno.json or the env files from the mirror turns it red and
leaves the other four tests green.
@kwakayama
kwakayama added this pull request to the merge queue Aug 22, 2026
Merged via the queue into main with commit 7eee200 Aug 22, 2026
38 checks passed
@kwakayama
kwakayama deleted the fix/dx-init-cwd-overwrite branch August 22, 2026 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants