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

Infer EOLs from existing file or use OS EOL #1405

Closed
wants to merge 24 commits into from
Closed

Infer EOLs from existing file or use OS EOL #1405

wants to merge 24 commits into from

Conversation

iredchuk
Copy link
Contributor

Summary

Yarn uses UNIX line endings on all systems when writing lock file. We want to solve this problem as described in #1061: infer line endings from the existing file, and if it does not exist, use the system default.

Test plan

On a UNIX system, in an empty directory:
$ yarn add <some_package>
$ cat -e yarn.lock
You should only see LF line endings.
$ unix2dos yarn.lock
$ yarn add <some_other_package>
$ cat -e yarn.lock
You should only see CRLF line endings.

On a Windows system, in an empty directory:
$ yarn add <some_package>
$ cat.exe -e yarn.lock
You should only see CRLF line endings.
$ dos2unix.exe yarn.lock
$ yarn add <some_other_package>
$ cat -e yarn.lock
You should only see LF line endings.

Copy link
Member

@bestander bestander left a comment

Choose a reason for hiding this comment

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

@iredchuk would you write a test for this please?
We have both Unix and Windows CI setup

@iredchuk
Copy link
Contributor Author

@bestander Will try, thanks.

@iredchuk
Copy link
Contributor Author

@bestander Added, please check.

Copy link
Member

@bestander bestander left a comment

Choose a reason for hiding this comment

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

Inferring line endings puts performance at risk.
How about just setting line ending rule in .yarnrc?
This file can be committed so that teams use the same line ending rules per project

const cr = new Buffer('\r', 'utf8')[0];
const lf = new Buffer('\n', 'utf8')[0];

async function getEolFromFile(path: string) : Promise<string | void> {
Copy link
Member

Choose a reason for hiding this comment

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

The unfortunate bit is that it adds a read file to every write file operation.
That could unexpectedly slow down quite a few things.
Any ideas how to apply this only to yarn.lock/package.json writing?

Copy link
Contributor Author

@iredchuk iredchuk Nov 15, 2016

Choose a reason for hiding this comment

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

@bestander
IMHO putting the line ending setting into .yarnrc would be not so nice when team members work on different OSs, which is quite probable for a relatively big project.

I tried to measure the overhead and got about 20ms for 10000 read iterations, so for one read it should not be significant.

However, we could limit this behaviour to only files included into source control. Is it only yarn.lock and package.json? If so, maybe we could expose both write functions and use them selectively?

Copy link
Member

Choose a reason for hiding this comment

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

I would use this explicitly for yarn.lock, package.json and .yarnrc files only then.
How about fs would expose fs.writeFilePreservingEol and we would use it sparsely?
This kind of file parsing does not sit well with me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. Updated.

bestander and others added 13 commits November 15, 2016 22:15
* Set UID and GID of untared files to zero if user is root

* Remove second platform check
* Add very basic test for global add

* Add assertion & Fix typo
I don't think we need this any more
* Skip setting hash if hash was not set previously

* Add end to end test for installing a github package

* Update README.md

* Fix eslint

* Reverse accidental fixture changes

* Add unit tests

* No end to end tests for github installs
Copy link
Member

@bestander bestander left a comment

Choose a reason for hiding this comment

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

Tests are great and the change looks good.
Just one nit + PR needs a rebase

async function getEolFromFile(path: string) : Promise<string | void> {
let buffer;
try {
buffer = await readFileBuffer(path);
Copy link
Member

Choose a reason for hiding this comment

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

better return undefined if files does not exist (check if it exists first).
And don't catch error in readFile

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about it, but if the file is inaccessible for some other reason - is it OK to just let it fail here? Will this be handled on a higher level?

James Ide and others added 6 commits November 16, 2016 23:26
… built-ins (#1790)

The reason for this is that Yarn is useful in many JS environments such as browsers and React Native, which don't provide the Node built-ins. Depending on polyfills is the right thing to do in that scenario and the reality is that people intentionally publish these polyfills under the same name as the Node built-ins (e.g. url and buffer).
Implemented as proposed by @ahelmberger

Resolves #1061
@bestander
Copy link
Member

Commits still look quite broken in the PR.
They repeat recently merged ones

@iredchuk
Copy link
Contributor Author

iredchuk commented Nov 17, 2016

@bestander Sorry I messed up with rebasing :( Created a new PR: #1911
Please take a look.

@iredchuk iredchuk closed this Nov 17, 2016
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.

9 participants