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 {TransformCache} from '../lib/TransformCaching';
import type {Reporter} from '../lib/reporting';
import type {HasteImpl} from '../node-haste/Module';
import type {BabelSourceMap} from 'babel-core';
import type {
MetroSourceMapSegmentTuple,
@ -90,7 +89,7 @@ export type Options = {|
+getPolyfills: ({platform: ?string}) => $ReadOnlyArray<string>,
+getTransformOptions?: GetTransformOptions,
+globalTransformCache: ?GlobalTransformCache,
+hasteImpl?: HasteImpl,
+hasteImplModulePath?: string,
+maxWorkers: number,
+platforms: Array<string>,
+polyfillModuleNames: Array<string>,
@ -148,7 +147,7 @@ class Bundler {
transformModulePath: opts.transformModulePath,
}),
globalTransformCache: opts.globalTransformCache,
hasteImpl: opts.hasteImpl,
hasteImplModulePath: opts.hasteImplModulePath,
maxWorkers: opts.maxWorkers,
platforms: new Set(opts.platforms),
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 {TransformVariants} from './ModuleGraph/types.flow';
import type {DynamicRequiresBehavior} from './ModuleGraph/worker/collectDependencies';
import type {HasteImpl} from './node-haste/Module';
import type {IncomingMessage, ServerResponse} from 'http';
type Middleware = (IncomingMessage, ServerResponse, ?() => mixed) => mixed;
@ -139,11 +138,11 @@ export type ConfigT = {
postProcessModulesForBuck: PostProcessModulesForBuck,
/**
* A module that exports:
* Path to a require-able module that exports:
* - a `getHasteName(filePath)` method that returns `hasteName` for module at
* `filePath`, or undefined if `filePath` is not a haste module.
*/
hasteImpl?: HasteImpl,
hasteImplModulePath?: string,
transformVariants: () => TransformVariants,

View File

@ -41,7 +41,7 @@ import type {Ast} from 'babel-core';
export type TransformOptions<ExtraOptions> = {|
+asyncRequireModulePath: string,
filename: string,
hasteImpl?: HasteImpl,
hasteImplModulePath?: string,
polyfill?: boolean,
+sourceExts: Set<string>,
transformer: Transformer<ExtraOptions>,
@ -102,11 +102,16 @@ function transformModule(
let hasteID = null;
if (filename.indexOf(NODE_MODULES) === -1 && !polyfill) {
hasteID = docblock.parse(docblock.extract(sourceCode)).providesModule;
if (options.hasteImpl) {
if (options.hasteImpl.enforceHasteNameMatches) {
options.hasteImpl.enforceHasteNameMatches(filename, hasteID);
if (options.hasteImplModulePath != null) {
// eslint-disable-next-line no-useless-call
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');
import type {CustomError} from '../lib/formatBundlingError';
import type {HasteImpl} from '../node-haste/Module';
import type {IncomingMessage, ServerResponse} from 'http';
import type {Reporter} from '../lib/reporting';
import type {Options as DeltaBundlerOptions} from '../DeltaBundler/Serializers';
@ -76,7 +75,7 @@ class Server {
extraNodeModules: {},
getPolyfills: ({platform: ?string}) => $ReadOnlyArray<string>,
getTransformOptions?: GetTransformOptions,
hasteImpl?: HasteImpl,
hasteImplModulePath?: string,
maxWorkers: number,
moduleFormat: string,
platforms: Array<string>,
@ -132,7 +131,7 @@ class Server {
getPolyfills: options.getPolyfills,
getTransformOptions: options.getTransformOptions,
globalTransformCache: options.globalTransformCache,
hasteImpl: options.hasteImpl,
hasteImplModulePath: options.hasteImplModulePath,
maxWorkers,
moduleFormat:
options.moduleFormat != null ? options.moduleFormat : 'haste',

View File

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

View File

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

View File

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

View File

@ -64,7 +64,7 @@ export type HasteImpl = {
export type Options = {
globalTransformCache: ?GlobalTransformCache,
hasteImpl: ?HasteImpl,
hasteImplModulePath?: string,
reporter: Reporter,
resetCache: boolean,
transformCache: TransformCache,
@ -217,16 +217,17 @@ class Module {
* the "@providesModule" name (ex. "foo").
*/
_readHasteName(): ?string {
const hasteImpl = this._options.hasteImpl;
if (hasteImpl == null) {
const hasteImplModulePath = this._options.hasteImplModulePath;
if (hasteImplModulePath == null) {
return this._readHasteNameFromDocBlock();
}
const {enforceHasteNameMatches} = hasteImpl;
if (enforceHasteNameMatches != null) {
// eslint-disable-next-line no-useless-call
const HasteImpl = (require.call(null, hasteImplModulePath): HasteImpl);
if (HasteImpl.enforceHasteNameMatches != null) {
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';
import type {Reporter} from '../lib/reporting';
import type DependencyGraphHelpers from './DependencyGraph/DependencyGraphHelpers';
import type {TransformCode, HasteImpl} from './Module';
import type {TransformCode} from './Module';
type GetClosestPackageFn = (filePath: string) => ?string;
type Options = {|
assetDependencies: Array<string>,
depGraphHelpers: DependencyGraphHelpers,
hasteImpl: ?HasteImpl,
hasteImplModulePath?: string,
getClosestPackage: GetClosestPackageFn,
getTransformCacheKey: GetTransformCacheKey,
globalTransformCache: ?GlobalTransformCache,
@ -183,7 +183,7 @@ class ModuleCache {
transformCache: this._opts.transformCache,
globalTransformCache: this._opts.globalTransformCache,
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 {TransformCache} from '../lib/TransformCaching';
import type {Reporter} from '../lib/reporting';
import type {HasteImpl} from '../node-haste/Module';
import type {
MetroSourceMap,
MetroSourceMapSegmentTuple,
@ -82,7 +81,7 @@ export type Options = {|
getPolyfills: ({platform: ?string}) => $ReadOnlyArray<string>,
getTransformOptions?: GetTransformOptions,
globalTransformCache: ?GlobalTransformCache,
hasteImpl?: HasteImpl,
hasteImplModulePath?: string,
maxWorkers?: number,
moduleFormat?: string,
platforms?: Array<string>,