diff --git a/react-packager/src/DependencyResolver/DependencyGraph/__tests__/DependencyGraph-test.js b/react-packager/src/DependencyResolver/DependencyGraph/__tests__/DependencyGraph-test.js index dbe7dc3a..09861b52 100644 --- a/react-packager/src/DependencyResolver/DependencyGraph/__tests__/DependencyGraph-test.js +++ b/react-packager/src/DependencyResolver/DependencyGraph/__tests__/DependencyGraph-test.js @@ -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'; diff --git a/react-packager/src/DependencyResolver/DependencyGraph/index.js b/react-packager/src/DependencyResolver/DependencyGraph/index.js index 63ba7875..9390a10e 100644 --- a/react-packager/src/DependencyResolver/DependencyGraph/index.js +++ b/react-packager/src/DependencyResolver/DependencyGraph/index.js @@ -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; } }