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

Update node_modules_path to resolve symlinks to real paths #5085

Merged
merged 25 commits into from
Feb 23, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
178a2dd
Update node_modules_path to follow symlinks
nickpape-msft Dec 15, 2017
81499cb
Update whitespace to make prettier happy
nickpape-msft Dec 15, 2017
71c7fa3
Update CHANGELOG.md
nickpape-msft Dec 15, 2017
047ea85
Update CHANGELOG.md
nickpape-msft Dec 15, 2017
866dc5c
Update node_modules_paths.js
nickpape-msft Dec 15, 2017
1b1bf90
Code Review feedback
nickpape-msft Dec 15, 2017
a4622ec
Add missing dependency in jest-resolve
nick-pape Dec 15, 2017
f338a87
Fix import statement
nick-pape Dec 15, 2017
070ed48
Fix a lint warning
nick-pape Dec 15, 2017
0d14ebb
Fix lint issues caused by editor
nick-pape Dec 15, 2017
0d38947
Add test
nick-pape Dec 15, 2017
d903193
passing tests
nick-pape Dec 15, 2017
6378e09
Make lint happy
nick-pape Dec 15, 2017
67f0155
Make lint happy
nick-pape Dec 15, 2017
ad713d4
Make lint happy
nick-pape Dec 15, 2017
6473273
AppVeyor should keep symlinks
nickpape-msft Dec 15, 2017
f82fc37
Update appveyor.yml
nickpape-msft Dec 15, 2017
3db5514
Merge pull request #1 from facebook/master
nickpape-msft Dec 19, 2017
4cf6e5d
Merge branch 'master' into nickpape-msft-patch-1
nick-pape Dec 19, 2017
88776f9
Merge pull request #2 from facebook/master
nickpape-msft Feb 9, 2018
39f7f07
Fix imports
nick-pape Feb 9, 2018
2ec7a40
fixed the rel/abs path test suite that was failing with realpath
Feb 21, 2018
d45c6ff
Update CHANGELOG.md
SimenB Feb 23, 2018
1305408
Update package.json
SimenB Feb 23, 2018
47bd870
Merge branch 'master' into nickpape-msft-patch-1
SimenB Feb 23, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Fixes

* `[jest-resolve]` Update node module resolution algorithm to correctly handle symlinked paths ([#5085](https://github.com/facebook/jest/pull/5085))
* `[jest-worker]` Remove `debug` and `inspect` flags from the arguments sent to
the child ([#5068](https://github.com/facebook/jest/pull/5068))
* `[jest-config]` Use all `--testPathPattern` and `<regexForTestFiles>` args in
Expand Down
15 changes: 11 additions & 4 deletions packages/jest-resolve/src/node_modules_paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import type {Path} from 'types/Config';
import path from 'path';
import * as fs from 'fs';
Copy link
Member

Choose a reason for hiding this comment

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

why not import fs from 'fs'?

Copy link
Author

@nickpape nickpape Dec 15, 2017

Choose a reason for hiding this comment

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

Changed! I ended up not needing this as we used the utility function from jest-util


type NodeModulesPathsOptions = {|
moduleDirectory?: Array<string>,
Expand All @@ -37,11 +38,17 @@ export default function nodeModulesPaths(
prefix = '\\\\';
}

const paths = [basedirAbs];
let parsed = path.parse(basedirAbs);
// The node resolution algorithm (as implemented by NodeJS
// and TypeScript) traverses parents of the physical path,
// not the symlinked path
const physicalBasedir: string = fs.realpathSync(basedirAbs);
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

we've had issues with casing on windows using fs.realpathSync

Copy link
Author

Choose a reason for hiding this comment

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

Thanks


const paths = [physicalBasedir];
let parsed = path.parse(physicalBasedir);
while (parsed.dir !== paths[paths.length - 1]) {
paths.push(parsed.dir);
parsed = path.parse(parsed.dir);
const realParsedDir: string = fs.realpathSync(parsed.dir);
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you need the type annotation here.

Copy link
Author

Choose a reason for hiding this comment

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

Ah, yes, we require this in our repositories (even in some places where it is a bit redundant). I'll go ahead and remove it.

Copy link

@octogonz octogonz Dec 15, 2017

Choose a reason for hiding this comment

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

// obviously x is a number, so this annotation is redundant
const x = 123;
// Nobody has any clue what the type of x is without
// using an analysis tool like VS Code
const x = getThing(); 

paths.push(realParsedDir);
parsed = path.parse(realParsedDir);
}

const dirs = paths.reduce((dirs, aPath) => {
Expand Down