88 */
99'use strict' ;
1010
11+ const H = require ( './constants' ) ;
12+
1113const crypto = require ( 'crypto' ) ;
1214const denodeify = require ( 'denodeify' ) ;
1315const execSync = require ( 'child_process' ) . execSync ;
@@ -20,7 +22,6 @@ const watchmanCrawl = require('./crawlers/watchman');
2022const worker = require ( './worker' ) ;
2123const workerFarm = require ( 'worker-farm' ) ;
2224
23- const GENERIC_PLATFORM = 'g' ;
2425const NODE_MODULES = path . sep + 'node_modules' + path . sep ;
2526const VERSION = require ( '../package.json' ) . version ;
2627
@@ -42,6 +43,7 @@ class HasteMap {
4243 maxWorkers : options . maxWorkers ,
4344 mocksPattern :
4445 options . mocksPattern ? new RegExp ( options . mocksPattern ) : null ,
46+ name : options . name ,
4547 platforms : options . platforms ,
4648 resetCache : options . resetCache ,
4749 roots : options . roots ,
@@ -57,6 +59,7 @@ class HasteMap {
5759 this . _cachePath = HasteMap . getCacheFilePath (
5860 this . _options . cacheDirectory ,
5961 VERSION ,
62+ this . _options . name ,
6063 this . _options . roots . join ( ':' ) ,
6164 this . _options . extensions . join ( ':' ) ,
6265 this . _options . platforms . join ( ':' ) ,
@@ -121,17 +124,19 @@ class HasteMap {
121124 const mocksPattern = this . _options . mocksPattern ;
122125 const promises = [ ] ;
123126 const setModule = module => {
124- if ( ! map [ module . id ] ) {
125- map [ module . id ] = Object . create ( null ) ;
127+ if ( ! map [ module [ H . ID ] ] ) {
128+ map [ module [ H . ID ] ] = Object . create ( null ) ;
126129 }
127- const moduleMap = map [ module . id ] ;
128- const platform = getPlatformExtension ( module . path ) || GENERIC_PLATFORM ;
130+ const moduleMap = map [ module [ H . ID ] ] ;
131+ const platform =
132+ getPlatformExtension ( module [ H . PATH ] ) || H . GENERIC_PLATFORM ;
129133 const existingModule = moduleMap [ platform ] ;
130- if ( existingModule && existingModule . path !== module . path ) {
134+ if ( existingModule && existingModule [ H . PATH ] !== module [ H . PATH ] ) {
131135 console . warn (
132136 `@providesModule naming collision:\n` +
133137 ` Duplicate module name: ${ module . id } \n` +
134- ` Paths: ${ module . path } collides with ${ existingModule . path } \n\n` +
138+ ` Paths: ${ module [ H . PATH ] } collides with ` +
139+ `${ existingModule [ H . PATH ] } \n\n` +
135140 `This warning is caused by a @providesModule declaration ` +
136141 `with the same name accross two different files.`
137142 ) ;
@@ -145,31 +150,29 @@ class HasteMap {
145150 mocks [ path . basename ( filePath , path . extname ( filePath ) ) ] = filePath ;
146151 }
147152
148- if ( ! this . _isNodeModulesDir ( filePath ) ) {
149- const fileData = data . files [ filePath ] ;
150- const moduleData = data . map [ fileData . id ] ;
151- if ( fileData . visited ) {
152- if ( ! fileData . id ) {
153- continue ;
154- } else if ( fileData . id && moduleData ) {
155- map [ fileData . id ] = moduleData ;
156- continue ;
157- }
153+ const fileData = data . files [ filePath ] ;
154+ const moduleData = data . map [ fileData [ H . ID ] ] ;
155+ if ( fileData [ H . VISITED ] ) {
156+ if ( ! fileData [ H . ID ] ) {
157+ continue ;
158+ } else if ( fileData [ H . ID ] && moduleData ) {
159+ map [ fileData [ H . ID ] ] = moduleData ;
160+ continue ;
158161 }
159-
160- promises . push (
161- this . _getWorker ( ) ( { filePath} ) . then ( data => {
162- fileData . visited = true ;
163- if ( data . module ) {
164- fileData . id = data . module . id ;
165- setModule ( data . module ) ;
166- }
167- if ( data . dependencies ) {
168- fileData . dependencies = data . dependencies ;
169- }
170- } )
171- ) ;
172162 }
163+
164+ promises . push (
165+ this . _getWorker ( ) ( { filePath} ) . then ( data => {
166+ fileData [ H . VISITED ] = 1 ;
167+ if ( data . module ) {
168+ fileData [ H . ID ] = data . module [ H . ID ] ;
169+ setModule ( data . module ) ;
170+ }
171+ if ( data . dependencies ) {
172+ fileData [ H . DEPENDENCIES ] = data [ H . DEPENDENCIES ] ;
173+ }
174+ } )
175+ ) ;
173176 }
174177
175178 return Promise . all ( promises )
@@ -228,11 +231,18 @@ class HasteMap {
228231 return crawl (
229232 this . _options . roots ,
230233 this . _options . extensions ,
231- this . _options . ignorePattern ,
234+ this . _ignore . bind ( this ) ,
232235 data
233236 ) ;
234237 }
235238
239+ _ignore ( filePath ) {
240+ return (
241+ this . _options . ignorePattern . test ( filePath ) ||
242+ this . _isNodeModulesDir ( filePath )
243+ ) ;
244+ }
245+
236246 _isNodeModulesDir ( filePath ) {
237247 if ( ! filePath . includes ( NODE_MODULES ) ) {
238248 return false ;
@@ -257,6 +267,4 @@ class HasteMap {
257267
258268}
259269
260- HasteMap . GENERIC_PLATFORM = GENERIC_PLATFORM ;
261-
262270module . exports = HasteMap ;
0 commit comments