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

Windows compatibility fix #583

Merged
merged 3 commits into from
May 6, 2018
Merged

Windows compatibility fix #583

merged 3 commits into from
May 6, 2018

Conversation

zenflow
Copy link
Contributor

@zenflow zenflow commented Apr 18, 2018

Simple fix for simple problem causing errors on Windows machines, where Git by default converts line endings from \n to \r\n when checking out code and back to \r when checking it in.

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Apr 18, 2018
@yangshun
Copy link
Contributor

Hi @zenflow what's the current behavior on Windows machines without this fix?

@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented May 3, 2018

Deploy preview for docusaurus-preview ready!

Built with commit 7477ae7

https://deploy-preview-583--docusaurus-preview.netlify.com

@zenflow
Copy link
Contributor Author

zenflow commented May 3, 2018

Sorry for the delay.. I can answer this tomorrow probably

@zenflow
Copy link
Contributor Author

zenflow commented May 3, 2018

I remember that (on Windows) the markdown header is parsed incorrectly as being empty, and some error is thrown later on because of that.

Reminder that it's not simply a matter of using \n line endings because Git on Windows is typically configured to change line endings to /r/n when code comes out and back to /n when it goes back in.

Copy link
Contributor

@yangshun yangshun left a comment

Choose a reason for hiding this comment

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

@zenflow Got it. I did a bit of research and stumbled upon this answer on StackOverflow

Could you patch #628 and see if it works? Using \r?\n is not a common pattern in code and it's very likely that other developers are unaware of this nuance.

@zenflow
Copy link
Contributor Author

zenflow commented May 3, 2018

@yangshun I can give it a go tomorrow. But I'm a little confused.. Are the new .gitattributes and .editorconfig files in that PR copied to projects when you do $ docusaurus-init? (because that is what I'll try)

@yangshun
Copy link
Contributor

yangshun commented May 3, 2018

Oh hmm I was only fixing it on local development. I think you are right, this needs to be copied upon docusaurus-init too. Could you try my PR and build the Docusaurus site locally by cloning this repo? If that works, then this is a feasible solution and we can add these files as into the scaffolded files when docusaurus-init-ing. Would you be interested in making a PR to do that?

@zenflow
Copy link
Contributor Author

zenflow commented May 3, 2018

@yangshun

Could you try my PR and build the Docusaurus site locally by cloning this repo?

Yeah for sure I'll give it a test and review. I think it will help for local development.

But I don't think it's a good idea to copy the files when docusaurus-init-ing.. .editorconfig doesn't always help because it will only ensure proper line endings once the individual files get opened in your IDE.. and .gitattributes needs to be in the root directory of the repo in order to work, and it's possible a project already has a file there that would be overwritten. Also we can include this in the scaffolding, but that becomes end-user-level configuration.. wouldn't it be considered more robust for Docusaurus to handle things properly without requiring more specific configuration?

I've seen the /\r?\n/ pattern used a number of places (Next.js, Pino) without code comments and did not consider that it would be unfamiliar to linux-only developers.. but we can make this more clear I think... what if I extract that regex into a const with a short code comment like "this pattern matches \n (unix line endings) and \r\n (windows line endings)"?

Copy link
Contributor

@yangshun yangshun left a comment

Choose a reason for hiding this comment

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

@zenflow I'm gonna merge this first since it's a relatively safe fix. I see many occurrences of .split('\n') in the code, you might want to have a look and fix them too 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants