sveltejs / svelte

Cybernetically enhanced web apps
https://svelte.dev
MIT License
78.9k stars 4.14k forks source link

svelte-migrate: When there where no changes to file(s) git still reports them as having diff. #13496

Open VismaTobbe opened 2 weeks ago

VismaTobbe commented 2 weeks ago

Describe the bug

When running svelte-migrate and there where no changes to file(s) they still are reported as changed by git. Running git diff reports lots of LF will be replaced by CRLF the next time Git touches it.

I noticed on certain files, Rider reports wrong encoding. image

Example

The file image

Reported change image

Reproduction

  1. Create dummy.ts file with a comment
  2. Commit file
  3. Run npx svelte-migrate svelte-5
  4. Run git diff

Logs

No response

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (16) x64 Intel(R) Core(TM) i9-10885H CPU @ 2.40GHz
    Memory: 8.52 GB / 31.75 GB
  Binaries:
    Node: 20.13.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.22 - C:\Program Files\nodejs\yarn.CMD
    npm: 10.5.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (127.0.2651.98)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    svelte: ^4.2.19 => 5.0.0-next.262

Severity

annoyance

dummdidumm commented 1 week ago

Can you provide more details on the "wrong encoding" case? What was the file encoded with before?

I'm also not able to reproduce the lf->crlf issue. If I have a file with crlf in it, that ending is preserved, likewise for lf.

VismaTobbe commented 1 week ago

@dummdidumm Some more details: I created the file in Rider, viewing it in VSCODE says UTF-8 with BOM (and CRLF). After migration it becomes UTF-8 only (and CRLF).

I seem to forgot to mention the command line i used npx svelte-migrate svelte-5 if that helps.

dummdidumm commented 1 week ago

Ok so then this is related to the BOM, and our writeFile logic not accounting for the format (it just assumes utf8 on read and write)