diff --git a/react-packager/src/DependencyResolver/DependencyGraph/HasteMap.js b/react-packager/src/DependencyResolver/DependencyGraph/HasteMap.js index e1626fef..38d27e3e 100644 --- a/react-packager/src/DependencyResolver/DependencyGraph/HasteMap.js +++ b/react-packager/src/DependencyResolver/DependencyGraph/HasteMap.js @@ -7,7 +7,6 @@ * of patent rights can be found in the PATENTS file in the same directory. */ 'use strict'; - const path = require('path'); const getPlatformExtension = require('../lib/getPlatformExtension'); const Promise = require('promise'); @@ -118,11 +117,12 @@ class HasteMap { const moduleMap = this._map[name]; const modulePlatform = getPlatformExtension(mod.path) || GENERIC_PLATFORM; + const existingModule = moduleMap[modulePlatform]; - if (moduleMap[modulePlatform]) { + if (existingModule && existingModule.path !== mod.path) { throw new Error( `Naming collision detected: ${mod.path} ` + - `collides with ${moduleMap[modulePlatform].path}` + `collides with ${existingModule.path}` ); } diff --git a/react-packager/src/DependencyResolver/DependencyGraph/__tests__/DependencyGraph-test.js b/react-packager/src/DependencyResolver/DependencyGraph/__tests__/DependencyGraph-test.js index a89ce97a..d830cc82 100644 --- a/react-packager/src/DependencyResolver/DependencyGraph/__tests__/DependencyGraph-test.js +++ b/react-packager/src/DependencyResolver/DependencyGraph/__tests__/DependencyGraph-test.js @@ -3821,6 +3821,36 @@ describe('DependencyGraph', function() { }); }); }); + + pit('should not error when the watcher reports a known file as added', function() { + var root = '/root'; + fs.__setMockFilesystem({ + 'root': { + 'index.js': [ + '/**', + ' * @providesModule index', + ' */', + 'var b = require("b");', + ].join('\n'), + 'b.js': [ + '/**', + ' * @providesModule b', + ' */', + 'module.exports = function() {};', + ].join('\n'), + }, + }); + + var dgraph = new DependencyGraph({ + ...defaults, + roots: [root], + }); + + return getOrderedDependenciesAsJSON(dgraph, '/root/index.js').then(function() { + triggerFileChange('add', 'index.js', root, mockStat); + return getOrderedDependenciesAsJSON(dgraph, '/root/index.js'); + }); + }); }); describe('getAsyncDependencies', () => {