Skip to content

Commit

Permalink
packager: DependencyGraphHelpers: @flow
Browse files Browse the repository at this point in the history
Reviewed By: cpojer

Differential Revision: D4190148

fbshipit-source-id: 320496bb683288a19605bd667de1472c7fc9c6b4
  • Loading branch information
Jean Lauliac authored and Facebook Github Bot committed Nov 17, 2016
1 parent 3267037 commit eb2cbea
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
* @flow
*/

'use strict';

import DependencyGraphHelpers from '../../node-haste/DependencyGraph/DependencyGraphHelpers';

type ModuleID = string;
export type Path = string;
type Platform = string;
Expand Down Expand Up @@ -45,21 +49,10 @@ export type FastFS = {
matches(directory: Path, pattern: RegExp): Array<Path>,
};

type HelpersOptions = {|
assetExts: Extensions,
providesModuleNodeModules: Array<string>,
|};

declare class Helpers {
// node-haste/DependencyGraph/DependencyGraphHelpers.js
constructor(options: HelpersOptions): void,
}
export type HelpersT = Helpers;

type DeprecatedAssetMapOptions = {|
assetExts: Extensions,
files: Array<Path>,
helpers: Helpers,
helpers: DependencyGraphHelpers,
platforms: Platforms,
|};

Expand All @@ -74,7 +67,7 @@ type HasteMapOptions = {|
fastfs: FastFS,
moduleCache: ModuleCache,
preferNativePlatform: true,
helpers: Helpers,
helpers: DependencyGraphHelpers,
platforms: Platforms,
|};

Expand All @@ -90,7 +83,7 @@ type ResolutionRequestOptions = {|
preferNativePlatform: true,
hasteMap: HasteMap,
deprecatedAssetMap: DeprecatedAssetMap,
helpers: Helpers,
helpers: DependencyGraphHelpers,
moduleCache: ModuleCache,
fastfs: FastFS,
shouldThrowOnUnresolvedErrors: () => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import type { // eslint-disable-line sort-requires
DeprecatedAssetMapT,
Extensions,
HasteMapT,
HelpersT,
Path,
ResolutionRequestT,
} from './node-haste.flow';
Expand All @@ -25,7 +24,7 @@ import type {
TransformedFile,
} from '../types.flow';

const DependencyGraphHelpers: Class<HelpersT> = require('../../node-haste/DependencyGraph/DependencyGraphHelpers');
const DependencyGraphHelpers = require('../../node-haste/DependencyGraph/DependencyGraphHelpers');
const DeprecatedAssetMap: Class<DeprecatedAssetMapT> = require('../../node-haste/DependencyGraph/DeprecatedAssetMap');
const FastFS = require('./FastFS');
const HasteMap: Class<HasteMapT> = require('../../node-haste/DependencyGraph/HasteMap');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,30 @@
* 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');

const NODE_MODULES = path.sep + 'node_modules' + path.sep;

class DependencyGraphHelpers {
constructor({ providesModuleNodeModules, assetExts }) {

_providesModuleNodeModules: Array<string>;
_assetExts: Array<string>;

constructor({ providesModuleNodeModules, assetExts }: {
providesModuleNodeModules: Array<string>,
assetExts: Array<string>,
}) {
this._providesModuleNodeModules = providesModuleNodeModules;
this._assetExts = assetExts;
}

isNodeModulesDir(file) {
isNodeModulesDir(file: string) {
const index = file.lastIndexOf(NODE_MODULES);
if (index === -1) {
return false;
Expand All @@ -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);
}
}
Expand Down
7 changes: 3 additions & 4 deletions packager/react-packager/src/node-haste/Module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -44,16 +45,14 @@ export type Options = {
cacheTransformResults?: boolean,
};

export type DepGraphHelpers = {isNodeModulesDir: (filePath: string) => boolean};

export type ConstructorArgs = {
file: string,
fastfs: FastFs,
moduleCache: ModuleCache,
cache: Cache,
transformCode: ?TransformCode,
transformCacheKey: ?string,
depGraphHelpers: DepGraphHelpers,
depGraphHelpers: DependencyGraphHelpers,
options: Options,
};

Expand All @@ -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}}>;
Expand Down
6 changes: 3 additions & 3 deletions packager/react-packager/src/node-haste/ModuleCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -32,7 +32,7 @@ class ModuleCache {
_cache: Cache;
_transformCode: TransformCode;
_transformCacheKey: string;
_depGraphHelpers: DepGraphHelpers;
_depGraphHelpers: DependencyGraphHelpers;
_platforms: mixed;
_assetDependencies: mixed;
_moduleOptions: ModuleOptions;
Expand All @@ -52,7 +52,7 @@ class ModuleCache {
cache: Cache,
transformCode: TransformCode,
transformCacheKey: string,
depGraphHelpers: DepGraphHelpers,
depGraphHelpers: DependencyGraphHelpers,
assetDependencies: mixed,
moduleOptions: ModuleOptions,
}, platforms: mixed) {
Expand Down
4 changes: 2 additions & 2 deletions packager/react-packager/src/node-haste/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class DependencyGraph {
forceNodeFilesystemAPI: boolean,
assetRoots_DEPRECATED: Array<string>,
assetExts: Array<string>,
providesModuleNodeModules: mixed,
providesModuleNodeModules: Array<string>,
platforms: Set<mixed>,
preferNativePlatform: boolean,
extensions: Array<string>,
Expand Down Expand Up @@ -118,7 +118,7 @@ class DependencyGraph {
forceNodeFilesystemAPI?: boolean,
assetRoots_DEPRECATED: Array<string>,
assetExts: Array<string>,
providesModuleNodeModules: mixed,
providesModuleNodeModules: Array<string>,
platforms: mixed,
preferNativePlatform: boolean,
cache: Cache,
Expand Down

0 comments on commit eb2cbea

Please sign in to comment.