fix: normalize line endings in prisma format on Windows#29299
fix: normalize line endings in prisma format on Windows#29299Iceshen87 wants to merge 1 commit intoprisma:mainfrom
Conversation
- 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
|
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. |
WalkthroughThe 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
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
| // Normalize line endings to platform-specific format | ||
| // On Windows, ensure we don't add extra CRLF (issue #8548) |
There was a problem hiding this comment.
🧹 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."
| const normalizedData = data.replace(/\r\n/g, '\n').replace(/\n/g, require('node:os').EOL) | ||
| await fs.writeFile(filename, normalizedData) |
There was a problem hiding this comment.
🧩 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 -20Repository: 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 -nRepository: 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.
|
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! |
jacek-prisma
left a comment
There was a problem hiding this comment.
The line endings used during formatted should be decided in prisma-engines and not post-processed here
Summary
This PR fixes issue #8548 where
prisma formatends the file with a single CRLF on Windows.Root Cause
The file writing logic in
Format.tswas 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:
This ensures:
Testing
prisma format --checkworks correctlyRelated Issue
Fixes: #8548
/claim #8548
Summary by CodeRabbit