Skip to content

fix(codemod): preserve line endings in new-link transform - #98608

Open
armanbagherim wants to merge 1 commit into
vercel:canaryfrom
armanbagherim:fix/codemod-windows-line-endings
Open

fix(codemod): preserve line endings in new-link transform#98608
armanbagherim wants to merge 1 commit into
vercel:canaryfrom
armanbagherim:fix/codemod-windows-line-endings

Conversation

@armanbagherim

Copy link
Copy Markdown

What?

Preserves the original line endings when running the new-link codemod.

Added regression tests for both LF and CRLF inputs.

Why?

On Windows, running the new-link codemod could change files using LF line endings to CRLF because the output was generated without specifying a line terminator.

This caused unrelated line-ending changes in files modified by the codemod.

How?

The transform detects the line ending used by the source file and passes it to toSource() as the lineTerminator.

Added tests to verify that:

  • LF input remains LF
  • CRLF input remains CRLF

Tested with:

npx pnpm@10.33.0 --filter @next/codemod build

npx pnpm@10.33.0 --filter @next/codemod test -- transforms/__tests__/new-link.test.js

Result: 12 tests passed.

Fixes #42437

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.

[next-codemod] codemod changes all line endings to carriage returns on windows

1 participant