Pass hasteImplModulePath to JestHasteMap and everywhere else

Reviewed By: jeanlauliac

Differential Revision: D6641294

fbshipit-source-id: 36ebec95e69fe920c6cc10addd96406521cb4b82
This commit is contained in:
Bhuwan Khattar 2018-01-30 11:20:20 -08:00 committed by Facebook Github Bot
parent 448c85014c
commit 1ddb0227ff
10 changed files with 34 additions and 31 deletions

View File

@ -32,7 +32,6 @@ import type {DynamicRequiresBehavior} from '../ModuleGraph/worker/collectDepende
import type {GlobalTransformCache} from '../lib/GlobalTransformCache'; import type {GlobalTransformCache} from '../lib/GlobalTransformCache';
import type {TransformCache} from '../lib/TransformCaching'; import type {TransformCache} from '../lib/TransformCaching';
import type {Reporter} from '../lib/reporting'; import type {Reporter} from '../lib/reporting';
import type {HasteImpl} from '../node-haste/Module';
import type {BabelSourceMap} from 'babel-core'; import type {BabelSourceMap} from 'babel-core';
import type { import type {
MetroSourceMapSegmentTuple, MetroSourceMapSegmentTuple,
@ -90,7 +89,7 @@ export type Options = {|
+getPolyfills: ({platform: ?string}) => $ReadOnlyArray<string>, +getPolyfills: ({platform: ?string}) => $ReadOnlyArray<string>,
+getTransformOptions?: GetTransformOptions, +getTransformOptions?: GetTransformOptions,
+globalTransformCache: ?GlobalTransformCache, +globalTransformCache: ?GlobalTransformCache,
+hasteImpl?: HasteImpl, +hasteImplModulePath?: string,
+maxWorkers: number, +maxWorkers: number,
+platforms: Array<string>, +platforms: Array<string>,
+polyfillModuleNames: Array<string>, +polyfillModuleNames: Array<string>,
@ -148,7 +147,7 @@ class Bundler {
transformModulePath: opts.transformModulePath, transformModulePath: opts.transformModulePath,
}), }),
globalTransformCache: opts.globalTransformCache, globalTransformCache: opts.globalTransformCache,
hasteImpl: opts.hasteImpl, hasteImplModulePath: opts.hasteImplModulePath,
maxWorkers: opts.maxWorkers, maxWorkers: opts.maxWorkers,
platforms: new Set(opts.platforms), platforms: new Set(opts.platforms),
polyfillModuleNames: opts.polyfillModuleNames, polyfillModuleNames: opts.polyfillModuleNames,

View File

