diff --git a/react-packager/src/ModuleGraph/node-haste/node-haste.flow.js b/react-packager/src/ModuleGraph/node-haste/node-haste.flow.js index cae82416..9d0cf00b 100644 --- a/react-packager/src/ModuleGraph/node-haste/node-haste.flow.js +++ b/react-packager/src/ModuleGraph/node-haste/node-haste.flow.js @@ -9,6 +9,10 @@ * @flow */ +'use strict'; + +import DependencyGraphHelpers from '../../node-haste/DependencyGraph/DependencyGraphHelpers'; + type ModuleID = string; export type Path = string; type Platform = string; @@ -45,21 +49,10 @@ export type FastFS = { matches(directory: Path, pattern: RegExp): Array, }; -type HelpersOptions = {| - assetExts: Extensions, - providesModuleNodeModules: Array, -|}; - -declare class Helpers { - // node-haste/DependencyGraph/DependencyGraphHelpers.js - constructor(options: HelpersOptions): void, -} -export type HelpersT = Helpers; - type DeprecatedAssetMapOptions = {| assetExts: Extensions, files: Array, - helpers: Helpers, + helpers: DependencyGraphHelpers, platforms: Platforms, |}; @@ -74,7 +67,7 @@ type HasteMapOptions = {| fastfs: FastFS, moduleCache: ModuleCache, preferNativePlatform: true, - helpers: Helpers, + helpers: DependencyGraphHelpers, platforms: Platforms, |}; @@ -90,7 +83,7 @@ type ResolutionRequestOptions = {| preferNativePlatform: true, hasteMap: HasteMap, deprecatedAssetMap: DeprecatedAssetMap, - helpers: Helpers, + helpers: DependencyGraphHelpers, moduleCache: ModuleCache, fastfs: FastFS, shouldThrowOnUnresolvedErrors: () => true, diff --git a/react-packager/src/ModuleGraph/node-haste/node-haste.js b/react-packager/src/ModuleGraph/node-haste/node-haste.js index 6013e689..8a0ff3b9 100644 --- a/react-packager/src/ModuleGraph/node-haste/node-haste.js +++ b/react-packager/src/ModuleGraph/node-haste/node-haste.js @@ -15,7 +15,6 @@ import type { // eslint-disable-line sort-requires DeprecatedAssetMapT, Extensions, HasteMapT, - HelpersT, Path, ResolutionRequestT, } from './node-haste.flow'; @@ -25,7 +24,7 @@ import type { TransformedFile, } from '../types.flow'; -const DependencyGraphHelpers: Class = require('../../node-haste/DependencyGraph/DependencyGraphHelpers'); +const DependencyGraphHelpers = require('../../node-haste/DependencyGraph/DependencyGraphHelpers'); const DeprecatedAssetMap: Class = require('../../node-haste/DependencyGraph/DeprecatedAssetMap'); const FastFS = require('./FastFS'); const HasteMap: Class = require('../../node-haste/DependencyGraph/HasteMap'); diff --git a/react-packager/src/node-haste/DependencyGraph/DependencyGraphHelpers.js b/react-packager/src/node-haste/DependencyGraph/DependencyGraphHelpers.js index 6f5d9916..355c3ce8 100644 --- a/react-packager/src/node-haste/DependencyGraph/DependencyGraphHelpers.js +++ b/react-packager/src/node-haste/DependencyGraph/DependencyGraphHelpers.js @@ -5,7 +5,10 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. + * + * @flow */ + 'use strict'; const path = require('path'); @@ -13,12 +16,19 @@ const path = require('path'); const NODE_MODULES = path.sep + 'node_modules' + path.sep; class DependencyGraphHelpers { - constructor({ providesModuleNodeModules, assetExts }) { + + _providesModuleNodeModules: Array; + _assetExts: Array; + + constructor({ providesModuleNodeModules, assetExts }: { + providesModuleNodeModules: Array, + assetExts: Array, + }) { this._providesModuleNodeModules = providesModuleNodeModules; this._assetExts = assetExts; } - isNodeModulesDir(file) { + isNodeModulesDir(file: string) { const index = file.lastIndexOf(NODE_MODULES); if (index === -1) { return false; @@ -35,11 +45,11 @@ class DependencyGraphHelpers { return true; } - isAssetFile(file) { + isAssetFile(file: string) { return this._assetExts.indexOf(this.extname(file)) !== -1; } - extname(name) { + extname(name: string) { return path.extname(name).substr(1); } } diff --git a/react-packager/src/node-haste/Module.js b/react-packager/src/node-haste/Module.js index 3cea23d0..4b8072e7 100644 --- a/react-packager/src/node-haste/Module.js +++ b/react-packager/src/node-haste/Module.js @@ -23,6 +23,7 @@ const {join: joinPath, relative: relativePath, extname} = require('path'); import type {TransformedCode} from '../JSTransformer/worker/worker'; import type Cache from './Cache'; +import type DependencyGraphHelpers from './DependencyGraph/DependencyGraphHelpers'; import type ModuleCache from './ModuleCache'; import type FastFs from './fastfs'; @@ -44,8 +45,6 @@ export type Options = { cacheTransformResults?: boolean, }; -export type DepGraphHelpers = {isNodeModulesDir: (filePath: string) => boolean}; - export type ConstructorArgs = { file: string, fastfs: FastFs, @@ -53,7 +52,7 @@ export type ConstructorArgs = { cache: Cache, transformCode: ?TransformCode, transformCacheKey: ?string, - depGraphHelpers: DepGraphHelpers, + depGraphHelpers: DependencyGraphHelpers, options: Options, }; @@ -67,7 +66,7 @@ class Module { _cache: Cache; _transformCode: ?TransformCode; _transformCacheKey: ?string; - _depGraphHelpers: DepGraphHelpers; + _depGraphHelpers: DependencyGraphHelpers; _options: Options; _docBlock: Promise<{id?: string, moduleDocBlock: {[key: string]: mixed}}>; diff --git a/react-packager/src/node-haste/ModuleCache.js b/react-packager/src/node-haste/ModuleCache.js index a963c24a..b82c2ba4 100644 --- a/react-packager/src/node-haste/ModuleCache.js +++ b/react-packager/src/node-haste/ModuleCache.js @@ -17,8 +17,8 @@ const Package = require('./Package'); const Polyfill = require('./Polyfill'); import type Cache from './Cache'; +import type DependencyGraphHelpers from './DependencyGraph/DependencyGraphHelpers'; import type { - DepGraphHelpers, TransformCode, Options as ModuleOptions, } from './Module'; @@ -32,7 +32,7 @@ class ModuleCache { _cache: Cache; _transformCode: TransformCode; _transformCacheKey: string; - _depGraphHelpers: DepGraphHelpers; + _depGraphHelpers: DependencyGraphHelpers; _platforms: mixed; _assetDependencies: mixed; _moduleOptions: ModuleOptions; @@ -52,7 +52,7 @@ class ModuleCache { cache: Cache, transformCode: TransformCode, transformCacheKey: string, - depGraphHelpers: DepGraphHelpers, + depGraphHelpers: DependencyGraphHelpers, assetDependencies: mixed, moduleOptions: ModuleOptions, }, platforms: mixed) { diff --git a/react-packager/src/node-haste/index.js b/react-packager/src/node-haste/index.js index 1397723b..8fcdda7a 100644 --- a/react-packager/src/node-haste/index.js +++ b/react-packager/src/node-haste/index.js @@ -59,7 +59,7 @@ class DependencyGraph { forceNodeFilesystemAPI: boolean, assetRoots_DEPRECATED: Array, assetExts: Array, - providesModuleNodeModules: mixed, + providesModuleNodeModules: Array, platforms: Set, preferNativePlatform: boolean, extensions: Array, @@ -118,7 +118,7 @@ class DependencyGraph { forceNodeFilesystemAPI?: boolean, assetRoots_DEPRECATED: Array, assetExts: Array, - providesModuleNodeModules: mixed, + providesModuleNodeModules: Array, platforms: mixed, preferNativePlatform: boolean, cache: Cache,