Skip to content

fix: ensure newline separator when appending to files - #396

Merged
tannerlinsley merged 2 commits into
TanStack:mainfrom
Ktsierra:fix/append-file-missing-newline
Nov 1, 2026
Merged

tannerlinsley merged 2 commits into
TanStack:mainfrom
Ktsierra:fix/append-file-missing-newline

Conversation

@Ktsierra

@Ktsierra Ktsierra commented Feb 25, 2026 •

Copy link
Copy Markdown
Contributor

Appending to a file without a final newline can join ignore patterns or environment sections. This adds the missing separator in both Node and edge template generation, preserves existing spacing and keeps raw file appends unchanged.

AI review notes:
The missing-newline regression failed in disk, Node memory and edge memory environments before the fix. All 27 cases now pass, covering missing and empty targets, existing separators, empty appends and CRLF.
The normal pre-commit build, unit and blocking e2e gates passed. A real Sentry/PostHog app was also generated outside the monorepo without installation or provider calls, and its environment sections are separate.
The original trailing-newline fixes and contributor history are retained.

Summary by CodeRabbit

  • Bug Fixes
    • Generated add-on files now append on a separate line when the existing file has content but no final newline. Existing newlines and intentional blank lines are preserved, and empty appends do not add extra separators. This behavior is consistent across disk-based, Node-memory, and edge-generation workflows.

appendFile concatenated content without checking for a trailing
  newline, causing malformed output when multiple add-ons append to the
  same file (e.g. .env.local with sentry + posthog).

  Add newline guard in both fs and memfs appendFile implementations.
  Fix 4 .append files missing trailing newlines (sentry, strapi, mcp).
Copilot AI review requested due to automatic review settings February 25, 2026 19:11

Copilot AI 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.

Pull request overview

This PR fixes a content concatenation issue where multiple add-ons appending to the same file (e.g., .env.local) would have their content directly concatenated without proper separation. The fix ensures proper formatting by automatically inserting blank line separators between appended sections.

Changes:

  • Modified appendFile implementations in both real fs and memfs to automatically add a blank line separator when appending to existing files
  • Added missing trailing newlines to 4 .append template files (Sentry, Strapi for React and Solid, MCP gitignore)
  • Updated test assertions to reflect the new blank-line separator behavior

Reviewed changes

Copilot reviewed 4 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/create/src/environment.ts Added logic to automatically insert blank line separators (1 or 2 newlines depending on existing content) when appending to files in both real fs and memfs implementations
packages/create/src/frameworks/react/add-ons/sentry/assets/_dot_env.local.append Added missing trailing newline to Sentry environment config
packages/create/src/frameworks/react/add-ons/strapi/assets/_dot_env.local.append Added missing trailing newline to Strapi environment config for React
packages/create/src/frameworks/solid/add-ons/strapi/assets/_dot_env.local.append Added missing trailing newline to Strapi environment config for Solid
packages/create/src/frameworks/react/add-ons/mcp/assets/_dot_gitignore.append Added missing trailing newline to MCP gitignore
packages/create/tests/template-file.test.ts Updated test assertion to expect blank line separator between appended content
packages/create/tests/filename-processing.test.ts Updated test assertion to account for the blank line separator behavior
packages/create/tests/environment.test.ts Updated test assertion to verify blank line separator in appendFile operations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tannerlinsley

Copy link
Copy Markdown
Member

Heads up: #501 removes memfs from the published runtime and routes the Node memory environment through edge-environment.ts. If #501 lands first, the append separator change here should move to packages/create/src/edge-environment.ts; environment.ts will only adapt Node path resolution.

@changeset-bot

changeset-bot Bot commented Nov 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 978cc04

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@tanstack/create Patch
create-start-app Patch
create-tanstack-app Patch
create-tanstack Patch
create-tsrouter-app Patch
@tanstack/create-start Patch
@tanstack/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 06bd1795-2c4b-4bd8-8a3c-2e52dec9b935
Commits

Reviewing files that changed from the base of the PR and between cff01c6 and 978cc04.

Files selected for processing: 8
  • .changeset/append-separators.md
  • packages/create/src/edge-template-file.ts
  • packages/create/src/frameworks/react/add-ons/mcp/assets/_dot_gitignore.append
  • packages/create/src/frameworks/react/add-ons/sentry/assets/_dot_env.local.append
  • packages/create/src/frameworks/react/add-ons/strapi/assets/_dot_env.local.append
  • packages/create/src/frameworks/solid/add-ons/strapi/assets/_dot_env.local.append
  • packages/create/src/template-file.ts
  • packages/create/tests/append-separators.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

Walkthrough

The Node and edge template append paths now insert a newline when existing nonempty file content lacks a final newline and appended content does not begin with one. Parameterized tests cover disk and memory environments, and a patch changeset records the update.

Changes: Append separator handling

Layer / File(s) Summary
Append paths and validation
packages/create/src/template-file.ts, packages/create/src/edge-template-file.ts, packages/create/tests/append-separators.test.ts, .changeset/append-separators.md, packages/create/src/frameworks/{react,solid}/add-ons/*/assets/*.append
Both append paths conditionally prepend a newline before appending. Tests cover missing or empty targets, newline combinations, blank lines, empty appends, and CRLF. The changeset describes the update. The listed add-on asset entries are unchanged.

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

Change: Bug fix

Merge Risk: Minimal · up to 978cc

Template appends preserve existing separators and keep sections separate. No merge-blocking risk was found.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: adding a newline separator when appending content to files.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 3 files. (5 skipped: 5 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/create/tests/append-separators.test.ts

Parsing error: "parserOptions.project" has been provided for @typescript-eslint/parser.
The file was not found in any of the provided project(s): packages/create/tests/append-separators.test.ts

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

@tannerlinsley
tannerlinsley merged commit 6e3e869 into TanStack:main Nov 1, 2026
7 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 1, 2026
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.

3 participants