More updates from Wed, 24 Jun

This commit is contained in:
Alex Kotliarskyi 2015-06-24 16:24:42 -07:00
commit 6b2f239406
2 changed files with 66 additions and 5 deletions

View File

@ -2171,6 +2171,65 @@ describe('DependencyGraph', function() {
});
});
pit('should not be confused by prev occuring whitelisted names', function() {
var root = '/react-tools';
fs.__setMockFilesystem({
'react-tools': {
'index.js': [
'/**',
' * @providesModule index',
' */',
'require("shouldWork");',
].join('\n'),
'node_modules': {
'react-tools': {
'package.json': JSON.stringify({
name: 'react-tools',
main: 'main.js',
}),
'main.js': [
'/**',
' * @providesModule shouldWork',
' */',
].join('\n'),
},
},
}
});
var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher,
assetExts: ['png', 'jpg'],
});
return dgraph.getOrderedDependencies('/react-tools/index.js').then(function(deps) {
expect(deps)
.toEqual([
{
id: 'index',
path: '/react-tools/index.js',
dependencies: ['shouldWork'],
isAsset: false,
isAsset_DEPRECATED: false,
isJSON: false,
isPolyfill: false,
resolution: undefined,
},
{
id: 'shouldWork',
path: '/react-tools/node_modules/react-tools/main.js',
dependencies: [],
isAsset: false,
isAsset_DEPRECATED: false,
isJSON: false,
isPolyfill: false,
resolution: undefined,
},
]);
});
});
pit('should ignore modules it cant find (assumes own require system)', function() {
// For example SourceMap.js implements it's own require system.
var root = '/root';

View File

@ -414,18 +414,20 @@ class DependencyGraph {
}
_isNodeModulesDir(file) {
const inNodeModules = file.indexOf('/node_modules/') !== -1;
let parts = path.normalize(file).split(path.sep);
const indexOfNodeModules = parts.lastIndexOf('node_modules');
if (!inNodeModules) {
if (indexOfNodeModules === -1) {
return false;
}
parts = parts.slice(indexOfNodeModules + 1);
const dirs = this._opts.providesModuleNodeModules;
for (let i = 0; i < dirs.length; i++) {
const index = file.indexOf(dirs[i]);
if (index !== -1) {
return file.slice(index).indexOf('/node_modules/') !== -1;
if (parts.indexOf(dirs[i]) > -1) {
return false;
}
}