Skip to content

Commit e06186f

Browse files
committed
sync with node-haste
1 parent 783b299 commit e06186f

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

packager/react-packager/src/DependencyResolver/DependencyGraph/DependencyGraphHelpers.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,40 @@ class DependencyGraphHelpers {
3131
* or examples).
3232
*/
3333
_resolveHastePackages(packages) {
34-
const _packagePathForPackage = ({ name, parent }, rootDir) => {
34+
const packagePathForPackage = ({ name, parent }, rootDir) => {
35+
let packagePath;
3536
if (parent) {
3637
if (!Array.isArray(parent)) {
3738
parent = [parent];
3839
}
3940
parent.push(name);
40-
return path.join(rootDir, 'node_modules', parent.join(`${path.sep}node_modules${path.sep}`)) + path.sep;
41+
packagePath = path.join(
42+
rootDir,
43+
'node_modules',
44+
parent.join(path.sep + 'node_modules' + path.sep)
45+
);
4146
} else {
42-
return path.join(rootDir, 'node_modules', name) + path.sep;
47+
packagePath = path.join(rootDir, 'node_modules', name);
48+
}
49+
50+
if (packagePath[packagePath.length - 1] === path.sep) {
51+
return packagePath.slice(0, -1);
52+
} else {
53+
return packagePath;
4354
}
4455
};
4556

4657
return packages.reduce((hastePackages, p) => {
4758
this._roots.forEach(rootDir => {
48-
const packagePath = _packagePathForPackage(p, rootDir);
59+
const packagePath = packagePathForPackage(p, rootDir);
4960
try {
5061
const stats = fs.statSync(packagePath);
5162
if (stats && stats.isDirectory()) {
5263
hastePackages.push(packagePath);
5364
}
5465
} catch (e) {
5566
// if we don't find the package, let's just default to node_modules/[package name]
56-
hastePackages.push(_packagePathForPackage({ name: p.name }, rootDir));
67+
hastePackages.push(packagePathForPackage({ name: p.name }, rootDir));
5768
}
5869
});
5970
return hastePackages;
@@ -75,16 +86,13 @@ class DependencyGraphHelpers {
7586
return false;
7687
}
7788

78-
const isHaste = this._providesModuleNodeModuleDirs.map(dir => {
79-
if (file.startsWith(dir) &&
80-
!file.startsWith(path.join(dir, 'node_modules'))
89+
for (let i = 0; i < this._providesModuleNodeModuleDirs.length; i++) {
90+
const dir = this._providesModuleNodeModuleDirs[i];
91+
if (file.startsWith(dir + path.sep) &&
92+
!file.startsWith(dir + path.sep + 'node_modules')
8193
) { // the file is contained in one of the haste packages
82-
return true;
94+
return false;
8395
}
84-
});
85-
86-
if (isHaste.indexOf(true) !== -1) {
87-
return false;
8896
}
8997

9098
return true;

packager/react-packager/src/__mocks__/fs.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,6 @@ function getToNode(filepath) {
216216
throw new Error('Make sure all paths are absolute.');
217217
}
218218
var node = filesystem;
219-
if (parts[parts.length - 1] === '') {
220-
delete parts[parts.length - 1];
221-
}
222219
parts.slice(1).forEach(function(part) {
223220
if (node && node.SYMLINK) {
224221
node = getToNode(node.SYMLINK);

0 commit comments

Comments
 (0)