Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Messed up lock file formatting when using CRLF EOL #6

Closed
Maxim-Mazurok opened this issue Sep 12, 2022 · 2 comments · Fixed by #7
Closed

Messed up lock file formatting when using CRLF EOL #6

Maxim-Mazurok opened this issue Sep 12, 2022 · 2 comments · Fixed by #7

Comments

@Maxim-Mazurok
Copy link
Contributor

After the first run of npx -y update-browserslist-db@latest in our project, it messed up package-lock.json formatting, see:

This is on my colleague's PC (windows, I believe)
image

This is on my PC (Ubuntu, WSL2):
image

This is my output:
image

After that, I changed nothing re-running the command worked just fine. Can't reproduce anymore.

@Maxim-Mazurok Maxim-Mazurok changed the title Messed up lock file formatting Messed up lock file formatting when using CRLF EOL Sep 12, 2022
@Maxim-Mazurok
Copy link
Contributor Author

Maxim-Mazurok commented Sep 12, 2022

Here's a reproduction:

const DEFAULT_INDENT = "  ";
const INDENT_REGEXP = /^(\s+)[^\s]/m;

function detectIndent(text) {
  try {
    return INDENT_REGEXP.exec(text)[1] || DEFAULT_INDENT;
  } catch (e) {
    /* c8 ignore next 2 */
    return DEFAULT_INDENT;
  }
}

const text = `{\r\n  \"name\": \"my-project\",\r\n`;

console.log(JSON.stringify(detectIndent(text)));

will print "\n "

As you can see, it includes \n into the detected indentation.

The problem is with this function: https://github1s.com/browserslist/update-db/blob/HEAD/index.js#L10-L17

@Maxim-Mazurok
Copy link
Contributor Author

My colleague and I would like to take on this issue if that's ok

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 a pull request may close this issue.

1 participant