@ -25,7 +25,6 @@ import type {PostProcessModules} from './DeltaBundler';
import type {PostProcessModules as PostProcessModulesForBuck} from './ModuleGraph/types.flow.js'; import type {PostProcessModules as PostProcessModulesForBuck} from './ModuleGraph/types.flow.js';
import type {TransformVariants} from './ModuleGraph/types.flow'; import type {TransformVariants} from './ModuleGraph/types.flow';
import type {DynamicRequiresBehavior} from './ModuleGraph/worker/collectDependencies'; import type {DynamicRequiresBehavior} from './ModuleGraph/worker/collectDependencies';
import type {HasteImpl} from './node-haste/Module';
import type {IncomingMessage, ServerResponse} from 'http'; import type {IncomingMessage, ServerResponse} from 'http';
type Middleware = (IncomingMessage, ServerResponse, ?() => mixed) => mixed; type Middleware = (IncomingMessage, ServerResponse, ?() => mixed) => mixed;
@ -139,11 +138,11 @@ export type ConfigT = {
postProcessModulesForBuck: PostProcessModulesForBuck, postProcessModulesForBuck: PostProcessModulesForBuck,
/** /**
* A module that exports: * Path to a require-able module that exports:
* - a `getHasteName(filePath)` method that returns `hasteName` for module at * - a `getHasteName(filePath)` method that returns `hasteName` for module at
* `filePath`, or undefined if `filePath` is not a haste module. * `filePath`, or undefined if `filePath` is not a haste module.
*/ */
hasteImpl?: HasteImpl, hasteImplModulePath?: string,
transformVariants: () => TransformVariants, transformVariants: () => TransformVariants,

View File

@ -41,7 +41,7 @@ import type {Ast} from 'babel-core';
export type TransformOptions<ExtraOptions> = {| export type TransformOptions<ExtraOptions> = {|
+asyncRequireModulePath: string, +asyncRequireModulePath: string,
filename: string, filename: string,
hasteImpl?: HasteImpl, hasteImplModulePath?: string,
polyfill?: boolean, polyfill?: boolean,
+sourceExts: Set<string>, +sourceExts: Set<string>,
transformer: Transformer<ExtraOptions>, transformer: Transformer<ExtraOptions>,
@ -102,11 +102,16 @@ function transformModule(
let hasteID = null; let hasteID = null;
if (filename.indexOf(NODE_MODULES) === -1 && !polyfill) { if (filename.indexOf(NODE_MODULES) === -1 && !polyfill) {
hasteID = docblock.parse(docblock.extract(sourceCode)).providesModule; hasteID = docblock.parse(docblock.extract(sourceCode)).providesModule;
if (options.hasteImpl) { if (options.hasteImplModulePath != null) {
if (options.hasteImpl.enforceHasteNameMatches) { // eslint-disable-next-line no-useless-call
options.hasteImpl.enforceHasteNameMatches(filename, hasteID); const HasteImpl = (require.call(
null,
options.hasteImplModulePath,
): HasteImpl);
if (HasteImpl.enforceHasteNameMatches) {
HasteImpl.enforceHasteNameMatches(filename, hasteID);
} }
hasteID = options.hasteImpl.getHasteName(filename); hasteID = HasteImpl.getHasteName(filename);
} }
} }

View File

@ -30,7 +30,6 @@ const url = require('url');
const {getAsset} = require('../Assets'); const {getAsset} = require('../Assets');
import type {CustomError} from '../lib/formatBundlingError'; import type {CustomError} from '../lib/formatBundlingError';
import type {HasteImpl} from '../node-haste/Module';
import type {IncomingMessage, ServerResponse} from 'http'; import type {IncomingMessage, ServerResponse} from 'http';
import type {Reporter} from '../lib/reporting'; import type {Reporter} from '../lib/reporting';
import type {Options as DeltaBundlerOptions} from '../DeltaBundler/Serializers'; import type {Options as DeltaBundlerOptions} from '../DeltaBundler/Serializers';
@ -76,7 +75,7 @@ class Server {
extraNodeModules: {}, extraNodeModules: {},
getPolyfills: ({platform: ?string}) => $ReadOnlyArray<string>, getPolyfills: ({platform: ?string}) => $ReadOnlyArray<string>,
getTransformOptions?: GetTransformOptions, getTransformOptions?: GetTransformOptions,
hasteImpl?: HasteImpl, hasteImplModulePath?: string,
maxWorkers: number, maxWorkers: number,
moduleFormat: string, moduleFormat: string,
platforms: Array<string>, platforms: Array<string>,
@ -132,7 +131,7 @@ class Server {
getPolyfills: options.getPolyfills, getPolyfills: options.getPolyfills,
getTransformOptions: options.getTransformOptions, getTransformOptions: options.getTransformOptions,
globalTransformCache: options.globalTransformCache, globalTransformCache: options.globalTransformCache,
hasteImpl: options.hasteImpl, hasteImplModulePath: options.hasteImplModulePath,
maxWorkers, maxWorkers,
moduleFormat: moduleFormat:
options.moduleFormat != null ? options.moduleFormat : 'haste', options.moduleFormat != null ? options.moduleFormat : 'haste',

View File

@ -122,7 +122,7 @@ async function runMetro({
normalizedConfig.getModulesRunBeforeMainModule, normalizedConfig.getModulesRunBeforeMainModule,
getTransformOptions: normalizedConfig.getTransformOptions, getTransformOptions: normalizedConfig.getTransformOptions,
globalTransformCache: null, globalTransformCache: null,
hasteImpl: normalizedConfig.hasteImpl, hasteImplModulePath: normalizedConfig.hasteImplModulePath,
maxWorkers, maxWorkers,
platforms: defaults.platforms.concat(platforms), platforms: defaults.platforms.concat(platforms),
postMinifyProcess: normalizedConfig.postMinifyProcess, postMinifyProcess: normalizedConfig.postMinifyProcess,

View File

@ -179,7 +179,7 @@ function toServerOptions(options: Options): ServerOptions {
getPolyfills: options.getPolyfills, getPolyfills: options.getPolyfills,
getTransformOptions: options.getTransformOptions, getTransformOptions: options.getTransformOptions,
globalTransformCache: options.globalTransformCache, globalTransformCache: options.globalTransformCache,
hasteImpl: options.hasteImpl, hasteImplModulePath: options.hasteImplModulePath,
maxWorkers: options.maxWorkers, maxWorkers: options.maxWorkers,
moduleFormat: options.moduleFormat, moduleFormat: options.moduleFormat,
platforms: options.platforms, platforms: options.platforms,

View File

@ -40,7 +40,7 @@ import type {
} from '../lib/TransformCaching'; } from '../lib/TransformCaching';
import type {Reporter} from '../lib/reporting'; import type {Reporter} from '../lib/reporting';
import type {ModuleMap} from './DependencyGraph/ModuleResolution'; import type {ModuleMap} from './DependencyGraph/ModuleResolution';
import type {TransformCode, HasteImpl} from './Module'; import type {TransformCode} from './Module';
import type Package from './Package'; import type Package from './Package';
import type {HasteFS} from './types'; import type {HasteFS} from './types';
@ -52,7 +52,7 @@ type Options = {|
+getPolyfills: ({platform: ?string}) => $ReadOnlyArray<string>, +getPolyfills: ({platform: ?string}) => $ReadOnlyArray<string>,
+getTransformCacheKey: GetTransformCacheKey, +getTransformCacheKey: GetTransformCacheKey,
+globalTransformCache: ?GlobalTransformCache, +globalTransformCache: ?GlobalTransformCache,
+hasteImpl?: ?HasteImpl, +hasteImplModulePath?: string,
+maxWorkers: number, +maxWorkers: number,
+platforms: Set<string>, +platforms: Set<string>,
+polyfillModuleNames?: Array<string>, +polyfillModuleNames?: Array<string>,
@ -111,6 +111,7 @@ class DependencyGraph extends EventEmitter {
return new JestHasteMap({ return new JestHasteMap({
extensions: opts.sourceExts.concat(opts.assetExts), extensions: opts.sourceExts.concat(opts.assetExts),
forceNodeFilesystemAPI: !useWatchman, forceNodeFilesystemAPI: !useWatchman,
hasteImplModulePath: opts.hasteImplModulePath,
ignorePattern: opts.blacklistRE || / ^/, ignorePattern: opts.blacklistRE || / ^/,
maxWorkers: opts.maxWorkers, maxWorkers: opts.maxWorkers,
mocksPattern: '', mocksPattern: '',
@ -205,7 +206,7 @@ class DependencyGraph extends EventEmitter {
getClosestPackage: this._getClosestPackage.bind(this), getClosestPackage: this._getClosestPackage.bind(this),
getTransformCacheKey: _opts.getTransformCacheKey, getTransformCacheKey: _opts.getTransformCacheKey,
globalTransformCache: _opts.globalTransformCache, globalTransformCache: _opts.globalTransformCache,
hasteImpl: _opts.hasteImpl, hasteImplModulePath: _opts.hasteImplModulePath,
resetCache: _opts.resetCache, resetCache: _opts.resetCache,
transformCache: _opts.transformCache, transformCache: _opts.transformCache,
reporter: _opts.reporter, reporter: _opts.reporter,

View File

@ -64,7 +64,7 @@ export type HasteImpl = {
export type Options = { export type Options = {
globalTransformCache: ?GlobalTransformCache, globalTransformCache: ?GlobalTransformCache,
hasteImpl: ?HasteImpl, hasteImplModulePath?: string,
reporter: Reporter, reporter: Reporter,
resetCache: boolean, resetCache: boolean,
transformCache: TransformCache, transformCache: TransformCache,
@ -217,16 +217,17 @@ class Module {
* the "@providesModule" name (ex. "foo"). * the "@providesModule" name (ex. "foo").
*/ */
_readHasteName(): ?string { _readHasteName(): ?string {
const hasteImpl = this._options.hasteImpl; const hasteImplModulePath = this._options.hasteImplModulePath;
if (hasteImpl == null) { if (hasteImplModulePath == null) {
return this._readHasteNameFromDocBlock(); return this._readHasteNameFromDocBlock();
} }
const {enforceHasteNameMatches} = hasteImpl; // eslint-disable-next-line no-useless-call
if (enforceHasteNameMatches != null) { const HasteImpl = (require.call(null, hasteImplModulePath): HasteImpl);
if (HasteImpl.enforceHasteNameMatches != null) {
const name = this._readHasteNameFromDocBlock(); const name = this._readHasteNameFromDocBlock();
enforceHasteNameMatches(this.path, name || undefined); HasteImpl.enforceHasteNameMatches(this.path, name || undefined);
} }
return hasteImpl.getHasteName(this.path); return HasteImpl.getHasteName(this.path);
} }
/** /**

View File

@ -26,14 +26,14 @@ import type {
} from '../lib/TransformCaching'; } from '../lib/TransformCaching';
import type {Reporter} from '../lib/reporting'; import type {Reporter} from '../lib/reporting';
import type DependencyGraphHelpers from './DependencyGraph/DependencyGraphHelpers'; import type DependencyGraphHelpers from './DependencyGraph/DependencyGraphHelpers';
import type {TransformCode, HasteImpl} from './Module'; import type {TransformCode} from './Module';
type GetClosestPackageFn = (filePath: string) => ?string; type GetClosestPackageFn = (filePath: string) => ?string;
type Options = {| type Options = {|
assetDependencies: Array<string>, assetDependencies: Array<string>,
depGraphHelpers: DependencyGraphHelpers, depGraphHelpers: DependencyGraphHelpers,
hasteImpl: ?HasteImpl, hasteImplModulePath?: string,
getClosestPackage: GetClosestPackageFn, getClosestPackage: GetClosestPackageFn,
getTransformCacheKey: GetTransformCacheKey, getTransformCacheKey: GetTransformCacheKey,
globalTransformCache: ?GlobalTransformCache, globalTransformCache: ?GlobalTransformCache,
@ -183,7 +183,7 @@ class ModuleCache {
transformCache: this._opts.transformCache, transformCache: this._opts.transformCache,
globalTransformCache: this._opts.globalTransformCache, globalTransformCache: this._opts.globalTransformCache,
resetCache: this._opts.resetCache, resetCache: this._opts.resetCache,
hasteImpl: this._opts.hasteImpl, hasteImplModulePath: this._opts.hasteImplModulePath,
}; };
} }
} }

View File

@ -21,7 +21,6 @@ import type {DynamicRequiresBehavior} from '../ModuleGraph/worker/collectDepende
import type {GlobalTransformCache} from '../lib/GlobalTransformCache'; import type {GlobalTransformCache} from '../lib/GlobalTransformCache';
import type {TransformCache} from '../lib/TransformCaching'; import type {TransformCache} from '../lib/TransformCaching';
import type {Reporter} from '../lib/reporting'; import type {Reporter} from '../lib/reporting';
import type {HasteImpl} from '../node-haste/Module';
import type { import type {
MetroSourceMap, MetroSourceMap,
MetroSourceMapSegmentTuple, MetroSourceMapSegmentTuple,
@ -82,7 +81,7 @@ export type Options = {|
getPolyfills: ({platform: ?string}) => $ReadOnlyArray<string>, getPolyfills: ({platform: ?string}) => $ReadOnlyArray<string>,
getTransformOptions?: GetTransformOptions, getTransformOptions?: GetTransformOptions,
globalTransformCache: ?GlobalTransformCache, globalTransformCache: ?GlobalTransformCache,
hasteImpl?: HasteImpl, hasteImplModulePath?: string,
maxWorkers?: number, maxWorkers?: number,
moduleFormat?: string, moduleFormat?: string,
platforms?: Array<string>, platforms?: Array<string>,