Skip to content

fix: normalize line endings in prisma format on Windows#29299

Open
Iceshen87 wants to merge 1 commit intoprisma:mainfrom
Iceshen87:fix/format-crlf-windows-8548
Open

fix: normalize line endings in prisma format on Windows#29299
Iceshen87 wants to merge 1 commit intoprisma:mainfrom
Iceshen87:fix/format-crlf-windows-8548

Conversation

@Iceshen87
Copy link
Copy Markdown

@Iceshen87 Iceshen87 commented Mar 5, 2026

Summary

This PR fixes issue #8548 where prisma format ends the file with a single CRLF on Windows.

Root Cause

The file writing logic in Format.ts was not normalizing line endings for Windows platforms, causing an extra CRLF to be added at the end of the formatted schema file.

Solution

Normalize line endings before writing to disk:

// Normalize line endings to platform-specific format
const normalizedData = data.replace(/\r\n/g, '\n').replace(/\n/g, require('node:os').EOL)
await fs.writeFile(filename, normalizedData)

This ensures:

  1. All line endings are first normalized to LF
  2. Then converted to platform-specific EOL (CRLF on Windows, LF on Unix)
  3. Prevents double CRLF on Windows

Testing

  • Tested on Windows: No extra CRLF at end of file
  • Tested on Unix: LF line endings preserved
  • prisma format --check works correctly

Related Issue

Fixes: #8548


/claim #8548

Summary by CodeRabbit

  • Bug Fixes
    • Improved line ending handling in the format command. Formatted files now normalize line endings to match your platform's standard format, ensuring consistent output across different operating systems.

- Normalize line endings to platform-specific format
- Prevent extra CRLF at end of file on Windows
- Use os.EOL for consistent cross-platform behavior

Fixes: prisma#8548

/claim prisma#8548
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Iceshen87 seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 5, 2026

Walkthrough

The format command now normalizes line endings before writing files, replacing CRLF with platform-specific line endings to ensure consistent output across different operating systems.

Changes

Cohort / File(s) Summary
Line ending normalization
packages/cli/src/Format.ts
Added logic to normalize line endings by converting CRLF to LF, then to platform-specific EOL before file writes, addressing inconsistent line ending behavior on Windows.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: normalizing line endings in the Prisma format command specifically for Windows, which directly addresses the core issue.
Linked Issues check ✅ Passed The code changes implement the exact solution from issue #8548: normalizing line endings by converting CRLF to LF then to platform-specific EOL, preventing the extra CRLF at EOF on Windows.
Out of Scope Changes check ✅ Passed The changes are scoped to Format.ts and directly address the line ending normalization requirement from issue #8548, with no unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 59457a63-2042-4b3c-a8e3-0b7fc3212401

📥 Commits

Reviewing files that changed from the base of the PR and between 9fa295d and a39a906.

📒 Files selected for processing (1)
  • packages/cli/src/Format.ts

Comment on lines +106 to +107
// Normalize line endings to platform-specific format
// On Windows, ensure we don't add extra CRLF (issue #8548)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Trim redundant inline comment at Line 106; keep the issue-context comment.

Line 107 already captures the rationale (issue #8548``), so Line 106 is unnecessary “what/how” commentary.

As per coding guidelines "Avoid adding useless code comments that do not add new information. Only write inline comments explaining Why (context, background, GitHub issues, decisions), not What or How."

Comment on lines +108 to +109
const normalizedData = data.replace(/\r\n/g, '\n').replace(/\n/g, require('node:os').EOL)
await fs.writeFile(filename, normalizedData)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Format.ts file (lines 100-115) ==="
sed -n '100,115p' packages/cli/src/Format.ts | cat -n

echo
echo "=== CLI package configuration ==="
cat packages/cli/package.json | jq '{name, type, main, module}' 2>/dev/null || echo "jq parse failed, checking raw:"
head -20 packages/cli/package.json

echo
echo "=== CLI tsconfig.json (module settings) ==="
if [ -f packages/cli/tsconfig.json ]; then
  cat packages/cli/tsconfig.json | jq '.compilerOptions | {module, moduleResolution, target, declaration}'
else
  echo "tsconfig.json not found in packages/cli"
fi

echo
echo "=== Checking os/EOL usage in packages/cli/src ==="
rg -nP --type=ts "require\('node:os'\)|from 'node:os'|import.*os" packages/cli/src 2>/dev/null | head -20

Repository: prisma/prisma

Length of output: 1694


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Format.ts top imports ==="
head -30 packages/cli/src/Format.ts | cat -n

echo
echo "=== CLI tsconfig.json raw ==="
cat packages/cli/tsconfig.json 2>/dev/null || echo "Not found in packages/cli"

echo
echo "=== Root tsconfig.json compiler options (module/target) ==="
cat tsconfig.json | head -40

echo
echo "=== os/EOL patterns in packages/cli/src (all occurrences) ==="
rg -nP --type=ts "require\('node:os'\)|from 'node:os'|import.*\bos\b" packages/cli/src/ 2>/dev/null || echo "No matches"

echo
echo "=== Check if Format.ts is in a packages/cli/src context ==="
ls -la packages/cli/src/Format.ts 2>/dev/null && echo "File exists" || echo "File not found"

Repository: prisma/prisma

Length of output: 2176


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Root tsconfig compiler options ==="
cat tsconfig.json | sed -n '/"compilerOptions"/,/^  }/p' | head -30

echo
echo "=== tsconfig.utils.typecheck.json (for module config) ==="
cat tsconfig.utils.typecheck.json | sed -n '/"compilerOptions"/,/^  }/p' | head -30

echo
echo "=== Version.ts check: how 'os' is imported ==="
head -25 packages/cli/src/Version.ts | cat -n

echo
echo "=== Full context around require in Format.ts (lines 105-112) ==="
sed -n '105,112p' packages/cli/src/Format.ts | cat -n

Repository: prisma/prisma

Length of output: 1497


Replace inline require('node:os') with a static import statement.

Add import { EOL } from 'node:os' at the top of the file and use EOL directly at line 109. This aligns with the static imports already used throughout the file (e.g., import fs from 'node:fs/promises') and matches the pattern in other CLI modules like SubCommand.ts.

Additionally, remove the comment at line 107 ("Normalize line endings to platform-specific format") as it restates what the code already expresses; keep line 108's comment which explains the platform-specific rationale.

@Iceshen87
Copy link
Copy Markdown
Author

Hi! I saw Prisma has a bounty program. Does this bug fix qualify for a bounty? If so, could you please add the appropriate bounty label? Thanks!

Copy link
Copy Markdown
Contributor

@jacek-prisma jacek-prisma left a comment

Choose a reason for hiding this comment

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

The line endings used during formatted should be decided in prisma-engines and not post-processed here

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.

prisma format ends the file with a single CRLF on windows

3 participants