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

jest-haste-map: watchman crawler: normalize paths #3887

Merged
merged 4 commits into from
Jun 27, 2017

Conversation

jeanlauliac
Copy link
Contributor

See the inline comment. New versions of Watchman on Window are now returning paths using forward slashes, but consumers of jest-haste-map use to work and assume backslashes would be used (because they rely on path.sep, that is backslash on win32, along the other path functions).

This changeset make it so we path.normalize the paths we read from watchman. On POSIX systems this should not make any difference, but on Window this will have the effect of replacing forward slashes by the usual backslashes.

@cpojer
Copy link
Member

cpojer commented Jun 26, 2017

Can you rebase this?

@@ -104,7 +104,7 @@ module.exports = function watchmanCrawl(

clocks[root] = response.clock;
response.files.forEach(fileData => {
const name = root + path.sep + fileData.name;
const name = path.normalize(path.join(root, fileData.name));
Copy link
Member

Choose a reason for hiding this comment

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

The initial implementation used to have this, however it is a source of significant slowdown (~20% of the entire time spent in jest-haste-map). Is there something else we could do here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, got it. Is it also for performance that path.join wasn't used?

The alternative would be to use a RegExp to replace all / with path.sep. Do you think that'd be reasonnable? It sounds like the performance would be better because it wouldn't have to do any parsing that normalize is probably doing.

Copy link
Member

Choose a reason for hiding this comment

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

Do you mind doing some benchmarking on what is fastest on node8? Things may have changed and the path module was rewritten for node 6 also.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, you known what, the thing is we don't really need to 'normalize' paths logically speaking. Watchman ensures that the paths don't contain any ".." for example, so that's unnecessary work to parse and reform the paths. It's really just a matter of slashes/backslashes. I'll just do a regex replacement.

@codecov-io
Copy link

Codecov Report

Merging #3887 into master will increase coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3887      +/-   ##
==========================================
+ Coverage   58.09%   58.12%   +0.03%     
==========================================
  Files         195      196       +1     
  Lines        6751     6756       +5     
  Branches        6        6              
==========================================
+ Hits         3922     3927       +5     
  Misses       2826     2826              
  Partials        3        3
Impacted Files Coverage Δ
...kages/jest-haste-map/src/lib/normalize_path_sep.js 100% <100%> (ø)
packages/jest-haste-map/src/index.js 92.8% <100%> (ø) ⬆️
packages/jest-haste-map/src/crawlers/watchman.js 90.74% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c8a5135...27c749b. Read the comment docs.

@cpojer cpojer merged commit fc48b91 into jestjs:master Jun 27, 2017
@iremlopsum
Copy link

@cpojer when can we see this released in a new npm version?

@patroza
Copy link
Contributor

patroza commented Jul 4, 2017

@jeanlauliac In my testing of the hack, I had to replace slashes in multiple places, not just the name variable.
In my case, I wasn't even getting to the name part of the code. My details are in facebook/watchman#479 (comment)

@jeanlauliac
Copy link
Contributor Author

jeanlauliac commented Jul 12, 2017

@patroza do you know which location needs additional transformation of the code? You referred some lines in the comment, but I'm not sure in which file it is. Would you be able to test with the new version of code from this PR, and if it misses some stuff, send a new PR? 😊 I have limited ability to reproduce unfortunately because I don't have a Windows machine to test with at the moment.

Thank you so much!

@patroza
Copy link
Contributor

patroza commented Jul 12, 2017

@jeanlauliac posted at #4018

@patroza patroza mentioned this pull request Jul 12, 2017
tushardhole pushed a commit to tushardhole/jest that referenced this pull request Aug 21, 2017
* jest-haste-map: watchman crawler: normalize paths

* also normalize path coming from watcher

* simplify, add module + tests

* add posix case
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants